From b89ae07b3b04c613a4d213195e9978f0f4adc0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 15:25:43 +0100 Subject: [PATCH 001/567] What?! --- src/AbstractResourceLoader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h index 038054604..096d3d1fc 100644 --- a/src/AbstractResourceLoader.h +++ b/src/AbstractResourceLoader.h @@ -55,7 +55,7 @@ template class AbstractResourceLoader { * Count of resources requested by calling load(), but not found by * the loader. */ - inline std::size_t notFountCount() const { return _notFoundCount; } + inline std::size_t notFoundCount() const { return _notFoundCount; } /** * @brief Count of loaded resources From c3462ea2668a4f671d093c86b07f9db085adde02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 15:40:58 +0100 Subject: [PATCH 002/567] Doc++ --- doc/building.dox | 3 +- src/AbstractResourceLoader.h | 63 +++++++++++++++++++++++++++++++++--- src/Math/RectangularMatrix.h | 2 +- src/ResourceManager.h | 5 +-- src/Texture.h | 2 +- 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/doc/building.dox b/doc/building.dox index 8d122190c..9bf5dd1b1 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -161,7 +161,8 @@ Tested version is `pepper_22`. Make sure you have `toolchains` Git submodule updated, as @ref building-download "explained above". Don't forget to adapt `NACL_PREFIX variable in `generic/NaCl-glibc-x86-32.cmake` and `generic/NaCl-glibc-x86-64.cmake` -to path where your SDK is installed. Default is `/usr/nacl`. +to path where your SDK is installed. Default is `/usr/nacl`. You may need to +adapt also `NACL_TOOLCHAIN_PATH` so CMake is able to find the compiler. Then create build directories for x86-32 and x86-64 and run cmake and make in them. The toolchains needs access to its platform file, so be sure to properly diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h index 096d3d1fc..553529bf1 100644 --- a/src/AbstractResourceLoader.h +++ b/src/AbstractResourceLoader.h @@ -30,7 +30,59 @@ namespace Magnum { /** @brief Base for resource loaders -Provides asynchronous resource loading for ResourceManager. +Provides (a)synchronous resource loading for ResourceManager. + +@section AbstractResourceLoader-usage Usage and subclassing + +Usage is done by subclassing. Subclass instances can be added to +ResourceManager using ResourceManager::setLoader(). After adding the loader, +each call to ResourceManager::get() will call load() implementation unless the +resource is already loaded (or loading is in progress). Note that resources +requested before the loader was added are not be affected by the loader. + +Subclassing is done by implementing at least load() function. The loading can +be done synchronously or asynchronously (i.e., in another thread). The base +implementation provides interface to ResourceManager and manages loading +progress (which is then available through functions requestedCount(), +loadedCount() and notFoundCount()). You shouldn't access the ResourceManager +directly when loading the data. + +Your load() implementation must call the base implementation at the beginning +so ResourceManager is informed about loading state. Then, after your resources +are loaded, call set() to pass them to ResourceManager or call setNotFound() +to indicate that the resource was not found. + +You can also implement name() to provide meaningful names for resource keys. + +Example implementation for synchronous mesh loader: +@code +class MeshResourceLoader: public AbstractResourceLoader { + public: + void load(ResourceKey key) { + // Indicate that loading has begun + AbstractResourceLoader::load(key); + + // Load the mesh... + + // Not found + if(!found) { + setNotFound(key); + return; + } + + // Found, pass it to resource manager + set(key, mesh, state, policy); + } +}; +@endcode + +You can then add it to resource manager instance like this: +@code +MyResourceManager manager; +MeshResourceLoader loader; + +manager->setLoader(loader); +@endcode */ template class AbstractResourceLoader { friend class Implementation::ResourceManagerData; @@ -78,11 +130,12 @@ template class AbstractResourceLoader { * * If the resource isn't yet loaded or loading, state of the resource * is set to @ref Resource::ResourceState "ResourceState::Loading" and count of - * requested features is incremented. + * requested features is incremented. Depending on implementation the + * resource might be loaded synchronously or asynchronously. + * + * See class documentation for reimplementation guide. * - * The resource might be loaded asynchronously and added to - * ResourceManager when loading is done. - * @see ResourceManager::state(), requestedCount(), notFountCount(), + * @see ResourceManager::state(), requestedCount(), notFoundCount(), * loadedCount() */ virtual void load(ResourceKey key) = 0; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index e01321277..42e43559c 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -128,7 +128,7 @@ template class RectangularMatrix { */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr RectangularMatrix(T first, U... next): _data{first, next...} { - static_assert(sizeof...(next)+1 == cols*rows, "Improper number of arguments passed to Matrix constructor"); + static_assert(sizeof...(next)+1 == cols*rows, "Improper number of arguments passed to RectangularMatrix constructor"); } #else template inline constexpr RectangularMatrix(T first, U... next); diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 9546e3dc5..19bb8f1aa 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -325,6 +325,8 @@ cube->draw(); @endcode - Destroying resource references and deleting manager instance when nothing references the resources anymore. + +@see AbstractResourceLoader */ /* Due to too much work involved with explicit template instantiation (all Resource combinations, all ResourceManagerData...), this class doesn't have @@ -460,8 +462,7 @@ template class ResourceManager: private Implementation::Resource /** * @brief Set loader for given type of resources * - * The loader will affect only loading of resources requested after - * that. + * See AbstractResourceLoader documentation for more information. */ template inline void setLoader(AbstractResourceLoader* loader) { return this->Implementation::ResourceManagerData::setLoader(loader); diff --git a/src/Texture.h b/src/Texture.h index 91cca9459..9ca9d60b7 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -34,7 +34,7 @@ In shader, the texture is used via `sampler1D`, `sampler2D` or `sampler3D` depending on dimension count. Note that you can have more than one texture bound to the shader - the only requirement is to have each texture in another layer. -@section RectangleTextures Rectangle textures +@section Texture-rectangle Rectangle textures If you want to use rectangle textures, set target in constructor to `Target::Rectangle` and in shader use `sampler2DRect`. Unlike `sampler2D`, From 12817b505dd9f1b29a87df1857bfa935b2c6393e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 18:15:22 +0100 Subject: [PATCH 003/567] Test vector component accessors. Really. To be sure. Forever. --- src/Math/Test/Vector2Test.cpp | 11 +++++++++++ src/Math/Test/Vector2Test.h | 1 + src/Math/Test/Vector3Test.cpp | 13 +++++++++++++ src/Math/Test/Vector3Test.h | 1 + src/Math/Test/Vector4Test.cpp | 15 +++++++++++++++ src/Math/Test/Vector4Test.h | 1 + src/Test/ColorTest.cpp | 28 +++++++++++++++++++++++++++- src/Test/ColorTest.h | 2 ++ 8 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 297e0e67a..a5ec5b443 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -30,6 +30,7 @@ typedef Math::Vector2 Vector2; Vector2Test::Vector2Test() { addTests(&Vector2Test::construct, + &Vector2Test::access, &Vector2Test::axes, &Vector2Test::scales, &Vector2Test::debug, @@ -40,6 +41,16 @@ void Vector2Test::construct() { CORRADE_COMPARE(Vector2(1, 2), (Vector<2, float>(1.0f, 2.0f))); } +void Vector2Test::access() { + Vector2 vec(1.0f, -2.0f); + const Vector2 cvec(1.0f, -2.0f); + + CORRADE_COMPARE(vec.x(), 1.0f); + CORRADE_COMPARE(vec.y(), -2.0f); + CORRADE_COMPARE(cvec.x(), 1.0f); + CORRADE_COMPARE(cvec.y(), -2.0f); +} + void Vector2Test::axes() { CORRADE_COMPARE(Vector2::xAxis(5.0f), Vector2(5.0f, 0.0f)); CORRADE_COMPARE(Vector2::yAxis(6.0f), Vector2(0.0f, 6.0f)); diff --git a/src/Math/Test/Vector2Test.h b/src/Math/Test/Vector2Test.h index 48bcc1b9f..1e35c4704 100644 --- a/src/Math/Test/Vector2Test.h +++ b/src/Math/Test/Vector2Test.h @@ -24,6 +24,7 @@ class Vector2Test: public Corrade::TestSuite::Tester { Vector2Test(); void construct(); + void access(); void axes(); void scales(); diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 7ef022ff7..ea2f3409a 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -31,6 +31,7 @@ typedef Math::Vector2 Vector2; Vector3Test::Vector3Test() { addTests(&Vector3Test::construct, + &Vector3Test::access, &Vector3Test::cross, &Vector3Test::axes, &Vector3Test::scales, @@ -45,6 +46,18 @@ void Vector3Test::construct() { CORRADE_COMPARE(Vector3(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); } +void Vector3Test::access() { + Vector3 vec(1.0f, -2.0f, 5.0f); + const Vector3 cvec(1.0f, -2.0f, 5.0f); + + CORRADE_COMPARE(vec.x(), 1.0f); + CORRADE_COMPARE(vec.y(), -2.0f); + CORRADE_COMPARE(vec.z(), 5.0f); + CORRADE_COMPARE(cvec.x(), 1.0f); + CORRADE_COMPARE(cvec.y(), -2.0f); + CORRADE_COMPARE(cvec.z(), 5.0f); +} + void Vector3Test::cross() { Vector3 a(1, -1, 1); Vector3 b(4, 3, 7); diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h index 1542c6a06..706b3c68a 100644 --- a/src/Math/Test/Vector3Test.h +++ b/src/Math/Test/Vector3Test.h @@ -24,6 +24,7 @@ class Vector3Test: public Corrade::TestSuite::Tester { Vector3Test(); void construct(); + void access(); void cross(); void axes(); void scales(); diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index 33d52deb0..04f93d1e5 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -32,6 +32,7 @@ typedef Math::Vector2 Vector2; Vector4Test::Vector4Test() { addTests(&Vector4Test::construct, + &Vector4Test::access, &Vector4Test::threeComponent, &Vector4Test::twoComponent, &Vector4Test::debug, @@ -44,6 +45,20 @@ void Vector4Test::construct() { CORRADE_COMPARE(Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); } +void Vector4Test::access() { + Vector4 vec(1.0f, -2.0f, 5.0f, 0.5f); + const Vector4 cvec(1.0f, -2.0f, 5.0f, 0.5f); + + CORRADE_COMPARE(vec.x(), 1.0f); + CORRADE_COMPARE(vec.y(), -2.0f); + CORRADE_COMPARE(vec.z(), 5.0f); + CORRADE_COMPARE(vec.w(), 0.5f); + CORRADE_COMPARE(cvec.x(), 1.0f); + CORRADE_COMPARE(cvec.y(), -2.0f); + CORRADE_COMPARE(cvec.z(), 5.0f); + CORRADE_COMPARE(cvec.w(), 0.5f); +} + void Vector4Test::threeComponent() { CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xyz(), Vector3(1.0f, 2.0f, 3.0f)); } diff --git a/src/Math/Test/Vector4Test.h b/src/Math/Test/Vector4Test.h index e06ce248a..7e8cc5ae2 100644 --- a/src/Math/Test/Vector4Test.h +++ b/src/Math/Test/Vector4Test.h @@ -23,6 +23,7 @@ class Vector4Test: public Corrade::TestSuite::Tester { public: Vector4Test(); + void access(); void construct(); void threeComponent(); void twoComponent(); diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 176270f2b..903da1e3d 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -33,7 +33,9 @@ typedef Magnum::Color3 Color3f; typedef Magnum::Color4 Color4f; ColorTest::ColorTest() { - addTests(&ColorTest::fromDenormalized, + addTests(&ColorTest::access, + + &ColorTest::fromDenormalized, &ColorTest::fromNormalized, &ColorTest::fromHue, @@ -52,6 +54,30 @@ ColorTest::ColorTest() { &ColorTest::configuration); } +void ColorTest::access() { + Color3f c3(15, 255, 10); + const Color3f cc3(15, 255, 10); + + CORRADE_COMPARE(c3.r(), 15); + CORRADE_COMPARE(c3.g(), 255); + CORRADE_COMPARE(c3.b(), 10); + CORRADE_COMPARE(cc3.r(), 15); + CORRADE_COMPARE(cc3.g(), 255); + CORRADE_COMPARE(cc3.b(), 10); + + Color4 c4(125, 98, 51, 22); + const Color4f cc4(125, 98, 51, 22); + + CORRADE_COMPARE(c4.r(), 125); + CORRADE_COMPARE(c4.g(), 98); + CORRADE_COMPARE(c4.b(), 51); + CORRADE_COMPARE(c4.a(), 22); + CORRADE_COMPARE(cc4.r(), 125); + CORRADE_COMPARE(cc4.g(), 98); + CORRADE_COMPARE(cc4.b(), 51); + CORRADE_COMPARE(cc4.a(), 22); +} + void ColorTest::fromDenormalized() { CORRADE_COMPARE(Color3f::fromDenormalized(Color3(75, 115, 224)), Color3f(0.294118, 0.45098, 0.878431)); } diff --git a/src/Test/ColorTest.h b/src/Test/ColorTest.h index 47b18101d..172211f29 100644 --- a/src/Test/ColorTest.h +++ b/src/Test/ColorTest.h @@ -23,6 +23,8 @@ class ColorTest: public Corrade::TestSuite::Tester { public: ColorTest(); + void access(); + void fromDenormalized(); void fromNormalized(); From f27fe75e4ab9c887bccd60c9603cf39464b4269c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 18:22:39 +0100 Subject: [PATCH 004/567] New class Array, usable instead of Vector for non-numeric purposes. --- src/Array.h | 211 ++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/Magnum.h | 6 ++ src/Test/ArrayTest.cpp | 92 ++++++++++++++++++ src/Test/ArrayTest.h | 34 +++++++ src/Test/CMakeLists.txt | 1 + 6 files changed, 345 insertions(+) create mode 100644 src/Array.h create mode 100644 src/Test/ArrayTest.cpp create mode 100644 src/Test/ArrayTest.h diff --git a/src/Array.h b/src/Array.h new file mode 100644 index 000000000..fc940fc7e --- /dev/null +++ b/src/Array.h @@ -0,0 +1,211 @@ +#ifndef Magnum_Array_h +#define Magnum_Array_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Array, Magnum::Array1D, Magnum::Array2D, Magnum::Array3D + */ + +#include +#include +#include + +namespace Magnum { + +/** +@brief %Array +@tparam dimensions Dimension count +@tparam T Data type + +Similar to Math::Vector, but more suitable for storing enum values which don't +need any math operations and fuzzy comparison (e.g. enum values). Unlike +Math::Vector this class has non-explicit constructor from one value. +@see Array1D, Array2D, Array3D +*/ +template class Array { + public: + typedef T Type; /**< @brief Data type */ + const static std::uint8_t Dimensions = dimensions; /**< @brief Dimension count */ + + /** + * @brief Default constructor + * + * Sets all components to their default-constructed values + */ + inline constexpr Array(): _data() {} + + /** + * @brief Initializer-list constructor + * @param first First value + * @param next Next values + */ + #ifndef DOXYGEN_GENERATING_OUTPUT + template inline constexpr Array(T first, T second, U... next): _data{first, second, next...} { + static_assert(sizeof...(next)+2 == dimensions, "Improper number of arguments passed to Array constructor"); + } + template inline constexpr Array(typename std::enable_if::value && dimensions == 1, U>::type first): _data{first} {} + #else + template inline constexpr Array(T first, U... next); + #endif + + /** + * @brief Constructor + * @param value Value for all fields + */ + template::value && dimensions != 1, U>::type> inline Array(U value) { + for(std::uint8_t i = 0; i != dimensions; ++i) + _data[i] = value; + } + + /** @brief Equality */ + inline bool operator==(const Array& other) const { + for(std::uint8_t i = 0; i != dimensions; ++i) + if(_data[i] != other._data[i]) return false; + return true; + } + + /** @brief Non-equality */ + inline bool operator!=(const Array& other) const { + return !operator==(other); + } + + /** @brief Value at given position */ + inline T& operator[](std::uint8_t pos) { return _data[pos]; } + inline constexpr T operator[](std::uint8_t pos) const { return _data[pos]; } /**< @overload */ + + /** + * @brief Raw data + * @return One-dimensional array of `dimensions` length + */ + inline T* data() { return _data; } + inline constexpr const T* data() const { return _data; } /**< @overload */ + + private: + T _data[dimensions]; +}; + +/** +@brief One-dimensional array +@tparam T Data type +*/ +template class Array1D: public Array<1, T> { + public: + /** @copydoc Array::Array() */ + inline constexpr Array1D() = default; + + /** + * @brief Constructor + * @param x X component + */ + inline constexpr Array1D(T x): Array<1, T>(x) {} + + /** @brief Copy constructor */ + inline constexpr Array1D(const Array<1, T>& other): Array<1, T>(other) {} + + inline T& x() { return (*this)[0]; } /**< @brief X component */ + inline constexpr T x() const { return (*this)[0]; } /**< @overload */ +}; + +/** +@brief Two-dimensional array +@tparam T Data type +*/ +template class Array2D: public Array<2, T> { + public: + /** @copydoc Array::Array() */ + inline constexpr Array2D() = default; + + /** + * @brief Constructor + * @param x X component + * @param y Y component + */ + inline constexpr Array2D(T x, T y): Array<2, T>(x, y) {} + + /** @copydoc Array::Array(U) */ + inline constexpr Array2D(T value): Array<2, T>(value, value) {} + + /** @brief Copy constructor */ + inline constexpr Array2D(const Array<2, T>& other): Array<2, T>(other) {} + + inline T& x() { return (*this)[0]; } /**< @brief X component */ + inline constexpr T x() const { return (*this)[0]; } /**< @overload */ + inline T& y() { return (*this)[1]; } /**< @brief Y component */ + inline constexpr T y() const { return (*this)[1]; } /**< @overload */ +}; + +/** +@brief Three-dimensional array +@tparam T Data type +*/ +template class Array3D: public Array<3, T> { + public: + /** @copydoc Array::Array() */ + inline constexpr Array3D() {} + + /** + * @brief Constructor + * @param x X component + * @param y Y component + * @param z Z component + */ + inline constexpr Array3D(T x, T y, T z): Array<3, T>(x, y, z) {} + + /** @copydoc Array::Array(U) */ + inline constexpr Array3D(T value): Array<3, T>(value, value, value) {} + + /** @brief Copy constructor */ + inline constexpr Array3D(const Array<3, T>& other): Array<3, T>(other) {} + + inline T& x() { return (*this)[0]; } /**< @brief X component */ + inline constexpr T x() const { return (*this)[0]; } /**< @overload */ + inline T& y() { return (*this)[1]; } /**< @brief Y component */ + inline constexpr T y() const { return (*this)[1]; } /**< @overload */ + inline T& z() { return (*this)[2]; } /**< @brief Z component */ + inline constexpr T z() const { return (*this)[2]; } /**< @overload */ +}; + +/** @debugoperator{Magnum::Array} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array& value) { + debug << "Array("; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + for(std::uint8_t i = 0; i != dimensions; ++i) { + if(i != 0) debug << ", "; + debug << value[i]; + } + debug << ')'; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/** @debugoperator{Magnum::Array1D} */ +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array1D& value) { + return debug << static_cast&>(value); +} + +/** @debugoperator{Magnum::Array2D} */ +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array2D& value) { + return debug << static_cast&>(value); +} + +/** @debugoperator{Magnum::Array3D} */ +template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array3D& value) { + return debug << static_cast&>(value); +} + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e9051cd8..a9d4b9d59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ set(Magnum_HEADERS AbstractResourceLoader.h AbstractShaderProgram.h AbstractTexture.h + Array.h Buffer.h Color.h Context.h diff --git a/src/Magnum.h b/src/Magnum.h index 6635feb97..3e5da96e6 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -107,6 +107,12 @@ using Math::rad; class AbstractImage; class AbstractShaderProgram; class AbstractTexture; + +template class Array; +template class Array1D; +template class Array2D; +template class Array3D; + class Buffer; #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/Test/ArrayTest.cpp b/src/Test/ArrayTest.cpp new file mode 100644 index 000000000..928ecc274 --- /dev/null +++ b/src/Test/ArrayTest.cpp @@ -0,0 +1,92 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ArrayTest.h" + +#include "Array.h" + +CORRADE_TEST_MAIN(Magnum::Test::ArrayTest) + +namespace Magnum { namespace Test { + +typedef Magnum::Array1D Array1D; +typedef Magnum::Array2D Array2D; +typedef Magnum::Array3D Array3D; + +ArrayTest::ArrayTest() { + addTests(&ArrayTest::construct, + &ArrayTest::constexprConstruct, + &ArrayTest::equality, + &ArrayTest::access); +} + +void ArrayTest::construct() { + CORRADE_COMPARE(Array1D(5), (Array<1, int>(5))); + CORRADE_COMPARE(Array2D(5, 3), (Array<2, int>(5, 3))); + CORRADE_COMPARE(Array3D(5, 3, -2), (Array<3, int>(5, 3, -2))); + + /* Verify proper expansion */ + CORRADE_COMPARE((Array<3, int>(5)), (Array<3, int>(5, 5, 5))); + CORRADE_COMPARE(Array2D(5), (Array<2, int>(5, 5))); + CORRADE_COMPARE(Array3D(5), (Array<3, int>(5, 5, 5))); +} + +void ArrayTest::constexprConstruct() { + /* Verify that all full constructors can be called as constexpr */ + constexpr Array1D a(5); + constexpr Array2D b(5, 3); + constexpr Array2D b2(5); + constexpr Array3D c(5, 6, 7); + constexpr Array3D c2(5); + constexpr Array<3, int> d(5, 6, 7); + + CORRADE_COMPARE(a, Array1D(5)); + CORRADE_COMPARE(b, Array2D(5, 3)); + CORRADE_COMPARE(b2, Array2D(5)); + CORRADE_COMPARE(c, Array3D(5, 6, 7)); + CORRADE_COMPARE(c2, Array3D(5)); + CORRADE_COMPARE(d, (Array<3, int>(5, 6, 7))); +} + +void ArrayTest::equality() { + CORRADE_VERIFY((Array<3, int>(5, 6, 7) == Array<3, int>(5, 6, 7))); + CORRADE_VERIFY((Array<3, int>(5, 6, 7) != Array<3, int>(5, 6, 8))); +} + +void ArrayTest::access() { + Array1D a(50); + const Array1D ac(50); + Array2D b(5, 3); + const Array2D bc(5, 3); + Array3D c(-5, 6, 7); + const Array3D cc(-5, 6, 7); + + CORRADE_COMPARE(a.x(), 50); + CORRADE_COMPARE(ac.x(), 50); + + CORRADE_COMPARE(b.x(), 5); + CORRADE_COMPARE(b.y(), 3); + CORRADE_COMPARE(bc.x(), 5); + CORRADE_COMPARE(bc.y(), 3); + + CORRADE_COMPARE(c.x(), -5); + CORRADE_COMPARE(c.y(), 6); + CORRADE_COMPARE(c.z(), 7); + CORRADE_COMPARE(cc.x(), -5); + CORRADE_COMPARE(cc.y(), 6); + CORRADE_COMPARE(cc.z(), 7); +} + +}} diff --git a/src/Test/ArrayTest.h b/src/Test/ArrayTest.h new file mode 100644 index 000000000..f90059f40 --- /dev/null +++ b/src/Test/ArrayTest.h @@ -0,0 +1,34 @@ +#ifndef Magnum_Test_ArrayTest_h +#define Magnum_Test_ArrayTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Test { + +class ArrayTest: public Corrade::TestSuite::Tester { + public: + ArrayTest(); + + void construct(); + void constexprConstruct(); + void equality(); + void access(); +}; + +}} + +#endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 2e6f58e3e..68ebd975e 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,3 +1,4 @@ +corrade_add_test2(ArrayTest ArrayTest.cpp) corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test2(MeshTest MeshTest.cpp LIBRARIES Magnum) corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) From 06e526d7a1bd031b22c4e78e374a17d246672030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 18:24:31 +0100 Subject: [PATCH 005/567] Using Array instead of Vector for *Texture::setWrapping(). Allows simple and convenient call with one value for all axes instead of that unholy mess: texture.setWrapping(Texture2D::Wrapping::ClampToEdge); Previous way (for entertainment purposes): textute.setWrapping(Math::Vector2( Texture2D::Wrapping::ClampToEdge)); --- src/AbstractTexture.cpp | 6 +++--- src/AbstractTexture.h | 10 +++++----- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/Texture.h | 4 +--- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 41fb407e6..e5ef0c416 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -378,16 +378,16 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp #endif #ifndef DOXYGEN_GENERATING_OUTPUT -void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Math::Vector2& wrapping) { +void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D& wrapping) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); + CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping.x() == Wrapping::ClampToEdge || wrapping.x() == Wrapping::ClampToBorder) && (wrapping.y() == Wrapping::ClampToEdge || wrapping.y() == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); #endif (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_T, static_cast(wrapping.y())); } -void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Math::Vector3& wrapping) { +void AbstractTexture::DataHelper<3>::setWrapping(AbstractTexture* texture, const Array3D& wrapping) { (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_T, static_cast(wrapping.y())); #ifndef MAGNUM_TARGET_GLES diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 038e4ad5d..12b5a162b 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -19,7 +19,7 @@ * @brief Class Magnum::AbstractTexture */ -#include "Magnum.h" +#include "Array.h" #include "Color.h" #include "AbstractImage.h" @@ -836,8 +836,8 @@ template<> struct AbstractTexture::DataHelper<1> { inline constexpr static Target target() { return Target::Texture1D; } - inline static void setWrapping(AbstractTexture* texture, const Math::Vector<1, Wrapping>& wrapping) { - (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping[0])); + inline static void setWrapping(AbstractTexture* texture, const Array1D& wrapping) { + (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); } template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { @@ -861,7 +861,7 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { inline constexpr static Target target() { return Target::Texture2D; } - static void setWrapping(AbstractTexture* texture, const Math::Vector2& wrapping); + static void setWrapping(AbstractTexture* texture, const Array2D& wrapping); template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { (texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); @@ -887,7 +887,7 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { inline constexpr static Target target() { return Target::Texture3D; } - static void setWrapping(AbstractTexture* texture, const Math::Vector3& wrapping); + static void setWrapping(AbstractTexture* texture, const Array3D& wrapping); template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { (texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 5141f0a24..9c734d80e 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -85,7 +85,7 @@ class CubeMapTexture: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline CubeMapTexture* setWrapping(const Math::Vector<3, Wrapping>& wrapping) { + inline CubeMapTexture* setWrapping(const Array3D& wrapping) { DataHelper<3>::setWrapping(this, wrapping); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index fdf55ca79..2d928edc6 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -63,7 +63,7 @@ class CubeMapTextureArray: public AbstractTexture { /** * @copydoc Texture::setWrapping() */ - inline CubeMapTextureArray* setWrapping(const Math::Vector3& wrapping) { + inline CubeMapTextureArray* setWrapping(const Array3D& wrapping) { DataHelper<3>::setWrapping(this, wrapping); return this; } diff --git a/src/Texture.h b/src/Texture.h index 9ca9d60b7..1191b8bc7 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -132,10 +132,8 @@ template class Texture: public AbstractTexture { * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_WRAP_S}, @def_gl{TEXTURE_WRAP_T}, * @def_gl{TEXTURE_WRAP_R} - * @todo Use something better for this than Vector (mainly something - * that can easily create all values the same) */ - inline Texture* setWrapping(const Math::Vector& wrapping) { + inline Texture* setWrapping(const Array& wrapping) { DataHelper::setWrapping(this, wrapping); return this; } From 44a10e0e9d47e49df181c8ecc7b00c128fa0d21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 19:52:42 +0100 Subject: [PATCH 006/567] Documentation and example usage of textures. Mentions some not-yet-done features such as Vector2i or proper texture formats. --- src/AbstractTexture.h | 19 ++++------- src/CubeMapTexture.h | 35 ++++++++++++++------ src/CubeMapTextureArray.h | 39 ++++++++++++++++++++--- src/Texture.h | 67 +++++++++++++++++++++++++++++++++++---- 4 files changed, 127 insertions(+), 33 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 12b5a162b..933e4ec90 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -28,22 +28,11 @@ namespace Magnum { /** @brief Base for textures -@attention Don't forget to call @ref Texture::setWrapping() "setWrapping()", - setMinificationFilter() and setMagnificationFilter() after creating the - texture, otherwise the texture will be incomplete. If you specified - @ref Wrapping "Wrapping::ClampToBorder" in @ref Texture::setWrapping() "setWrapping()", - be sure to also call setBorderColor(). If you specified mipmap filtering - in setMinificationFilter(), be sure to also either explicitly set all mip - levels or call generateMipmap(). - -The texture is bound to shader via bind(). Texture uniform on the shader must -also be set to particular texture layer using -AbstractShaderProgram::setUniform(GLint, GLint). - See Texture, CubeMapTexture and CubeMapTextureArray documentation for more -information. +information and usage examples. @section AbstractTexture-performance-optimization Performance optimizations + The engine tracks currently bound textures in all available layers to avoid unnecessary calls to @fn_gl{ActiveTexture} and @fn_gl{BindTexture}. %Texture configuration functions use dedicated highest available texture layer to not @@ -639,6 +628,8 @@ class MAGNUM_EXPORT AbstractTexture { * Sets filter used when the object pixel size is smaller than the * texture size. If @extension{EXT,direct_state_access} is not * available, the texture is bound to some layer before the operation. + * Initial value is (@ref AbstractTexture::Filter "Filter::NearestNeighbor", + * @ref AbstractTexture::Mipmap "Mipmap::Linear"). * @attention For rectangle textures only some modes are supported, * see @ref AbstractTexture::Filter "Filter" and * @ref AbstractTexture::Mipmap "Mipmap" documentation for more @@ -657,6 +648,7 @@ class MAGNUM_EXPORT AbstractTexture { * Sets filter used when the object pixel size is larger than largest * texture size. If @extension{EXT,direct_state_access} is not * available, the texture is bound to some layer before the operation. + * Initial value is @ref AbstractTexture::Filter "Filter::Linear". * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_MAG_FILTER} @@ -674,6 +666,7 @@ class MAGNUM_EXPORT AbstractTexture { * Border color when @ref AbstractTexture::Wrapping "wrapping" is set * to `ClampToBorder`. If @extension{EXT,direct_state_access} is not * available, the texture is bound to some layer before the operation. + * Initial value is `{0.0f, 0.0f, 0.0f, 0.0f}`. * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexParameter} * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_BORDER_COLOR} diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 9c734d80e..7da8f60a4 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -26,10 +26,9 @@ namespace Magnum { /** @brief Cube map texture -%Texture used mainly for environemnt maps. See AbstractTexture documentation -for more information. It consists of 6 square textures generating 6 faces of -the cube as following. Note that all images must be turned upside down (+Y is -top): +%Texture used mainly for environment maps. It consists of 6 square textures +generating 6 faces of the cube as following. Note that all images must be +turned upside down (+Y is top): +----+ | -Y | @@ -39,11 +38,29 @@ top): | +Y | +----+ -When using cube map texture in the shader, use `samplerCube`. Unlike classic -textures, coordinates for cube map textures is signed three-part vector from -the center of the cube, which intersects one of the six sides of the cube map. - -See AbstractTexture documentation for more information about usage. +@section CubeMapTexture-usage Basic usage + +See Texture documentation for introduction. + +Common usage is to fully configure all texture parameters and then set the +data from e.g. set of Image objects: +@code +Image2D positiveX({256, 256}, Image2D::Components::RGBA, Image2D::ComponentType::UnsignedByte, dataPositiveX); +// ... + +CubeMapTexture texture; +texture.setMagnificationFilter(Texture2D::Filter::Linear) + // ... + ->setData(CubeMapTexture::Coordinate::PositiveX, 0, Texture2D::Format::RGBA8, &positiveX) + ->setData(CubeMapTexture::Coordinate::NegativeX, 0, Texture2D::Format::RGBA8, &negativeX) + // ... +@endcode + +The texture is bound to layer specified by shader via bind(). In shader, the +texture is used via `samplerCube`. Unlike classic textures, coordinates for +cube map textures is signed three-part vector from the center of the cube, +which intersects one of the six sides of the cube map. See also +AbstractShaderProgram for more information. @see CubeMapTextureArray */ diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 2d928edc6..cc558a5ee 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -29,12 +29,41 @@ namespace Magnum { /** @brief Cube map texture array -For information, see CubeMapTexture and AbstractTexture documentation. +See CubeMapTexture documentation for introduction. + +@section CubeMapTextureArray-usage Usage + +Common usage is to specify each layer and face separately using setSubData(). +You have to allocate the memory for all layers and faces first, possibly by +passing properly sized empty Image to setData(). Example: array with 16 +layers of cube map faces, each face consisting of six 64x64 images: +@code +Image3D dummy({64, 64, 16*6}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, nullptr); + +CubeMapTextureArray texture; +texture.setMagnificationFilter(CubeMapTextureArray::Filter::Linear) + // ... + ->setData(0, CubeMapTextureArray::Format::RGBA8, &dummy); + +for(std::size_t i = 0; i != 16; ++i) { + void* dataPositiveX = ...; + Image2D imagePositiveX({64, 64}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, imagePositiveX); + // ... + + texture->setSubData(i, CubeMapTextureArray::Coordinate::PositiveX, 0, imagePositiveX); + texture->setSubData(i, CubeMapTextureArray::Coordinate::NegativeX, 0, imageNegativeX); + // ... +} + +// ... +@endcode -When using cube map texture in the shader, use `samplerCubeArray`. Unlike -classic textures, coordinates for cube map textures is signed three-part -vector from the center of the cube, which intersects one of the six sides of -the cube map. +The texture is bound to layer specified by shader via bind(). In shader, the +texture is used via `samplerCubeArray`. Unlike classic textures, coordinates +for cube map texture arrays is signed four-part vector. First three parts +define vector from the center of the cube which intersects with one of the six +sides of the cube map, fourth part is layer in the array. See also +AbstractShaderProgram for more information. @see CubeMapTexture::setSeamless() @requires_gl40 Extension @extension{ARB,texture_cube_map_array} diff --git a/src/Texture.h b/src/Texture.h index 1191b8bc7..9d2c45e06 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -27,12 +27,66 @@ namespace Magnum { /** @brief %Texture -Template class for one- to three-dimensional textures. See AbstractTexture -documentation for more information. +Template class for one- to three-dimensional textures. See also +AbstractTexture documentation for more information. + +@section Texture-usage Usage + +Common usage is to fully configure all texture parameters and then set the +data from e.g. Image. Example configuration of high quality texture with +trilinear anisotropic filtering, i.e. the best you can ask for: +@code +void* data; +Image2D image({4096, 4096}, Image2D::Components::RGBA, Image2D::ComponentType::UnsignedByte, data); + +Texture2D texture; +texture.setMagnificationFilter(Texture2D::Filter::Linear) + ->setMinificationFilter(Texture2D::Filter::Linear, Texture2D::Mipmap::Linear) + ->setWrapping(Texture2D::Wrapping::ClampToEdge) + ->setMaxAnisotropy(Texture2D::maxSupportedAnisotropy) + ->setData(0, Texture2D::Format::RGBA8, &image) + ->generateMipmap(); +@endcode + +@attention Don't forget to fully configure the texture before use. Note that + default configuration (if setMinificationFilter() is not called with + another value) is to use mipmaps, so be sure to either call setMinificationFilter(), + explicitly set all mip levels or call generateMipmap(). If using rectangle + texture, you must also call setWrapping(), because the initial value is + not supported on rectangle textures. See also setMagnificationFilter() and + setBorderColor(). + +The texture is bound to layer specified by shader via bind(). In shader, the +texture is used via `sampler1D`, `sampler2D` or `sampler3D` depending on +dimension count. See also AbstractShaderProgram documentation for more +information. + +@section Texture-array Texture arrays + +It is possible to specify each layer separately using setSubData(), but you +have to allocate the memory for all layers first, possibly by passing properly +sized empty Image to setData(). Example: 2D texture array with 16 layers of +64x64 images: +@code +Image3D dummy({64, 64, 16}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, nullptr); + +Texture3D texture(Texture3D::Target::Texture2DArray); +texture.setMagnificationFilter(Texture2D::Filter::Linear) + // ... + ->setData(0, Texture2D::Format::RGBA8, &dummy); + +for(std::size_t i = 0; i != 16; ++i) { + void* data = ...; + Image2D image({64, 64}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, image); + texture->setSubData(0, Vector3i::zAxis(i), image); +} + +// ... +@endcode -In shader, the texture is used via `sampler1D`, `sampler2D` or `sampler3D` -depending on dimension count. Note that you can have more than one texture bound -to the shader - the only requirement is to have each texture in another layer. +Similar approach can be used for any other texture types (e.g. setting +Texture3D data using 2D layers, Texture2D data using one-dimensional chunks +etc.). @section Texture-rectangle Rectangle textures @@ -124,7 +178,8 @@ template class Texture: public AbstractTexture { * Sets wrapping type for coordinates out of range (0, 1) for normal * textures and (0, textureSizeInGivenDirection-1) for rectangle * textures. If @extension{EXT,direct_state_access} is not available, - * the texture is bound to some layer before the operation. + * the texture is bound to some layer before the operation. Initial + * value is @ref AbstractTexture::Wrapping "Wrapping::Repeat". * @attention For rectangle textures only some modes are supported, * see @ref AbstractTexture::Wrapping "Wrapping" documentation * for more information. From 3dafbb6ed95371d39637dd693ef02f7249ad9d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 20:00:37 +0100 Subject: [PATCH 007/567] Assert that GLsizei is signed integer. --- src/TypeTraits.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp index 2d598de4a..8e19a76c5 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -29,6 +29,7 @@ static_assert(is_same::value, "GLushort is not the same as u static_assert(is_same::value, "GLshort is not the same as int16_t"); static_assert(is_same::value, "GLuint is not the same as uint32_t"); static_assert(is_same::value, "GLint is not the same as int32_t"); +static_assert(is_same::value, "GLsizei is not the same as int32_t"); static_assert(is_same::value, "GLfloat is not the same as float"); #ifndef MAGNUM_TARGET_GLES static_assert(is_same::value, "GLdouble is not the same as double"); From 34a8ad47241d40cba41761b3eb40788dde0476a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 21:06:50 +0100 Subject: [PATCH 008/567] Aliases for integer and unsigned integer vector types. --- src/Magnum.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Magnum.h b/src/Magnum.h index 3e5da96e6..bc0b133f3 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -83,6 +83,24 @@ typedef Math::Vector3 Vector3; /** @brief Four-component floating-point vector */ typedef Math::Vector4 Vector4; +/** @brief Two-component signed integer vector */ +typedef Math::Vector2 Vector2i; + +/** @brief Three-component signed integer vector */ +typedef Math::Vector3 Vector3i; + +/** @brief Four-component signed integer vector */ +typedef Math::Vector4 Vector4i; + +/** @brief Two-component unsigned integer vector */ +typedef Math::Vector2 Vector2ui; + +/** @brief Three-component unsigned integer vector */ +typedef Math::Vector3 Vector3ui; + +/** @brief Four-component unsigned integer vector */ +typedef Math::Vector4 Vector4ui; + /** @brief Two-dimensional floating-point homogeneous coordinates */ typedef Math::Point2D Point2D; From 43f6dbc72d461fa3b25d2eebd7a47284bc1c433e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 30 Nov 2012 21:08:55 +0100 Subject: [PATCH 009/567] Using integer vector aliases all over the place. --- doc/portability.dox | 4 +-- src/AbstractShaderProgram.h | 17 ++++++------ src/AbstractTexture.cpp | 16 +++++------ src/AbstractTexture.h | 36 ++++++++++++------------- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 8 +++--- src/Framebuffer.cpp | 4 +-- src/Framebuffer.h | 12 ++++----- src/Platform/AbstractXApplication.cpp | 4 +-- src/Platform/AbstractXApplication.h | 26 +++++++++--------- src/Platform/GlutApplication.cpp | 2 +- src/Platform/GlutApplication.h | 22 ++++++++-------- src/Platform/GlxApplication.h | 2 +- src/Platform/NaClApplication.cpp | 4 +-- src/Platform/NaClApplication.h | 20 +++++++------- src/Platform/Sdl2Application.cpp | 2 +- src/Platform/Sdl2Application.h | 18 ++++++------- src/Platform/XEglApplication.h | 2 +- src/Renderbuffer.h | 2 +- src/SceneGraph/AbstractCamera.h | 8 +++--- src/SceneGraph/Test/CameraTest.cpp | 6 ++--- src/Swizzle.h | 4 +-- src/Test/SwizzleTest.cpp | 38 ++++++++++++--------------- 23 files changed, 127 insertions(+), 132 deletions(-) diff --git a/doc/portability.dox b/doc/portability.dox index 673ca1f42..fb0d32d8d 100644 --- a/doc/portability.dox +++ b/doc/portability.dox @@ -157,7 +157,7 @@ class MyApplication: public ApplicationBase { } protected: - void viewportEvent(const Math::Vector2& size) override { + void viewportEvent(const Vector2i& size) override { // ... } @@ -165,7 +165,7 @@ class MyApplication: public ApplicationBase { // ... } - void keyPressEvent(Key key, Modifiers modifiers, const Math::Vector2& position) { + void keyPressEvent(Key key, Modifiers modifiers, const Vector2i& position) { // ... } }; diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 19653753c..53a383d1a 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -298,14 +298,13 @@ class MAGNUM_EXPORT AbstractShaderProgram { * location `0`. * * Template parameter @p T is the type which is used for shader - * attribute, e.g. @ref Math::Vector4 "Vector4" for `ivec4`. - * DataType is type of passed data when adding vertex buffers to mesh. - * By default it is the same as type used in shader (e.g. - * @ref DataType "DataType::Int" for @ref Math::Vector4 "Vector4"). - * It's also possible to pass integer data to floating-point shader - * inputs. In this case you may want to normalize the values (e.g. - * color components from 0-255 to 0.0f-1.0f) - see - * @ref DataOption "DataOption::Normalize". + * attribute, e.g. @ref Vector4i for `ivec4`. DataType is type of + * passed data when adding vertex buffers to mesh. By default it is + * the same as type used in shader (e.g. @ref DataType "DataType::Int" + * for @ref Vector4i). It's also possible to pass integer data to + * floating-point shader inputs. In this case you may want to + * normalize the values (e.g. color components from 0-255 to + * 0.0f - 1.0f) -- see @ref DataOption "DataOption::Normalize". * * Only some types are allowed as attribute types, see * @ref AbstractShaderProgram-types or TypeTraits::AttributeType for @@ -425,7 +424,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @brief Constructor * @param dataType Type of passed data. Default is the * same as type used in shader (e.g. DataType::Integer - * for Vector4). + * for Vector4i). * @param dataOptions Data options. Default is no options. */ inline constexpr Attribute(DataType dataType = Implementation::Attribute::DefaultDataType, DataOptions dataOptions = DataOptions()): _dataType(dataType), _dataOptions(dataOptions) {} diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index e5ef0c416..dedbd221c 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -235,18 +235,18 @@ void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, Inte } #endif -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); glTexImage2D(target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureImage2DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); } #endif -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 @@ -263,7 +263,7 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureImage3DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); } #endif @@ -279,18 +279,18 @@ void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, c } #endif -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); } #endif -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexSubImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 @@ -307,7 +307,7 @@ void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLeve } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 933e4ec90..37d00b61b 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -772,14 +772,14 @@ class MAGNUM_EXPORT AbstractTexture { static Image1DImplementation image1DImplementation; #endif - typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector2&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static Image2DImplementation image2DImplementation; - typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector3&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static Image3DImplementation image3DImplementation; #ifndef MAGNUM_TARGET_GLES @@ -789,14 +789,14 @@ class MAGNUM_EXPORT AbstractTexture { static SubImage1DImplementation subImage1DImplementation; #endif - typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Math::Vector2&, const Math::Vector2&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static SubImage2DImplementation subImage2DImplementation; - typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Math::Vector3&, const Math::Vector3&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector3& offset, const Math::Vector3& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); static SubImage3DImplementation subImage3DImplementation; GLuint _id; @@ -860,12 +860,12 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { (texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector2& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) { (texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector2& offset, Image* image) { - (texture->*subImage2DImplementation)(target, mipLevel, offset, Math::Vector2(image->size(), 1), image->components(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) { + (texture->*subImage2DImplementation)(target, mipLevel, offset, Vector2i(image->size(), 1), image->components(), image->type(), image->data()); } }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { @@ -886,12 +886,12 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { (texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector3& offset, Image* image) { + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) { (texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector3& offset, Image* image) { - (texture->*subImage3DImplementation)(target, mipLevel, offset, Math::Vector3(image->size(), 1), image->components(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) { + (texture->*subImage3DImplementation)(target, mipLevel, offset, Vector3i(image->size(), 1), image->components(), image->type(), image->data()); } }; #endif diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 7da8f60a4..f645a45c0 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -122,7 +122,7 @@ class CubeMapTexture: public AbstractTexture { * @param coordinate Coordinate * @return Pointer to self (for method chaining) */ - template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector2& offset, const Image* image) { + template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Vector2i& offset, const Image* image) { DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index cc558a5ee..a232c5888 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -127,8 +127,8 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ - template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Math::Vector3& offset, const Image* image) { - DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Math::Vector3(Math::Vector())); + template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Vector3i& offset, const Image* image) { + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Vector3i(Math::Vector())); return this; } @@ -147,8 +147,8 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) */ - template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Math::Vector2& offset, const Image* image) { - DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Math::Vector3(offset, layer*6+static_cast(coordinate)), image, Math::Vector<2, GLsizei>(Math::Vector())); + template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Vector2i& offset, const Image* image) { + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Vector3i(offset, layer*6+static_cast(coordinate)), image, Vector2i(Math::Vector())); return this; } diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index f63c9915f..cec234536 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -45,14 +45,14 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments delete[] attachments; } -void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { +void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { char* data = new char[AbstractImage::pixelSize(components, type)*size.product()]; glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); image->setData(size, components, type, data); } #ifndef MAGNUM_TARGET_GLES2 -void Framebuffer::read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { +void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ if(image->size() != size || image->components() != components || image->type() != type) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index afe0a57f1..f4aba3115 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -127,7 +127,7 @@ class MAGNUM_EXPORT Framebuffer { * Call when window size changes. * @see @fn_gl{Viewport} */ - inline static void setViewport(const Math::Vector2& position, const Math::Vector2& size) { + inline static void setViewport(const Vector2i& position, const Vector2i& size) { glViewport(position.x(), position.y(), size.x(), size.y()); } @@ -211,7 +211,7 @@ class MAGNUM_EXPORT Framebuffer { * @attention You have to enable scissoring with setFeature() first. * @see @fn_gl{Scissor} */ - inline static void setScissor(const Math::Vector2& bottomLeft, const Math::Vector2& size) { + inline static void setScissor(const Vector2i& bottomLeft, const Vector2i& size) { glScissor(bottomLeft.x(), bottomLeft.y(), size.x(), size.y()); } @@ -1235,7 +1235,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_blit} * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ - inline static void blit(const Math::Vector2& bottomLeft, const Math::Vector2& topRight, const Math::Vector2& destinationBottomLeft, const Math::Vector2& destinationTopRight, BlitMask blitMask, AbstractTexture::Filter filter) { + inline static void blit(const Vector2i& bottomLeft, const Vector2i& topRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask blitMask, AbstractTexture::Filter filter) { /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 glBlitFramebuffer(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(blitMask), static_cast(filter)); @@ -1266,7 +1266,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_blit} * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ - inline static void blit(const Math::Vector2& bottomLeft, const Math::Vector2& topRight, BlitMask blitMask) { + inline static void blit(const Vector2i& bottomLeft, const Vector2i& topRight, BlitMask blitMask) { /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 glBlitFramebuffer(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), static_cast(blitMask), static_cast(AbstractTexture::Filter::NearestNeighbor)); @@ -1288,7 +1288,7 @@ class MAGNUM_EXPORT Framebuffer { * @see @fn_gl{ReadPixels} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); + static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); #ifndef MAGNUM_TARGET_GLES2 /** @@ -1304,7 +1304,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ - static void read(const Math::Vector2& offset, const Math::Vector2& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); + static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); #endif /*@}*/ diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 9379d7492..aa71c876d 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -29,7 +29,7 @@ using namespace std; namespace Magnum { namespace Platform { -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, int&, char**, const string& title, const Math::Vector2& size): contextHandler(contextHandler), viewportSize(size), flags(Flag::Redraw) { +AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, int&, char**, const string& title, const Vector2i& size): contextHandler(contextHandler), viewportSize(size), flags(Flag::Redraw) { /* Get default X display */ display = XOpenDisplay(0); @@ -108,7 +108,7 @@ int AbstractXApplication::exec() { switch(event.type) { /* Window resizing */ case ConfigureNotify: { - Math::Vector2 size(event.xconfigure.width, event.xconfigure.height); + Vector2i size(event.xconfigure.width, event.xconfigure.height); if(size != viewportSize) { viewportSize = size; viewportEvent(size); diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 783f7c479..d26ddcc8b 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -57,7 +57,7 @@ class AbstractXApplication { * * Creates window with double-buffered OpenGL ES 2 context. */ - AbstractXApplication(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X application", const Math::Vector2& size = Math::Vector2(800, 600)); + AbstractXApplication(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X application", const Vector2i& size = Vector2i(800, 600)); /** * @brief Destructor @@ -79,7 +79,7 @@ class AbstractXApplication { protected: /** @copydoc GlutApplication::viewportEvent() */ - virtual void viewportEvent(const Math::Vector2& size) = 0; + virtual void viewportEvent(const Vector2i& size) = 0; /** @copydoc GlutApplication::drawEvent() */ virtual void drawEvent() = 0; @@ -209,7 +209,7 @@ class AbstractXApplication { * * Called when an key is pressed. Default implementation does nothing. */ - virtual void keyPressEvent(Key key, Modifiers modifiers, const Math::Vector2& position); + virtual void keyPressEvent(Key key, Modifiers modifiers, const Vector2i& position); /** * @brief Key press event @@ -219,7 +219,7 @@ class AbstractXApplication { * * Called when an key is released. Default implementation does nothing. */ - virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Math::Vector2& position); + virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Vector2i& position); /*@}*/ @@ -249,7 +249,7 @@ class AbstractXApplication { * Called when mouse button is pressed. Default implementation does * nothing. */ - virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); + virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Vector2i& position); /** * @brief Mouse release event @@ -260,7 +260,7 @@ class AbstractXApplication { * Called when mouse button is released. Default implementation does * nothing. */ - virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Math::Vector2& position); + virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Vector2i& position); /** * @brief Mouse motion event @@ -269,7 +269,7 @@ class AbstractXApplication { * * Called when mouse is moved. */ - virtual void mouseMotionEvent(Modifiers modifiers, const Math::Vector2& position); + virtual void mouseMotionEvent(Modifiers modifiers, const Vector2i& position); /*@}*/ @@ -291,7 +291,7 @@ class AbstractXApplication { Context* c; /** @todo Get this from the created window */ - Math::Vector2 viewportSize; + Vector2i viewportSize; Flags flags; }; @@ -328,11 +328,11 @@ CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Modifiers) CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags) /* Implementations for inline functions with unused parameters */ -inline void AbstractXApplication::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} -inline void AbstractXApplication::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} -inline void AbstractXApplication::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} -inline void AbstractXApplication::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} -inline void AbstractXApplication::mouseMotionEvent(Modifiers, const Math::Vector2&) {} +inline void AbstractXApplication::keyPressEvent(Key, Modifiers, const Vector2i&) {} +inline void AbstractXApplication::keyReleaseEvent(Key, Modifiers, const Vector2i&) {} +inline void AbstractXApplication::mousePressEvent(MouseButton, Modifiers, const Vector2i&) {} +inline void AbstractXApplication::mouseReleaseEvent(MouseButton, Modifiers, const Vector2i&) {} +inline void AbstractXApplication::mouseMotionEvent(Modifiers, const Vector2i&) {} }} diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 321d51c2b..85eab4416 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace Platform { GlutApplication* GlutApplication::instance = nullptr; -GlutApplication::GlutApplication(int& argc, char** argv, const std::string& title, const Math::Vector2& size) { +GlutApplication::GlutApplication(int& argc, char** argv, const std::string& title, const Vector2i& size) { /* Save global instance */ instance = this; diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 07e5c4572..9d7e65c6a 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -61,7 +61,7 @@ class GlutApplication { * * Creates double-buffered RGBA window with depth and stencil buffers. */ - GlutApplication(int& argc, char** argv, const std::string& title = "Magnum GLUT application", const Math::Vector2& size = Math::Vector2(800, 600)); + GlutApplication(int& argc, char** argv, const std::string& title = "Magnum GLUT application", const Vector2i& size = Vector2i(800, 600)); virtual ~GlutApplication(); @@ -84,7 +84,7 @@ class GlutApplication { * Framebuffer::setViewport() (and SceneGraph::AbstractCamera::setViewport(), * if using scene graph). */ - virtual void viewportEvent(const Math::Vector2& size) = 0; + virtual void viewportEvent(const Vector2i& size) = 0; /** * @brief Draw event @@ -157,7 +157,7 @@ class GlutApplication { * * Called when an key is pressed. Default implementation does nothing. */ - virtual void keyPressEvent(Key key, const Math::Vector2& position); + virtual void keyPressEvent(Key key, const Vector2i& position); /*@}*/ @@ -203,7 +203,7 @@ class GlutApplication { } /** @brief Warp mouse cursor to given coordinates */ - inline void warpMouseCursor(const Math::Vector2& position) { + inline void warpMouseCursor(const Vector2i& position) { glutWarpPointer(position.x(), position.y()); } @@ -214,7 +214,7 @@ class GlutApplication { * Called when mouse button is pressed. Default implementation does * nothing. */ - virtual void mousePressEvent(MouseButton button, const Math::Vector2& position); + virtual void mousePressEvent(MouseButton button, const Vector2i& position); /** * @brief Mouse release event @@ -222,7 +222,7 @@ class GlutApplication { * Called when mouse button is released. Default implementation does * nothing. */ - virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); + virtual void mouseReleaseEvent(MouseButton button, const Vector2i& position); /** * @brief Mouse motion event @@ -231,7 +231,7 @@ class GlutApplication { * implementation does nothing. * @see setMouseTracking() */ - virtual void mouseMotionEvent(const Math::Vector2& position); + virtual void mouseMotionEvent(const Vector2i& position); /*@}*/ @@ -293,10 +293,10 @@ When no other application header is included this macro is also aliased to #endif /* Implementations for inline functions with unused parameters */ -inline void GlutApplication::keyPressEvent(Key, const Math::Vector2&) {} -inline void GlutApplication::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void GlutApplication::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void GlutApplication::mouseMotionEvent(const Math::Vector2&) {} +inline void GlutApplication::keyPressEvent(Key, const Vector2i&) {} +inline void GlutApplication::mousePressEvent(MouseButton, const Vector2i&) {} +inline void GlutApplication::mouseReleaseEvent(MouseButton, const Vector2i&) {} +inline void GlutApplication::mouseMotionEvent(const Vector2i&) {} }} diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index f17d683be..fec492946 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -53,7 +53,7 @@ class GlxApplication: public AbstractXApplication { * Creates window with double-buffered OpenGL 3.2 core context or * OpenGL ES 2.0 context, if targetting OpenGL ES. */ - inline GlxApplication(int& argc, char** argv, const std::string& title = "Magnum GLX application", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXApplication(new GlxContextHandler, argc, argv, title, size) {} + inline GlxApplication(int& argc, char** argv, const std::string& title = "Magnum GLX application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new GlxContextHandler, argc, argv, title, size) {} }; }} diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 909aea265..6bcf4203d 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -23,7 +23,7 @@ namespace Magnum { namespace Platform { -NaClApplication::NaClApplication(PP_Instance instance, const Math::Vector2& size): Instance(instance), Graphics3DClient(this), MouseLock(this), viewportSize(size) { +NaClApplication::NaClApplication(PP_Instance instance, const Vector2i& size): Instance(instance), Graphics3DClient(this), MouseLock(this), viewportSize(size) { int32_t attributes[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, @@ -101,7 +101,7 @@ void NaClApplication::DidChangeView(const pp::View& view) { else return; } - Math::Vector2 size(view.GetRect().width(), view.GetRect().height()); + Vector2i size(view.GetRect().width(), view.GetRect().height()); /* Canvas resized */ if(viewportSize != size) { diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index aabdb6c9a..81d670603 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -72,7 +72,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public * * Creates double-buffered RGBA canvas with depth and stencil buffers. */ - explicit NaClApplication(PP_Instance instance, const Math::Vector2& size = Math::Vector2(640, 480)); + explicit NaClApplication(PP_Instance instance, const Vector2i& size = Vector2i(640, 480)); ~NaClApplication(); @@ -94,7 +94,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public /** @{ @name Drawing functions */ /** @copydoc GlutApplication::viewportEvent() */ - virtual void viewportEvent(const Math::Vector2& size) = 0; + virtual void viewportEvent(const Vector2i& size) = 0; /** @copydoc GlutApplication::drawEvent() */ virtual void drawEvent() = 0; @@ -205,7 +205,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public pp::Graphics3D* graphics; pp::Fullscreen* fullscreen; Context* c; - Math::Vector2 viewportSize; + Vector2i viewportSize; Flags flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) @@ -399,13 +399,13 @@ class NaClApplication::MouseEvent: public NaClApplication::InputEvent { inline Button button() const { return _button; } /** @brief Position */ - inline Math::Vector2 position() const { return _position; } + inline Vector2i position() const { return _position; } private: - inline MouseEvent(Button button, const Math::Vector2& position, Modifiers modifiers): InputEvent(modifiers), _button(button), _position(position) {} + inline MouseEvent(Button button, const Vector2i& position, Modifiers modifiers): InputEvent(modifiers), _button(button), _position(position) {} const Button _button; - const Math::Vector2 _position; + const Vector2i _position; }; /** @@ -419,19 +419,19 @@ class NaClApplication::MouseMoveEvent: public NaClApplication::InputEvent { public: /** @brief Position */ - inline Math::Vector2 position() const { return _position; } + inline Vector2i position() const { return _position; } /** * @brief Relative position * * Position relative to previous event. */ - inline Math::Vector2 relativePosition() const { return _relativePosition; } + inline Vector2i relativePosition() const { return _relativePosition; } private: - inline MouseMoveEvent(const Math::Vector2& position, const Math::Vector2& relativePosition, Modifiers modifiers): InputEvent(modifiers), _position(position), _relativePosition(relativePosition) {} + inline MouseMoveEvent(const Vector2i& position, const Vector2i& relativePosition, Modifiers modifiers): InputEvent(modifiers), _position(position), _relativePosition(relativePosition) {} - const Math::Vector2 _position, _relativePosition; + const Vector2i _position, _relativePosition; }; CORRADE_ENUMSET_OPERATORS(NaClApplication::Flags) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index cf6a31b34..49e6980e8 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -40,7 +40,7 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { } -Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Math::Vector2& size): _redraw(true) { +Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vector2i& size): _redraw(true) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; exit(1); diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index c7b634d31..ac1265881 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -65,7 +65,7 @@ class Sdl2Application { * @param title Window title * @param size Window size */ - Sdl2Application(int argc, char** argv, const std::string& title = "Magnum SDL2 application", const Math::Vector2& size = Math::Vector2(800, 600)); + Sdl2Application(int argc, char** argv, const std::string& title = "Magnum SDL2 application", const Vector2i& size = Vector2i(800, 600)); /** * @brief Destructor @@ -85,7 +85,7 @@ class Sdl2Application { /** @{ @name Drawing functions */ /** @copydoc GlutApplication::viewportEvent() */ - virtual void viewportEvent(const Math::Vector2& size) = 0; + virtual void viewportEvent(const Vector2i& size) = 0; /** @copydoc GlutApplication::drawEvent() */ virtual void drawEvent() = 0; @@ -351,7 +351,7 @@ class Sdl2Application::MouseEvent: public Sdl2Application::InputEvent { inline Button button() const { return _button; } /** @brief Position */ - inline Math::Vector2 position() const { return _position; } + inline Vector2i position() const { return _position; } /** * @brief Modifiers @@ -361,10 +361,10 @@ class Sdl2Application::MouseEvent: public Sdl2Application::InputEvent { Modifiers modifiers(); private: - inline MouseEvent(Button button, const Math::Vector2& position): _button(button), _position(position), modifiersLoaded(false) {} + inline MouseEvent(Button button, const Vector2i& position): _button(button), _position(position), modifiersLoaded(false) {} const Button _button; - const Math::Vector2 _position; + const Vector2i _position; bool modifiersLoaded; Modifiers _modifiers; }; @@ -379,14 +379,14 @@ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { public: /** @brief Position */ - inline Math::Vector2 position() const { return _position; } + inline Vector2i position() const { return _position; } /** * @brief Relative position * * Position relative to previous event. */ - inline Math::Vector2 relativePosition() const { return _relativePosition; } + inline Vector2i relativePosition() const { return _relativePosition; } /** * @brief Modifiers @@ -396,9 +396,9 @@ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { Modifiers modifiers(); private: - inline MouseMoveEvent(const Math::Vector2& position, const Math::Vector2& relativePosition): _position(position), _relativePosition(relativePosition), modifiersLoaded(false) {} + inline MouseMoveEvent(const Vector2i& position, const Vector2i& relativePosition): _position(position), _relativePosition(relativePosition), modifiersLoaded(false) {} - const Math::Vector2 _position, _relativePosition; + const Vector2i _position, _relativePosition; bool modifiersLoaded; Modifiers _modifiers; }; diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index 7fdcfe1f4..c0a12317f 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -52,7 +52,7 @@ class XEglApplication: public AbstractXApplication { * * Creates window with double-buffered OpenGL ES 2 context. */ - inline XEglApplication(int& argc, char** argv, const std::string& title = "Magnum X/EGL application", const Math::Vector2& size = Math::Vector2(800, 600)): AbstractXApplication(new EglContextHandler, argc, argv, title, size) {} + inline XEglApplication(int& argc, char** argv, const std::string& title = "Magnum X/EGL application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new EglContextHandler, argc, argv, title, size) {} }; }} diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 23b03e657..2ee87b8bc 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -230,7 +230,7 @@ class Renderbuffer { * * @see bind(), @fn_gl{RenderbufferStorage} */ - inline void setStorage(InternalFormat internalFormat, const Math::Vector2& size) { + inline void setStorage(InternalFormat internalFormat, const Vector2i& size) { bind(); glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, size.x(), size.y()); } diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 8af0eec73..31c11fa39 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -40,7 +40,7 @@ enum class AspectRatioPolicy: std::uint8_t { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Math::Vector2& viewport); + template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Vector2i& viewport); } #endif @@ -121,7 +121,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature viewport() const { return _viewport; } + inline Vector2i viewport() const { return _viewport; } /** * @brief Set viewport size @@ -130,7 +130,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature& size); + virtual void setViewport(const Vector2i& size); /** * @brief Draw @@ -158,7 +158,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature::MatrixType _projectionMatrix; typename DimensionTraits::MatrixType _cameraMatrix; - Math::Vector2 _viewport; + Vector2i _viewport; }; template inline AbstractCamera::~AbstractCamera() {} diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index c3396e458..4dd856798 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -47,13 +47,13 @@ CameraTest::CameraTest() { void CameraTest::fixAspectRatio() { Vector2 projectionScale(0.5f, 1.0f/3.0f); - Math::Vector2 size(400, 300); + Vector2i size(400, 300); /* Division by zero */ Vector2 projectionScaleZeroY(0.5f, 0.0f); Vector2 projectionScaleZeroX(0.0f, 0.5f); - Math::Vector2 sizeZeroY(400, 0); - Math::Vector2 sizeZeroX(0, 300); + Vector2i sizeZeroY(400, 0); + Vector2i sizeZeroX(0, 300); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Matrix4()); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Matrix4()); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Matrix4()); diff --git a/src/Swizzle.h b/src/Swizzle.h index 529d538ec..0805f6a9c 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -90,7 +90,7 @@ namespace Implementation { Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4i 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 inline constexpr typename Implementation:: Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4i original(-1, 2, 3, 4); auto vec = swizzle(original, "a10rgb"); // vec == { 4, 1, 0, -1, 2, 3 } diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index fa36a4576..3ac1c4139 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -23,10 +23,6 @@ CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) namespace Magnum { namespace Test { -typedef Math::Vector2 Vector2; -typedef Math::Vector3 Vector3; -typedef Math::Vector4 Vector4; - SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::xyzw, &SwizzleTest::rgba, @@ -37,42 +33,42 @@ SwizzleTest::SwizzleTest() { } void SwizzleTest::xyzw() { - Vector4 orig(2, 4, 5, 7); - Vector4 swizzled(5, 2, 7, 4); + Vector4i orig(2, 4, 5, 7); + Vector4i swizzled(5, 2, 7, 4); CORRADE_COMPARE(swizzle(orig, "zxwy"), swizzled); CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y'>(orig)), swizzled); } void SwizzleTest::rgba() { - Vector4 orig(2, 4, 5, 7); - Vector4 swizzled(5, 2, 7, 4); + Vector4i orig(2, 4, 5, 7); + Vector4i swizzled(5, 2, 7, 4); CORRADE_COMPARE(swizzle(orig, "brag"), swizzled); CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g'>(orig)), swizzled); } void SwizzleTest::constants() { - Vector4 orig(2, 4, 5, 7); - Vector4 swizzled(1, 7, 0, 4); + Vector4i orig(2, 4, 5, 7); + Vector4i swizzled(1, 7, 0, 4); CORRADE_COMPARE(swizzle(orig, "1w0g"), swizzled); CORRADE_COMPARE((swizzle<'1', 'w', '0', 'g'>(orig)), swizzled); } void SwizzleTest::fromSmall() { /* Force compile-time evaluation for both */ - constexpr Vector2 orig(1, 2); - constexpr Vector3 swizzled(swizzle(orig, "gxr")); + constexpr Vector2i orig(1, 2); + constexpr Vector3i swizzled(swizzle(orig, "gxr")); CORRADE_VERIFY((integral_constant::value)); - CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(orig)), Vector3(2, 1, 1)); + CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(orig)), Vector3i(2, 1, 1)); } void SwizzleTest::type() { - Vector4 orig; - CORRADE_VERIFY((is_same(orig)), Vector2>::value)); - CORRADE_VERIFY((is_same::value)); - CORRADE_VERIFY((is_same(orig)), Vector3>::value)); - CORRADE_VERIFY((is_same::value)); - CORRADE_VERIFY((is_same(orig)), Vector4>::value)); - CORRADE_VERIFY((is_same::value)); + Vector4i orig; + CORRADE_VERIFY((is_same(orig)), Vector2i>::value)); + CORRADE_VERIFY((is_same::value)); + CORRADE_VERIFY((is_same(orig)), Vector3i>::value)); + CORRADE_VERIFY((is_same::value)); + CORRADE_VERIFY((is_same(orig)), Vector4i>::value)); + CORRADE_VERIFY((is_same::value)); Color3 origColor3; Color4 origColor4; @@ -87,7 +83,7 @@ void SwizzleTest::type() { } void SwizzleTest::defaultType() { - Vector4 orig(1, 2, 3, 4); + Vector4i orig(1, 2, 3, 4); 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))); From ae013effff73a7da38c34297542b5b50eb590a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 6 Dec 2012 19:41:15 +0100 Subject: [PATCH 010/567] Adapted to Corrade changes. Optimalizations in Corrade::TestSuite and Corrade::Utility::Debug leaded to significant reduction of compilation time - on my machine it was ~5:38 before with building of unit tests enabled, now only ~5:00. --- src/AbstractImage.cpp | 2 +- src/Implementation/BufferState.cpp | 2 +- src/Math/Algorithms/Test/GaussJordanTest.h | 2 +- src/Math/Geometry/Test/DistanceTest.h | 2 +- src/Math/Geometry/Test/IntersectionTest.h | 2 +- src/Math/Test/ConstantsTest.h | 2 +- src/Math/Test/MathTest.h | 2 +- src/Math/Test/MathTypeTraitsTest.h | 2 +- src/Math/Test/Matrix3Test.h | 2 +- src/Math/Test/Matrix4Test.h | 2 +- src/Math/Test/MatrixTest.h | 2 +- src/Math/Test/Point2DTest.h | 2 +- src/Math/Test/Point3DTest.h | 2 +- src/Math/Test/RectangularMatrixTest.h | 2 +- src/Math/Test/Vector2Test.h | 2 +- src/Math/Test/Vector3Test.h | 2 +- src/Math/Test/Vector4Test.h | 2 +- src/Math/Test/VectorTest.h | 2 +- src/Math/Vector.h | 2 ++ src/Mesh.h | 2 +- src/MeshTools/Test/CleanTest.h | 2 +- src/MeshTools/Test/CombineIndexedArraysTest.h | 2 +- src/MeshTools/Test/CompressIndicesTest.h | 2 +- src/MeshTools/Test/FlipNormalsTest.h | 2 +- src/MeshTools/Test/GenerateFlatNormalsTest.h | 2 +- src/MeshTools/Test/InterleaveTest.h | 2 +- src/MeshTools/Test/SubdivideTest.h | 2 +- src/MeshTools/Test/TipsifyTest.h | 2 +- src/Physics/ShapeGroup.h | 1 + src/Physics/Test/AbstractShapeTest.h | 2 +- src/Physics/Test/AxisAlignedBoxTest.h | 2 +- src/Physics/Test/BoxTest.h | 2 +- src/Physics/Test/CapsuleTest.h | 2 +- src/Physics/Test/LineTest.h | 2 +- src/Physics/Test/ObjectShapeTest.h | 2 +- src/Physics/Test/PlaneTest.h | 2 +- src/Physics/Test/PointTest.h | 2 +- src/Physics/Test/ShapeGroupTest.h | 2 +- src/Physics/Test/SphereTest.h | 2 +- src/Platform/ExtensionWrangler.cpp | 1 + src/Primitives/Test/CapsuleTest.h | 2 +- src/Primitives/Test/CylinderTest.h | 2 +- src/Primitives/Test/UVSphereTest.h | 2 +- src/Profiler.cpp | 2 +- src/Resource.h | 1 + src/SceneGraph/FeatureGroup.h | 2 +- src/SceneGraph/Test/CameraTest.h | 2 +- src/SceneGraph/Test/ObjectTest.h | 2 +- src/SceneGraph/Test/SceneTest.h | 2 +- src/Shader.cpp | 2 +- src/Test/ArrayTest.h | 2 +- src/Test/ColorTest.h | 2 +- src/Test/MeshTest.h | 2 +- src/Test/ResourceManagerTest.h | 2 +- src/Test/SwizzleTest.h | 2 +- src/Test/TypeTraitsTest.h | 2 +- 56 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 04f14f2b6..84b2b82eb 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -15,7 +15,7 @@ #include "AbstractImage.h" -#include +#include #include "TypeTraits.h" diff --git a/src/Implementation/BufferState.cpp b/src/Implementation/BufferState.cpp index 229be3504..323f5a015 100644 --- a/src/Implementation/BufferState.cpp +++ b/src/Implementation/BufferState.cpp @@ -15,7 +15,7 @@ #include "BufferState.h" -#include +#include namespace Magnum { namespace Implementation { diff --git a/src/Math/Algorithms/Test/GaussJordanTest.h b/src/Math/Algorithms/Test/GaussJordanTest.h index 0c25d27e0..fb5389cf9 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.h +++ b/src/Math/Algorithms/Test/GaussJordanTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Algorithms { namespace Test { -class GaussJordanTest: public Corrade::TestSuite::Tester { +class GaussJordanTest: public Corrade::TestSuite::Tester { public: GaussJordanTest(); diff --git a/src/Math/Geometry/Test/DistanceTest.h b/src/Math/Geometry/Test/DistanceTest.h index dc7c7bc88..485e1d576 100644 --- a/src/Math/Geometry/Test/DistanceTest.h +++ b/src/Math/Geometry/Test/DistanceTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Test { -class DistanceTest: public Corrade::TestSuite::Tester { +class DistanceTest: public Corrade::TestSuite::Tester { public: DistanceTest(); diff --git a/src/Math/Geometry/Test/IntersectionTest.h b/src/Math/Geometry/Test/IntersectionTest.h index 7187a28c2..7375b2d51 100644 --- a/src/Math/Geometry/Test/IntersectionTest.h +++ b/src/Math/Geometry/Test/IntersectionTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Test { -class IntersectionTest: public Corrade::TestSuite::Tester { +class IntersectionTest: public Corrade::TestSuite::Tester { public: IntersectionTest(); diff --git a/src/Math/Test/ConstantsTest.h b/src/Math/Test/ConstantsTest.h index a52c49543..3a96e0c35 100644 --- a/src/Math/Test/ConstantsTest.h +++ b/src/Math/Test/ConstantsTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class ConstantsTest: public Corrade::TestSuite::Tester { +class ConstantsTest: public Corrade::TestSuite::Tester { public: ConstantsTest(); diff --git a/src/Math/Test/MathTest.h b/src/Math/Test/MathTest.h index 658d47690..3f16d33d9 100644 --- a/src/Math/Test/MathTest.h +++ b/src/Math/Test/MathTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class MathTest: public Corrade::TestSuite::Tester { +class MathTest: public Corrade::TestSuite::Tester { public: MathTest(); diff --git a/src/Math/Test/MathTypeTraitsTest.h b/src/Math/Test/MathTypeTraitsTest.h index 76a4f8882..5baa9da49 100644 --- a/src/Math/Test/MathTypeTraitsTest.h +++ b/src/Math/Test/MathTypeTraitsTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class MathTypeTraitsTest: public Corrade::TestSuite::Tester { +class MathTypeTraitsTest: public Corrade::TestSuite::Tester { public: MathTypeTraitsTest(); diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h index ede0d7fca..0b189e726 100644 --- a/src/Math/Test/Matrix3Test.h +++ b/src/Math/Test/Matrix3Test.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Matrix3Test: public Corrade::TestSuite::Tester { +class Matrix3Test: public Corrade::TestSuite::Tester { public: Matrix3Test(); diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 7c360f618..f00ac7393 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Matrix4Test: public Corrade::TestSuite::Tester { +class Matrix4Test: public Corrade::TestSuite::Tester { public: Matrix4Test(); diff --git a/src/Math/Test/MatrixTest.h b/src/Math/Test/MatrixTest.h index ba1cb02ee..a3c6f53ea 100644 --- a/src/Math/Test/MatrixTest.h +++ b/src/Math/Test/MatrixTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class MatrixTest: public Corrade::TestSuite::Tester { +class MatrixTest: public Corrade::TestSuite::Tester { public: MatrixTest(); diff --git a/src/Math/Test/Point2DTest.h b/src/Math/Test/Point2DTest.h index 39ec72d3b..8baf04980 100644 --- a/src/Math/Test/Point2DTest.h +++ b/src/Math/Test/Point2DTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Point2DTest: public Corrade::TestSuite::Tester { +class Point2DTest: public Corrade::TestSuite::Tester { public: Point2DTest(); diff --git a/src/Math/Test/Point3DTest.h b/src/Math/Test/Point3DTest.h index 9560e01d5..54518afa7 100644 --- a/src/Math/Test/Point3DTest.h +++ b/src/Math/Test/Point3DTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Point3DTest: public Corrade::TestSuite::Tester { +class Point3DTest: public Corrade::TestSuite::Tester { public: Point3DTest(); diff --git a/src/Math/Test/RectangularMatrixTest.h b/src/Math/Test/RectangularMatrixTest.h index 469762177..34754f583 100644 --- a/src/Math/Test/RectangularMatrixTest.h +++ b/src/Math/Test/RectangularMatrixTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class RectangularMatrixTest: public Corrade::TestSuite::Tester { +class RectangularMatrixTest: public Corrade::TestSuite::Tester { public: RectangularMatrixTest(); diff --git a/src/Math/Test/Vector2Test.h b/src/Math/Test/Vector2Test.h index 1e35c4704..b9cc71797 100644 --- a/src/Math/Test/Vector2Test.h +++ b/src/Math/Test/Vector2Test.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Vector2Test: public Corrade::TestSuite::Tester { +class Vector2Test: public Corrade::TestSuite::Tester { public: Vector2Test(); diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h index 706b3c68a..23ecd5db5 100644 --- a/src/Math/Test/Vector3Test.h +++ b/src/Math/Test/Vector3Test.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Vector3Test: public Corrade::TestSuite::Tester { +class Vector3Test: public Corrade::TestSuite::Tester { public: Vector3Test(); diff --git a/src/Math/Test/Vector4Test.h b/src/Math/Test/Vector4Test.h index 7e8cc5ae2..95b41c986 100644 --- a/src/Math/Test/Vector4Test.h +++ b/src/Math/Test/Vector4Test.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class Vector4Test: public Corrade::TestSuite::Tester { +class Vector4Test: public Corrade::TestSuite::Tester { public: Vector4Test(); diff --git a/src/Math/Test/VectorTest.h b/src/Math/Test/VectorTest.h index ca8f48e48..6c70e6e02 100644 --- a/src/Math/Test/VectorTest.h +++ b/src/Math/Test/VectorTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Math { namespace Test { -class VectorTest: public Corrade::TestSuite::Tester { +class VectorTest: public Corrade::TestSuite::Tester { public: VectorTest(); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 3ed1f71b3..1f315d9fd 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Math::Vector */ +#include + #include "RectangularMatrix.h" namespace Magnum { namespace Math { diff --git a/src/Mesh.h b/src/Mesh.h index a7bcc2286..9c65327f5 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -20,7 +20,7 @@ */ #include -#include +#include #include "AbstractShaderProgram.h" #include "TypeTraits.h" diff --git a/src/MeshTools/Test/CleanTest.h b/src/MeshTools/Test/CleanTest.h index 57169d736..2b6b797ef 100644 --- a/src/MeshTools/Test/CleanTest.h +++ b/src/MeshTools/Test/CleanTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class CleanTest: public Corrade::TestSuite::Tester { +class CleanTest: public Corrade::TestSuite::Tester { public: CleanTest(); diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.h b/src/MeshTools/Test/CombineIndexedArraysTest.h index df90f02f8..80b08c418 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.h +++ b/src/MeshTools/Test/CombineIndexedArraysTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class CombineIndexedArraysTest: public Corrade::TestSuite::Tester { +class CombineIndexedArraysTest: public Corrade::TestSuite::Tester { public: CombineIndexedArraysTest(); diff --git a/src/MeshTools/Test/CompressIndicesTest.h b/src/MeshTools/Test/CompressIndicesTest.h index fcbcc85dd..187610326 100644 --- a/src/MeshTools/Test/CompressIndicesTest.h +++ b/src/MeshTools/Test/CompressIndicesTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class CompressIndicesTest: public Corrade::TestSuite::Tester { +class CompressIndicesTest: public Corrade::TestSuite::Tester { public: CompressIndicesTest(); diff --git a/src/MeshTools/Test/FlipNormalsTest.h b/src/MeshTools/Test/FlipNormalsTest.h index f6f0422cd..8a25d8bed 100644 --- a/src/MeshTools/Test/FlipNormalsTest.h +++ b/src/MeshTools/Test/FlipNormalsTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class FlipNormalsTest: public Corrade::TestSuite::Tester { +class FlipNormalsTest: public Corrade::TestSuite::Tester { public: FlipNormalsTest(); diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.h b/src/MeshTools/Test/GenerateFlatNormalsTest.h index 130636498..b699e991e 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.h +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class GenerateFlatNormalsTest: public Corrade::TestSuite::Tester { +class GenerateFlatNormalsTest: public Corrade::TestSuite::Tester { public: GenerateFlatNormalsTest(); diff --git a/src/MeshTools/Test/InterleaveTest.h b/src/MeshTools/Test/InterleaveTest.h index e360d0554..19aae30fb 100644 --- a/src/MeshTools/Test/InterleaveTest.h +++ b/src/MeshTools/Test/InterleaveTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class InterleaveTest: public Corrade::TestSuite::Tester { +class InterleaveTest: public Corrade::TestSuite::Tester { public: InterleaveTest(); diff --git a/src/MeshTools/Test/SubdivideTest.h b/src/MeshTools/Test/SubdivideTest.h index b5ff7f0ef..9d1521a9c 100644 --- a/src/MeshTools/Test/SubdivideTest.h +++ b/src/MeshTools/Test/SubdivideTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class SubdivideTest: public Corrade::TestSuite::Tester { +class SubdivideTest: public Corrade::TestSuite::Tester { public: SubdivideTest(); diff --git a/src/MeshTools/Test/TipsifyTest.h b/src/MeshTools/Test/TipsifyTest.h index 37ca6d4fb..5e4952430 100644 --- a/src/MeshTools/Test/TipsifyTest.h +++ b/src/MeshTools/Test/TipsifyTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { namespace Test { -class TipsifyTest: public Corrade::TestSuite::Tester { +class TipsifyTest: public Corrade::TestSuite::Tester { public: TipsifyTest(); diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index d1ed8bce6..0c89901a7 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -21,6 +21,7 @@ #include "AbstractShape.h" +#include #include #include diff --git a/src/Physics/Test/AbstractShapeTest.h b/src/Physics/Test/AbstractShapeTest.h index 1fa4c4531..4272b72d5 100644 --- a/src/Physics/Test/AbstractShapeTest.h +++ b/src/Physics/Test/AbstractShapeTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class AbstractShapeTest: public Corrade::TestSuite::Tester { +class AbstractShapeTest: public Corrade::TestSuite::Tester { public: AbstractShapeTest(); diff --git a/src/Physics/Test/AxisAlignedBoxTest.h b/src/Physics/Test/AxisAlignedBoxTest.h index bbbbd1083..63451a508 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.h +++ b/src/Physics/Test/AxisAlignedBoxTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class AxisAlignedBoxTest: public Corrade::TestSuite::Tester { +class AxisAlignedBoxTest: public Corrade::TestSuite::Tester { public: AxisAlignedBoxTest(); diff --git a/src/Physics/Test/BoxTest.h b/src/Physics/Test/BoxTest.h index 48781ad08..abf67ce52 100644 --- a/src/Physics/Test/BoxTest.h +++ b/src/Physics/Test/BoxTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class BoxTest: public Corrade::TestSuite::Tester { +class BoxTest: public Corrade::TestSuite::Tester { public: BoxTest(); diff --git a/src/Physics/Test/CapsuleTest.h b/src/Physics/Test/CapsuleTest.h index 88dec80df..6c6c969a1 100644 --- a/src/Physics/Test/CapsuleTest.h +++ b/src/Physics/Test/CapsuleTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class CapsuleTest: public Corrade::TestSuite::Tester, ShapeTestBase { +class CapsuleTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: CapsuleTest(); diff --git a/src/Physics/Test/LineTest.h b/src/Physics/Test/LineTest.h index fd264747b..8f33c3245 100644 --- a/src/Physics/Test/LineTest.h +++ b/src/Physics/Test/LineTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class LineTest: public Corrade::TestSuite::Tester { +class LineTest: public Corrade::TestSuite::Tester { public: LineTest(); diff --git a/src/Physics/Test/ObjectShapeTest.h b/src/Physics/Test/ObjectShapeTest.h index 65d051da1..6a3f0b398 100644 --- a/src/Physics/Test/ObjectShapeTest.h +++ b/src/Physics/Test/ObjectShapeTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class ObjectShapeTest: public Corrade::TestSuite::Tester { +class ObjectShapeTest: public Corrade::TestSuite::Tester { public: ObjectShapeTest(); diff --git a/src/Physics/Test/PlaneTest.h b/src/Physics/Test/PlaneTest.h index 4381e3dc6..d685917e4 100644 --- a/src/Physics/Test/PlaneTest.h +++ b/src/Physics/Test/PlaneTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class PlaneTest: public Corrade::TestSuite::Tester, ShapeTestBase { +class PlaneTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: PlaneTest(); diff --git a/src/Physics/Test/PointTest.h b/src/Physics/Test/PointTest.h index f158954fb..529ffbd9e 100644 --- a/src/Physics/Test/PointTest.h +++ b/src/Physics/Test/PointTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class PointTest: public Corrade::TestSuite::Tester { +class PointTest: public Corrade::TestSuite::Tester { public: PointTest(); diff --git a/src/Physics/Test/ShapeGroupTest.h b/src/Physics/Test/ShapeGroupTest.h index 7e12a3633..49c93a949 100644 --- a/src/Physics/Test/ShapeGroupTest.h +++ b/src/Physics/Test/ShapeGroupTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class ShapeGroupTest: public Corrade::TestSuite::Tester { +class ShapeGroupTest: public Corrade::TestSuite::Tester { public: ShapeGroupTest(); diff --git a/src/Physics/Test/SphereTest.h b/src/Physics/Test/SphereTest.h index 48a2d2d3c..a8fa7ef0b 100644 --- a/src/Physics/Test/SphereTest.h +++ b/src/Physics/Test/SphereTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { namespace Test { -class SphereTest: public Corrade::TestSuite::Tester, ShapeTestBase { +class SphereTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: SphereTest(); diff --git a/src/Platform/ExtensionWrangler.cpp b/src/Platform/ExtensionWrangler.cpp index c84795546..1216075a8 100644 --- a/src/Platform/ExtensionWrangler.cpp +++ b/src/Platform/ExtensionWrangler.cpp @@ -15,6 +15,7 @@ #include "ExtensionWrangler.h" +#include #include #include "Magnum.h" diff --git a/src/Primitives/Test/CapsuleTest.h b/src/Primitives/Test/CapsuleTest.h index e8bc1f495..ab276ae4f 100644 --- a/src/Primitives/Test/CapsuleTest.h +++ b/src/Primitives/Test/CapsuleTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { namespace Test { -class CapsuleTest: public Corrade::TestSuite::Tester { +class CapsuleTest: public Corrade::TestSuite::Tester { public: CapsuleTest(); diff --git a/src/Primitives/Test/CylinderTest.h b/src/Primitives/Test/CylinderTest.h index 0d575bc23..48234fb99 100644 --- a/src/Primitives/Test/CylinderTest.h +++ b/src/Primitives/Test/CylinderTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { namespace Test { -class CylinderTest: public Corrade::TestSuite::Tester { +class CylinderTest: public Corrade::TestSuite::Tester { public: CylinderTest(); diff --git a/src/Primitives/Test/UVSphereTest.h b/src/Primitives/Test/UVSphereTest.h index 8afd27522..560cb9d4c 100644 --- a/src/Primitives/Test/UVSphereTest.h +++ b/src/Primitives/Test/UVSphereTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { namespace Test { -class UVSphereTest: public Corrade::TestSuite::Tester { +class UVSphereTest: public Corrade::TestSuite::Tester { public: UVSphereTest(); diff --git a/src/Profiler.cpp b/src/Profiler.cpp index dcede5b73..8e4178fcf 100644 --- a/src/Profiler.cpp +++ b/src/Profiler.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include using namespace std; diff --git a/src/Resource.h b/src/Resource.h index 33085cb7c..b4abf8196 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -19,6 +19,7 @@ * @brief Class Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState */ +#include #include #include "Magnum.h" diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 6ff5cd9c7..914b4dd0c 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include "SceneGraph.h" diff --git a/src/SceneGraph/Test/CameraTest.h b/src/SceneGraph/Test/CameraTest.h index 1a9ab9198..b43ec879b 100644 --- a/src/SceneGraph/Test/CameraTest.h +++ b/src/SceneGraph/Test/CameraTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace SceneGraph { namespace Test { -class CameraTest: public Corrade::TestSuite::Tester { +class CameraTest: public Corrade::TestSuite::Tester { public: CameraTest(); diff --git a/src/SceneGraph/Test/ObjectTest.h b/src/SceneGraph/Test/ObjectTest.h index 7a04a1bd5..0c2e594d9 100644 --- a/src/SceneGraph/Test/ObjectTest.h +++ b/src/SceneGraph/Test/ObjectTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace SceneGraph { namespace Test { -class ObjectTest: public Corrade::TestSuite::Tester { +class ObjectTest: public Corrade::TestSuite::Tester { public: ObjectTest(); diff --git a/src/SceneGraph/Test/SceneTest.h b/src/SceneGraph/Test/SceneTest.h index 6d1af5c9b..93aef48a7 100644 --- a/src/SceneGraph/Test/SceneTest.h +++ b/src/SceneGraph/Test/SceneTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace SceneGraph { namespace Test { -class SceneTest: public Corrade::TestSuite::Tester { +class SceneTest: public Corrade::TestSuite::Tester { public: SceneTest(); diff --git a/src/Shader.cpp b/src/Shader.cpp index 5695b383a..c23d66adf 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -16,7 +16,7 @@ #include "Shader.h" #include -#include +#include #define COMPILER_MESSAGE_MAX_LENGTH 1024 diff --git a/src/Test/ArrayTest.h b/src/Test/ArrayTest.h index f90059f40..eab504e9b 100644 --- a/src/Test/ArrayTest.h +++ b/src/Test/ArrayTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Test { -class ArrayTest: public Corrade::TestSuite::Tester { +class ArrayTest: public Corrade::TestSuite::Tester { public: ArrayTest(); diff --git a/src/Test/ColorTest.h b/src/Test/ColorTest.h index 172211f29..27991ea3d 100644 --- a/src/Test/ColorTest.h +++ b/src/Test/ColorTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Test { -class ColorTest: public Corrade::TestSuite::Tester { +class ColorTest: public Corrade::TestSuite::Tester { public: ColorTest(); diff --git a/src/Test/MeshTest.h b/src/Test/MeshTest.h index 051488fbf..4b40a3f69 100644 --- a/src/Test/MeshTest.h +++ b/src/Test/MeshTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Test { -class MeshTest: public Corrade::TestSuite::Tester { +class MeshTest: public Corrade::TestSuite::Tester { public: MeshTest(); diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index fa95ec724..35aa5aa0a 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Test { -class ResourceManagerTest: public Corrade::TestSuite::Tester { +class ResourceManagerTest: public Corrade::TestSuite::Tester { public: ResourceManagerTest(); diff --git a/src/Test/SwizzleTest.h b/src/Test/SwizzleTest.h index 56a705f5d..d9b581517 100644 --- a/src/Test/SwizzleTest.h +++ b/src/Test/SwizzleTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Test { -class SwizzleTest: public Corrade::TestSuite::Tester { +class SwizzleTest: public Corrade::TestSuite::Tester { public: SwizzleTest(); diff --git a/src/Test/TypeTraitsTest.h b/src/Test/TypeTraitsTest.h index 2f634f50c..d39a42265 100644 --- a/src/Test/TypeTraitsTest.h +++ b/src/Test/TypeTraitsTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Test { -class TypeTraitsTest: public Corrade::TestSuite::Tester { +class TypeTraitsTest: public Corrade::TestSuite::Tester { public: TypeTraitsTest(); From 508200d99e3b405a35b5150f6213a5b9a0f44e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Dec 2012 20:49:49 +0100 Subject: [PATCH 011/567] Updated FindCorrade.cmake from Corrade repository. --- modules/FindCorrade.cmake | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index 6c196f700..528927df0 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -5,6 +5,8 @@ # This module tries to find Corrade library and then defines: # CORRADE_FOUND - True if Corrade library is found # CORRADE_INCLUDE_DIR - Include dir for Corrade +# CORRADE_INTERCONNECT_LIBRARIES - Corrade Interconnect library and +# dependent libraries # CORRADE_UTILITY_LIBRARIES - Corrade Utility library and dependent # libraries # CORRADE_PLUGINMANAGER_LIBRARIES - Corrade Plugin manager library and @@ -23,39 +25,15 @@ # # # Add unit test using Corrade's TestSuite. -# corrade_add_test2(test_name -# sources... -# [LIBRARIES libraries...]) +# corrade_add_test(test_name +# sources... +# [LIBRARIES libraries...]) # Test name is also executable name. You can also specify libraries to link # with instead of using target_link_libraries(). CORRADE_TESTSUITE_LIBRARIES # are linked atuomatically to each test. Note that the enable_testing() # function must be called explicitly. # # -# Add QtTest unit test. -# corrade_add_test(test_name moc_header source_file -# [libraries...]) -# These tests contain mainly from one source file and one header, which is -# processed by Qt meta-object compiler. The executable is then linked to QtCore -# and QtTest library, more libraries can be specified as another parameters. -# Test name is also executable name. Header file is processed with Qt's moc. -# -# Note: Before using this function you must find package Qt4. The -# enable_testing() function must be also called explicitly. -# -# -# Add QtTest unit test with multiple source files. -# corrade_add_multifile_test(test_name -# moc_header_variable -# source_files_variable) -# Useful when there is need to compile more than one cpp/h file into the test. -# -# Example usage: -# set(test_headers ComplexTest.h MyObject.h) -# set(test_sources ComplexTest.cpp MyObject.cpp) -# corrade_add_test(MyComplexTest test_headers test_sources -# CoreLibrary AnotherLibrary) -# # Compile data resources into application binary. # corrade_add_resource(name group_name # file [ALIAS alias] @@ -107,6 +85,7 @@ # # Libraries +find_library(CORRADE_INTERCONNECT_LIBRARY CorradeInterconnect) find_library(CORRADE_UTILITY_LIBRARY CorradeUtility) find_library(CORRADE_PLUGINMANAGER_LIBRARY CorradePluginManager) find_library(CORRADE_TESTSUITE_LIBRARY CorradeTestSuite) @@ -122,6 +101,7 @@ find_path(CORRADE_INCLUDE_DIR include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Corrade DEFAULT_MSG CORRADE_UTILITY_LIBRARY + CORRADE_INTERCONNECT_LIBRARY CORRADE_PLUGINMANAGER_LIBRARY CORRADE_TESTSUITE_LIBRARY CORRADE_INCLUDE_DIR @@ -141,6 +121,7 @@ if(NOT _GCC46_COMPATIBILITY EQUAL -1) endif() set(CORRADE_UTILITY_LIBRARIES ${CORRADE_UTILITY_LIBRARY}) +set(CORRADE_INTERCONNECT_LIBRARIES ${CORRADE_INTERCONNECT_LIBRARY} ${CORRADE_UTILITY_LIBRARIES}) set(CORRADE_PLUGINMANAGER_LIBRARIES ${CORRADE_PLUGINMANAGER_LIBRARY} ${CORRADE_UTILITY_LIBRARIES}) set(CORRADE_TESTSUITE_LIBRARIES ${CORRADE_TESTSUITE_LIBRARY} ${CORRADE_UTILITY_LIBRARIES}) mark_as_advanced(CORRADE_UTILITY_LIBRARY CORRADE_PLUGINMANAGER_LIBRARY CORRADE_TESTSUITE_LIBRARY) From c319962d6eb7ba6b38b4d093665ea3ad20d11549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Dec 2012 20:50:48 +0100 Subject: [PATCH 012/567] Adapted to Corrade changes. --- src/Math/Algorithms/Test/CMakeLists.txt | 2 +- src/Math/Geometry/Test/CMakeLists.txt | 4 ++-- src/Math/Test/CMakeLists.txt | 26 ++++++++++++------------- src/MeshTools/Test/CMakeLists.txt | 16 +++++++-------- src/Physics/Test/CMakeLists.txt | 20 +++++++++---------- src/Primitives/Test/CMakeLists.txt | 6 +++--- src/SceneGraph/Test/CMakeLists.txt | 6 +++--- src/Test/CMakeLists.txt | 12 ++++++------ 8 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Math/Algorithms/Test/CMakeLists.txt b/src/Math/Algorithms/Test/CMakeLists.txt index 41e1779f2..88eb779c5 100644 --- a/src/Math/Algorithms/Test/CMakeLists.txt +++ b/src/Math/Algorithms/Test/CMakeLists.txt @@ -1 +1 @@ -corrade_add_test2(MathAlgorithmsGaussJordanTest GaussJordanTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathAlgorithmsGaussJordanTest GaussJordanTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Geometry/Test/CMakeLists.txt b/src/Math/Geometry/Test/CMakeLists.txt index eb7810334..7d6dcfa93 100644 --- a/src/Math/Geometry/Test/CMakeLists.txt +++ b/src/Math/Geometry/Test/CMakeLists.txt @@ -1,2 +1,2 @@ -corrade_add_test2(MathGeometryDistanceTest DistanceTest.cpp) -corrade_add_test2(MathGeometryIntersectionTest IntersectionTest.cpp) +corrade_add_test(MathGeometryDistanceTest DistanceTest.cpp) +corrade_add_test(MathGeometryIntersectionTest IntersectionTest.cpp) diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index c641a04a5..ad6385d3f 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -1,19 +1,19 @@ -corrade_add_test2(MathConstantsTest ConstantsTest.cpp) -corrade_add_test2(MathTest MathTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) +corrade_add_test(MathConstantsTest ConstantsTest.cpp) +corrade_add_test(MathTest MathTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) -corrade_add_test2(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathVector3Test Vector3Test.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathVector4Test Vector4Test.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathVector3Test Vector3Test.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathVector4Test Vector4Test.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathPoint2DTest Point2DTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathPoint3DTest Point3DTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathPoint2DTest Point2DTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathPoint3DTest Point3DTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathMatrixTest MatrixTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathMatrix3Test Matrix3Test.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathMatrixTest MatrixTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathMatrix3Test Matrix3Test.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) set_target_properties(MathVectorTest MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index 0a4608faf..e98374b66 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -1,12 +1,12 @@ -corrade_add_test2(MeshToolsCleanTest CleanTest.cpp) -corrade_add_test2(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp) -corrade_add_test2(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshTools) -corrade_add_test2(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) -corrade_add_test2(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) -corrade_add_test2(MeshToolsInterleaveTest InterleaveTest.cpp) -corrade_add_test2(MeshToolsSubdivideTest SubdivideTest.cpp) +corrade_add_test(MeshToolsCleanTest CleanTest.cpp) +corrade_add_test(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp) +corrade_add_test(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshTools) +corrade_add_test(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) +corrade_add_test(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib) +corrade_add_test(MeshToolsInterleaveTest InterleaveTest.cpp) +corrade_add_test(MeshToolsSubdivideTest SubdivideTest.cpp) # corrade_add_test(MeshToolsSubdivideCleanBenchmark SubdivideCleanBenchmark.h SubdivideCleanBenchmark.cpp MagnumPrimitives) -corrade_add_test2(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools) +corrade_add_test(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools) # Graceful assert for testing set_target_properties(MeshToolsCombineIndexedArraysTest MeshToolsInterleaveTest MeshToolsSubdivideTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Physics/Test/CMakeLists.txt b/src/Physics/Test/CMakeLists.txt index 5c6c5f2a5..4477fdda6 100644 --- a/src/Physics/Test/CMakeLists.txt +++ b/src/Physics/Test/CMakeLists.txt @@ -1,11 +1,11 @@ -corrade_add_test2(PhysicsAbstractShapeTest AbstractShapeTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsPointTest PointTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsShapeGroupTest ShapeGroupTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsSphereTest SphereTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsAbstractShapeTest AbstractShapeTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsPointTest PointTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsShapeGroupTest ShapeGroupTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsSphereTest SphereTest.cpp LIBRARIES MagnumPhysics) -corrade_add_test2(PhysicsObjectShapeTest ObjectShapeTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test(PhysicsObjectShapeTest ObjectShapeTest.cpp LIBRARIES MagnumPhysics) diff --git a/src/Primitives/Test/CMakeLists.txt b/src/Primitives/Test/CMakeLists.txt index c8374ccd0..cf9d61c75 100644 --- a/src/Primitives/Test/CMakeLists.txt +++ b/src/Primitives/Test/CMakeLists.txt @@ -1,3 +1,3 @@ -corrade_add_test2(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitives) -corrade_add_test2(PrimitivesUVSphereTest UVSphereTest.cpp LIBRARIES MagnumPrimitives) -corrade_add_test2(PrimitivesCylinderTest CylinderTest.cpp LIBRARIES MagnumPrimitives) +corrade_add_test(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitives) +corrade_add_test(PrimitivesUVSphereTest UVSphereTest.cpp LIBRARIES MagnumPrimitives) +corrade_add_test(PrimitivesCylinderTest CylinderTest.cpp LIBRARIES MagnumPrimitives) diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index e0db0910d..eef3c02cb 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -1,3 +1,3 @@ -corrade_add_test2(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) -corrade_add_test2(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) -corrade_add_test2(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) +corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 68ebd975e..743268bed 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,8 +1,8 @@ -corrade_add_test2(ArrayTest ArrayTest.cpp) -corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(MeshTest MeshTest.cpp LIBRARIES Magnum) -corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) -corrade_add_test2(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum) +corrade_add_test(ArrayTest ArrayTest.cpp) +corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) +corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) +corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum) set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) From 0f889369f4b12d37f6bda9e8b982fb928bd0219f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Dec 2012 23:19:52 +0100 Subject: [PATCH 013/567] No `using namespace std` anywhere. Also added missing std:: prefix to remaining cases of std::size_t, std::[u]int[0-9]+_t, std::sin() etc., std::exit(). --- src/AbstractImage.cpp | 6 +- src/AbstractShaderProgram.cpp | 4 +- src/AbstractShaderProgram.h | 16 +++--- src/Color.h | 4 +- src/Context.cpp | 18 +++--- src/Context.h | 4 +- src/Math/Geometry/Test/DistanceTest.cpp | 2 - src/Math/Geometry/Test/IntersectionTest.cpp | 6 +- src/Math/Math.cpp | 4 +- src/Math/Math.h | 2 +- src/Math/Test/MathTest.cpp | 56 +++++++++---------- src/Math/Test/MathTypeTraitsTest.cpp | 18 +++--- src/Math/Test/Matrix3Test.cpp | 7 +-- src/Math/Test/Matrix4Test.cpp | 9 ++- src/Math/Test/MatrixTest.cpp | 11 ++-- src/Math/Test/Point2DTest.cpp | 7 +-- src/Math/Test/Point3DTest.cpp | 7 +-- src/Math/Test/RectangularMatrixTest.cpp | 21 ++++--- src/Math/Test/Vector2Test.cpp | 7 +-- src/Math/Test/Vector3Test.cpp | 7 +-- src/Math/Test/Vector4Test.cpp | 7 +-- src/Math/Test/VectorTest.cpp | 13 ++--- src/Mesh.cpp | 2 - src/MeshTools/CompressIndices.cpp | 10 ++-- src/MeshTools/FlipNormals.cpp | 10 ++-- src/MeshTools/GenerateFlatNormals.cpp | 14 ++--- src/MeshTools/Test/CleanTest.cpp | 10 ++-- .../Test/CombineIndexedArraysTest.cpp | 38 ++++++------- src/MeshTools/Test/CompressIndicesTest.cpp | 39 +++++++------ src/MeshTools/Test/FlipNormalsTest.cpp | 26 ++++----- .../Test/GenerateFlatNormalsTest.cpp | 20 +++---- src/MeshTools/Test/InterleaveTest.cpp | 41 +++++++------- src/MeshTools/Test/SubdivideTest.cpp | 16 +++--- src/MeshTools/Test/TipsifyTest.cpp | 12 ++-- src/MeshTools/Tipsify.cpp | 40 +++++++------ src/Physics/ObjectShape.cpp | 10 ++-- src/Physics/Plane.cpp | 3 +- src/Physics/Test/ShapeGroupTest.cpp | 4 +- src/Platform/AbstractXApplication.cpp | 4 +- src/Platform/EglContextHandler.cpp | 14 ++--- src/Platform/ExtensionWrangler.cpp | 2 +- src/Platform/GlxContextHandler.cpp | 6 +- src/Platform/NaClApplication.cpp | 8 +-- src/Platform/Sdl2Application.cpp | 4 +- src/Primitives/Capsule.cpp | 52 +++++++++-------- src/Primitives/Cube.cpp | 6 +- src/Primitives/Cylinder.cpp | 8 +-- src/Primitives/Icosphere.cpp | 6 +- src/Primitives/Plane.cpp | 6 +- src/Primitives/Square.cpp | 4 +- src/Primitives/Test/CapsuleTest.cpp | 13 ++--- src/Primitives/Test/CylinderTest.cpp | 15 +++-- src/Primitives/Test/UVSphereTest.cpp | 13 ++--- src/Primitives/UVSphere.cpp | 6 +- src/Profiler.cpp | 36 ++++++------ src/SceneGraph/Test/ObjectTest.cpp | 26 ++++----- src/Shader.cpp | 12 ++-- src/Test/ColorTest.cpp | 20 +++---- src/Test/ResourceManagerTest.cpp | 21 ++++--- src/Test/SwizzleTest.cpp | 40 +++++++------ src/Trade/AbstractImporter.cpp | 1 - src/TypeTraits.cpp | 22 ++++---- 62 files changed, 394 insertions(+), 482 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 84b2b82eb..00e2fcbd8 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -19,12 +19,10 @@ #include "TypeTraits.h" -using namespace std; - namespace Magnum { -size_t AbstractImage::pixelSize(Components format, ComponentType type) { - size_t size = 0; +std::size_t AbstractImage::pixelSize(Components format, ComponentType type) { + std::size_t size = 0; switch(type) { #ifndef MAGNUM_TARGET_GLES case ComponentType::RGB332: diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index cb181b9b4..7fe59d747 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -25,8 +25,6 @@ #define LINKER_MESSAGE_MAX_LENGTH 1024 -using namespace std; - namespace Magnum { AbstractShaderProgram::Uniform1fImplementation AbstractShaderProgram::uniform1fImplementation = &AbstractShaderProgram::uniformImplementationDefault; @@ -108,7 +106,7 @@ bool AbstractShaderProgram::attachShader(Shader& shader) { return true; } -void AbstractShaderProgram::bindAttributeLocation(GLuint location, const string& name) { +void AbstractShaderProgram::bindAttributeLocation(GLuint location, const std::string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: attribute cannot be bound after linking.", ); glBindAttribLocation(_id, location, name.c_str()); diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 53a383d1a..4f506270a 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1095,17 +1095,17 @@ template<> struct Attribute { CORRADE_ENUMSET_OPERATORS(Attribute::DataOptions) -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size(DataOptions) { return vectorSize; } inline constexpr static std::size_t vectorCount() { return 1; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size(DataOptions) { return rows; } inline constexpr static std::size_t vectorCount() { return cols; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size(DataOptions) { return matrixSize; } inline constexpr static std::size_t vectorCount() { return matrixSize; } }; @@ -1192,11 +1192,11 @@ template<> struct Attribute { inline constexpr static GLint size() { return 1; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size() { return size; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size() { return size; } }; @@ -1216,17 +1216,17 @@ template<> struct Attribute { inline constexpr static std::size_t vectorCount() { return 1; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size() { return rows; } inline constexpr static std::size_t vectorCount() { return cols; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size() { return size; } inline constexpr static std::size_t vectorCount() { return size; } }; -template struct Attribute>: public Attribute { +template struct Attribute>: public Attribute { inline constexpr static GLint size() { return size; } inline constexpr static std::size_t vectorCount() { return size; } }; diff --git a/src/Color.h b/src/Color.h index 300fa549a..54eac2a1c 100644 --- a/src/Color.h +++ b/src/Color.h @@ -167,7 +167,7 @@ class Color3: public Math::Vector3 { * @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 `uint8_t`. + * `{75, 115, 224}`, if resulting type is `std::uint8_t`. * * @note This function is enabled only if source type is floating-point * and destination type is integral. @@ -182,7 +182,7 @@ class Color3: public Math::Vector3 { * @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 `uint8_t`. + * `{0.294118, 0.45098, 0.878431}`, if source type is `std::uint8_t`. * * @note This function is enabled only if source type is integral * and destination type is floating-point. diff --git a/src/Context.cpp b/src/Context.cpp index 8b43039bb..28f49000c 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -30,8 +30,6 @@ #include "Implementation/State.h" #include "DebugMarker.h" -using namespace std; - namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -202,7 +200,7 @@ Context::Context() { _version = static_cast(_majorVersion*100+_minorVersion*10); /* Get first future (not supported) version */ - vector versions{ + std::vector versions{ #ifndef MAGNUM_TARGET_GLES Version::GL300, Version::GL310, @@ -218,17 +216,17 @@ Context::Context() { #endif Version::None }; - size_t future = 0; + std::size_t future = 0; while(versions[future] != Version::None && !isVersionSupported(_version)) ++future; /* List of extensions from future versions (extensions from current and previous versions should be supported automatically, so we don't need to check for them) */ - unordered_map futureExtensions; - for(size_t i = future; i != versions.size(); ++i) + std::unordered_map futureExtensions; + for(std::size_t i = future; i != versions.size(); ++i) for(const Extension& extension: Extension::extensions(versions[i])) - futureExtensions.insert(make_pair(extension._string, extension)); + futureExtensions.insert(std::make_pair(extension._string, extension)); /* Check for presence of extensions in future versions */ #ifndef MAGNUM_TARGET_GLES @@ -253,8 +251,8 @@ Context::Context() { /* Don't crash when glGetString() returns nullptr */ const char* e = reinterpret_cast(glGetString(GL_EXTENSIONS)); if(e) { - vector extensions = Corrade::Utility::String::split(e, ' '); - for(const string& extension: extensions) { + std::vector extensions = Corrade::Utility::String::split(e, ' '); + for(const std::string& extension: extensions) { auto found = futureExtensions.find(extension); if(found != futureExtensions.end()) { _supportedExtensions.push_back(found->second); @@ -289,7 +287,7 @@ Context::~Context() { _current = nullptr; } -Version Context::supportedVersion(initializer_list versions) const { +Version Context::supportedVersion(std::initializer_list versions) const { for(auto version: versions) if(isVersionSupported(version)) return version; diff --git a/src/Context.h b/src/Context.h index 5704762ab..ea6172e31 100644 --- a/src/Context.h +++ b/src/Context.h @@ -318,7 +318,7 @@ MAGNUM_ASSERT_VERSION_SUPPORTED(Version::GL330); do { \ if(!Context::current()->isVersionSupported(version)) { \ Corrade::Utility::Error() << "Magnum: required version" << version << "is not supported"; \ - exit(-3); \ + std::exit(-3); \ } \ } while(0) #endif @@ -348,7 +348,7 @@ MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4); do { \ if(!Context::current()->isExtensionSupported()) { \ Corrade::Utility::Error() << "Magnum: required extension" << extension::string() << "is not supported"; \ - exit(-3); \ + std::exit(-3); \ } \ } while(0) #endif diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index ace9c485a..79de37345 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -22,8 +22,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::DistanceTest) -using namespace std; - namespace Magnum { namespace Math { namespace Geometry { namespace Test { typedef Magnum::Math::Vector2 Vector2; diff --git a/src/Math/Geometry/Test/IntersectionTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp index 5112b5e84..c19591be8 100644 --- a/src/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -21,8 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::IntersectionTest) -using namespace std; - namespace Magnum { namespace Math { namespace Geometry { namespace Test { typedef Magnum::Math::Vector3 Vector3; @@ -45,11 +43,11 @@ void IntersectionTest::planeLine() { /* Line lies on the plane */ CORRADE_COMPARE(Intersection::planeLine(planePosition, planeNormal, - Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)), numeric_limits::quiet_NaN()); + Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)), std::numeric_limits::quiet_NaN()); /* Line is parallell to the plane */ CORRADE_COMPARE((Intersection::planeLine(planePosition, planeNormal, - Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), -numeric_limits::infinity()); + Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), -std::numeric_limits::infinity()); } }}}} diff --git a/src/Math/Math.cpp b/src/Math/Math.cpp index ec39d403d..7e432040f 100644 --- a/src/Math/Math.cpp +++ b/src/Math/Math.cpp @@ -15,12 +15,10 @@ #include "Math.h" -using namespace std; - namespace Magnum { namespace Math { std::uint32_t log(std::uint32_t base, std::uint32_t number) { - uint32_t log = 0; + std::uint32_t log = 0; while(number /= base) ++log; return log; diff --git a/src/Math/Math.h b/src/Math/Math.h index a11f3c142..5d68b2e2d 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -78,7 +78,7 @@ explicit, e.g.: float a = normalize('\127'); // b = 1.0f -float b = normalize('\127'); +float b = normalize('\127'); @endcode @todo Signed normalization to [-1.0, 1.0] like in OpenGL? diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 3aa7348ed..424e470cc 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -17,8 +17,6 @@ #include "Math.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) namespace Magnum { namespace Math { namespace Test { @@ -33,46 +31,46 @@ MathTest::MathTest() { void MathTest::normalize() { /* Range for signed and unsigned */ - CORRADE_COMPARE((Math::normalize(-128)), 0.0f); - CORRADE_COMPARE((Math::normalize(127)), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(255)), 1.0f); + CORRADE_COMPARE((Math::normalize(-128)), 0.0f); + CORRADE_COMPARE((Math::normalize(127)), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(255)), 1.0f); /* Between */ - CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); - CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); + CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); + CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); /* Test overflow for large types */ - CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0f); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); - - CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), 0.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + + CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), 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); } void MathTest::denormalize() { /* Range for signed and unsigned */ - CORRADE_COMPARE(Math::denormalize(0.0f), -128); - CORRADE_COMPARE(Math::denormalize(1.0f), 127); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 255); + CORRADE_COMPARE(Math::denormalize(0.0f), -128); + CORRADE_COMPARE(Math::denormalize(1.0f), 127); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), 255); /* Between */ - CORRADE_COMPARE(Math::denormalize(0.33f), -11141); - CORRADE_COMPARE(Math::denormalize(0.66f), 10485); + CORRADE_COMPARE(Math::denormalize(0.33f), -11141); + CORRADE_COMPARE(Math::denormalize(0.66f), 10485); /* Test overflow for large types */ - CORRADE_COMPARE(Math::denormalize(0.0f), numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(0.0), numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0), 0); + CORRADE_COMPARE(Math::denormalize(0.0f), std::numeric_limits::min()); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(0.0), std::numeric_limits::min()); + CORRADE_COMPARE(Math::denormalize(0.0), 0); - CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); - CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); // { // CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index cae312032..e2d08dd1c 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -21,8 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) -using namespace std; - namespace Magnum { namespace Math { namespace Test { MathTypeTraitsTest::MathTypeTraitsTest() { @@ -31,14 +29,14 @@ MathTypeTraitsTest::MathTypeTraitsTest() { } void MathTypeTraitsTest::equalsIntegral() { - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); } void MathTypeTraitsTest::equalsFloatingPoint() { diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index e25c020b0..107d61494 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -22,7 +22,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Test) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -140,7 +139,7 @@ void Matrix3Test::debug() { 7.0f, -1.0f, 8.0f ); - ostringstream o; + std::ostringstream o; Debug(&o) << m; CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7,\n" " 5, 4, -1,\n" @@ -155,10 +154,10 @@ void Matrix3Test::configuration() { 4.0f, 7.0f, 3.125f, 4.0f, 5.0f, 9.55f ); - string value("5 4 4 8 7 5 4 3.125 9.55"); + std::string value("5 4 4 8 7 5 4 3.125 9.55"); c.setValue("matrix", m); - CORRADE_COMPARE(c.value("matrix"), value); + CORRADE_COMPARE(c.value("matrix"), value); CORRADE_COMPARE(c.value("matrix"), m); } diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 7ecac7095..5b2ed7a1b 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -22,7 +22,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix4Test) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -93,7 +92,7 @@ void Matrix4Test::scaling() { } void Matrix4Test::rotation() { - ostringstream o; + std::ostringstream o; Error::setOutput(&o); CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); @@ -190,7 +189,7 @@ void Matrix4Test::debug() { 9.0f, 4.0f, 5.0f, 9.0f ); - ostringstream o; + std::ostringstream o; Debug(&o) << m; CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7, 9,\n" " 5, 4, -1, 4,\n" @@ -207,10 +206,10 @@ void Matrix4Test::configuration() { 7.0f, -1.0f, 8.0f, 0.0f, 9.0f, 4.0f, 5.0f, 9.55f ); - string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); + std::string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); c.setValue("matrix", m); - CORRADE_COMPARE(c.value("matrix"), value); + CORRADE_COMPARE(c.value("matrix"), value); CORRADE_COMPARE(c.value("matrix"), m); } diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index cc902f199..924ac0afe 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::MatrixTest) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -98,7 +97,7 @@ void MatrixTest::constructZero() { } void MatrixTest::trace() { - Matrix<5, int32_t> m( + Matrix<5, std::int32_t> m( 1, 2, 3, 0, 0, 2, 3, 2, 1, -2, 1, 1, -20, 1, 0, @@ -127,7 +126,7 @@ void MatrixTest::ij() { } void MatrixTest::determinant() { - Matrix<5, int32_t> m( + Matrix<5, std::int32_t> m( 1, 2, 2, 1, 0, 2, 3, 2, 1, -2, 1, 1, 1, 1, 0, @@ -167,7 +166,7 @@ void MatrixTest::debug() { 9.0f, 4.0f, 5.0f, 9.0f ); - ostringstream o; + std::ostringstream o; Debug(&o) << m; CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7, 9,\n" " 5, 4, -1, 4,\n" @@ -194,10 +193,10 @@ void MatrixTest::configuration() { 7.0f, -1.0f, 8.0f, 0.0f, 9.0f, 4.0f, 5.0f, 9.55f ); - string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); + std::string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); c.setValue("matrix", m); - CORRADE_COMPARE(c.value("matrix"), value); + CORRADE_COMPARE(c.value("matrix"), value); CORRADE_COMPARE(c.value("matrix"), m); } diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp index 63a93c345..0ad2c4dae 100644 --- a/src/Math/Test/Point2DTest.cpp +++ b/src/Math/Test/Point2DTest.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -41,7 +40,7 @@ void Point2DTest::construct() { } void Point2DTest::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Point2D(0.5f, 15.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n"); } @@ -50,10 +49,10 @@ void Point2DTest::configuration() { Configuration c; Point2D vec(3.0f, 3.125f, 9.55f); - string value("3 3.125 9.55"); + std::string value("3 3.125 9.55"); c.setValue("point", vec); - CORRADE_COMPARE(c.value("point"), value); + CORRADE_COMPARE(c.value("point"), value); CORRADE_COMPARE(c.value("point"), vec); } diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp index e4f24920f..9293b7881 100644 --- a/src/Math/Test/Point3DTest.cpp +++ b/src/Math/Test/Point3DTest.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -41,7 +40,7 @@ void Point3DTest::construct() { } void Point3DTest::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Point3D(0.5f, 15.0f, 1.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n"); } @@ -50,10 +49,10 @@ void Point3DTest::configuration() { Configuration c; Point3D vec(3.0f, 3.125f, 9.0f, 9.55f); - string value("3 3.125 9 9.55"); + std::string value("3 3.125 9 9.55"); c.setValue("point", vec); - CORRADE_COMPARE(c.value("point"), value); + CORRADE_COMPARE(c.value("point"), value); CORRADE_COMPARE(c.value("point"), vec); } diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 344e2fcd1..adb989de0 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::RectangularMatrixTest) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -29,7 +28,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, int32_t> Matrix2i; +typedef RectangularMatrix<2, 2, std::int32_t> Matrix2i; typedef Vector<4, float> Vector4; RectangularMatrixTest::RectangularMatrixTest() { @@ -154,8 +153,8 @@ void RectangularMatrixTest::multiplyDivide() { CORRADE_COMPARE(-1.5f*vec, multiplied); CORRADE_COMPARE(multiplied/-1.5f, vec); - Math::RectangularMatrix<1, 1, int8_t> vecChar(32); - Math::RectangularMatrix<1, 1, int8_t> multipliedChar(-48); + Math::RectangularMatrix<1, 1, std::int8_t> vecChar(32); + Math::RectangularMatrix<1, 1, std::int8_t> multipliedChar(-48); CORRADE_COMPARE(vecChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, vecChar); CORRADE_COMPARE(-1.5f*vecChar, multipliedChar); @@ -168,14 +167,14 @@ void RectangularMatrixTest::multiplyDivide() { } void RectangularMatrixTest::multiply() { - RectangularMatrix<4, 6, int32_t> left( + RectangularMatrix<4, 6, std::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, int32_t> right( + RectangularMatrix<5, 4, std::int32_t> right( 1, -7, 0, 158, 2, 24, -3, 40, 3, -15, -2, -50, @@ -183,7 +182,7 @@ void RectangularMatrixTest::multiply() { 5, 30, 4, 18 ); - RectangularMatrix<5, 6, int32_t> expected( + RectangularMatrix<5, 6, std::int32_t> expected( 1368, -16165, 2550, -7716, 158, 1575, 506, -2725, 2352, -1870, 37, -234, -578, 4159, -1918, 2534, -52, -127, @@ -218,7 +217,7 @@ void RectangularMatrixTest::debug() { 7.0f, -1.0f, 8.0f, 0.0f ); - ostringstream o; + std::ostringstream o; Debug(&o) << m; CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7,\n" " 5, 4, -1,\n" @@ -226,7 +225,7 @@ void RectangularMatrixTest::debug() { " 4, 3, 0)\n"); o.str(""); - Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, int8_t>(); + Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, std::int8_t>(); CORRADE_COMPARE(o.str(), "a Matrix(0, 0, 0,\n" " 0, 0, 0,\n" " 0, 0, 0,\n" @@ -241,12 +240,12 @@ void RectangularMatrixTest::configuration() { 4.0f, 4.0f, 7.0f, 3.125f, 7.0f, -1.0f, 8.0f, 9.55f ); - string value("3 4 7 5 4 -1 8 7 8 4 3.125 9.55"); + std::string value("3 4 7 5 4 -1 8 7 8 4 3.125 9.55"); Configuration c; c.setValue("matrix", m); - CORRADE_COMPARE(c.value("matrix"), value); + CORRADE_COMPARE(c.value("matrix"), value); CORRADE_COMPARE(c.value("matrix"), m); } diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index a5ec5b443..316094de0 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Vector2Test) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -62,7 +61,7 @@ void Vector2Test::scales() { } void Vector2Test::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Vector2(0.5f, 15.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15)\n"); } @@ -71,10 +70,10 @@ void Vector2Test::configuration() { Configuration c; Vector2 vec(3.125f, 9.0f); - string value("3.125 9"); + std::string value("3.125 9"); c.setValue("vector", vec); - CORRADE_COMPARE(c.value("vector"), value); + CORRADE_COMPARE(c.value("vector"), value); CORRADE_COMPARE(c.value("vector"), vec); } diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index ea2f3409a..51b31437f 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Vector3Test) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -82,7 +81,7 @@ void Vector3Test::twoComponent() { } void Vector3Test::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Vector3(0.5f, 15.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n"); } @@ -91,10 +90,10 @@ void Vector3Test::configuration() { Configuration c; Vector3 vec(3.0f, 3.125f, 9.55f); - string value("3 3.125 9.55"); + std::string value("3 3.125 9.55"); c.setValue("vector", vec); - CORRADE_COMPARE(c.value("vector"), value); + CORRADE_COMPARE(c.value("vector"), value); CORRADE_COMPARE(c.value("vector"), vec); } diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index 04f93d1e5..e8f40f4ae 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::Vector4Test) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -68,7 +67,7 @@ void Vector4Test::twoComponent() { } void Vector4Test::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n"); } @@ -77,10 +76,10 @@ void Vector4Test::configuration() { Configuration c; Vector4 vec(3.0f, 3.125f, 9.0f, 9.55f); - string value("3 3.125 9 9.55"); + std::string value("3 3.125 9 9.55"); c.setValue("vector", vec); - CORRADE_COMPARE(c.value("vector"), value); + CORRADE_COMPARE(c.value("vector"), value); CORRADE_COMPARE(c.value("vector"), vec); } diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index f9a86cc62..99486230f 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -22,7 +22,6 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::VectorTest) -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { @@ -110,18 +109,18 @@ void VectorTest::max() { } void VectorTest::angle() { - ostringstream o; + std::ostringstream o; Error::setOutput(&o); /* Both vectors must be normalized, otherwise NaN is returned */ - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), numeric_limits::quiet_NaN()); + CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); - CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), numeric_limits::quiet_NaN()); + CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), Vector3(1.0f, -2.0f, 3.0f).normalized()), rad(1.162514f)); } void VectorTest::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n"); @@ -134,10 +133,10 @@ void VectorTest::configuration() { Configuration c; Vector4 vec(3.0f, 3.125f, 9.0f, 9.55f); - string value("3 3.125 9 9.55"); + std::string value("3 3.125 9 9.55"); c.setValue("vector", vec); - CORRADE_COMPARE(c.value("vector"), value); + CORRADE_COMPARE(c.value("vector"), value); CORRADE_COMPARE(c.value("vector"), vec); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 621642dd1..67260b7cf 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -23,8 +23,6 @@ #include "Implementation/MeshState.h" #include "Implementation/State.h" -using namespace std; - namespace Magnum { Mesh::CreateImplementation Mesh::createImplementation = &Mesh::createImplementationDefault; diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index e3e53b674..af2a53e93 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -22,19 +22,17 @@ #include "IndexedMesh.h" #include "SizeTraits.h" -using namespace std; - namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -std::tuple CompressIndices::operator()() const { +std::tuple CompressIndices::operator()() const { return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); } void CompressIndices::operator()(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage) const { - size_t indexCount; + std::size_t indexCount; Type indexType; char* data; std::tie(indexCount, indexType, data) = operator()(); @@ -47,10 +45,10 @@ void CompressIndices::operator()(IndexedMesh* mesh, Buffer* buffer, Buffer::Usag delete[] data; } -template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { +template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { /* Create smallest possible version of index buffer */ char* buffer = new char[indices.size()*sizeof(IndexType)]; - for(size_t i = 0; i != indices.size(); ++i) { + for(std::size_t i = 0; i != indices.size(); ++i) { IndexType index = indices[i]; memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); } diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index f34304fa1..596dfb4a3 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -17,18 +17,16 @@ #include "Math/Vector3.h" -using namespace std; - namespace Magnum { namespace MeshTools { -void flipFaceWinding(vector& indices) { +void flipFaceWinding(std::vector& indices) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); - for(size_t i = 0; i != indices.size(); i += 3) - swap(indices[i+1], indices[i+2]); + for(std::size_t i = 0; i != indices.size(); i += 3) + std::swap(indices[i+1], indices[i+2]); } -void flipNormals(vector& normals) { +void flipNormals(std::vector& normals) { for(Vector3& normal: normals) normal = -normal; } diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 918d19d68..0ea2de883 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -18,19 +18,17 @@ #include "Math/Point3D.h" #include "MeshTools/Clean.h" -using namespace std; - namespace Magnum { namespace MeshTools { -tuple, vector> generateFlatNormals(const vector& indices, const vector& positions) { - CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (tuple, vector>())); +std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { + CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple, std::vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ - vector normalIndices; + std::vector normalIndices; normalIndices.reserve(indices.size()); - vector normals; + std::vector normals; normals.reserve(indices.size()/3); - for(size_t i = 0; i != indices.size(); i += 3) { + for(std::size_t i = 0; i != indices.size(); i += 3) { Vector3 normal = Vector3::cross(positions[indices[i+2]].xyz()-positions[indices[i+1]].xyz(), positions[indices[i]].xyz()-positions[indices[i+1]].xyz()).normalized(); @@ -43,7 +41,7 @@ tuple, vector> generateFlatNormals(const vector positions{1, 2, 1, 4}; - vector indices{0, 1, 2, 1, 2, 3}; + std::vector positions{1, 2, 1, 4}; + std::vector indices{0, 1, 2, 1, 2, 3}; MeshTools::clean(indices, positions); /* Verify cleanup */ - CORRADE_VERIFY(positions == (vector{1, 2, 4})); - CORRADE_COMPARE(indices, (vector{0, 1, 0, 1, 0, 2})); + CORRADE_VERIFY(positions == (std::vector{1, 2, 4})); + CORRADE_COMPARE(indices, (std::vector{0, 1, 0, 1, 0, 2})); } }}} diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index 57211078b..b97447e68 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -21,8 +21,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CombineIndexedArraysTest) -using namespace std; - namespace Magnum { namespace MeshTools { namespace Test { CombineIndexedArraysTest::CombineIndexedArraysTest() { @@ -31,31 +29,31 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() { } void CombineIndexedArraysTest::wrongIndexCount() { - stringstream ss; + std::stringstream ss; Error::setOutput(&ss); - vector array; - vector result = MeshTools::combineIndexedArrays( - tuple&, vector&>(vector{0, 1, 0}, array), - tuple&, vector&>(vector{3, 4}, array)); + std::vector array; + std::vector result = MeshTools::combineIndexedArrays( + std::tuple&, std::vector&>(std::vector{0, 1, 0}, array), + std::tuple&, std::vector&>(std::vector{3, 4}, array)); CORRADE_COMPARE(result.size(), 0); CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n"); } void CombineIndexedArraysTest::combine() { - vector array1{ 0, 1 }; - vector array2{ 0, 1, 2, 3, 4 }; - vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; - - vector result = MeshTools::combineIndexedArrays( - tuple&, vector&>(vector{0, 1, 0}, array1), - tuple&, vector&>(vector{3, 4, 3}, array2), - tuple&, vector&>(vector{6, 7, 6}, array3)); - - CORRADE_COMPARE(result, (vector{0, 1, 0})); - CORRADE_COMPARE(array1, (vector{0, 1})); - CORRADE_COMPARE(array2, (vector{3, 4})); - CORRADE_COMPARE(array3, (vector{6, 7})); + std::vector array1{ 0, 1 }; + std::vector array2{ 0, 1, 2, 3, 4 }; + std::vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; + + std::vector result = MeshTools::combineIndexedArrays( + std::tuple&, std::vector&>(std::vector{0, 1, 0}, array1), + std::tuple&, std::vector&>(std::vector{3, 4, 3}, array2), + std::tuple&, std::vector&>(std::vector{6, 7, 6}, array3)); + + CORRADE_COMPARE(result, (std::vector{0, 1, 0})); + CORRADE_COMPARE(array1, (std::vector{0, 1})); + CORRADE_COMPARE(array2, (std::vector{3, 4})); + CORRADE_COMPARE(array3, (std::vector{6, 7})); } }}} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index f50b7ce49..7814e2872 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -21,7 +21,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CompressIndicesTest) -using namespace std; using Corrade::Utility::Endianness; namespace Magnum { namespace MeshTools { namespace Test { @@ -33,38 +32,38 @@ CompressIndicesTest::CompressIndicesTest() { } void CompressIndicesTest::compressChar() { - size_t indexCount; + std::size_t indexCount; Type indexType; char* data; - tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{1, 2, 3, 0, 4}); + std::tie(indexCount, indexType, data) = MeshTools::compressIndices( + std::vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); CORRADE_VERIFY(indexType == Type::UnsignedByte); - CORRADE_COMPARE(vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), - (vector{ 0x01, 0x02, 0x03, 0x00, 0x04 })); + CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + (std::vector{ 0x01, 0x02, 0x03, 0x00, 0x04 })); delete[] data; } void CompressIndicesTest::compressShort() { - size_t indexCount; + std::size_t indexCount; Type indexType; char* data; - tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{1, 256, 0, 5}); + std::tie(indexCount, indexType, data) = MeshTools::compressIndices( + std::vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); CORRADE_VERIFY(indexType == Type::UnsignedShort); if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), - (vector{ 0x01, 0x00, + CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + (std::vector{ 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00 })); } else { - CORRADE_COMPARE(vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), - (vector{ 0x00, 0x01, + CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + (std::vector{ 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x05 })); @@ -74,23 +73,23 @@ void CompressIndicesTest::compressShort() { } void CompressIndicesTest::compressInt() { - size_t indexCount; + std::size_t indexCount; Type indexType; char* data; - tie(indexCount, indexType, data) = MeshTools::compressIndices( - vector{65536, 3, 2}); + std::tie(indexCount, indexType, data) = MeshTools::compressIndices( + std::vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); CORRADE_VERIFY(indexType == Type::UnsignedInt); if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), - (vector{ 0x00, 0x00, 0x01, 0x00, + CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + (std::vector{ 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 })); } else { - CORRADE_COMPARE(vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), - (vector{ 0x00, 0x01, 0x00, 0x00, + CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + (std::vector{ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02 })); } diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index b900f39d5..0a693b6de 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -22,8 +22,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::FlipNormalsTest) -using namespace std; - namespace Magnum { namespace MeshTools { namespace Test { FlipNormalsTest::FlipNormalsTest() { @@ -33,33 +31,33 @@ FlipNormalsTest::FlipNormalsTest() { } void FlipNormalsTest::wrongIndexCount() { - stringstream ss; + std::stringstream ss; Error::setOutput(&ss); - vector indices{0, 1}; + std::vector indices{0, 1}; MeshTools::flipFaceWinding(indices); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); } void FlipNormalsTest::flipFaceWinding() { - vector indices{0, 1, 2, - 3, 4, 5}; + std::vector indices{0, 1, 2, + 3, 4, 5}; MeshTools::flipFaceWinding(indices); - CORRADE_COMPARE(indices, (vector{0, 2, 1, - 3, 5, 4})); + CORRADE_COMPARE(indices, (std::vector{0, 2, 1, + 3, 5, 4})); } void FlipNormalsTest::flipNormals() { - vector normals{Vector3::xAxis(), - Vector3::yAxis(), - Vector3::zAxis()}; + std::vector normals{Vector3::xAxis(), + Vector3::yAxis(), + Vector3::zAxis()}; MeshTools::flipNormals(normals); - CORRADE_COMPARE(normals, (vector{-Vector3::xAxis(), - -Vector3::yAxis(), - -Vector3::zAxis()})); + CORRADE_COMPARE(normals, (std::vector{-Vector3::xAxis(), + -Vector3::yAxis(), + -Vector3::zAxis()})); } }}} diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 8cd88d313..5f91f05d9 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -22,8 +22,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) -using namespace std; - namespace Magnum { namespace MeshTools { namespace Test { GenerateFlatNormalsTest::GenerateFlatNormalsTest() { @@ -32,11 +30,11 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() { } void GenerateFlatNormalsTest::wrongIndexCount() { - stringstream ss; + std::stringstream ss; Error::setOutput(&ss); - vector indices; - vector normals; - tie(indices, normals) = MeshTools::generateFlatNormals({ + std::vector indices; + std::vector normals; + std::tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1 }, {}); @@ -47,9 +45,9 @@ void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::generate() { /* Two vertices connected by one edge, each winded in another direction */ - vector indices; - vector normals; - tie(indices, normals) = MeshTools::generateFlatNormals({ + std::vector indices; + std::vector normals; + std::tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1, 2, 1, 2, 3 }, { @@ -59,11 +57,11 @@ void GenerateFlatNormalsTest::generate() { {1.0f, 0.0f, 0.0f} }); - CORRADE_COMPARE(indices, (vector{ + CORRADE_COMPARE(indices, (std::vector{ 0, 0, 0, 1, 1, 1 })); - CORRADE_COMPARE(normals, (vector{ + CORRADE_COMPARE(normals, (std::vector{ Vector3::zAxis(), -Vector3::zAxis() })); diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index b734ea39a..e3416b166 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -23,7 +23,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::InterleaveTest) -using namespace std; using Corrade::Utility::Endianness; namespace Magnum { namespace MeshTools { namespace Test { @@ -35,42 +34,42 @@ InterleaveTest::InterleaveTest() { } void InterleaveTest::attributeCount() { - stringstream ss; + std::stringstream ss; Error::setOutput(&ss); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, - vector{0, 1, 2, 3, 4, 5})), size_t(0)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, + std::vector{0, 1, 2, 3, 4, 5})), std::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{0, 1, 2}, - vector{3, 4, 5})), size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, + std::vector{3, 4, 5})), std::size_t(3)); } void InterleaveTest::stride() { - CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(1)); - CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(4)); - CORRADE_COMPARE((Implementation::Interleave::stride(vector(), vector())), size_t(5)); + CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(1)); + CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(4)); + CORRADE_COMPARE((Implementation::Interleave::stride(std::vector(), std::vector())), std::size_t(5)); } void InterleaveTest::write() { - size_t attributeCount; - size_t stride; + std::size_t attributeCount; + std::size_t stride; char* data; - tie(attributeCount, stride, data) = MeshTools::interleave( - vector{0, 1, 2}, - vector{3, 4, 5}, - vector{6, 7, 8}); - - CORRADE_COMPARE(attributeCount, size_t(3)); - CORRADE_COMPARE(stride, size_t(7)); - size_t size = attributeCount*stride; + std::tie(attributeCount, stride, data) = MeshTools::interleave( + std::vector{0, 1, 2}, + std::vector{3, 4, 5}, + std::vector{6, 7, 8}); + + CORRADE_COMPARE(attributeCount, std::size_t(3)); + CORRADE_COMPARE(stride, std::size_t(7)); + std::size_t size = attributeCount*stride; if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(vector(data, data+size), (vector{ + CORRADE_COMPARE(std::vector(data, data+size), (std::vector{ 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00 })); } else { - CORRADE_COMPARE(vector(data, data+size), (vector{ + CORRADE_COMPARE(std::vector(data, data+size), (std::vector{ 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08 diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 965c3ad36..33401d54d 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -22,8 +22,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::SubdivideTest) -using namespace std; - namespace Magnum { namespace MeshTools { namespace Test { SubdivideTest::SubdivideTest() { @@ -32,24 +30,24 @@ SubdivideTest::SubdivideTest() { } void SubdivideTest::wrongIndexCount() { - stringstream ss; + std::stringstream ss; Error::setOutput(&ss); - vector positions; - vector indices{0, 1}; + std::vector positions; + std::vector indices{0, 1}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n"); } void SubdivideTest::subdivide() { - vector positions{0, 2, 6, 8}; - vector indices{0, 1, 2, 1, 2, 3}; + std::vector positions{0, 2, 6, 8}; + std::vector indices{0, 1, 2, 1, 2, 3}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(indices.size(), 24); - CORRADE_VERIFY(positions == (vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); - CORRADE_COMPARE(indices, (vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); + CORRADE_VERIFY(positions == (std::vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); + CORRADE_COMPARE(indices, (std::vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); MeshTools::clean(indices, positions); diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index fc0a7c243..6138075b7 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -19,8 +19,6 @@ CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TipsifyTest) -using namespace std; - namespace Magnum { namespace MeshTools { namespace Test { /* @@ -67,10 +65,10 @@ TipsifyTest::TipsifyTest(): indices{ } void TipsifyTest::buildAdjacency() { - vector liveTriangleCount, neighborOffset, neighbors; + std::vector liveTriangleCount, neighborOffset, neighbors; Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); - CORRADE_COMPARE(liveTriangleCount, (vector{ + CORRADE_COMPARE(liveTriangleCount, (std::vector{ 1, 3, 3, 2, 4, 6, 6, 2, 2, 6, 6, 4, @@ -78,7 +76,7 @@ void TipsifyTest::buildAdjacency() { 1, 1, 1 })); - CORRADE_COMPARE(neighborOffset, (vector{ + CORRADE_COMPARE(neighborOffset, (std::vector{ 0, 1, 4, 7, 9, 13, 19, 25, 27, 29, 35, 41, @@ -86,7 +84,7 @@ void TipsifyTest::buildAdjacency() { 54, 55, 56, 57 })); - CORRADE_COMPARE(neighbors, (vector{ + CORRADE_COMPARE(neighbors, (std::vector{ 0, 0, 7, 11, 2, 7, 13, @@ -114,7 +112,7 @@ void TipsifyTest::buildAdjacency() { void TipsifyTest::tipsify() { MeshTools::tipsify(indices, vertexCount, 3); - CORRADE_COMPARE(indices, (vector{ + CORRADE_COMPARE(indices, (std::vector{ 4, 1, 0, 9, 5, 4, 1, 4, 5, diff --git a/src/MeshTools/Tipsify.cpp b/src/MeshTools/Tipsify.cpp index 7b5b6c00b..803304daf 100644 --- a/src/MeshTools/Tipsify.cpp +++ b/src/MeshTools/Tipsify.cpp @@ -17,44 +17,42 @@ #include -using namespace std; - #ifndef DOXYGEN_GENERATING_OUTPUT namespace Magnum { namespace MeshTools { namespace Implementation { -void Tipsify::operator()(size_t cacheSize) { +void Tipsify::operator()(std::size_t cacheSize) { /* Neighboring triangles for each vertex, per-vertex live triangle count */ - std::vector liveTriangleCount, neighborPosition, neighbors; + std::vector liveTriangleCount, neighborPosition, neighbors; buildAdjacency(liveTriangleCount, neighborPosition, neighbors); /* Global time, per-vertex caching timestamps, per-triangle emmited flag */ - uint32_t time = cacheSize+1; - std::vector timestamp(vertexCount); + std::uint32_t time = cacheSize+1; + std::vector timestamp(vertexCount); std::vector emitted(indices.size()/3); /* Dead-end vertex stack */ - std::stack deadEndStack; + std::stack deadEndStack; /* Output index buffer */ - std::vector outputIndices; + std::vector outputIndices; outputIndices.reserve(indices.size()); /* Starting vertex for fanning, cursor */ - uint32_t fanningVertex = 0; - uint32_t i = 0; + std::uint32_t fanningVertex = 0; + std::uint32_t i = 0; while(fanningVertex != 0xFFFFFFFFu) { /* Array with candidates for next fanning vertex (in 1-ring around fanning vertex) */ - std::vector candidates; + std::vector candidates; /* For all neighbors of fanning vertex */ - for(uint32_t ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { + for(std::uint32_t ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { /* Continue if already emitted */ if(emitted[t]) continue; emitted[t] = true; /* Write all vertices of the triangle to output buffer */ - for(uint32_t vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { + for(std::uint32_t vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { outputIndices.push_back(v); /* Add to dead end stack and candidates array */ @@ -75,15 +73,15 @@ void Tipsify::operator()(size_t cacheSize) { fanningVertex = 0xFFFFFFFFu; /* Go through candidates in 1-ring around fanning vertex */ - int32_t candidatePriority = -1; - for(uint32_t v: candidates) { + std::int32_t candidatePriority = -1; + for(std::uint32_t v: candidates) { /* Skip if it doesn't have any live triangles */ if(!liveTriangleCount[v]) continue; /* Get most fresh candidate which will still be in cache even after fanning. Every fanned triangle will generate at most two cache misses, thus 2*liveTriangleCount */ - int32_t priority = 0; + std::int32_t priority = 0; if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize) priority = time-timestamp[v]; if(priority > candidatePriority) { @@ -119,12 +117,12 @@ void Tipsify::operator()(size_t cacheSize) { std::swap(indices, outputIndices); } -void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { +void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { /* How many times is each vertex referenced == count of neighboring triangles for each vertex */ liveTriangleCount.clear(); liveTriangleCount.resize(vertexCount); - for(size_t i = 0; i != indices.size(); ++i) + for(std::size_t i = 0; i != indices.size(); ++i) ++liveTriangleCount[indices[i]]; /* Building offset array from counts. Neighbors for i-th vertex will at @@ -134,8 +132,8 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vect neighborOffset.clear(); neighborOffset.reserve(vertexCount+1); neighborOffset.push_back(0); - uint32_t sum = 0; - for(size_t i = 0; i != vertexCount; ++i) { + std::uint32_t sum = 0; + for(std::size_t i = 0; i != vertexCount; ++i) { neighborOffset.push_back(sum); sum += liveTriangleCount[i]; } @@ -144,7 +142,7 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vect positioning */ neighbors.clear(); neighbors.resize(sum); - for(size_t i = 0; i != indices.size(); ++i) + for(std::size_t i = 0; i != indices.size(); ++i) neighbors[neighborOffset[indices[i]+1]++] = i/3; } diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index 766a475a9..41469f188 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -20,23 +20,21 @@ #include "AbstractShape.h" #include "ObjectShapeGroup.h" -using namespace std; - namespace Magnum { namespace Physics { -template ObjectShape::ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group): SceneGraph::AbstractGroupedFeature>(object, group), _shape(nullptr) { +template ObjectShape::ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group): SceneGraph::AbstractGroupedFeature>(object, group), _shape(nullptr) { this->setCachedTransformations(SceneGraph::AbstractFeature::CachedTransformation::Absolute); } -template ObjectShape::~ObjectShape() { +template ObjectShape::~ObjectShape() { delete _shape; } -template void ObjectShape::markDirty() { +template void ObjectShape::markDirty() { group()->setDirty(); } -template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { +template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); } diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 4798b991c..77af71cc9 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -22,7 +22,6 @@ #include "Math/Geometry/Intersection.h" #include "LineSegment.h" -using namespace std; using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { @@ -43,7 +42,7 @@ bool Plane::collides(const AbstractShape<3>* other) const { bool Plane::operator%(const Line3D& other) const { float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); - return t != t || (t != numeric_limits::infinity() && t != -numeric_limits::infinity()); + return t != t || (t != std::numeric_limits::infinity() && t != -std::numeric_limits::infinity()); } bool Plane::operator%(const LineSegment3D& other) const { diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index 249dc8dd7..eb5d0f989 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -20,8 +20,6 @@ #include "Physics/LineSegment.h" #include "Physics/ShapeGroup.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapeGroupTest) namespace Magnum { namespace Physics { namespace Test { @@ -50,7 +48,7 @@ void ShapeGroupTest::reference() { Physics::Point3D point({1.0f, 2.0f, 3.0f}); Physics::LineSegment3D segment({2.0f, 1.0f, 30.0f}, {1.0f, -20.0f, 3.0f}); - ShapeGroup3D group = !(ref(point) || ref(segment)); + ShapeGroup3D group = !(std::ref(point) || std::ref(segment)); group.applyTransformationMatrix(Matrix4::translation(Vector3(1.0f))); diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index aa71c876d..db8b58c7b 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -25,11 +25,9 @@ /* Mask for X events */ #define INPUT_MASK KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|StructureNotifyMask -using namespace std; - namespace Magnum { namespace Platform { -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, int&, char**, const string& title, const Vector2i& size): contextHandler(contextHandler), viewportSize(size), flags(Flag::Redraw) { +AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, int&, char**, const std::string& title, const Vector2i& size): contextHandler(contextHandler), viewportSize(size), flags(Flag::Redraw) { /* Get default X display */ display = XOpenDisplay(0); diff --git a/src/Platform/EglContextHandler.cpp b/src/Platform/EglContextHandler.cpp index 6f0c9884d..92cae17b6 100644 --- a/src/Platform/EglContextHandler.cpp +++ b/src/Platform/EglContextHandler.cpp @@ -32,7 +32,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { display = eglGetDisplay(nativeDisplay); if(!eglInitialize(display, nullptr, nullptr)) { Error() << "Cannot initialize EGL:" << errorString(eglGetError()); - exit(1); + std::exit(1); } #ifndef MAGNUM_TARGET_GLES @@ -42,7 +42,7 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { #endif if(!eglBindAPI(api)) { Error() << "Cannot bind EGL API:" << errorString(eglGetError()); - exit(1); + std::exit(1); } /* Choose EGL config */ @@ -61,19 +61,19 @@ VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { EGLint configCount; if(!eglChooseConfig(display, attribs, &config, 1, &configCount)) { Error() << "Cannot get EGL visual config:" << errorString(eglGetError()); - exit(1); + std::exit(1); } if(!configCount) { Error() << "No matching EGL visual config available"; - exit(1); + std::exit(1); } /* Get visual ID */ EGLint visualId; if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) { Error() << "Cannot get native visual ID:" << errorString(eglGetError()); - exit(1); + std::exit(1); } return visualId; @@ -88,11 +88,11 @@ void EglContextHandler::createContext(EGLNativeWindowType window) { }; if(!eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes)) { Error() << "Cannot create EGL context:" << errorString(eglGetError()); - exit(1); + std::exit(1); } if(!(surface = eglCreateWindowSurface(display, config, window, NULL))) { Error() << "Cannot create window surface:" << errorString(eglGetError()); - exit(1); + std::exit(1); } /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ diff --git a/src/Platform/ExtensionWrangler.cpp b/src/Platform/ExtensionWrangler.cpp index 1216075a8..3c58b7da1 100644 --- a/src/Platform/ExtensionWrangler.cpp +++ b/src/Platform/ExtensionWrangler.cpp @@ -32,7 +32,7 @@ void ExtensionWrangler::initialize(ExperimentalFeatures experimentalFeatures) { GLenum err = glewInit(); if(err != GLEW_OK) { Error() << "ExtensionWrangler: cannot initialize GLEW:" << glewGetErrorString(err); - exit(1); + std::exit(1); } #else static_cast(experimentalFeatures); /* Shut up about unused parameter */ diff --git a/src/Platform/GlxContextHandler.cpp b/src/Platform/GlxContextHandler.cpp index cc6ab5698..f7915e98e 100644 --- a/src/Platform/GlxContextHandler.cpp +++ b/src/Platform/GlxContextHandler.cpp @@ -32,7 +32,7 @@ VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) { glXQueryVersion(nativeDisplay, &major, &minor); if(major == 1 && minor < 4) { Error() << "GlxContextHandler: GLX version 1.4 or greater is required."; - exit(1); + std::exit(1); } /* Choose config */ @@ -50,7 +50,7 @@ VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) { configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount); if(!configCount) { Error() << "GlxContextHandler: no supported framebuffer configuration found."; - exit(1); + std::exit(1); } /* Get visual ID */ @@ -83,7 +83,7 @@ void GlxContextHandler::createContext(Window nativeWindow) { XFree(configs); if(!context) { Error() << "GlxContextHandler: cannot create context."; - exit(1); + std::exit(1); } } diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 6bcf4203d..20da70355 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -24,7 +24,7 @@ namespace Magnum { namespace Platform { NaClApplication::NaClApplication(PP_Instance instance, const Vector2i& size): Instance(instance), Graphics3DClient(this), MouseLock(this), viewportSize(size) { - int32_t attributes[] = { + std::int32_t attributes[] = { PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, @@ -38,11 +38,11 @@ NaClApplication::NaClApplication(PP_Instance instance, const Vector2i& size): In graphics = new pp::Graphics3D(this, attributes); if(graphics->is_null()) { Error() << "Platform::NaClApplication::NaClApplication(): cannot create graphics"; - exit(1); + std::exit(1); } if(!BindGraphics(*graphics)) { Error() << "Platform::NaClApplication::NaClApplication(): cannot bind graphics"; - exit(1); + std::exit(1); } fullscreen = new pp::Fullscreen(this); @@ -195,7 +195,7 @@ void NaClApplication::setMouseLocked(bool enabled) { else UnlockMouse(); } -void NaClApplication::mouseLockCallback(void* applicationInstance, int32_t) { +void NaClApplication::mouseLockCallback(void* applicationInstance, std::int32_t) { NaClApplication* instance = static_cast(applicationInstance); instance->flags |= Flag::MouseLocked; } diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 49e6980e8..f8a0a0a8f 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -43,7 +43,7 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vector2i& size): _redraw(true) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; - exit(1); + std::exit(1); } /* Enable double buffering and 24bt depth buffer */ @@ -54,7 +54,7 @@ Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vec size.x(), size.y(), SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if(!window) { Error() << "Cannot create window."; - exit(2); + std::exit(2); } context = SDL_GL_CreateContext(window); diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index c7d6568c7..3f1fcca20 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -18,11 +18,9 @@ #include "Math/Constants.h" #include "Math/Point3D.h" -using namespace std; - namespace Magnum { namespace Primitives { -Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), 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 +48,7 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std topFaceRing(); } -Capsule::Capsule(uint32_t segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(std::uint32_t segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); @@ -60,18 +58,18 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { textureCoords2D(0)->push_back({0.5, textureCoordsV}); } -void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; GLfloat x, y, z; - for(uint32_t i = 0; i != count; ++i) { + for(std::uint32_t i = 0; i != count; ++i) { GLfloat ringAngle = startRingAngle + i*ringAngleIncrement; - x = z = cos(ringAngle); - y = sin(ringAngle); + x = z = std::cos(ringAngle); + y = std::sin(ringAngle); - for(uint32_t j = 0; j != segments; ++j) { + for(std::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)}); + positions(0)->push_back({x*std::sin(segmentAngle), centerY+y, z*std::cos(segmentAngle)}); + normals(0)->push_back({x*std::sin(segmentAngle), y, z*std::cos(segmentAngle)}); if(textureCoords == TextureCoords::Generate) textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement}); @@ -86,13 +84,13 @@ void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat sta } } -void Capsule::cylinderVertexRings(uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; - for(uint32_t i = 0; i != count; ++i) { - for(uint32_t j = 0; j != segments; ++j) { + for(std::uint32_t i = 0; i != count; ++i) { + for(std::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)}); + positions(0)->push_back({std::sin(segmentAngle), startY, std::cos(segmentAngle)}); + normals(0)->push_back({std::sin(segmentAngle), 0.0f, std::cos(segmentAngle)}); if(textureCoords == TextureCoords::Generate) textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement}); @@ -110,7 +108,7 @@ void Capsule::cylinderVertexRings(uint32_t count, GLfloat startY, GLfloat yIncre } void Capsule::bottomFaceRing() { - for(uint32_t j = 0; j != segments; ++j) { + for(std::uint32_t j = 0; j != segments; ++j) { /* Bottom vertex */ indices()->push_back(0); @@ -123,16 +121,16 @@ void Capsule::bottomFaceRing() { } } -void Capsule::faceRings(uint32_t count, uint32_t offset) { - uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); +void Capsule::faceRings(std::uint32_t count, std::uint32_t offset) { + std::uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - 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) ? + for(std::uint32_t i = 0; i != count; ++i) { + for(std::uint32_t j = 0; j != segments; ++j) { + std::uint32_t bottomLeft = i*vertexSegments+j+offset; + std::uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? i*vertexSegments+j+1+offset : i*segments+offset); - uint32_t topLeft = bottomLeft+vertexSegments; - uint32_t topRight = bottomRight+vertexSegments; + std::uint32_t topLeft = bottomLeft+vertexSegments; + std::uint32_t topRight = bottomRight+vertexSegments; indices()->push_back(bottomLeft); indices()->push_back(bottomRight); @@ -145,9 +143,9 @@ void Capsule::faceRings(uint32_t count, uint32_t offset) { } void Capsule::topFaceRing() { - uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); + std::uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(uint32_t j = 0; j != segments; ++j) { + for(std::uint32_t j = 0; j != segments; ++j) { /* Bottom left vertex */ indices()->push_back(normals(0)->size()-vertexSegments+j-1); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 12d92139f..f3fd4f44e 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -17,11 +17,9 @@ #include "Math/Point3D.h" -using namespace std; - namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new std::vector{ {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, /* +Z */ @@ -63,7 +61,7 @@ Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new vector{ +}}, {new std::vector{ { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, 1.0f}, /* +Z */ diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 0d8460107..025242e39 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -17,11 +17,9 @@ #include "Math/Constants.h" -using namespace std; - namespace Magnum { namespace Primitives { -Cylinder::Cylinder(uint32_t rings, uint32_t segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { +Cylinder::Cylinder(std::uint32_t rings, std::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,9 +49,9 @@ Cylinder::Cylinder(uint32_t rings, uint32_t segments, GLfloat length, Flags flag void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; - for(uint32_t i = 0; i != segments; ++i) { + for(std::uint32_t i = 0; i != segments; ++i) { GLfloat segmentAngle = i*segmentAngleIncrement; - positions(0)->push_back({sin(segmentAngle), y, cos(segmentAngle)}); + positions(0)->push_back({std::sin(segmentAngle), y, std::cos(segmentAngle)}); normals(0)->push_back(normal); if(textureCoords == TextureCoords::Generate) diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 379365e18..e637db8e4 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -17,11 +17,9 @@ #include "Math/Vector4.h" -using namespace std; - namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new std::vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, @@ -42,7 +40,7 @@ Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new vector 7, 1, 0, 3, 9, 8, 4, 8, 0 -}, {new vector}, {new vector{ +}, {new std::vector}, {new std::vector{ Vector3(0, -0.525731f, 0.850651f), Vector3(0.850651f, 0, 0.525731f), Vector3(0.850651f, 0, -0.525731f), diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 99627bab1..d50a994a4 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -17,16 +17,14 @@ #include "Math/Point3D.h" -using namespace std; - namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData3D("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ +Plane::Plane(): MeshData3D("", Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, {-1.0f, 1.0f, 0.0f} -}}, {new vector{ +}}, {new std::vector{ {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index 1855bcd6e..73d8b1f2b 100644 --- a/src/Primitives/Square.cpp +++ b/src/Primitives/Square.cpp @@ -17,11 +17,9 @@ #include "Math/Point2D.h" -using namespace std; - namespace Magnum { namespace Primitives { -Square::Square(): MeshData2D("", Mesh::Primitive::TriangleStrip, nullptr, {new vector{ +Square::Square(): MeshData2D("", Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ {1.0f, -1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 1f6fb6183..51f2230ea 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -23,7 +23,6 @@ #include "Math/Point3D.h" #include "Primitives/Capsule.h" -using namespace std; using Corrade::TestSuite::Compare::Container; CORRADE_TEST_MAIN(Magnum::Primitives::Test::CapsuleTest) @@ -38,7 +37,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 2, 3, 1.0f); - CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, @@ -64,7 +63,7 @@ void CapsuleTest::withoutTextureCoords() { {0.0f, 1.5f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.normals(0), (vector{ + CORRADE_COMPARE_AS(*capsule.normals(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.707107f, 0.707107f}, @@ -90,7 +89,7 @@ void CapsuleTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, @@ -103,7 +102,7 @@ void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withTextureCoords() { Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); - CORRADE_COMPARE_AS(*capsule.positions(0), (vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, @@ -134,7 +133,7 @@ void CapsuleTest::withTextureCoords() { {0.0f, 1.5f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.textureCoords2D(0), (vector{ + CORRADE_COMPARE_AS(*capsule.textureCoords2D(0), (std::vector{ {0.5f, 0.0f}, {0.0f, 0.166667f}, @@ -165,7 +164,7 @@ void CapsuleTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index f7f919cae..4eda71de4 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -20,7 +20,6 @@ #include "Math/Point3D.h" #include "Primitives/Cylinder.h" -using namespace std; using Corrade::TestSuite::Compare::Container; CORRADE_TEST_MAIN(Magnum::Primitives::Test::CylinderTest) @@ -35,7 +34,7 @@ CylinderTest::CylinderTest() { void CylinderTest::withoutAnything() { Cylinder cylinder(2, 3, 3.0f); - CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector{ {0.0f, -1.5f, 1.0f}, {0.866025f, -1.5f, -0.5f}, {-0.866025f, -1.5f, -0.5f}, @@ -49,7 +48,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 1.5f, -0.5f} }), Container); - CORRADE_COMPARE_AS(*cylinder.normals(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.normals(0), (std::vector{ {0.0f, 0.0f, 1.0f}, {0.866025f, 0.0f, -0.5f}, {-0.866025f, 0.0f, -0.5f}, @@ -63,7 +62,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 0.0f, -0.5f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5, 3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8 }), Container); @@ -72,7 +71,7 @@ void CylinderTest::withoutAnything() { void CylinderTest::withTextureCoordsAndCaps() { Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds); - CORRADE_COMPARE_AS(*cylinder.positions(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 1.0f}, @@ -103,7 +102,7 @@ void CylinderTest::withTextureCoordsAndCaps() { {0.0f, 1.5f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*cylinder.normals(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.normals(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, @@ -134,7 +133,7 @@ void CylinderTest::withTextureCoordsAndCaps() { {0.0f, 1.0f, 0.0f}, }), Container); - CORRADE_COMPARE_AS(*cylinder.textureCoords2D(0), (vector{ + CORRADE_COMPARE_AS(*cylinder.textureCoords2D(0), (std::vector{ {0.5f, 0.0f}, {0.0f, 0.2f}, @@ -165,7 +164,7 @@ void CylinderTest::withTextureCoordsAndCaps() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 1599eeb0d..4a57c5c0b 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -20,7 +20,6 @@ #include "Math/Point3D.h" #include "Primitives/UVSphere.h" -using namespace std; using Corrade::TestSuite::Compare::Container; CORRADE_TEST_MAIN(Magnum::Primitives::Test::UVSphereTest) @@ -35,7 +34,7 @@ UVSphereTest::UVSphereTest() { void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); - CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, @@ -49,7 +48,7 @@ void UVSphereTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.normals(0), (vector{ + CORRADE_COMPARE_AS(*sphere.normals(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, @@ -63,7 +62,7 @@ void UVSphereTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 7, 5, 6, 7, 6, 4, 7 @@ -73,7 +72,7 @@ void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); - CORRADE_COMPARE_AS(*sphere.positions(0), (vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, @@ -89,7 +88,7 @@ void UVSphereTest::withTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (vector{ + CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (std::vector{ {0.5f, 0.0f}, {0.0f, 0.333333f}, @@ -105,7 +104,7 @@ void UVSphereTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 9, 6, 7, 9, 7, 8, 9 diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 920ac2dd3..5d181dd79 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -15,15 +15,11 @@ #include "UVSphere.h" -#include - #include "Math/Constants.h" -using namespace std; - namespace Magnum { namespace Primitives { -UVSphere::UVSphere(uint32_t rings, uint32_t segments, TextureCoords textureCoords): Capsule(segments, textureCoords) { +UVSphere::UVSphere(std::uint32_t rings, std::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; diff --git a/src/Profiler.cpp b/src/Profiler.cpp index 8e4178fcf..5682c3072 100644 --- a/src/Profiler.cpp +++ b/src/Profiler.cpp @@ -19,25 +19,25 @@ #include #include -using namespace std; +#include "Magnum.h" namespace Magnum { -Profiler::Section Profiler::addSection(const string& name) { +Profiler::Section Profiler::addSection(const std::string& name) { CORRADE_ASSERT(!enabled, "Profiler: cannot add section when profiling is enabled", 0); sections.push_back(name); return sections.size()-1; } -void Profiler::setMeasureDuration(size_t frames) { +void Profiler::setMeasureDuration(std::size_t frames) { CORRADE_ASSERT(!enabled, "Profiler: cannot set measure duration when profiling is enabled", ); measureDuration = frames; } void Profiler::enable() { enabled = true; - frameData.assign(measureDuration*sections.size(), chrono::high_resolution_clock::duration::zero()); - totalData.assign(sections.size(), chrono::high_resolution_clock::duration::zero()); + frameData.assign(measureDuration*sections.size(), std::chrono::high_resolution_clock::duration::zero()); + totalData.assign(sections.size(), std::chrono::high_resolution_clock::duration::zero()); frameCount = 0; } @@ -59,14 +59,14 @@ void Profiler::stop() { save(); - previousTime = chrono::high_resolution_clock::time_point(); + previousTime = std::chrono::high_resolution_clock::time_point(); } void Profiler::save() { - auto now = chrono::high_resolution_clock::now(); + auto now = std::chrono::high_resolution_clock::now(); /* If the profiler is already running, add time to given section */ - if(previousTime != chrono::high_resolution_clock::time_point()) + if(previousTime != std::chrono::high_resolution_clock::time_point()) frameData[currentFrame*sections.size()+currentSection] += now-previousTime; /* Set current time as previous for next section */ @@ -77,16 +77,16 @@ void Profiler::nextFrame() { if(!enabled) return; /* Next frame index */ - size_t nextFrame = (currentFrame+1) % measureDuration; + std::size_t nextFrame = (currentFrame+1) % measureDuration; /* Add times of current frame to total */ - for(size_t i = 0; i != sections.size(); ++i) + for(std::size_t i = 0; i != sections.size(); ++i) totalData[i] += frameData[currentFrame*sections.size()+i]; /* Subtract times of next frame from total and erase them */ - for(size_t i = 0; i != sections.size(); ++i) { + for(std::size_t i = 0; i != sections.size(); ++i) { totalData[i] -= frameData[nextFrame*sections.size()+i]; - frameData[nextFrame*sections.size()+i] = chrono::high_resolution_clock::duration::zero(); + frameData[nextFrame*sections.size()+i] = std::chrono::high_resolution_clock::duration::zero(); } /* Advance to next frame */ @@ -98,14 +98,14 @@ void Profiler::nextFrame() { void Profiler::printStatistics() { if(!enabled) return; - vector totalSorted(sections.size()); - iota(totalSorted.begin(), totalSorted.end(), 0); + std::vector totalSorted(sections.size()); + std::iota(totalSorted.begin(), totalSorted.end(), 0); - sort(totalSorted.begin(), totalSorted.end(), [this](size_t i, size_t j){return totalData[i] > totalData[j];}); + std::sort(totalSorted.begin(), totalSorted.end(), [this](std::size_t i, std::size_t j){return totalData[i] > totalData[j];}); - Corrade::Utility::Debug() << "Statistics for last" << measureDuration << "frames:"; - for(size_t i = 0; i != sections.size(); ++i) - Corrade::Utility::Debug() << ' ' << sections[totalSorted[i]] << chrono::microseconds(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; + Debug() << "Statistics for last" << measureDuration << "frames:"; + for(std::size_t i = 0; i != sections.size(); ++i) + Debug() << ' ' << sections[totalSorted[i]] << std::chrono::microseconds(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; } } diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index abe60f4c7..60bab57b6 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -21,8 +21,6 @@ #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::ObjectTest) namespace Magnum { namespace SceneGraph { namespace Test { @@ -121,22 +119,22 @@ void ObjectTest::transformations() { Matrix4 initial = Matrix4::rotationX(deg(90.0f)).inverted(); /* Empty list */ - CORRADE_COMPARE(s.transformations(vector(), initial), vector()); + CORRADE_COMPARE(s.transformations(std::vector(), initial), std::vector()); /* Scene alone */ - CORRADE_COMPARE(s.transformations({&s}, initial), vector{initial}); + CORRADE_COMPARE(s.transformations({&s}, initial), std::vector{initial}); /* One object */ Object3D first(&s); first.rotateZ(deg(30.0f)); Object3D second(&first); second.scale(Vector3(0.5f)); - CORRADE_COMPARE(s.transformations({&second}, initial), vector{ + CORRADE_COMPARE(s.transformations({&second}, initial), std::vector{ initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)) }); /* One object and scene */ - CORRADE_COMPARE(s.transformations({&second, &s}, initial), (vector{ + CORRADE_COMPARE(s.transformations({&second, &s}, initial), (std::vector{ initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial })); @@ -144,13 +142,13 @@ void ObjectTest::transformations() { /* Two objects with foreign joint */ Object3D third(&first); third.translate(Vector3::xAxis(5.0f)); - CORRADE_COMPARE(s.transformations({&second, &third}, initial), (vector{ + CORRADE_COMPARE(s.transformations({&second, &third}, initial), (std::vector{ initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), })); /* Three objects with joint as one of them */ - CORRADE_COMPARE(s.transformations({&second, &third, &first}, initial), (vector{ + CORRADE_COMPARE(s.transformations({&second, &third, &first}, initial), (std::vector{ initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), initial*Matrix4::rotationZ(deg(30.0f)), @@ -160,7 +158,7 @@ void ObjectTest::transformations() { CORRADE_EXPECT_FAIL("Transformations not relative to scene are not yet implemented."); /* Transformation relative to another object */ - CORRADE_COMPARE(second.transformations({&third}), vector{ + CORRADE_COMPARE(second.transformations({&third}), std::vector{ Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f)) }); @@ -172,17 +170,17 @@ void ObjectTest::transformations() { orphan1.scale(Vector3::xScale(3.0f)); Object3D orphan2(&orphanParent); orphan2.translate(Vector3::zAxis(5.0f)); - CORRADE_COMPARE(orphan1.transformations({&orphan2}), vector{ + CORRADE_COMPARE(orphan1.transformations({&orphan2}), std::vector{ Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f)) }); } - ostringstream o; + std::ostringstream o; Error::setOutput(&o); /* Transformation of objects not part of the same scene */ Object3D orphan; - CORRADE_COMPARE(s.transformations({&orphan}), vector()); + CORRADE_COMPARE(s.transformations({&orphan}), std::vector()); CORRADE_COMPARE(o.str(), "SceneGraph::Object::transformations(): the objects are not part of the same tree\n"); } @@ -283,7 +281,7 @@ void ObjectTest::setClean() { void ObjectTest::bulkSetClean() { /* Verify it doesn't crash when passed empty list */ - Object3D::setClean(vector()); + Object3D::setClean(std::vector()); Scene3D scene; Object3D a(&scene); @@ -294,7 +292,7 @@ void ObjectTest::bulkSetClean() { CachingObject d(&c); d.scale(Vector3(-2.0f)); Object3D e(&scene); - vector cleanAll{&a, &b, &c, &d, &e}; + std::vector cleanAll{&a, &b, &c, &d, &e}; /* All objects should be cleaned */ CORRADE_VERIFY(a.isDirty()); diff --git a/src/Shader.cpp b/src/Shader.cpp index c23d66adf..d6a756720 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -25,8 +25,6 @@ typedef char GLchar; #endif -using namespace std; - namespace Magnum { Shader::Shader(Version version, Type type): _type(type), _state(State::Initialized), shader(0) { @@ -72,7 +70,7 @@ Shader& Shader::operator=(Shader&& other) { bool Shader::addFile(const std::string& filename) { /* Open file */ - ifstream file(filename.c_str()); + std::ifstream file(filename.c_str()); if(!file.good()) { file.close(); @@ -81,13 +79,13 @@ bool Shader::addFile(const std::string& filename) { } /* Get size of shader and initialize buffer */ - file.seekg(0, ios::end); - size_t size = file.tellg(); + file.seekg(0, std::ios::end); + std::size_t size = file.tellg(); char* source = new char[size+1]; source[size] = '\0'; /* Read data, close */ - file.seekg(0, ios::beg); + file.seekg(0, std::ios::beg); file.read(source, size); file.close(); @@ -104,7 +102,7 @@ GLuint Shader::compile() { /* Array of sources */ const GLchar** _sources = new const GLchar*[sources.size()]; - for(size_t i = 0; i != sources.size(); ++i) + for(std::size_t i = 0; i != sources.size(); ++i) _sources[i] = static_cast(sources[i].c_str()); /* Create shader and set its source */ diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 903da1e3d..403c38668 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -19,16 +19,14 @@ #include "Color.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::Test::ColorTest) using namespace Corrade::Utility; namespace Magnum { namespace Test { -typedef Magnum::Color3 Color3; -typedef Magnum::Color4 Color4; +typedef Magnum::Color3 Color3; +typedef Magnum::Color4 Color4; typedef Magnum::Color3 Color3f; typedef Magnum::Color4 Color4f; @@ -125,7 +123,7 @@ void ColorTest::hsv() { CORRADE_COMPARE(Color3::fromHSV(230.0f, 0.749f, 0.427f), Color3(27, 41, 109)); float hue, saturation, value; - tie(hue, saturation, value) = Color3(27, 41, 109).toHSV(); + std::tie(hue, saturation, value) = Color3(27, 41, 109).toHSV(); CORRADE_COMPARE(hue, 229.756106f); CORRADE_COMPARE(saturation, 0.752294f); CORRADE_COMPARE(value, 0.427451f); @@ -148,12 +146,12 @@ void ColorTest::hsvOverflow() { } void ColorTest::hsvAlpha() { - CORRADE_COMPARE(Color4::fromHSV(make_tuple(230.0f, 0.749f, 0.427f), 23), Color4(27, 41, 109, 23)); + CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(230.0f, 0.749f, 0.427f), 23), Color4(27, 41, 109, 23)); CORRADE_COMPARE(Color4::fromHSV(230.0f, 0.749f, 0.427f, 23), Color4(27, 41, 109, 23)); } void ColorTest::debug() { - ostringstream o; + std::ostringstream o; Debug(&o) << Color3f(0.5f, 0.75f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 1)\n"); @@ -166,17 +164,17 @@ void ColorTest::configuration() { Configuration c; Color3f color3(0.5f, 0.75f, 1.0f); - string value3("0.5 0.75 1"); + std::string value3("0.5 0.75 1"); c.setValue("color3", color3); - CORRADE_COMPARE(c.value("color3"), value3); + CORRADE_COMPARE(c.value("color3"), value3); CORRADE_COMPARE(c.value("color3"), color3); Color4f color4(0.5f, 0.75f, 0.0f, 1.0f); - string value4("0.5 0.75 0 1"); + std::string value4("0.5 0.75 0 1"); c.setValue("color4", color4); - CORRADE_COMPARE(c.value("color4"), value4); + CORRADE_COMPARE(c.value("color4"), value4); CORRADE_COMPARE(c.value("color4"), color4); } diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index bd73a6b5b..6efa8c520 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -22,7 +22,6 @@ #include "corradeCompatibility.h" -using namespace std; using namespace Corrade::Utility; CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerTest) @@ -37,7 +36,7 @@ class Data { inline ~Data() { --count; } }; -typedef Magnum::ResourceManager ResourceManager; +typedef Magnum::ResourceManager ResourceManager; class IntResourceLoader: public AbstractResourceLoader { public: @@ -117,7 +116,7 @@ void ResourceManagerTest::stateFallback() { void ResourceManagerTest::stateDisallowed() { ResourceManager rm; - stringstream out; + std::ostringstream out; Error::setOutput(&out); Data d; @@ -135,27 +134,27 @@ void ResourceManagerTest::basic() { /* One mutable, one final */ ResourceKey questionKey("the-question"); ResourceKey answerKey("the-answer"); - rm.set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); - rm.set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); - Resource theQuestion = rm.get(questionKey); - Resource theAnswer = rm.get(answerKey); + rm.set(questionKey, new std::int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm.set(answerKey, new std::int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); + Resource theQuestion = rm.get(questionKey); + Resource theAnswer = rm.get(answerKey); /* Check basic functionality */ CORRADE_COMPARE(theQuestion.state(), ResourceState::Mutable); CORRADE_COMPARE(theAnswer.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 10); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(rm.count(), 2); + CORRADE_COMPARE(rm.count(), 2); /* Cannot change already final resource */ - stringstream out; + std::ostringstream out; Error::setOutput(&out); - rm.set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm.set(answerKey, new std::int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource\n"); /* But non-final can be changed */ - rm.set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); + rm.set(questionKey, new std::int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_COMPARE(theQuestion.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 3ac1c4139..5da5a9bf3 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -17,8 +17,6 @@ #include "Swizzle.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) namespace Magnum { namespace Test { @@ -57,37 +55,37 @@ void SwizzleTest::fromSmall() { /* Force compile-time evaluation for both */ constexpr Vector2i orig(1, 2); constexpr Vector3i swizzled(swizzle(orig, "gxr")); - CORRADE_VERIFY((integral_constant::value)); + CORRADE_VERIFY((std::integral_constant::value)); CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(orig)), Vector3i(2, 1, 1)); } void SwizzleTest::type() { Vector4i orig; - CORRADE_VERIFY((is_same(orig)), Vector2i>::value)); - CORRADE_VERIFY((is_same::value)); - CORRADE_VERIFY((is_same(orig)), Vector3i>::value)); - CORRADE_VERIFY((is_same::value)); - CORRADE_VERIFY((is_same(orig)), Vector4i>::value)); - CORRADE_VERIFY((is_same::value)); + CORRADE_VERIFY((std::is_same(orig)), Vector2i>::value)); + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same(orig)), Vector3i>::value)); + CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same(orig)), Vector4i>::value)); + CORRADE_VERIFY((std::is_same::value)); Color3 origColor3; Color4 origColor4; - CORRADE_VERIFY((is_same(origColor3)), Color3>::value)); - CORRADE_VERIFY((is_same(origColor4)), Color3>::value)); - CORRADE_VERIFY((is_same>::value)); - CORRADE_VERIFY((is_same>::value)); - CORRADE_VERIFY((is_same(origColor3)), Color4>::value)); - CORRADE_VERIFY((is_same(origColor4)), Color4>::value)); - CORRADE_VERIFY((is_same>::value)); - CORRADE_VERIFY((is_same>::value)); + CORRADE_VERIFY((std::is_same(origColor3)), Color3<>>::value)); + CORRADE_VERIFY((std::is_same(origColor4)), Color3>::value)); + CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same(origColor3)), Color4<>>::value)); + CORRADE_VERIFY((std::is_same(origColor4)), Color4>::value)); + CORRADE_VERIFY((std::is_same>::value)); + CORRADE_VERIFY((std::is_same>::value)); } void SwizzleTest::defaultType() { Vector4i orig(1, 2, 3, 4); - 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))); + CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, std::int32_t>(3))); + CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, std::int32_t>(3))); + CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); } }} diff --git a/src/Trade/AbstractImporter.cpp b/src/Trade/AbstractImporter.cpp index ec68d9c21..1ccf4da86 100644 --- a/src/Trade/AbstractImporter.cpp +++ b/src/Trade/AbstractImporter.cpp @@ -17,7 +17,6 @@ #include -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Trade { diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp index 8e19a76c5..bf764d21d 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -18,25 +18,23 @@ #include #include -using namespace std; - namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(is_same::value, "GLubyte is not the same as uint8_t"); -static_assert(is_same::value, "GLbyte is not the same as int8_t"); -static_assert(is_same::value, "GLushort is not the same as uint16_t"); -static_assert(is_same::value, "GLshort is not the same as int16_t"); -static_assert(is_same::value, "GLuint is not the same as uint32_t"); -static_assert(is_same::value, "GLint is not the same as int32_t"); -static_assert(is_same::value, "GLsizei is not the same as int32_t"); -static_assert(is_same::value, "GLfloat is not the same as float"); +static_assert(std::is_same::value, "GLubyte is not the same as std::uint8_t"); +static_assert(std::is_same::value, "GLbyte is not the same as std::int8_t"); +static_assert(std::is_same::value, "GLushort is not the same as std::uint16_t"); +static_assert(std::is_same::value, "GLshort is not the same as std::int16_t"); +static_assert(std::is_same::value, "GLuint is not the same as std::uint32_t"); +static_assert(std::is_same::value, "GLint is not the same as std::int32_t"); +static_assert(std::is_same::value, "GLsizei is not the same as std::int32_t"); +static_assert(std::is_same::value, "GLfloat is not the same as float"); #ifndef MAGNUM_TARGET_GLES -static_assert(is_same::value, "GLdouble is not the same as double"); +static_assert(std::is_same::value, "GLdouble is not the same as double"); #endif #endif -size_t TypeInfo::sizeOf(Type type) { +std::size_t TypeInfo::sizeOf(Type type) { switch(type) { #define val(type) case Type::type: return TypeTraits::Type>::size(); val(UnsignedByte) From b6f1910599d8158db3e1c50346d3551c6bb1df50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Dec 2012 23:30:08 +0100 Subject: [PATCH 014/567] Making some asserts internal. They shouldn't be triggered by the user, so no explanational message is needed (but exact position in source is). --- src/Color.h | 3 +-- src/Implementation/BufferState.cpp | 3 +-- src/Shader.cpp | 28 +++++++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Color.h b/src/Color.h index 54eac2a1c..5b8bb83aa 100644 --- a/src/Color.h +++ b/src/Color.h @@ -54,8 +54,7 @@ template inline typename std::enable_if::valu case 3: return {p, q, value}; case 4: return {t, p, value}; case 5: return {value, p, q}; - default: - CORRADE_ASSERT(false, "It shouldn't get here.", {}); + default: CORRADE_INTERNAL_ASSERT(false); } } template inline typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { diff --git a/src/Implementation/BufferState.cpp b/src/Implementation/BufferState.cpp index 323f5a015..949c3bdb1 100644 --- a/src/Implementation/BufferState.cpp +++ b/src/Implementation/BufferState.cpp @@ -62,8 +62,7 @@ std::size_t BufferState::indexForTarget(Buffer::Target target) { #endif } - CORRADE_ASSERT(false, "Unknown Buffer target", 0); - return 0; + CORRADE_INTERNAL_ASSERT(false); } }} diff --git a/src/Shader.cpp b/src/Shader.cpp index d6a756720..b66a72742 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -32,23 +32,25 @@ Shader::Shader(Version version, Type type): _type(type), _state(State::Initializ switch(version) { #ifndef MAGNUM_TARGET_GLES - case Version::GL210: addSource("#version 120\n"); break; - case Version::GL300: addSource("#version 130\n"); break; - case Version::GL310: addSource("#version 140\n"); break; - case Version::GL320: addSource("#version 150\n"); break; - case Version::GL330: addSource("#version 330\n"); break; - case Version::GL400: addSource("#version 400\n"); break; - case Version::GL410: addSource("#version 410\n"); break; - case Version::GL420: addSource("#version 420\n"); break; - case Version::GL430: addSource("#version 430\n"); break; + case Version::GL210: addSource("#version 120\n"); return; + case Version::GL300: addSource("#version 130\n"); return; + case Version::GL310: addSource("#version 140\n"); return; + case Version::GL320: addSource("#version 150\n"); return; + case Version::GL330: addSource("#version 330\n"); return; + case Version::GL400: addSource("#version 400\n"); return; + case Version::GL410: addSource("#version 410\n"); return; + case Version::GL420: addSource("#version 420\n"); return; + case Version::GL430: addSource("#version 430\n"); return; #else - case Version::GLES200: addSource("#version 100\n"); break; - case Version::GLES300: addSource("#version 300\n"); break; + case Version::GLES200: addSource("#version 100\n"); return; + case Version::GLES300: addSource("#version 300\n"); return; #endif - default: - CORRADE_ASSERT(false, "Shader::Shader(): unsupported version" << GLint(version), ); + case Version::None: + CORRADE_ASSERT(false, "Shader::Shader(): unsupported version" << version, ); } + + CORRADE_INTERNAL_ASSERT(false); } Shader::Shader(Shader&& other): _type(other._type), _state(other._state), sources(other.sources), shader(other.shader) { From 0c7a448fddde060f71868e3828d6fe594029a068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 00:06:59 +0100 Subject: [PATCH 015/567] Doc++, code cleanup. Some things from Coding Style were moved to Corrade. --- doc/coding-style.dox | 11 ++++----- src/Timeline.h | 59 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/doc/coding-style.dox b/doc/coding-style.dox index 1e0e96b66..4a19a405b 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -35,12 +35,11 @@ removing redundant prefixes) is encouraged. @subsubsection cpp-forward-declarations Forward declarations and forward declaration headers -Use forward declarations in headers as much as possible, as it can -significantly reduce time of incremental compilation. When an namespace has -classes which are commonly forward-declared, consider making a forward -declaration header - it should have the same name as the namespace itself and -contain foward declarations for all classes, enums and copies of all -meaningful typedefs. See SceneGraph/SceneGraph.h for an example. +When an namespace has classes which are commonly forward-declared, consider +making a forward declaration header - it should have the same name as the +namespace itself and contain foward declarations for all classes, enums and +copies of all meaningful typedefs. See @ref compilation-forward-declarations +for more information. @section documentation Doxygen documentation diff --git a/src/Timeline.h b/src/Timeline.h index 093191677..a6d5b714e 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -27,26 +27,71 @@ namespace Magnum { -/** @brief %Timeline */ +/** +@brief %Timeline + +Keeps track of time delta between frames and allows FPS limiting. Can be used +as source for animation speed computations. + +@section Timeline-usage Basic usage + +Construct the timeline on initialization so the instance is available for +whole lifetime of the application. Call start() before first draw event is +performed, after everything is properly initialized. + +@note When timeline is started, it immediately starts measuring frame time. + Be prepared that time of first frame will be much longer than time of + following frames. It mainly depends on where you called start() in your + initialization routine, but can be also affected by driver- and + GPU-specific lazy texture binding, shader recompilations etc. + +In your draw event implementation don't forget to call nextFrame() after +buffer swap. You can use previousFrameDuration() to compute animation speed. + +Example usage (in e.g. @ref Platform::GlutApplication "GlutApplication" +subclass): +@code +MyApplication::MyApplication(...): Platform::GlutApplication(...) { + // Initialization ... + + timeline.setMinimalFrameTime(1/120.0f); // 120 FPS at max + timeline.start(); +} + +void MyApplication::drawEvent() { + // Distance of object travelling at speed of 15 units per second + GLfloat distance = 15.0f*timeline.previousFrameDuration(); + + // Move object, draw ... + + swapBuffers(); + redraw(); + timeline.nextFrame(); +} +@endcode +*/ class MAGNUM_EXPORT Timeline { public: /** * @brief Constructor * - * Constructs stopped timeline. + * Creates stopped timeline. * @see start() */ inline constexpr Timeline(): _minimalFrameTime(0), _previousFrameDuration(0), running(false) {} /** @brief Minimal frame time (in seconds) */ - GLfloat minimalFrameTime() const { return _minimalFrameTime; } + inline constexpr GLfloat minimalFrameTime() const { + return _minimalFrameTime; + } /** * @brief Set minimal frame time * + * Default value is 0. * @see nextFrame() */ - void setMinimalFrameTime(GLfloat seconds) { + inline void setMinimalFrameTime(GLfloat seconds) { _minimalFrameTime = seconds; } @@ -60,6 +105,8 @@ class MAGNUM_EXPORT Timeline { /** * @brief Stop timeline + * + * @see start(), nextFrame() */ void stop(); @@ -69,11 +116,11 @@ class MAGNUM_EXPORT Timeline { * If current frame time is smaller than minimal frame time, pauses * the execution for remaining time. * @note This function does nothing if the timeline is stopped. - * @see setMinimalFrameTime() + * @see setMinimalFrameTime(), stop() */ void nextFrame(); - /** @brief Duration of previous frame */ + /** @brief Duration of previous frame (in seconds) */ inline constexpr GLfloat previousFrameDuration() const { return _previousFrameDuration; } From 9ead1e9debf16bec468447e827559bfbcdbca271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 12:44:51 +0100 Subject: [PATCH 016/567] Thorough documentation review and update. Now whole Magnum, Magnum::SceneGraph and Magnum::Math namespaces are fully documented -- each class has at least "getting started" documentation, larger modules are documented on separate pages. --- src/AbstractResourceLoader.h | 3 ++ src/BufferedTexture.h | 34 +++++++++++++++---- src/Context.h | 5 ++- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 10 +++--- src/IndexedMesh.h | 17 +++++++++- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 2 +- src/Mesh.h | 6 ++-- src/Profiler.h | 2 +- src/Query.h | 6 ++-- src/Resource.h | 1 + src/SceneGraph/AbstractCamera.h | 4 +-- src/SceneGraph/AbstractGroupedFeature.h | 6 ++-- src/SceneGraph/AbstractTransformation.h | 6 ++-- .../AbstractTranslationRotation2D.h | 2 +- .../AbstractTranslationRotation3D.h | 2 +- .../AbstractTranslationRotationScaling2D.h | 2 +- .../AbstractTranslationRotationScaling3D.h | 2 +- src/SceneGraph/Camera2D.h | 11 ++++-- src/SceneGraph/Camera3D.h | 14 ++++++-- src/SceneGraph/Drawable.h | 22 +++++++----- src/SceneGraph/FeatureGroup.h | 2 +- src/SceneGraph/MatrixTransformation2D.h | 3 +- src/SceneGraph/MatrixTransformation3D.h | 3 +- src/Shader.h | 9 +++-- src/Texture.h | 17 ++++++---- 27 files changed, 132 insertions(+), 63 deletions(-) diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h index 553529bf1..01c68a2b5 100644 --- a/src/AbstractResourceLoader.h +++ b/src/AbstractResourceLoader.h @@ -82,6 +82,9 @@ MyResourceManager manager; MeshResourceLoader loader; manager->setLoader(loader); + +// This will now automatically request the mesh from loader by calling load() +Resource myMesh = manager->get("my-mesh"); @endcode */ template class AbstractResourceLoader { diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index 87f478ee0..ba2e5e4f8 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -30,13 +30,35 @@ namespace Magnum { @brief Buffered texture This texture is, unlike classic textures such as Texture or CubeMapTexture, -used as simple data source, without any unneccessary interpolation and -wrapping methods. Texture data are stored in buffer and after binding the -buffer to the texture using setBuffer(), you can fill the buffer at any time -using data setting functions in Buffer itself. +used as simple data source, without any unnecessary interpolation and +wrapping methods. -When using buffered texture in the shader, use `samplerBuffer` and fetch the -data using integer coordinates in `texelFetch()`. +@section BufferedTexture-usage Usage + +%Texture data are stored in buffer and after binding the buffer to the texture +using setBuffer(), you can fill the buffer at any time using data setting +functions in Buffer itself. + +Note that the buffer is not managed (e.g. deleted on destruction) by the +texture, so you have to manage it on your own. On the other hand it allows you +to use one buffer for more textures or store more than one data in it. + +Example usage: +@code +Buffer* buffer; +BufferedTexture texture; +texture.setBuffer(buffer); + +constexpr static Vector3 data[] = { + // ... +}; +buffer.setData(data, Buffer::Usage::StaticDraw); +@endcode + +The texture is bound to layer specified by shader via bind(). In shader, the +texture is used via `samplerBuffer`. Unlike in classic textures, coordinates +for buffered textures are integer coordinates passed to `texelFetch()`. See +also AbstractShaderProgram documentation for more information. @section BufferedTexture-performance-optimization Performance optimizations If extension @extension{EXT,direct_state_access} is available, setBuffer() diff --git a/src/Context.h b/src/Context.h index ea6172e31..ccc5ddbd4 100644 --- a/src/Context.h +++ b/src/Context.h @@ -123,7 +123,10 @@ class MAGNUM_EXPORT Extension { /** @brief OpenGL context -Provides access to version and extension information. +Provides access to version and extension information. Instance available +through Context::current() is automatically created during construction of +*Application classes in Platform namespace so you can safely assume that the +instance is available during whole lifetime of *Application object. */ class MAGNUM_EXPORT Context { Context(const Context&) = delete; diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index f645a45c0..d0efe7677 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -57,7 +57,7 @@ texture.setMagnificationFilter(Texture2D::Filter::Linear) @endcode The texture is bound to layer specified by shader via bind(). In shader, the -texture is used via `samplerCube`. Unlike classic textures, coordinates for +texture is used via `samplerCube`. Unlike in classic textures, coordinates for cube map textures is signed three-part vector from the center of the cube, which intersects one of the six sides of the cube map. See also AbstractShaderProgram for more information. diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index a232c5888..06824978f 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -59,11 +59,11 @@ for(std::size_t i = 0; i != 16; ++i) { @endcode The texture is bound to layer specified by shader via bind(). In shader, the -texture is used via `samplerCubeArray`. Unlike classic textures, coordinates -for cube map texture arrays is signed four-part vector. First three parts -define vector from the center of the cube which intersects with one of the six -sides of the cube map, fourth part is layer in the array. See also -AbstractShaderProgram for more information. +texture is used via `samplerCubeArray`. Unlike in classic textures, +coordinates for cube map texture arrays is signed four-part vector. First +three parts define vector from the center of the cube which intersects with +one of the six sides of the cube map, fourth part is layer in the array. See +also AbstractShaderProgram for more information. @see CubeMapTexture::setSeamless() @requires_gl40 Extension @extension{ARB,texture_cube_map_array} diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 0d5bfd045..9e6e3f6b3 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -41,6 +41,20 @@ you have to manage it on your own. On the other hand it allows you to use one index buffer for more meshes (with different vertex data in each mesh, for example) or store more than only index data in one buffer. +Example usage -- creating a cube mesh, assigning vertex buffer with +interleaved vertex attributes and compressed index buffer for use with +Shaders::PhongShader: +@code +Buffer *vertexBuffer, *indexBuffer; +Mesh* mesh; + +Primitives::Cube cube; +MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, *cube.positions(0), *cube.normals(0)); +MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cube.indices()); +mesh->setPrimitive(plane.primitive()) + ->addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); +@endcode + @section IndexedMesh-drawing Rendering meshes From user point-of-view the operation is the same as for @@ -50,7 +64,8 @@ From user point-of-view the operation is the same as for If @extension{APPLE,vertex_array_object} is supported, next to @ref Mesh-performance-optimization "optimizations in Mesh itself" the index -buffer is bound on object construction instead of in every draw() call. +buffer is bound on object construction instead of binding it in every draw() +call. */ class MAGNUM_EXPORT IndexedMesh: public Mesh { friend class Context; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 1d96ebbbb..59ba6b48c 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Math { Provides functions for transformations in 2D. See Matrix4 for 3D transformations. See also @ref matrix-vector for brief introduction. -@see Magnum::Matrix3 +@see Magnum::Matrix3, SceneGraph::MatrixTransformation2D @configurationvalueref{Magnum::Math::Matrix3} */ template class Matrix3: public Matrix<3, T> { diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 7d511cfcb..9e01c2104 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Math { Provides functions for transformations in 3D. See Matrix3 for 2D transformations. See also @ref matrix-vector for brief introduction. -@see Magnum::Matrix4 +@see Magnum::Matrix4, SceneGraph::MatrixTransformation3D @configurationvalueref{Magnum::Math::Matrix4} @todo Shearing @todo Reflection diff --git a/src/Mesh.h b/src/Mesh.h index 9c65327f5..6909bfe59 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -61,7 +61,7 @@ static constexpr Point3D positions[30] = { }; buffer->setData(positions, Buffer::Usage::StaticDraw); -mesh->setPrimitve(Mesh::Primitive::Triangles) +mesh->setPrimitive(Mesh::Primitive::Triangles) ->setVertexCount(30) ->addVertexBuffer(buffer, MyShader::Position()); @endcode @@ -95,7 +95,9 @@ mesh->addVertexBuffer(buffer, MyShader::Color(Type::UsignedByte, MyShader::Color @section Mesh-drawing Rendering meshes -Basic workflow is to set up respective shader (see @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" for more infromation) and call Mesh::draw(). +Basic workflow is to set up respective shader (see +@ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" +for more infromation) and call Mesh::draw(). @section Mesh-performance-optimization Performance optimizations diff --git a/src/Profiler.h b/src/Profiler.h index d17ef663b..db2e94f0c 100644 --- a/src/Profiler.h +++ b/src/Profiler.h @@ -50,7 +50,7 @@ sections.bufferSwap = p.addSection("Buffer swap"); p.enable(); // Mark sections in draw function -void MyContext::drawEvent() { +void MyApplication::drawEvent() { p.start(); // ... misc stuff belogning to "Other" section diff --git a/src/Query.h b/src/Query.h index 934f92e8d..723826ddc 100644 --- a/src/Query.h +++ b/src/Query.h @@ -326,9 +326,9 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { @brief %Query for elapsed time Queries timestamp after all previous OpenGL calls have been processed. It is -similar to Query::Target::TimeElapsed query, but this query just retrieves -timestamp, not time duration between Query::begin() and Query::end() calls. -Example usage, compared to Query::Target::TimeElapsed: +similar to @ref Query::Target "Query::Target::TimeElapsed" query, but this +query just retrieves timestamp, not time duration between Query::begin() and +Query::end() calls. Example usage, compared to @ref Query::Target "Query::Target::TimeElapsed": @code Query q1, q2; q1.begin(Query::Target::TimeElapsed); diff --git a/src/Resource.h b/src/Resource.h index b4abf8196..4084aebfb 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -65,6 +65,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, ResourceState value); /** @brief Key for accessing resource +See ResourceManager for more information. @see ResourceManager::referenceCount(), ResourceManager::state(), ResourceManager::get(), ResourceManager::set(), Resource::key() */ diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 31c11fa39..6340a86ff 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::AbstractCamera, enum AspectRatioPolicy, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D + * @brief Class Magnum::SceneGraph::AbstractCamera, enum Magnum::SceneGraph::AspectRatioPolicy, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D */ #include "Math/Matrix3.h" @@ -62,7 +62,7 @@ file to avoid linker errors. See also relevant sections in - @ref AbstractCamera "AbstractCamera<2>" - @ref AbstractCamera "AbstractCamera<3>" -@see Drawable, DrawableGroup, AbstractCamera2D, AbstractCamera3D +@see @ref scenegraph, Drawable, DrawableGroup, AbstractCamera2D, AbstractCamera3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index ffe33b1be..9e6aaf5f2 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -44,8 +44,8 @@ class Drawable: public SceneGraph::AbstractGroupedFeature3D { typedef SceneGraph::FeatureGroup3D DrawableGroup; @endcode -@see AbstractGroupedFeature2D, AbstractGroupedFeature3D, FeatureGroup, - FeatureGroup2D, FeatureGroup3D +@see @ref scenegraph, AbstractGroupedFeature2D, AbstractGroupedFeature3D, + FeatureGroup, FeatureGroup2D, FeatureGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template @@ -62,7 +62,7 @@ class AbstractGroupedFeature: public AbstractFeature { * @param group Group this feature belongs to * * Adds the feature to the object and to group, if specified. - * @see FeatureGroup::add(), FeatureGroup::remove() + * @see FeatureGroup::add() */ inline AbstractGroupedFeature(AbstractObject* object, FeatureGroup* group = nullptr): AbstractFeature(object), _group(nullptr) { if(group) group->add(static_cast(this)); diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 718d6c09f..d3fc55f99 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -34,12 +34,12 @@ for introduction. @section AbstractTransformation-subclassing Subclassing -When sublassing, you have to: +When subclassing, you have to: -- Implement all members described in **Subclass implementation** group above +- Implement all members listed in **Subclass implementation** group above - Provide implicit (parameterless) constructor -@see AbstractTransformation2D, AbstractTransformation3D +@see @ref scenegraph, AbstractTransformation2D, AbstractTransformation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index e06566397..62be8ef0e 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -26,7 +26,7 @@ namespace Magnum { namespace SceneGraph { /** @brief Base for two-dimensional transformations supporting translation and rotation -@see AbstractTranslationRotation3D +@see @ref scenegraph, AbstractTranslationRotation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index 1175b8af2..1bd1ff6b3 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -27,7 +27,7 @@ namespace Magnum { namespace SceneGraph { /** @brief Base for three-dimensional transformations supporting translation and rotation -@see AbstractTranslationRotation2D +@see @ref scenegraph, AbstractTranslationRotation2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/AbstractTranslationRotationScaling2D.h b/src/SceneGraph/AbstractTranslationRotationScaling2D.h index 26da23b36..269aada69 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling2D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling2D.h @@ -26,7 +26,7 @@ namespace Magnum { namespace SceneGraph { /** @brief Base for two-dimensional transformations supporting translation, rotation and scaling -@see AbstractTranslationRotationScaling2D +@see @ref scenegraph, AbstractTranslationRotationScaling2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/AbstractTranslationRotationScaling3D.h b/src/SceneGraph/AbstractTranslationRotationScaling3D.h index ab4ffd4f6..30cebf0ad 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling3D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling3D.h @@ -26,7 +26,7 @@ namespace Magnum { namespace SceneGraph { /** @brief Base for three-dimensional transformations supporting translation, rotation and scaling -@see AbstractTranslationRotationScaling2D +@see @ref scenegraph, AbstractTranslationRotationScaling2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 072fc6f92..cff11919b 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -26,7 +26,14 @@ namespace Magnum { namespace SceneGraph { /** @brief Camera for two-dimensional scenes -See Drawable documentation for more information. +See Drawable documentation for introduction. The camera by default displays +OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` and doesn't do any aspect ratio +correction. Common setup example: +@code +SceneGraph::Camera2D<>* camera = new SceneGraph::Camera2D<>(&cameraObject); +camera->setProjection({4.0f/3.0f, 1.0f}) + ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); +@endcode @section Camera2D-explicit-specializations Explicit template specializations @@ -36,7 +43,7 @@ avoid linker errors. See @ref compilation-speedup-hpp for more information. - @ref Camera2D "Camera2D" -@see Camera3D, Drawable, DrawableGroup +@see @ref scenegraph, Camera3D, Drawable, DrawableGroup */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index fae8579ff..688a5ce9b 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -31,7 +31,14 @@ namespace Magnum { namespace SceneGraph { /** @brief Camera for three-dimensional scenes -See Drawable documentation for more information. +See Drawable documentation for introduction. The camera by default displays +OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` with orthographic projection and +doesn't do any aspect ratio correction. Common setup example: +@code +SceneGraph::Camera3D<>* camera = new SceneGraph::Camera3D<>(&cameraObject); +camera->setPerspective(deg(35.0f), 0.001f, 100.0f) + ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); +@endcode @section Camera3D-explicit-specializations Explicit template specializations @@ -41,7 +48,7 @@ avoid linker errors. See @ref compilation-speedup-hpp for more information. - @ref Camera3D "Camera3D" -@see Camera2D, Drawable, DrawableGroup +@see @ref scenegraph, Camera2D, Drawable, DrawableGroup */ #ifndef DOXYGEN_GENERATING_OUTPUT template @@ -54,7 +61,8 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { * @brief Constructor * @param object %Object holding this feature * - * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). + * Sets orthographic projection to the default OpenGL cube + * (range @f$ [-1; 1] @f$ in all directions). * @see setOrthographic(), setPerspective() */ inline Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 9eaca737b..6852e7b1b 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -26,7 +26,7 @@ namespace Magnum { namespace SceneGraph { /** @brief %Drawable -Adds drawing function to object. Each %Drawable is part of some DrawableGroup +Adds drawing feature to object. Each %Drawable is part of some DrawableGroup and the whole group is drawn with particular camera using AbstractCamera::draw(). @section Drawable-usage Usage @@ -52,30 +52,34 @@ class DrawableObject: public Object3D, SceneGraph::Drawable3D<> { Then you add these objects to your scene and some drawable group and transform them as you like. You can also use DrawableGroup::add() and -DrawableGroup::remove() for that. +DrawableGroup::remove(). @code Scene3D scene; -SceneGraph::DrawableGroup3D<> group; +SceneGraph::DrawableGroup3D<> drawables; -(new DrawableObject(&scene, &group)) +(new DrawableObject(&scene, &drawables)) ->translate(Vector3::yAxis(-0.3f)) ->rotateX(deg(30.0f)); -(new AnotherDrawableObject(&scene, &group)) +(new AnotherDrawableObject(&scene, &drawables)) ->translate(Vector3::zAxis(0.5f)); // ... @endcode The last thing you need is Camera attached to some object (thus using its -transformation) and with it you can perform drawing in your draw event: +transformation) and with it you can perform drawing in your draw event +implementation. See Camera2D and Camera3D documentation for more information. @code Camera3D<> camera(&cameraObject); void MyApplication::drawEvent() { - camera.draw(&group); + camera.draw(drawables); + + swapBuffers(); + // ... } @endcode -@see Drawable2D, Drawable3D, DrawableGroup2D, DrawableGroup3D +@see @ref scenegraph, Drawable2D, Drawable3D, DrawableGroup2D, DrawableGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template @@ -136,7 +140,7 @@ typedef Drawable<3, T = GLfloat> Drawable3D; @brief Group of drawables See Drawable for more information. -@see DrawableGroup2D, DrawableGroup3D +@see @ref scenegraph, DrawableGroup2D, DrawableGroup3D @todoc Remove workaround when Doxygen supports alias template */ #if !defined(CORRADE_GCC46_COMPATIBILITY) && !defined(DOXYGEN_GENERATING_OUTPUT) diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 914b4dd0c..c17238dcb 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -31,7 +31,7 @@ namespace Magnum { namespace SceneGraph { @brief Group of features See AbstractGroupedFeature for more information. -@see FeatureGroup2D, FeatureGroup3D +@see @ref scenegraph, FeatureGroup2D, FeatureGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index e60dc18a6..ceeab86fc 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -28,7 +28,8 @@ namespace Magnum { namespace SceneGraph { /** @brief Two-dimensional transformation implemented using matrices -@see MatrixTransformation3D +Uses Math::Matrix3 as underlying type. +@see @ref scenegraph, MatrixTransformation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 763acbcc3..7eabf1938 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -28,7 +28,8 @@ namespace Magnum { namespace SceneGraph { /** @brief Three-dimensional transformation implemented using matrices -@see MatrixTransformation2D +Uses Math::Matrix4 as underlying type. +@see @ref scenegraph, MatrixTransformation2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/Shader.h b/src/Shader.h index 643674b77..566cadb68 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -30,11 +30,10 @@ namespace Magnum { /** - * @brief %Shader - * - * Allows loading and compiling the shader from file or directly from source - * string. Compiled shaders are then passed to AbstractShaderProgram subclasses - * for linking and usage. +@brief %Shader + +Allows loading and compiling the shader from file or directly from source +string. See AbstractShaderProgram for more information. */ class MAGNUM_EXPORT Shader { Shader(const Shader& other) = delete; diff --git a/src/Texture.h b/src/Texture.h index 9d2c45e06..6b55d1303 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -63,6 +63,9 @@ information. @section Texture-array Texture arrays +You can create texture arrays by passing @ref Texture::Target "Texture2D::Target::Texture1DArray" +or @ref Texture::Target "Texture3D::Target::Texture2DArray" to constructor. + It is possible to specify each layer separately using setSubData(), but you have to allocate the memory for all layers first, possibly by passing properly sized empty Image to setData(). Example: 2D texture array with 16 layers of @@ -90,13 +93,13 @@ etc.). @section Texture-rectangle Rectangle textures -If you want to use rectangle textures, set target in constructor to -`Target::Rectangle` and in shader use `sampler2DRect`. Unlike `sampler2D`, -which accepts coordinates between 0 and 1, `sampler2DRect` accepts coordinates -between 0 and `textureSizeInGivenDirection-1`. Note that rectangle textures -don't support mipmapping and repeating wrapping modes, see @ref Texture::Filter -"Filter", @ref Texture::Mipmap "Mipmap" and generateMipmap() documentation -for more information. +Rectangle texture is created by passing @ref Texture::Target "Texture::Target::Rectangle" +to constructor. In shader, the texture is used via sampler2DRect`. Unlike +`sampler2D`, which accepts coordinates between 0 and 1, `sampler2DRect` +accepts coordinates between 0 and `textureSizeInGivenDirection-1`. Note that +rectangle textures don't support mipmapping and repeating wrapping modes, see +@ref Texture::Filter "Filter", @ref Texture::Mipmap "Mipmap" and +generateMipmap() documentation for more information. @requires_gl Rectangle textures are not available in OpenGL ES. @requires_gl31 Extension @extension{ARB,texture_rectangle} (rectangle textures) From 5a9317085c8ecaa11672f48c851de580d0f8bed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 12:47:38 +0100 Subject: [PATCH 017/567] Moved functions not related to particular Framebuffer to Renderer class. Framebuffer::setViewport() and clear() should be non-static and operate on particular framebuffer in the future. --- src/CMakeLists.txt | 1 + src/Framebuffer.h | 608 +----------------------------------------- src/Renderer.h | 649 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 652 insertions(+), 606 deletions(-) create mode 100644 src/Renderer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a9d4b9d59..a65f447a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -71,6 +71,7 @@ set(Magnum_HEADERS Profiler.h Query.h Renderbuffer.h + Renderer.h Resource.h ResourceManager.h Shader.h diff --git a/src/Framebuffer.h b/src/Framebuffer.h index f4aba3115..67ae17619 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -43,84 +43,6 @@ class MAGNUM_EXPORT Framebuffer { Framebuffer& operator=(Framebuffer&& other) = delete; public: - /** - * @brief Affected polygon facing for culling, stencil operations and masks - * - * @see setFaceCullingMode(), - * setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint), - * setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation), - * setStencilMask(PolygonFacing, GLuint) - */ - enum class PolygonFacing: GLenum { - Front = GL_FRONT, /**< Front-facing polygons */ - Back = GL_BACK, /**< Back-facing polygons */ - FrontAndBack = GL_FRONT_AND_BACK /**< Front- and back-facing polygons */ - }; - - /** @{ @name Framebuffer features */ - - /** - * @brief Features - * - * If not specified otherwise, all features are disabled by default. - * @see setFeature() - */ - enum class Feature: GLenum { - /** - * Blending - * @see setBlendEquation(), setBlendFunction(), setBlendColor() - */ - Blending = GL_BLEND, - - #ifndef MAGNUM_TARGET_GLES - /** - * Logical operation - * @see setLogicOperation() - * @requires_gl Logical operations on framebuffer are not - * available in OpenGL ES. - */ - LogicOperation = GL_COLOR_LOGIC_OP, - - /** - * Depth clamping. If enabled, ignores near and far clipping plane. - * @requires_gl32 Extension @extension{ARB,depth_clamp} - * @requires_gl Depth clamping is not available in OpenGL ES. - */ - DepthClamp = GL_DEPTH_CLAMP, - #endif - - /** - * Scissor test - * @see setScissor() - */ - ScissorTest = GL_SCISSOR_TEST, - DepthTest = GL_DEPTH_TEST, /**< Depth test */ - StencilTest = GL_STENCIL_TEST, /**< Stencil test */ - Dithering = GL_DITHER, /**< Dithering (enabled by default) */ - FaceCulling = GL_CULL_FACE /**< Back face culling */ - }; - - /** - * @brief Set feature - * - * @see @fn_gl{Enable}/@fn_gl{Disable} - */ - inline static void setFeature(Feature feature, bool enabled) { - enabled ? glEnable(static_cast(feature)) : glDisable(static_cast(feature)); - } - - /** - * @brief Which polygon facing to cull - * - * Initial value is `PolygonFacing::Back`. If set to both front and - * back, only points and lines are drawn. - * @attention You have to also enable face culling with setFeature(). - * @see @fn_gl{CullFace} - */ - inline static void setFaceCullingMode(PolygonFacing mode) { - glCullFace(static_cast(mode)); - } - /** * @brief Set viewport size * @@ -131,10 +53,6 @@ class MAGNUM_EXPORT Framebuffer { glViewport(position.x(), position.y(), size.x(), size.y()); } - /*@}*/ - - /** @{ @name Clearing the framebuffer */ - /** * @brief Mask for clearing * @@ -153,534 +71,12 @@ class MAGNUM_EXPORT Framebuffer { /** * @brief Clear specified buffers in framebuffer * - * @see clear(), setClearColor(), setClearDepth(), setClearStencil(), - * @fn_gl{Clear} + * @see clear(), Renderer::setClearColor(), Renderer::setClearDepth(), + * Renderer::setClearStencil(), @fn_gl{Clear} * @todo Clearing only given draw buffer */ inline static void clear(ClearMask mask) { glClear(static_cast(mask)); } - /** - * @brief Set clear color - * - * Initial value is `{0.0f, 0.0f, 0.0f, 1.0f}`. - * @see @fn_gl{ClearColor} - */ - inline static void setClearColor(const Color4<>& color) { - glClearColor(color.r(), color.g(), color.b(), color.a()); - } - - #ifndef MAGNUM_TARGET_GLES - /** - * @brief Set clear depth - * - * Initial value is `1.0`. - * @see @fn_gl{ClearDepth} - * @requires_gl See setClearDepth(GLfloat), which is available in OpenGL ES. - */ - inline static void setClearDepth(GLdouble depth) { glClearDepth(depth); } - #endif - - /** - * @overload - * - * @see @fn_gl{ClearDepth} - * @requires_gl41 Extension @extension{ARB,ES2_compatibility} - * @todo Call double version if the extension is not available - */ - inline static void setClearDepth(GLfloat depth) { glClearDepthf(depth); } - - /** - * @brief Set clear stencil - * - * Initial value is `0`. - * @see @fn_gl{ClearStencil} - */ - inline static void setClearStencil(GLint stencil) { glClearStencil(stencil); } - - /*@}*/ - - /** @{ @name Scissor operations */ - - /** - * @brief Set scissor rectangle - * @param bottomLeft Bottom left corner. Initial value is `(0, 0)`. - * @param size Scissor rectangle size. Initial value is - * size of the window when the context is first attached to a - * window. - * - * @attention You have to enable scissoring with setFeature() first. - * @see @fn_gl{Scissor} - */ - inline static void setScissor(const Vector2i& bottomLeft, const Vector2i& size) { - glScissor(bottomLeft.x(), bottomLeft.y(), size.x(), size.y()); - } - - /*@}*/ - - /** @{ @name Stencil operations */ - - /** - * @brief Stencil function - * - * @see setStencilFunction() - */ - enum class StencilFunction: GLenum { - Never = GL_NEVER, /**< Never pass the test. */ - Always = GL_ALWAYS, /**< Always pass the test. */ - Less = GL_LESS, /**< Pass when reference value is less than buffer value. */ - LessOrEqual = GL_LEQUAL, /**< Pass when reference value is less than or equal to buffer value. */ - Equal = GL_EQUAL, /**< Pass when reference value is equal to buffer value. */ - NotEqual = GL_NOTEQUAL, /**< Pass when reference value is not equal to buffer value. */ - GreaterOrEqual = GL_GEQUAL, /**< Pass when reference value is greater than or equal to buffer value. */ - Greater = GL_GREATER /**< Pass when reference value is greater than buffer value. */ - }; - - /** - * @brief Stencil operation - * - * @see setStencilOperation() - */ - enum class StencilOperation: GLenum { - Keep = GL_KEEP, /**< Keep the current value. */ - Zero = GL_ZERO, /**< Set the stencil buffer value to `0`. */ - - /** - * Set the stencil value to reference value specified by - * setStencilFunction(). - */ - Replace = GL_REPLACE, - - /** - * Increment the current stencil buffer value, clamp to maximum - * possible value on overflow. - */ - Increment = GL_INCR, - - /** - * Increment the current stencil buffer value, wrap to zero on - * overflow. - */ - IncrementWrap = GL_INCR_WRAP, - - /** - * Increment the current stencil buffer value, clamp to minimum - * possible value on underflow. - */ - Decrement = GL_DECR, - - /** - * Decrement the current stencil buffer value, wrap to maximum - * possible value on underflow. - */ - DecrementWrap = GL_DECR_WRAP, - - /** - * Bitwise invert the current stencil buffer value. - */ - Invert = GL_INVERT - }; - - /** - * @brief Set stencil function - * @param facing Affected polygon facing - * @param function Stencil function. Initial value is - * `StencilFunction::Always`. - * @param referenceValue Reference value. Initial value is `0`. - * @param mask Mask for both reference and buffer value. - * Initial value is all `1`s. - * - * @attention You have to enable stencil test with setFeature() first. - * @see setStencilFunction(StencilFunction, GLint, GLuint), - * @fn_gl{StencilFuncSeparate} - */ - inline static void setStencilFunction(PolygonFacing facing, StencilFunction function, GLint referenceValue, GLuint mask) { - glStencilFuncSeparate(static_cast(facing), static_cast(function), referenceValue, mask); - } - - /** - * @brief Set stencil function - * - * The same as setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint) - * with `facing` set to `PolygonFacing::FrontAndBack`. - * @see @fn_gl{StencilFunc} - */ - inline static void setStencilFunction(StencilFunction function, GLint referenceValue, GLuint mask) { - glStencilFunc(static_cast(function), referenceValue, mask); - } - - /** - * @brief Set stencil operation - * @param facing Affected polygon facing - * @param stencilFail Action when stencil test fails - * @param depthFail Action when stencil test passes, but depth - * test fails - * @param depthPass Action when both stencil and depth test - * pass - * - * Initial value for all fields is `StencilOperation::Keep`. - * @attention You have to enable stencil test with setFeature() first. - * @see setStencilOperation(StencilOperation, StencilOperation, StencilOperation), - * @fn_gl{StencilOpSeparate} - */ - inline static void setStencilOperation(PolygonFacing facing, StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthPass) { - glStencilOpSeparate(static_cast(facing), static_cast(stencilFail), static_cast(depthFail), static_cast(depthPass)); - } - - /** - * @brief Set stencil operation - * - * The same as setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation) - * with `facing` set to `PolygonFacing::FrontAndBack`. - * @see @fn_gl{StencilOp} - */ - inline static void setStencilOperation(StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthPass) { - glStencilOp(static_cast(stencilFail), static_cast(depthFail), static_cast(depthPass)); - } - - /*@}*/ - - /** @{ @name Depth testing */ - - /** - * @brief Depth function - * - * @see setDepthFunction() - */ - typedef StencilFunction DepthFunction; - - /** - * @brief Set depth function - * - * Initial value is `DepthFunction::Less`. - * @attention You have to enable depth test with setFeature() first. - * @see @fn_gl{DepthFunc} - */ - inline static void setDepthFunction(DepthFunction function) { - glDepthFunc(static_cast(function)); - } - - /*@}*/ - - /** @{ @name Masking writes */ - - /** - * @brief Mask color writes - * - * Set to `false` to disallow writing to given color channel. Initial - * values are all `true`. - * @see @fn_gl{ColorMask} - * @todo Masking only given draw buffer - */ - inline static void setColorMask(GLboolean allowRed, GLboolean allowGreen, GLboolean allowBlue, GLboolean allowAlpha) { - glColorMask(allowRed, allowGreen, allowBlue, allowAlpha); - } - - /** - * @brief Mask depth writes - * - * Set to `false` to disallow writing to depth buffer. Initial value - * is `true`. - * @see @fn_gl{DepthMask} - */ - inline static void setDepthMask(GLboolean allow) { - glDepthMask(allow); - } - - /** - * @brief Mask stencil writes - * - * Set given bit to `0` to disallow writing stencil value for given - * faces to it. Initial value is all `1`s. - * @see setStencilMask(GLuint), @fn_gl{StencilMaskSeparate} - */ - inline static void setStencilMask(PolygonFacing facing, GLuint allowBits) { - glStencilMaskSeparate(static_cast(facing), allowBits); - } - - /** - * @brief Mask stencil writes - * - * The same as setStencilMask(PolygonFacing, GLuint) with `facing` set - * to `PolygonFacing::FrontAndBack`. - * @see @fn_gl{StencilMask} - */ - inline static void setStencilMask(GLuint allowBits) { - glStencilMask(allowBits); - } - - /*@}*/ - - /** @{ @name Blending - * You have to enable blending with setFeature() first. - * @todo Blending for given draw buffer - */ - - /** - * @brief Blend equation - * - * @see setBlendEquation() - */ - enum class BlendEquation: GLenum { - Add = GL_FUNC_ADD, /**< `source + destination` */ - Subtract = GL_FUNC_SUBTRACT, /**< `source - destination` */ - ReverseSubtract = GL_FUNC_REVERSE_SUBTRACT /**< `destination - source` */ - - #ifndef MAGNUM_TARGET_GLES2 - , - /** - * `min(source, destination)` - * @requires_gles30 %Extension @es_extension2{EXT,blend_minmax,blend_minmax} - */ - Min = GL_MIN, - - /** - * `max(source, destination)` - * @requires_gles30 %Extension @es_extension2{EXT,blend_minmax,blend_minmax} - */ - Max = GL_MAX - #endif - }; - - /** - * @brief Blend function - * - * @see setBlendFunction() - */ - enum class BlendFunction: GLenum { - /** Zero (@f$ RGB = (0.0, 0.0, 0.0); A = 0.0 @f$) */ - Zero = GL_ZERO, - - /** One (@f$ RGB = (1.0, 1.0, 1.0); A = 1.0 @f$) */ - One = GL_ONE, - - /** - * Constant color (@f$ RGB = (R_c, G_c, B_c); A = A_c @f$) - * - * @see setBlendColor() - */ - ConstantColor = GL_CONSTANT_COLOR, - - /** - * One minus constant color (@f$ RGB = (1.0 - R_c, 1.0 - G_c, 1.0 - B_c); A = 1.0 - A_c @f$) - * - * @see setBlendColor() - */ - OneMinusConstantColor = GL_ONE_MINUS_CONSTANT_COLOR, - - /** - * Constant alpha (@f$ RGB = (A_c, A_c, A_c); A = A_c @f$) - * - * @see setBlendColor() - */ - ConstantAlpha = GL_CONSTANT_ALPHA, - - /** - * One minus constant alpha (@f$ RGB = (1.0 - A_c, 1.0 - A_c, 1.0 - A_c); A = 1.0 - A_c @f$) - * - * @see setBlendColor() - */ - OneMinusConstantAlpha = GL_ONE_MINUS_CONSTANT_ALPHA, - - /** Source color (@f$ RGB = (R_{s0}, G_{s0}, B_{s0}); A = A_{s0} @f$) */ - SourceColor = GL_SRC_COLOR, - - #ifndef MAGNUM_TARGET_GLES - /** - * Second source color (@f$ RGB = (R_{s1}, G_{s1}, B_{s1}); A = A_{s1} @f$) - * - * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} - * @requires_gl Multiple blending inputs are not available in - * OpenGL ES. - */ - SecondSourceColor = GL_SRC1_COLOR, - #endif - - /** - * One minus source color (@f$ RGB = (1.0 - R_{s0}, 1.0 - G_{s0}, 1.0 - B_{s0}); A = 1.0 - A_{s0} @f$) - */ - OneMinusSourceColor = GL_ONE_MINUS_SRC_COLOR, - - #ifndef MAGNUM_TARGET_GLES - /** - * One minus second source color (@f$ RGB = (1.0 - R_{s1}, 1.0 - G_{s1}, 1.0 - B_{s1}); A = 1.0 - A_{s1} @f$) - * - * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} - * @requires_gl Multiple blending inputs are not available in - * OpenGL ES. - */ - OneMinusSecondSourceColor = GL_ONE_MINUS_SRC1_COLOR, - #endif - - /** Source alpha (@f$ RGB = (A_{s0}, A_{s0}, A_{s0}); A = A_{s0} @f$) */ - SourceAlpha = GL_SRC_ALPHA, - - /** - * Saturate source alpha (@f$ RGB = (f, f, f); A = 1.0; f = min(A_s, 1.0 - A_d) @f$) - * - * Can be used only in source parameter of setBlendFunction(). - */ - SourceAlphaSaturate = GL_SRC_ALPHA_SATURATE, - - #ifndef MAGNUM_TARGET_GLES - /** - * Second source alpha (@f$ RGB = (A_{s1}, A_{s1}, A_{s1}); A = A_{s1} @f$) - * - * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} - * @requires_gl Multiple blending inputs are not available in - * OpenGL ES. - */ - SecondSourceAlpha = GL_SRC1_ALPHA, - #endif - - /** - * One minus source alpha (@f$ RGB = (1.0 - A_{s0}, 1.0 - A_{s0}, 1.0 - A_{s0}); A = 1.0 - A_{s0} @f$) - */ - OneMinusSourceAlpha = GL_ONE_MINUS_SRC_ALPHA, - - #ifndef MAGNUM_TARGET_GLES - /** - * One minus second source alpha (@f$ RGB = (1.0 - A_{s1}, 1.0 - A_{s1}, 1.0 - A_{s1}); A = 1.0 - A_{s1} @f$) - * - * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} - * @requires_gl Multiple blending inputs are not available in - * OpenGL ES. - */ - OneMinusSecondSourceAlpha = GL_ONE_MINUS_SRC1_ALPHA, - #endif - - /** Destination color (@f$ RGB = (R_d, G_d, B_d); A = A_d @f$) */ - DestinationColor = GL_DST_COLOR, - - /** - * One minus source color (@f$ RGB = (1.0 - R_d, 1.0 - G_d, 1.0 - B_d); A = 1.0 - A_d @f$) - */ - OneMinusDestinationColor = GL_ONE_MINUS_DST_COLOR, - - /** Destination alpha (@f$ RGB = (A_d, A_d, A_d); A = A_d @f$) */ - DestinationAlpha = GL_DST_ALPHA, - - /** - * One minus source alpha (@f$ RGB = (1.0 - A_d, 1.0 - A_d, 1.0 - A_d); A = 1.0 - A_d @f$) - */ - OneMinusDestinationAlpha = GL_ONE_MINUS_DST_ALPHA - }; - - /** - * @brief Set blend equation - * - * How to combine source color (pixel value) with destination color - * (framebuffer). Initial value is `BlendEquation::Add`. - * @attention You have to enable blending with setFeature() first. - * @see setBlendEquation(BlendEquation, BlendEquation), - * @fn_gl{BlendEquation} - */ - inline static void setBlendEquation(BlendEquation equation) { - glBlendEquation(static_cast(equation)); - } - - /** - * @brief Set blend equation separately for RGB and alpha components - * - * See setBlendEquation(BlendEquation) for more information. - * @attention You have to enable blending with setFeature() first. - * @see @fn_gl{BlendEquationSeparate} - */ - inline static void setBlendEquation(BlendEquation rgb, BlendEquation alpha) { - glBlendEquationSeparate(static_cast(rgb), static_cast(alpha)); - } - - /** - * @brief Set blend function - * @param source How the source blending factor is computed - * from pixel value. Initial value is `BlendFunction::One`. - * @param destination How the destination blending factor is - * computed from framebuffer. Initial value is - * `BlendFunction::Zero`. - * - * @attention You have to enable blending with setFeature() first. - * @see setBlendFunction(BlendFunction, BlendFunction, BlendFunction, BlendFunction), - * @fn_gl{BlendFunc} - */ - inline static void setBlendFunction(BlendFunction source, BlendFunction destination) { - glBlendFunc(static_cast(source), static_cast(destination)); - } - - /** - * @brief Set blend function separately for RGB and alpha components - * - * See setBlendFunction(BlendFunction, BlendFunction) for more information. - * @attention You have to enable blending with setFeature() first. - * @see @fn_gl{BlendFuncSeparate} - */ - inline static void setBlendFunction(BlendFunction sourceRgb, BlendFunction destinationRgb, BlendFunction sourceAlpha, BlendFunction destinationAlpha) { - glBlendFuncSeparate(static_cast(sourceRgb), static_cast(destinationRgb), static_cast(sourceAlpha), static_cast(destinationAlpha)); - } - - /** - * @brief Set blend color - * - * Sets constant color used in setBlendFunction() by - * `BlendFunction::ConstantColor`, - * `BlendFunction::OneMinusConstantColor`, - * `BlendFunction::ConstantAlpha` and - * `BlendFunction::OneMinusConstantAlpha`. - * @attention You have to enable blending with setFeature() first. - * @see @fn_gl{BlendColor} - */ - inline static void setBlendColor(const Color4<>& color) { - glBlendColor(color.r(), color.g(), color.b(), color.a()); - } - - /*@}*/ - - #ifndef MAGNUM_TARGET_GLES - /** @{ @name Logical operation */ - - /** - * @brief Logical operation - * - * @see setLogicOperation() - * @requires_gl Logical operations on framebuffer are not available in - * OpenGL ES. - */ - enum class LogicOperation: GLenum { - Clear = GL_CLEAR, /**< `0` */ - Set = GL_SET, /**< `1` */ - Copy = GL_COPY, /**< `source` */ - CopyInverted = GL_COPY_INVERTED,/**< `~source` */ - Noop = GL_NOOP, /**< `destination` */ - Invert = GL_INVERT, /**< `~destination` */ - And = GL_AND, /**< `source & destination` */ - AndReverse = GL_AND_REVERSE, /**< `source & ~destination` */ - AndInverted = GL_AND_INVERTED, /**< `~source & destination` */ - Nand = GL_NAND, /**< `~(source & destination)` */ - Or = GL_OR, /**< `source | destination` */ - OrReverse = GL_OR_REVERSE, /**< `source | ~destination` */ - OrInverted = GL_OR_INVERTED, /**< `~source | destination` */ - Nor = GL_NOR, /**< `~(source | destination)` */ - Xor = GL_XOR, /**< `source ^ destination` */ - Equivalence = GL_EQUIV /**< `~(source ^ destination)` */ - }; - - /** - * @brief Set logical operation - * - * @attention You have to enable logical operation with setFeature() first. - * @see @fn_gl{LogicOp} - * @requires_gl Logical operations on framebuffer are not available in - * OpenGL ES. - */ - inline static void setLogicOperation(LogicOperation operation) { - glLogicOp(static_cast(operation)); - } - - /*@}*/ - #endif - /** @{ @name Framebuffer creation and binding */ /** diff --git a/src/Renderer.h b/src/Renderer.h new file mode 100644 index 000000000..d4b319676 --- /dev/null +++ b/src/Renderer.h @@ -0,0 +1,649 @@ +#ifndef Magnum_Renderer_h +#define Magnum_Renderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Renderer + */ + +#include + +#include "AbstractImage.h" +#include "Buffer.h" +#include "CubeMapTexture.h" +#include "Color.h" +#include "Renderbuffer.h" + +namespace Magnum { + +/** @nosubgrouping +@brief %Renderer + +Access to global renderer configuration. +@todo @extension{ARB,viewport_array} +*/ +class MAGNUM_EXPORT Renderer { + Renderer() = delete; + + public: + /** + * @brief Affected polygon facing for culling, stencil operations and masks + * + * @see setFaceCullingMode(), + * setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint), + * setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation), + * setStencilMask(PolygonFacing, GLuint) + */ + enum class PolygonFacing: GLenum { + Front = GL_FRONT, /**< Front-facing polygons */ + Back = GL_BACK, /**< Back-facing polygons */ + FrontAndBack = GL_FRONT_AND_BACK /**< Front- and back-facing polygons */ + }; + + /** @{ @name Renderer features */ + + /** + * @brief Features + * + * If not specified otherwise, all features are disabled by default. + * @see setFeature() + */ + enum class Feature: GLenum { + /** + * Blending + * @see setBlendEquation(), setBlendFunction(), setBlendColor() + */ + Blending = GL_BLEND, + + #ifndef MAGNUM_TARGET_GLES + /** + * Logical operation + * @see setLogicOperation() + * @requires_gl Logical operations on framebuffer are not + * available in OpenGL ES. + */ + LogicOperation = GL_COLOR_LOGIC_OP, + + /** + * Depth clamping. If enabled, ignores near and far clipping plane. + * @requires_gl32 Extension @extension{ARB,depth_clamp} + * @requires_gl Depth clamping is not available in OpenGL ES. + */ + DepthClamp = GL_DEPTH_CLAMP, + #endif + + /** + * Scissor test + * @see setScissor() + */ + ScissorTest = GL_SCISSOR_TEST, + DepthTest = GL_DEPTH_TEST, /**< Depth test */ + StencilTest = GL_STENCIL_TEST, /**< Stencil test */ + Dithering = GL_DITHER, /**< Dithering (enabled by default) */ + FaceCulling = GL_CULL_FACE /**< Back face culling */ + }; + + /** + * @brief Set feature + * + * @see @fn_gl{Enable}/@fn_gl{Disable} + */ + inline static void setFeature(Feature feature, bool enabled) { + enabled ? glEnable(static_cast(feature)) : glDisable(static_cast(feature)); + } + + /** + * @brief Which polygon facing to cull + * + * Initial value is `PolygonFacing::Back`. If set to both front and + * back, only points and lines are drawn. + * @attention You have to also enable face culling with setFeature(). + * @see @fn_gl{CullFace} + */ + inline static void setFaceCullingMode(PolygonFacing mode) { + glCullFace(static_cast(mode)); + } + + /*@}*/ + + /** @{ @name Clearing values */ + + /** + * @brief Set clear color + * + * Initial value is `{0.0f, 0.0f, 0.0f, 1.0f}`. + * @see @fn_gl{ClearColor} + */ + inline static void setClearColor(const Color4<>& color) { + glClearColor(color.r(), color.g(), color.b(), color.a()); + } + + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Set clear depth + * + * Initial value is `1.0`. + * @see @fn_gl{ClearDepth} + * @requires_gl See setClearDepth(GLfloat), which is available in OpenGL ES. + */ + inline static void setClearDepth(GLdouble depth) { glClearDepth(depth); } + #endif + + /** + * @overload + * + * @see @fn_gl{ClearDepth} + * @requires_gl41 Extension @extension{ARB,ES2_compatibility} + * @todo Call double version if the extension is not available + */ + inline static void setClearDepth(GLfloat depth) { glClearDepthf(depth); } + + /** + * @brief Set clear stencil + * + * Initial value is `0`. + * @see @fn_gl{ClearStencil} + */ + inline static void setClearStencil(GLint stencil) { glClearStencil(stencil); } + + /*@}*/ + + /** @{ @name Scissor operations */ + + /** + * @brief Set scissor rectangle + * @param bottomLeft Bottom left corner. Initial value is `(0, 0)`. + * @param size Scissor rectangle size. Initial value is + * size of the window when the context is first attached to a + * window. + * + * @attention You have to enable scissoring with setFeature() first. + * @see @fn_gl{Scissor} + */ + inline static void setScissor(const Vector2i& bottomLeft, const Vector2i& size) { + glScissor(bottomLeft.x(), bottomLeft.y(), size.x(), size.y()); + } + + /*@}*/ + + /** @{ @name Stencil operations */ + + /** + * @brief Stencil function + * + * @see setStencilFunction() + */ + enum class StencilFunction: GLenum { + Never = GL_NEVER, /**< Never pass the test. */ + Always = GL_ALWAYS, /**< Always pass the test. */ + Less = GL_LESS, /**< Pass when reference value is less than buffer value. */ + LessOrEqual = GL_LEQUAL, /**< Pass when reference value is less than or equal to buffer value. */ + Equal = GL_EQUAL, /**< Pass when reference value is equal to buffer value. */ + NotEqual = GL_NOTEQUAL, /**< Pass when reference value is not equal to buffer value. */ + GreaterOrEqual = GL_GEQUAL, /**< Pass when reference value is greater than or equal to buffer value. */ + Greater = GL_GREATER /**< Pass when reference value is greater than buffer value. */ + }; + + /** + * @brief Stencil operation + * + * @see setStencilOperation() + */ + enum class StencilOperation: GLenum { + Keep = GL_KEEP, /**< Keep the current value. */ + Zero = GL_ZERO, /**< Set the stencil buffer value to `0`. */ + + /** + * Set the stencil value to reference value specified by + * setStencilFunction(). + */ + Replace = GL_REPLACE, + + /** + * Increment the current stencil buffer value, clamp to maximum + * possible value on overflow. + */ + Increment = GL_INCR, + + /** + * Increment the current stencil buffer value, wrap to zero on + * overflow. + */ + IncrementWrap = GL_INCR_WRAP, + + /** + * Increment the current stencil buffer value, clamp to minimum + * possible value on underflow. + */ + Decrement = GL_DECR, + + /** + * Decrement the current stencil buffer value, wrap to maximum + * possible value on underflow. + */ + DecrementWrap = GL_DECR_WRAP, + + /** + * Bitwise invert the current stencil buffer value. + */ + Invert = GL_INVERT + }; + + /** + * @brief Set stencil function + * @param facing Affected polygon facing + * @param function Stencil function. Initial value is + * `StencilFunction::Always`. + * @param referenceValue Reference value. Initial value is `0`. + * @param mask Mask for both reference and buffer value. + * Initial value is all `1`s. + * + * @attention You have to enable stencil test with setFeature() first. + * @see setStencilFunction(StencilFunction, GLint, GLuint), + * @fn_gl{StencilFuncSeparate} + */ + inline static void setStencilFunction(PolygonFacing facing, StencilFunction function, GLint referenceValue, GLuint mask) { + glStencilFuncSeparate(static_cast(facing), static_cast(function), referenceValue, mask); + } + + /** + * @brief Set stencil function + * + * The same as setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint) + * with `facing` set to `PolygonFacing::FrontAndBack`. + * @see @fn_gl{StencilFunc} + */ + inline static void setStencilFunction(StencilFunction function, GLint referenceValue, GLuint mask) { + glStencilFunc(static_cast(function), referenceValue, mask); + } + + /** + * @brief Set stencil operation + * @param facing Affected polygon facing + * @param stencilFail Action when stencil test fails + * @param depthFail Action when stencil test passes, but depth + * test fails + * @param depthPass Action when both stencil and depth test + * pass + * + * Initial value for all fields is `StencilOperation::Keep`. + * @attention You have to enable stencil test with setFeature() first. + * @see setStencilOperation(StencilOperation, StencilOperation, StencilOperation), + * @fn_gl{StencilOpSeparate} + */ + inline static void setStencilOperation(PolygonFacing facing, StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthPass) { + glStencilOpSeparate(static_cast(facing), static_cast(stencilFail), static_cast(depthFail), static_cast(depthPass)); + } + + /** + * @brief Set stencil operation + * + * The same as setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation) + * with `facing` set to `PolygonFacing::FrontAndBack`. + * @see @fn_gl{StencilOp} + */ + inline static void setStencilOperation(StencilOperation stencilFail, StencilOperation depthFail, StencilOperation depthPass) { + glStencilOp(static_cast(stencilFail), static_cast(depthFail), static_cast(depthPass)); + } + + /*@}*/ + + /** @{ @name Depth testing */ + + /** + * @brief Depth function + * + * @see setDepthFunction() + */ + typedef StencilFunction DepthFunction; + + /** + * @brief Set depth function + * + * Initial value is `DepthFunction::Less`. + * @attention You have to enable depth test with setFeature() first. + * @see @fn_gl{DepthFunc} + */ + inline static void setDepthFunction(DepthFunction function) { + glDepthFunc(static_cast(function)); + } + + /*@}*/ + + /** @{ @name Masking writes */ + + /** + * @brief Mask color writes + * + * Set to `false` to disallow writing to given color channel. Initial + * values are all `true`. + * @see @fn_gl{ColorMask} + * @todo Masking only given draw buffer + */ + inline static void setColorMask(GLboolean allowRed, GLboolean allowGreen, GLboolean allowBlue, GLboolean allowAlpha) { + glColorMask(allowRed, allowGreen, allowBlue, allowAlpha); + } + + /** + * @brief Mask depth writes + * + * Set to `false` to disallow writing to depth buffer. Initial value + * is `true`. + * @see @fn_gl{DepthMask} + */ + inline static void setDepthMask(GLboolean allow) { + glDepthMask(allow); + } + + /** + * @brief Mask stencil writes + * + * Set given bit to `0` to disallow writing stencil value for given + * faces to it. Initial value is all `1`s. + * @see setStencilMask(GLuint), @fn_gl{StencilMaskSeparate} + */ + inline static void setStencilMask(PolygonFacing facing, GLuint allowBits) { + glStencilMaskSeparate(static_cast(facing), allowBits); + } + + /** + * @brief Mask stencil writes + * + * The same as setStencilMask(PolygonFacing, GLuint) with `facing` set + * to `PolygonFacing::FrontAndBack`. + * @see @fn_gl{StencilMask} + */ + inline static void setStencilMask(GLuint allowBits) { + glStencilMask(allowBits); + } + + /*@}*/ + + /** @{ @name Blending + * You have to enable blending with setFeature() first. + * @todo Blending for given draw buffer + */ + + /** + * @brief Blend equation + * + * @see setBlendEquation() + */ + enum class BlendEquation: GLenum { + Add = GL_FUNC_ADD, /**< `source + destination` */ + Subtract = GL_FUNC_SUBTRACT, /**< `source - destination` */ + ReverseSubtract = GL_FUNC_REVERSE_SUBTRACT /**< `destination - source` */ + + #ifndef MAGNUM_TARGET_GLES2 + , + /** + * `min(source, destination)` + * @requires_gles30 %Extension @es_extension2{EXT,blend_minmax,blend_minmax} + */ + Min = GL_MIN, + + /** + * `max(source, destination)` + * @requires_gles30 %Extension @es_extension2{EXT,blend_minmax,blend_minmax} + */ + Max = GL_MAX + #endif + }; + + /** + * @brief Blend function + * + * @see setBlendFunction() + */ + enum class BlendFunction: GLenum { + /** Zero (@f$ RGB = (0.0, 0.0, 0.0); A = 0.0 @f$) */ + Zero = GL_ZERO, + + /** One (@f$ RGB = (1.0, 1.0, 1.0); A = 1.0 @f$) */ + One = GL_ONE, + + /** + * Constant color (@f$ RGB = (R_c, G_c, B_c); A = A_c @f$) + * + * @see setBlendColor() + */ + ConstantColor = GL_CONSTANT_COLOR, + + /** + * One minus constant color (@f$ RGB = (1.0 - R_c, 1.0 - G_c, 1.0 - B_c); A = 1.0 - A_c @f$) + * + * @see setBlendColor() + */ + OneMinusConstantColor = GL_ONE_MINUS_CONSTANT_COLOR, + + /** + * Constant alpha (@f$ RGB = (A_c, A_c, A_c); A = A_c @f$) + * + * @see setBlendColor() + */ + ConstantAlpha = GL_CONSTANT_ALPHA, + + /** + * One minus constant alpha (@f$ RGB = (1.0 - A_c, 1.0 - A_c, 1.0 - A_c); A = 1.0 - A_c @f$) + * + * @see setBlendColor() + */ + OneMinusConstantAlpha = GL_ONE_MINUS_CONSTANT_ALPHA, + + /** Source color (@f$ RGB = (R_{s0}, G_{s0}, B_{s0}); A = A_{s0} @f$) */ + SourceColor = GL_SRC_COLOR, + + #ifndef MAGNUM_TARGET_GLES + /** + * Second source color (@f$ RGB = (R_{s1}, G_{s1}, B_{s1}); A = A_{s1} @f$) + * + * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() + * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. + */ + SecondSourceColor = GL_SRC1_COLOR, + #endif + + /** + * One minus source color (@f$ RGB = (1.0 - R_{s0}, 1.0 - G_{s0}, 1.0 - B_{s0}); A = 1.0 - A_{s0} @f$) + */ + OneMinusSourceColor = GL_ONE_MINUS_SRC_COLOR, + + #ifndef MAGNUM_TARGET_GLES + /** + * One minus second source color (@f$ RGB = (1.0 - R_{s1}, 1.0 - G_{s1}, 1.0 - B_{s1}); A = 1.0 - A_{s1} @f$) + * + * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() + * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. + */ + OneMinusSecondSourceColor = GL_ONE_MINUS_SRC1_COLOR, + #endif + + /** Source alpha (@f$ RGB = (A_{s0}, A_{s0}, A_{s0}); A = A_{s0} @f$) */ + SourceAlpha = GL_SRC_ALPHA, + + /** + * Saturate source alpha (@f$ RGB = (f, f, f); A = 1.0; f = min(A_s, 1.0 - A_d) @f$) + * + * Can be used only in source parameter of setBlendFunction(). + */ + SourceAlphaSaturate = GL_SRC_ALPHA_SATURATE, + + #ifndef MAGNUM_TARGET_GLES + /** + * Second source alpha (@f$ RGB = (A_{s1}, A_{s1}, A_{s1}); A = A_{s1} @f$) + * + * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() + * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. + */ + SecondSourceAlpha = GL_SRC1_ALPHA, + #endif + + /** + * One minus source alpha (@f$ RGB = (1.0 - A_{s0}, 1.0 - A_{s0}, 1.0 - A_{s0}); A = 1.0 - A_{s0} @f$) + */ + OneMinusSourceAlpha = GL_ONE_MINUS_SRC_ALPHA, + + #ifndef MAGNUM_TARGET_GLES + /** + * One minus second source alpha (@f$ RGB = (1.0 - A_{s1}, 1.0 - A_{s1}, 1.0 - A_{s1}); A = 1.0 - A_{s1} @f$) + * + * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() + * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl Multiple blending inputs are not available in + * OpenGL ES. + */ + OneMinusSecondSourceAlpha = GL_ONE_MINUS_SRC1_ALPHA, + #endif + + /** Destination color (@f$ RGB = (R_d, G_d, B_d); A = A_d @f$) */ + DestinationColor = GL_DST_COLOR, + + /** + * One minus source color (@f$ RGB = (1.0 - R_d, 1.0 - G_d, 1.0 - B_d); A = 1.0 - A_d @f$) + */ + OneMinusDestinationColor = GL_ONE_MINUS_DST_COLOR, + + /** Destination alpha (@f$ RGB = (A_d, A_d, A_d); A = A_d @f$) */ + DestinationAlpha = GL_DST_ALPHA, + + /** + * One minus source alpha (@f$ RGB = (1.0 - A_d, 1.0 - A_d, 1.0 - A_d); A = 1.0 - A_d @f$) + */ + OneMinusDestinationAlpha = GL_ONE_MINUS_DST_ALPHA + }; + + /** + * @brief Set blend equation + * + * How to combine source color (pixel value) with destination color + * (framebuffer). Initial value is `BlendEquation::Add`. + * @attention You have to enable blending with setFeature() first. + * @see setBlendEquation(BlendEquation, BlendEquation), + * @fn_gl{BlendEquation} + */ + inline static void setBlendEquation(BlendEquation equation) { + glBlendEquation(static_cast(equation)); + } + + /** + * @brief Set blend equation separately for RGB and alpha components + * + * See setBlendEquation(BlendEquation) for more information. + * @attention You have to enable blending with setFeature() first. + * @see @fn_gl{BlendEquationSeparate} + */ + inline static void setBlendEquation(BlendEquation rgb, BlendEquation alpha) { + glBlendEquationSeparate(static_cast(rgb), static_cast(alpha)); + } + + /** + * @brief Set blend function + * @param source How the source blending factor is computed + * from pixel value. Initial value is `BlendFunction::One`. + * @param destination How the destination blending factor is + * computed from framebuffer. Initial value is + * `BlendFunction::Zero`. + * + * @attention You have to enable blending with setFeature() first. + * @see setBlendFunction(BlendFunction, BlendFunction, BlendFunction, BlendFunction), + * @fn_gl{BlendFunc} + */ + inline static void setBlendFunction(BlendFunction source, BlendFunction destination) { + glBlendFunc(static_cast(source), static_cast(destination)); + } + + /** + * @brief Set blend function separately for RGB and alpha components + * + * See setBlendFunction(BlendFunction, BlendFunction) for more information. + * @attention You have to enable blending with setFeature() first. + * @see @fn_gl{BlendFuncSeparate} + */ + inline static void setBlendFunction(BlendFunction sourceRgb, BlendFunction destinationRgb, BlendFunction sourceAlpha, BlendFunction destinationAlpha) { + glBlendFuncSeparate(static_cast(sourceRgb), static_cast(destinationRgb), static_cast(sourceAlpha), static_cast(destinationAlpha)); + } + + /** + * @brief Set blend color + * + * Sets constant color used in setBlendFunction() by + * `BlendFunction::ConstantColor`, + * `BlendFunction::OneMinusConstantColor`, + * `BlendFunction::ConstantAlpha` and + * `BlendFunction::OneMinusConstantAlpha`. + * @attention You have to enable blending with setFeature() first. + * @see @fn_gl{BlendColor} + */ + inline static void setBlendColor(const Color4<>& color) { + glBlendColor(color.r(), color.g(), color.b(), color.a()); + } + + /*@}*/ + + #ifndef MAGNUM_TARGET_GLES + /** @{ @name Logical operation */ + + /** + * @brief Logical operation + * + * @see setLogicOperation() + * @requires_gl Logical operations on framebuffer are not available in + * OpenGL ES. + */ + enum class LogicOperation: GLenum { + Clear = GL_CLEAR, /**< `0` */ + Set = GL_SET, /**< `1` */ + Copy = GL_COPY, /**< `source` */ + CopyInverted = GL_COPY_INVERTED,/**< `~source` */ + Noop = GL_NOOP, /**< `destination` */ + Invert = GL_INVERT, /**< `~destination` */ + And = GL_AND, /**< `source & destination` */ + AndReverse = GL_AND_REVERSE, /**< `source & ~destination` */ + AndInverted = GL_AND_INVERTED, /**< `~source & destination` */ + Nand = GL_NAND, /**< `~(source & destination)` */ + Or = GL_OR, /**< `source | destination` */ + OrReverse = GL_OR_REVERSE, /**< `source | ~destination` */ + OrInverted = GL_OR_INVERTED, /**< `~source | destination` */ + Nor = GL_NOR, /**< `~(source | destination)` */ + Xor = GL_XOR, /**< `source ^ destination` */ + Equivalence = GL_EQUIV /**< `~(source ^ destination)` */ + }; + + /** + * @brief Set logical operation + * + * @attention You have to enable logical operation with setFeature() first. + * @see @fn_gl{LogicOp} + * @requires_gl Logical operations on framebuffer are not available in + * OpenGL ES. + */ + inline static void setLogicOperation(LogicOperation operation) { + glLogicOp(static_cast(operation)); + } + + /*@}*/ + #endif +}; + +} + +#endif From a9b7e24d81aa2a0bcd277cdfca2a1ebc34443772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 22:44:41 +0100 Subject: [PATCH 018/567] SceneGraph: method chaining in FeatureGroup. --- src/SceneGraph/FeatureGroup.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index c17238dcb..293942eb6 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -72,11 +72,12 @@ class FeatureGroup { /** * @brief Add feature to the group + * @return Pointer to self (for method chaining) * * If the features is part of another group, it is removed from it. * @see remove(), AbstractGroupedFeature::AbstractGroupedFeature() */ - void add(Feature* feature) { + FeatureGroup* add(Feature* feature) { /** @todo Assert the same scene for all items? -- can't easily watch when feature object is removed from hierarchy */ @@ -87,21 +88,24 @@ class FeatureGroup { /* Crossreference the feature and group together */ features.push_back(feature); feature->_group = this; + return this; } /** * @brief Remove feature from the group + * @return Pointer to self (for method chaining) * * The feature must be part of the group. * @see add() */ - void remove(Feature* feature) { + FeatureGroup* remove(Feature* feature) { CORRADE_ASSERT(feature->_group == this, - "SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", ); + "SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", this); /* Remove the feature and reset group pointer */ features.erase(std::find(features.begin(), features.end(), feature)); feature->_group = nullptr; + return this; } private: From a97c641e3e90f3cc3247e44ac7bd1998f0f92069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 23:01:21 +0100 Subject: [PATCH 019/567] Doc: explicitly specify template specialization type. Currently the documentation looked like "who would ever want something else than 2D/3D objects", now it hints that the objects can be also on steroids, err.., doubles instead of floats. --- src/SceneGraph/AbstractCamera.h | 4 ++-- src/SceneGraph/Object.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 6340a86ff..b66369436 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -59,8 +59,8 @@ file to avoid linker errors. See also relevant sections in @ref Camera3D-explicit-specializations "Camera3D" class documentation or @ref compilation-speedup-hpp for more information. - - @ref AbstractCamera "AbstractCamera<2>" - - @ref AbstractCamera "AbstractCamera<3>" + - @ref AbstractCamera "AbstractCamera<2, GLfloat>" + - @ref AbstractCamera "AbstractCamera<3, GLfloat>" @see @ref scenegraph, Drawable, DrawableGroup, AbstractCamera2D, AbstractCamera3D */ diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 0755cafe9..5c87c5a47 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -71,8 +71,8 @@ The following specialization are explicitly compiled into SceneGraph library. For other specializations you have to use Object.hpp implementation file to avoid linker errors. See @ref compilation-speedup-hpp for more information. - - @ref MatrixTransformation2D "Object>" - - @ref MatrixTransformation3D "Object>" + - @ref MatrixTransformation2D "Object>" + - @ref MatrixTransformation3D "Object>" @see Scene, AbstractFeature, AbstractTransformation */ From 99ce0bc5e08c0ae74fe4d070d53cafa0b4357590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 23:30:44 +0100 Subject: [PATCH 020/567] SceneGraph: document performance tricks with DrawableGroup. --- src/SceneGraph/Drawable.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 6852e7b1b..99148d2f2 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -79,6 +79,32 @@ void MyApplication::drawEvent() { } @endcode +@section Drawable-performance Using drawable groups to improve performance + +You can organize your drawables to multiple groups to minimize OpenGL state +changes - for example put all objects using the same shader, the same light +setup etc into one group, then put all transparent into another and set common +parameters once for whole group instead of setting them again in each draw() +implementation. Example: +@code +Shaders::PhongShader* shader; +SceneGraph::DrawableGroup3D<> phongObjects, transparentObjects; + +void MyApplication::drawEvent() { + shader->setProjectionMatrix(camera->projectionMatrix()) + ->setLightPosition(lightPosition) + ->setLightColor(lightColor) + ->setAmbientColor(ambientColor); + camera.draw(phongObjects); + + Renderer::setFeature(Renderer::Feature::Blending, true); + camera.draw(transparentObjects); + Renderer::setFeature(Renderer::Feature::Blending, false); + + // ... +} +@endcode + @see @ref scenegraph, Drawable2D, Drawable3D, DrawableGroup2D, DrawableGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT From 01021050be9b344025e9d6245181440e1e1d41e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 9 Dec 2012 17:42:19 +0100 Subject: [PATCH 021/567] Updated .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 20c227ec1..659b2d8c0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build* pkg *.kdev4 *~ +*.kate-swp *.pkg.tar.xz From 113ff70aecc1a89fc823a4839146f674b961f6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 22:45:50 +0100 Subject: [PATCH 022/567] Ability to retrieve absolute time in previous frame to Timeline. The time is relative to moment when Timeline::start() was called. --- src/Timeline.cpp | 16 +++++++++++----- src/Timeline.h | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 7183c899d..3a4419464 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -23,13 +23,15 @@ namespace Magnum { void Timeline::start() { running = true; - previousFrameTime = high_resolution_clock::now(); + _startTime = high_resolution_clock::now(); + _previousFrameTime = _startTime; _previousFrameDuration = 0; } void Timeline::stop() { running = false; - previousFrameTime = high_resolution_clock::time_point(); + _startTime = high_resolution_clock::time_point(); + _previousFrameTime = _startTime; _previousFrameDuration = 0; } @@ -37,16 +39,20 @@ void Timeline::nextFrame() { if(!running) return; auto now = high_resolution_clock::now(); - std::uint32_t duration = duration_cast(now-previousFrameTime).count(); + std::uint32_t duration = duration_cast(now-_previousFrameTime).count(); _previousFrameDuration = duration/1e6f; if(_previousFrameDuration < _minimalFrameTime) { Corrade::Utility::sleep(_minimalFrameTime*1000 - duration/1000); now = high_resolution_clock::now(); - _previousFrameDuration = duration_cast(now-previousFrameTime).count()/1e6f; + _previousFrameDuration = duration_cast(now-_previousFrameTime).count()/1e6f; } - previousFrameTime = now; + _previousFrameTime = now; +} + +GLfloat Timeline::previousFrameTime() const { + return duration_cast(_previousFrameTime-_startTime).count()/1e6f; } } diff --git a/src/Timeline.h b/src/Timeline.h index a6d5b714e..42c22249e 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -98,7 +98,7 @@ class MAGNUM_EXPORT Timeline { /** * @brief Start timeline * - * Sets previous frame duration to `0`. + * Sets previous frame time and duration to `0`. * @see stop(), previousFrameDuration() */ void start(); @@ -120,13 +120,26 @@ class MAGNUM_EXPORT Timeline { */ void nextFrame(); - /** @brief Duration of previous frame (in seconds) */ + /** + * @brief Time at previous frame (in seconds) + * + * Returns time elapsed since start() was called. If the timeline is + * stopped, the function returns `0.0f`. + */ + GLfloat previousFrameTime() const; + + /** + * @brief Duration of previous frame (in seconds) + * + * If the timeline is stopped, the function returns `0.0f`. + */ inline constexpr GLfloat previousFrameDuration() const { return _previousFrameDuration; } private: - std::chrono::high_resolution_clock::time_point previousFrameTime; + std::chrono::high_resolution_clock::time_point _startTime; + std::chrono::high_resolution_clock::time_point _previousFrameTime; GLfloat _minimalFrameTime; GLfloat _previousFrameDuration; From 4408a68e6df4e4d8cbc4de8e5104d28e96ccbad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Dec 2012 22:53:28 +0100 Subject: [PATCH 023/567] SceneGraph: new Animable feature. Allows to animate objects, pause, repeat and resume the animations. The user implements animation step and can perform actions on state changes. Each Animable is part of some group which is optimized for case when no animation is running, thus it is possible to create multiple independent "animation islands" to improve performance. --- src/SceneGraph/Animable.cpp | 39 +++ src/SceneGraph/Animable.h | 341 +++++++++++++++++++++++++++ src/SceneGraph/Animable.hpp | 126 ++++++++++ src/SceneGraph/AnimableGroup.h | 106 +++++++++ src/SceneGraph/CMakeLists.txt | 4 + src/SceneGraph/SceneGraph.h | 14 ++ src/SceneGraph/Test/AnimableTest.cpp | 304 ++++++++++++++++++++++++ src/SceneGraph/Test/AnimableTest.h | 38 +++ src/SceneGraph/Test/CMakeLists.txt | 1 + 9 files changed, 973 insertions(+) create mode 100644 src/SceneGraph/Animable.cpp create mode 100644 src/SceneGraph/Animable.h create mode 100644 src/SceneGraph/Animable.hpp create mode 100644 src/SceneGraph/AnimableGroup.h create mode 100644 src/SceneGraph/Test/AnimableTest.cpp create mode 100644 src/SceneGraph/Test/AnimableTest.h diff --git a/src/SceneGraph/Animable.cpp b/src/SceneGraph/Animable.cpp new file mode 100644 index 000000000..8af96cd96 --- /dev/null +++ b/src/SceneGraph/Animable.cpp @@ -0,0 +1,39 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Animable.hpp" + +namespace Magnum { namespace SceneGraph { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template class MAGNUM_SCENEGRAPH_EXPORT Animable<2>; +template class MAGNUM_SCENEGRAPH_EXPORT Animable<3>; +template class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup<2>; +template class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup<3>; +#endif + +Debug operator<<(Debug debug, AnimationState value) { + switch(value) { + #define _c(value) case AnimationState::value: return debug << "SceneGraph::AnimationState::" #value; + _c(Stopped) + _c(Paused) + _c(Running) + #undef _c + } + + return debug << "SceneGraph::AnimationState::(invalid)"; +} + +}} diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h new file mode 100644 index 000000000..9bb2b3ac8 --- /dev/null +++ b/src/SceneGraph/Animable.h @@ -0,0 +1,341 @@ +#ifndef Magnum_SceneGraph_Animable_h +#define Magnum_SceneGraph_Animable_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::Animable, enum Magnum::SceneGraph::AnimationState + */ + +#include "AbstractGroupedFeature.h" + +#include "magnumSceneGraphVisibility.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Animation state + +@see Animatable::setState() +*/ +enum class AnimationState: std::uint8_t { + /** + * The animation is stopped. The animation will be started from the + * beginning when state is changed to @ref AnimationState "AnimationState::Running". + */ + Stopped, + + /** + * The animation is stopped. The animation will continue from paused + * position when state is changed to @ref AnimationState "AnimationState::Running". + */ + Paused, + + /** The animation is running. */ + Running +}; + +/** @debugoperator{Magnum::SceneGraph::Animable} */ +Debug MAGNUM_SCENEGRAPH_EXPORT operator<<(Debug debug, AnimationState value); + +/** +@brief %Animable + +Adds animation feature to object. Each %Animable is part of some AnimableGroup, +which takes care of running the animations. + +@section Animable-usage Usage + +First thing is add Animable feature to some object and implement +animationStep(). You can do it conveniently using multiple inheritance (see +@ref scenegraph-features for introduction). You need to pass animation +duration to constructor, animationStep() provides both absolute animation +time and time delta. Example: +@code +typedef SceneGraph::Object> Object3D; +typedef SceneGraph::Scene> Scene3D; + +class AnimableObject: public Object3D, SceneGraph::Animable3D<> { + public: + AnimableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Animable3D<>(this, 10.0f, group) { + // ... + } + + void animationStep(GLfloat time, GLfloat delta) override { + rotateX(deg(15.0f)*delta); // rotate at 15 degrees per second + } +} +@endcode + +Then add the object to your scene and some animation group. You can also use +AnimableGroup::add() and AnimableGroup::remove(). The animation is initially +in stopped state and without repeat, see setState(), setRepeated() and +setRepeatCount() for more information. +@code +Scene3D scene; +SceneGraph::AnimableGroup3D<> animables; + +(new AnimableObject(&scene, &animables)) + ->setState(SceneGraph::AnimationState::Running); +// ... +@endcode + +Animation step is performed by calling AnimableGroup::step() in your draw event +implementation. The function expects absolute time from relative to some fixed +point in the past and time delta (i.e. duration of the frame). You can use +Timeline for that, see its documentation for more information. +@code +Timeline timeline; +timeline.start(); + +void MyApplication::drawEvent() { + animables.step(timeline.lastFrameTime(), timeline.lastFrameDuration()); + + // ... + + timeline.nextFrame(); +} +@endcode + +@section Animable-performance Using animable groups to improve performance + +AnimableGroup is optimized for case when no animation is running - it just +puts itself to rest and waits until some animation changes its state to +running again. If you put animations which are not pernamently running to +separate group, they will not be traversed when calling AnimableGroup::step(), +saving precious frame time. + +@section Animable-explicit-specializations Explicit template specializations + +The following specialization are explicitly compiled into %SceneGraph library. +For other specializations you have to use Animable.hpp implementation file to +avoid linker errors. See also @ref compilation-speedup-hpp for more information. + + - @ref Animable "Animable<2, GLfloat>", @ref AnimableGroup "AnimableGroup<2, GLfloat>" + - @ref Animable "Animable<3, GLfloat>", @ref AnimableGroup "AnimableGroup<3, GLfloat>" + +@see @ref scenegraph, Animable2D, Animable3D, AnimableGroup2D, AnimableGroup3D +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature, T> { + friend class AnimableGroup; + + public: + /** + * @brief Constructor + * @param object %Object this animable belongs to + * @param duration Duration of the animation cycle in seconds. Set to + * 0 for infinite non-repeating animation. + * @param group Group this animable belongs to + * + * Creates stopped non-repeating animation with specified duration, + * adds the feature to the object and also to group, if specified. + * @see setRepeated(), AnimableGroup::add() + */ + Animable(AbstractObject* object, GLfloat duration, AnimableGroup* group = nullptr); + + /** @brief Animation duration */ + inline GLfloat duration() const { return _duration; } + + /** @brief Animation state */ + inline AnimationState state() const { return currentState; } + + /** + * @brief Set animation state + * @return Pointer to self (for method chaining) + * + * Note that changing state from @ref AnimationState "AnimationState::Stopped" + * to @ref AnimationState "AnimationState::Paused" is ignored and + * animation remains in @ref AnimationState "AnimationState::Stopped" + * state. See also animationStep() for more information. + * @see animationStarted(), animationPaused(), animationResumed(), + * animationStopped() + */ + Animable* setState(AnimationState state); + + /** + * @brief Whether the animation is repeated + * + * @see repeatCount() + */ + inline bool isRepeated() const { return _repeated; } + + /** + * @brief Enable/disable repeated animation + * @return Pointer to self (for method chaining) + * + * Default is `false`. + * @see setRepeatCount() + */ + inline Animable* setRepeated(bool repeated) { + _repeated = repeated; + return this; + } + + /** + * @brief Repeat count + * + * @see isRepeated() + */ + inline std::uint16_t repeatCount() const { return _repeatCount; } + + /** + * @brief Set repeat count + * @return Pointer to self (for method chaining) + * + * Has effect only if repeated animation is enabled. `0` means + * infinitely repeated animation. Default is `0`. + * @see setRepeated() + */ + inline Animable* setRepeatCount(std::uint16_t count) { + _repeatCount = count; + return this; + } + + AnimableGroup* group(); + const AnimableGroup* group() const; + + protected: + /** + * @brief Perform animation step + * @param time Time from start of the animation + * @param delta Time delta for current frame + * + * This function is periodically called from AnimableGroup::step() if + * the animation state is set to @ref AnimationState "AnimationState::Running". + * After animation duration is exceeded and repeat is not enabled or + * repeat count is exceeded, the animation state is set to + * @ref AnimationState "AnimationState::Stopped". + * + * If the animation is resumed from @ref AnimationState "AnimationState::Paused", + * this function is called with @p time continuing from the point + * when it was paused. If the animation is resumed from + * @ref AnimationState "AnimationState::Stopped", @p time starts with + * zero. + * + * @see state(), duration(), isRepeated(), repeatCount() + */ + virtual void animationStep(GLfloat time, GLfloat delta) = 0; + + /** + * @brief Action on animation start + * + * Called from AnimableGroup::step() when state is changed from + * @ref AnimationState "AnimationState::Stopped" to + * @ref AnimationState "AnimationState::Running" and before first + * animationStep() is called. + * + * Default implementation does nothing. + * + * @see setState() + */ + inline virtual void animationStarted() {} + + /** + * @brief Action on animation pause + * + * Called from AnimableGroup::step() when state changes from + * @ref AnimationState "AnimationState::Running" to + * @ref AnimationState "AnimationState::Paused" and after last + * animationStep() is called. + * + * Default implementation does nothing. + * + * @see setState() + */ + inline virtual void animationPaused() {} + + /** + * @brief Action on animation resume + * + * Called from AnimableGroup::step() when state changes from + * @ref AnimationState "AnimationState::Paused" to + * @ref AnimationState "AnimationState::Running" and before first + * animationStep() is called. + * + * Default implementation does nothing. + * + * @see setState() + */ + inline virtual void animationResumed() {} + + /** + * @brief Action on animation stop + * + * Called from AnimableGroup::step() when state changes from either + * @ref AnimationState "AnimationState::Running" or + * @ref AnimationState "AnimationState::Paused" to + * @ref AnimationState "AnimationState::Stopped" and after last + * animationStep() is called. + * + * You may want to use this function to properly finish the animation + * in case the framerate is not high enough to have animationStep() + * called enough times. Default implementation does nothing. + * + * @see setState() + */ + inline virtual void animationStopped() {} + + private: + const GLfloat _duration; + GLfloat startTime, pauseTime; + AnimationState previousState; + AnimationState currentState; + bool _repeated; + std::uint16_t _repeatCount; + std::uint16_t repeats; +}; + +/** +@brief Two-dimensional drawable + +Convenience alternative to %Animable<2, T>. See Animable for more +information. +@note Not available on GCC < 4.7. Use %Animable<2, T> instead. +@see Animable3D +@todoc Remove workaround when Doxygen supports alias template +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef CORRADE_GCC46_COMPATIBILITY +template using Animable2D = Animable<2, T>; +#endif +#else +typedef Animable<2, T = GLfloat> Animable2D; +#endif + +/** +@brief Three-dimensional animable + +Convenience alternative to %Animable<3, T>. See Animable for more +information. +@note Not available on GCC < 4.7. Use %Animable<3, T> instead. +@see Animable2D +@todoc Remove workaround when Doxygen supports alias template +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef CORRADE_GCC46_COMPATIBILITY +template using Animable3D = Animable<3, T>; +#endif +#else +typedef Animable<3, T = GLfloat> Animable3D; +#endif + +}} + +#endif diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp new file mode 100644 index 000000000..dfa060a97 --- /dev/null +++ b/src/SceneGraph/Animable.hpp @@ -0,0 +1,126 @@ +#ifndef Magnum_SceneGraph_Animable_hpp +#define Magnum_SceneGraph_Animable_hpp +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief @ref compilation-speedup-hpp "Template implementation" for Animable.h and AnimableGroup.h + */ + +#include "AnimableGroup.h" +#include "Animable.h" + +#include "Timeline.h" + +namespace Magnum { namespace SceneGraph { + +template Animable::Animable(AbstractObject* object, GLfloat duration, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(duration), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} + +template Animable* Animable::setState(AnimationState state) { + if(currentState == state) return this; + + /* Not allowed (for sanity) */ + if(previousState == AnimationState::Stopped && state == AnimationState::Paused) + return this; + + /* Wake up the group in case no animations are running */ + group()->wakeUp = true; + currentState = state; + return this; +} + +template AnimableGroup* Animable::group() { + return static_cast*>(AbstractGroupedFeature, T>::group()); +} + +template const AnimableGroup* Animable::group() const { + return static_cast*>(AbstractGroupedFeature, T>::group()); +} + +template void AnimableGroup::step(const GLfloat time, const GLfloat delta) { + if(!_runningCount && !wakeUp) return; + wakeUp = false; + + for(std::size_t i = 0; i != this->size(); ++i) { + Animable* animable = (*this)[i]; + + /* The animation was stopped recently, just decrease count of running + animations if the animation was running before */ + if(animable->previousState != AnimationState::Stopped && animable->currentState == AnimationState::Stopped) { + if(animable->previousState == AnimationState::Running) + --_runningCount; + animable->previousState = AnimationState::Stopped; + animable->animationStopped(); + continue; + + /* The animation was paused recently, set pause time to previous frame time */ + } else if(animable->previousState == AnimationState::Running && animable->currentState == AnimationState::Paused) { + animable->previousState = AnimationState::Paused; + animable->pauseTime = time; + --_runningCount; + animable->animationPaused(); + continue; + + /* Skip the rest for not running animations */ + } else if(animable->currentState != AnimationState::Running) { + CORRADE_INTERNAL_ASSERT(animable->previousState == animable->currentState); + continue; + + /* The animation was started recently, set start time to previous frame time */ + } else if(animable->previousState == AnimationState::Stopped) { + animable->previousState = AnimationState::Running; + animable->startTime = time; + ++_runningCount; + animable->animationStarted(); + + /* The animation was resumed recently, add pause duration to start time */ + } else if(animable->previousState == AnimationState::Paused) { + animable->previousState = AnimationState::Running; + animable->startTime += time - animable->pauseTime; + ++_runningCount; + animable->animationResumed(); + } + + CORRADE_INTERNAL_ASSERT(animable->previousState == AnimationState::Running); + + /* Animation time exceeded duration */ + if(animable->_duration != 0.0f && time-animable->startTime > animable->_duration) { + /* Not repeated or repeat count exceeded, stop */ + if(!animable->_repeated || animable->repeats+1 == animable->_repeatCount) { + animable->previousState = AnimationState::Stopped; + animable->currentState = AnimationState::Stopped; + --_runningCount; + continue; + } + + /* Increase repeat count and add duration to startTime */ + ++animable->repeats; + animable->startTime += animable->_duration; + } + + /* Animation is still running, perform animation step */ + CORRADE_ASSERT(time-animable->startTime >= 0.0f, + "SceneGraph::AnimableGroup::step(): animation was started in future - probably wrong time passed", ); + CORRADE_ASSERT(delta >= 0.0f, + "SceneGraph::AnimableGroup::step(): negative delta passed", ); + animable->animationStep(time - animable->startTime, delta); + } + + CORRADE_INTERNAL_ASSERT(_runningCount <= this->size()); +} + +}} + +#endif diff --git a/src/SceneGraph/AnimableGroup.h b/src/SceneGraph/AnimableGroup.h new file mode 100644 index 000000000..243dfb5a7 --- /dev/null +++ b/src/SceneGraph/AnimableGroup.h @@ -0,0 +1,106 @@ +#ifndef Magnum_SceneGraph_AnimableGroup_h +#define Magnum_SceneGraph_AnimableGroup_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::AnimableGroup + */ + +#include "FeatureGroup.h" + +#include "magnumSceneGraphVisibility.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Group of animables + +See Animable for more information. +@see @ref scenegraph, AnimableGroup2D, AnimableGroup3D +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup: public FeatureGroup, T> { + friend class Animable; + + public: + /** + * @brief Constructor + */ + inline AnimableGroup(): _runningCount(0), wakeUp(false) {} + + /** + * @brief Count of running animations + * + * @see step() + */ + inline std::size_t runningCount() const { return _runningCount; } + + /** + * @brief Perform animation step + * @param time Absolute time (e.g. Timeline::previousFrameTime()) + * @param delta Time delta for current frame (e.g. Timeline::previousFrameDuration()) + * + * If there are no running animations the function does nothing. + * @see runningCount() + */ + void step(const GLfloat time, const GLfloat delta); + + private: + std::size_t _runningCount; + bool wakeUp; +}; + +/** +@brief Two-dimensional drawable + +Convenience alternative to %AnimableGroup<2, T>. See Animable for +more information. +@note Not available on GCC < 4.7. Use %AnimableGroup<2, T> instead. +@see AnimableGroup3D +@todoc Remove workaround when Doxygen supports alias template +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef CORRADE_GCC46_COMPATIBILITY +template using AnimableGroup2D = AnimableGroup<2, T>; +#endif +#else +typedef AnimableGroup<2, T = GLfloat> AnimableGroup2D; +#endif + +/** +@brief Three-dimensional animable + +Convenience alternative to %AnimableGroup<3, T>. See Animable for +more information. +@note Not available on GCC < 4.7. Use %AnimableGroup<3, T> instead. +@see AnimableGroup2D +@todoc Remove workaround when Doxygen supports alias template +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef CORRADE_GCC46_COMPATIBILITY +template using AnimableGroup3D = AnimableGroup<3, T>; +#endif +#else +typedef AnimableGroup<3, T = GLfloat> AnimableGroup3D; +#endif + +}} + +#endif diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 1cd0780fd..5348905bf 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -1,4 +1,5 @@ set(MagnumSceneGraph_SRCS + Animable.cpp Camera.cpp) set(MagnumSceneGraph_HEADERS AbstractCamera.h @@ -11,6 +12,9 @@ set(MagnumSceneGraph_HEADERS AbstractTranslationRotation3D.h AbstractTranslationRotationScaling2D.h AbstractTranslationRotationScaling3D.h + Animable.h + Animable.hpp + AnimableGroup.h Camera2D.h Camera2D.hpp Camera3D.h diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index e8e7bd6ad..14fba11ca 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -66,6 +66,20 @@ template class AbstractTranslationRotation3D; template class AbstractTranslationRotationScaling2D; template class AbstractTranslationRotationScaling3D; +template class Animable; +#ifndef CORRADE_GCC46_COMPATIBILITY +template using Animable2D = Animable<2, T>; +template using Animable3D = Animable<3, T>; +#endif + +enum class AnimationState: std::uint8_t; + +template class AnimableGroup; +#ifndef CORRADE_GCC46_COMPATIBILITY +template using AnimableGroup2D = AnimableGroup<2, T>; +template using AnimableGroup3D = AnimableGroup<3, T>; +#endif + template class Camera2D; template class Camera3D; diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp new file mode 100644 index 000000000..ad5c5ed5d --- /dev/null +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -0,0 +1,304 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AnimableTest.h" + +#include "SceneGraph/Animable.h" +#include "SceneGraph/AnimableGroup.h" +#include "SceneGraph/MatrixTransformation3D.h" + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::AnimableTest) + +namespace Magnum { namespace SceneGraph { namespace Test { + +typedef SceneGraph::Object> Object3D; + +AnimableTest::AnimableTest() { + addTests(&AnimableTest::state, + &AnimableTest::step, + &AnimableTest::duration, + &AnimableTest::repeat, + &AnimableTest::stop, + &AnimableTest::pause, + &AnimableTest::debug); +} + +void AnimableTest::state() { + class StateTrackingAnimable: public SceneGraph::Animable<3> { + public: + StateTrackingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 1.0f, group) {} + + std::string trackedState; + + protected: + void animationStep(GLfloat, GLfloat) override {} + + void animationStarted() override { trackedState += "started"; } + void animationPaused() override { trackedState += "paused"; } + void animationResumed() override { trackedState += "resumed"; } + void animationStopped() override { trackedState += "stopped"; } + }; + + Object3D object; + AnimableGroup<3> group; + CORRADE_COMPARE(group.runningCount(), 0); + + /* Verify initial state */ + StateTrackingAnimable animable(&object, &group); + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + CORRADE_VERIFY(animable.trackedState.empty()); + group.step(1.0f, 1.0f); + CORRADE_VERIFY(animable.trackedState.empty()); + CORRADE_COMPARE(group.runningCount(), 0); + + /* Stopped -> paused is not supported */ + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + animable.setState(AnimationState::Paused); + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + + /* Stopped -> running */ + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + animable.trackedState.clear(); + animable.setState(AnimationState::Running); + CORRADE_VERIFY(animable.trackedState.empty()); + group.step(1.0f, 1.0f); + CORRADE_COMPARE(animable.trackedState, "started"); + CORRADE_COMPARE(group.runningCount(), 1); + + /* Running -> paused */ + CORRADE_COMPARE(animable.state(), AnimationState::Running); + animable.trackedState.clear(); + animable.setState(AnimationState::Paused); + CORRADE_VERIFY(animable.trackedState.empty()); + group.step(1.0f, 1.0f); + CORRADE_COMPARE(animable.trackedState, "paused"); + CORRADE_COMPARE(group.runningCount(), 0); + + /* Paused -> running */ + CORRADE_COMPARE(animable.state(), AnimationState::Paused); + animable.trackedState.clear(); + animable.setState(AnimationState::Running); + CORRADE_VERIFY(animable.trackedState.empty()); + group.step(1.0f, 1.0f); + CORRADE_COMPARE(animable.trackedState, "resumed"); + CORRADE_COMPARE(group.runningCount(), 1); + + /* Running -> stopped */ + CORRADE_COMPARE(animable.state(), AnimationState::Running); + animable.trackedState.clear(); + animable.setState(AnimationState::Stopped); + CORRADE_VERIFY(animable.trackedState.empty()); + group.step(1.0f, 1.0f); + CORRADE_COMPARE(animable.trackedState, "stopped"); + CORRADE_COMPARE(group.runningCount(), 0); + + animable.setState(AnimationState::Running); + group.step(1.0f, 1.0f); + animable.setState(AnimationState::Paused); + + /* Paused -> stopped */ + CORRADE_COMPARE(animable.state(), AnimationState::Paused); + animable.trackedState.clear(); + animable.setState(AnimationState::Stopped); + CORRADE_VERIFY(animable.trackedState.empty()); + group.step(1.0f, 1.0f); + CORRADE_COMPARE(animable.trackedState, "stopped"); + CORRADE_COMPARE(group.runningCount(), 0); + + /* Verify running count can go past 0/1 */ + group.add((new StateTrackingAnimable(&object, &group))->setState(AnimationState::Running)); + group.add((new StateTrackingAnimable(&object, &group))->setState(AnimationState::Running)); + group.step(1.0f, 1.0f); + CORRADE_COMPARE(group.runningCount(), 2); +} + +class OneShotAnimable: public SceneGraph::Animable<3> { + public: + OneShotAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 10.0f, group), time(-1.0f) { + setState(AnimationState::Running); + } + + GLfloat time; + + protected: + void animationStep(GLfloat time, GLfloat) override { + this->time = time; + } +}; + +void AnimableTest::step() { + class InifiniteAnimable: public SceneGraph::Animable<3> { + public: + InifiniteAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 0.0f, group), time(-1.0f), delta(0.0f) {} + + GLfloat time, delta; + + protected: + void animationStep(GLfloat time, GLfloat delta) override { + this->time = time; + this->delta = delta; + } + }; + + Object3D object; + AnimableGroup<3> group; + InifiniteAnimable animable(&object, &group); + + /* Calling step() if no object is running should do nothing */ + group.step(5.0f, 0.5f); + CORRADE_COMPARE(group.runningCount(), 0); + CORRADE_COMPARE(animable.time, -1.0f); + CORRADE_COMPARE(animable.delta, 0.0f); + + /* Calling step() with running animation should start it with zero + absolute time */ + animable.setState(AnimationState::Running); + group.step(5.0f, 0.5f); + CORRADE_COMPARE(group.runningCount(), 1); + CORRADE_COMPARE(animable.time, 0.0f); + CORRADE_COMPARE(animable.delta, 0.5f); + + /* Repeated call to step() will add to absolute animation time */ + group.step(8.0f, 0.75f); + CORRADE_COMPARE(animable.time, 3.0f); + CORRADE_COMPARE(animable.delta, 0.75f); +} + +void AnimableTest::duration() { + Object3D object; + AnimableGroup<3> group; + OneShotAnimable animable(&object, &group); + CORRADE_VERIFY(!animable.isRepeated()); + + /* First animation step is in duration, verify that animation is still + running and animationStep() is called */ + group.step(1.0f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 0.0f); + + /* Next animation step is out of duration and repeat is not enabled, + animationStep() shouldn't be called and animation should be stopped */ + group.step(12.75f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + CORRADE_COMPARE(animable.time, 0.0f); +} + +void AnimableTest::repeat() { + class RepeatingAnimable: public SceneGraph::Animable<3> { + public: + RepeatingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 10.0f, group), time(-1.0f) { + setState(AnimationState::Running); + setRepeated(true); + } + + GLfloat time; + + protected: + void animationStep(GLfloat time, GLfloat) override { + this->time = time; + } + }; + + Object3D object; + AnimableGroup<3> group; + RepeatingAnimable animable(&object, &group); + CORRADE_COMPARE(animable.repeatCount(), 0); + + /* First animation steps is in first loop iteration */ + group.step(1.0f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 0.0f); + + /* Next animation step is in second loop iteration, animation should be + still running with time shifted by animation duration */ + group.step(11.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 0.5f); + + /* Third loop iteration (just to be sure) */ + group.step(25.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 4.5f); + + /* Cap repeat count to 3, the animation should be stopped now (and + animationStep() shouldn't be called)*/ + animable.setRepeatCount(3); + group.step(33.0f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + CORRADE_COMPARE(animable.time, 4.5f); +} + +void AnimableTest::stop() { + Object3D object; + AnimableGroup<3> group; + OneShotAnimable animable(&object, &group); + CORRADE_COMPARE(animable.repeatCount(), 0); + + /* Eat up some absolute time */ + group.step(1.0f, 0.5f); + group.step(1.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 0.5f); + + /* Stop the animable, nothing should be done */ + animable.setState(AnimationState::Stopped); + group.step(1.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + CORRADE_COMPARE(animable.time, 0.5f); + + /* Restarting the animation should start with zero absolute time */ + animable.setState(AnimationState::Running); + group.step(2.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 0.0f); +} + +void AnimableTest::pause() { + Object3D object; + AnimableGroup<3> group; + OneShotAnimable animable(&object, &group); + + /* First two steps, animation is running */ + group.step(1.0f, 0.5f); + group.step(2.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 1.5f); + + /* Pausing the animation, first step should decrease count of running + animations and save paused time, next steps shouldn't affect anything */ + CORRADE_COMPARE(group.runningCount(), 1); + animable.setState(AnimationState::Paused); + CORRADE_COMPARE(group.runningCount(), 1); + group.step(3.0f, 0.5f); + CORRADE_COMPARE(group.runningCount(), 0); + group.step(4.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Paused); + CORRADE_COMPARE(animable.time, 1.5f); + + /* Unpausing, next step should continue from absolute time when pause + occured */ + animable.setState(AnimationState::Running); + group.step(5.0f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.time, 2.0f); +} + +void AnimableTest::debug() { + std::ostringstream o; + Debug(&o) << AnimationState::Running; + CORRADE_COMPARE(o.str(), "SceneGraph::AnimationState::Running\n"); +} + +}}} diff --git a/src/SceneGraph/Test/AnimableTest.h b/src/SceneGraph/Test/AnimableTest.h new file mode 100644 index 000000000..1428db3ca --- /dev/null +++ b/src/SceneGraph/Test/AnimableTest.h @@ -0,0 +1,38 @@ +#ifndef Magnum_SceneGraph_Test_AnimableTest_h +#define Magnum_SceneGraph_Test_AnimableTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace SceneGraph { namespace Test { + +class AnimableTest: public Corrade::TestSuite::Tester { + public: + AnimableTest(); + + void state(); + void step(); + void duration(); + void repeat(); + void stop(); + void pause(); + + void debug(); +}; + +}}} + +#endif diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index eef3c02cb..aa0efa333 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -1,3 +1,4 @@ +corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) From 47c0a7456c1890468cf1db2e8d5dd998a0987329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 10:58:23 +0100 Subject: [PATCH 024/567] Adapted to Corrade changes. Removing of another <*stream> #include leads to more compilation time saving, now from ~5:12 to ~4:55. Another compilation time improvements will now be possible only by using Clang's modules, I don't know where to optimize further (except for getting rid of in tests). --- src/Math/RectangularMatrix.h | 18 +++++++++++------- src/Math/Test/Matrix3Test.cpp | 1 + src/Math/Test/Matrix4Test.cpp | 1 + src/Math/Test/MatrixTest.cpp | 1 + src/Math/Test/Point2DTest.cpp | 1 + src/Math/Test/Point3DTest.cpp | 1 + src/Math/Test/RectangularMatrixTest.cpp | 1 + src/Math/Test/Vector2Test.cpp | 1 + src/Math/Test/Vector3Test.cpp | 1 + src/Math/Test/Vector4Test.cpp | 1 + src/Math/Test/VectorTest.cpp | 1 + src/SceneGraph/Test/AnimableTest.cpp | 2 ++ src/Test/ColorTest.cpp | 1 + src/Test/MeshTest.cpp | 1 + src/Test/TypeTraitsTest.cpp | 1 + 15 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 42e43559c..014eebbf3 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -534,15 +534,19 @@ template struct ConfigurationValue< /** @brief Reads elements separated with whitespace */ static Magnum::Math::RectangularMatrix fromString(const std::string& stringValue, ConfigurationValueFlags flags) { Magnum::Math::RectangularMatrix result; - std::istringstream in(stringValue); - for(std::size_t row = 0; row != rows; ++row) { - for(std::size_t col = 0; col != cols; ++col) { - std::string num; - in >> num; - result(col, row) = ConfigurationValue::fromString(num, flags); + std::size_t oldpos = 0, pos = std::string::npos, i = 0; + do { + pos = stringValue.find(' ', oldpos); + std::string part = stringValue.substr(oldpos, pos-oldpos); + + if(!part.empty()) { + result(i%cols, i/cols) = ConfigurationValue::fromString(part, flags); + ++i; } - } + + oldpos = pos+1; + } while(pos != std::string::npos); return result; } diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 107d61494..0e7adb44b 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -15,6 +15,7 @@ #include "Matrix3Test.h" +#include #include #include "Constants.h" diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 5b2ed7a1b..7761bd8b7 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -15,6 +15,7 @@ #include "Matrix4Test.h" +#include #include #include "Constants.h" diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 924ac0afe..28432709d 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -15,6 +15,7 @@ #include "MatrixTest.h" +#include #include #include "Matrix.h" diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp index 0ad2c4dae..70093d026 100644 --- a/src/Math/Test/Point2DTest.cpp +++ b/src/Math/Test/Point2DTest.cpp @@ -15,6 +15,7 @@ #include "Point2DTest.h" +#include #include #include "Point2D.h" diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp index 9293b7881..dc77ab420 100644 --- a/src/Math/Test/Point3DTest.cpp +++ b/src/Math/Test/Point3DTest.cpp @@ -15,6 +15,7 @@ #include "Point3DTest.h" +#include #include #include "Point3D.h" diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index adb989de0..a2fbd0af8 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -15,6 +15,7 @@ #include "RectangularMatrixTest.h" +#include #include #include "RectangularMatrix.h" diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 316094de0..7b427650a 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -15,6 +15,7 @@ #include "Vector2Test.h" +#include #include #include "Vector2.h" diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 51b31437f..6a97a5f87 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -15,6 +15,7 @@ #include "Vector3Test.h" +#include #include #include "Vector3.h" diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index e8f40f4ae..9d4b1e959 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -15,6 +15,7 @@ #include "Vector4Test.h" +#include #include #include "Vector4.h" diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 99486230f..74f2960bd 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -15,6 +15,7 @@ #include "VectorTest.h" +#include #include #include "Constants.h" diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index ad5c5ed5d..9b6505589 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -15,6 +15,8 @@ #include "AnimableTest.h" +#include + #include "SceneGraph/Animable.h" #include "SceneGraph/AnimableGroup.h" #include "SceneGraph/MatrixTransformation3D.h" diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 403c38668..6d77f5555 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -15,6 +15,7 @@ #include "ColorTest.h" +#include #include #include "Color.h" diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index 0e1a9d949..36b3248d8 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -15,6 +15,7 @@ #include "MeshTest.h" +#include #include #include "Mesh.h" diff --git a/src/Test/TypeTraitsTest.cpp b/src/Test/TypeTraitsTest.cpp index 521e16019..6da0f265f 100644 --- a/src/Test/TypeTraitsTest.cpp +++ b/src/Test/TypeTraitsTest.cpp @@ -15,6 +15,7 @@ #include "TypeTraitsTest.h" +#include #include #include "TypeTraits.h" From 9138f1bcc91fa65f65dd7ede011bf9666e5ea4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:10:54 +0100 Subject: [PATCH 025/567] Added OpenGL 4.3 extensions to the list. --- src/Context.cpp | 24 +++++++++++++++++++++++- src/Extensions.h | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Context.cpp b/src/Context.cpp index 28f49000c..539a145a3 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -155,7 +155,29 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,shader_atomic_counters), _extension(GL,ARB,shader_image_load_store), _extension(GL,ARB,texture_storage)}; - static const std::vector extensions430; + static const std::vector extensions430{ + _extension(GL,ARB,arrays_of_arrays), + _extension(GL,ARB,ES3_compatibility), + _extension(GL,ARB,clear_buffer_object), + _extension(GL,ARB,compute_shader), + _extension(GL,ARB,copy_image), + _extension(GL,KHR,debug), + _extension(GL,ARB,explicit_uniform_location), + _extension(GL,ARB,fragment_layer_viewport), + _extension(GL,ARB,framebuffer_no_attachments), + _extension(GL,ARB,internalformat_query2), + _extension(GL,ARB,invalidate_subdata), + _extension(GL,ARB,multi_draw_indirect), + _extension(GL,ARB,program_interface_query), + _extension(GL,ARB,robust_buffer_access_behavior), + _extension(GL,ARB,shader_image_size), + _extension(GL,ARB,shader_storage_buffer_object), + _extension(GL,ARB,stencil_texturing), + _extension(GL,ARB,texture_buffer_range), + _extension(GL,ARB,texture_query_levels), + _extension(GL,ARB,texture_storage_multisample), + _extension(GL,ARB,texture_view), + _extension(GL,ARB,vertex_attrib_binding)}; #undef _extension #else static const std::vector extensions; diff --git a/src/Extensions.h b/src/Extensions.h index ab1f78830..cd805c12e 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -121,6 +121,27 @@ namespace GL { _extension(GL,ARB,shader_atomic_counters, GL300, GL420) // #114 _extension(GL,ARB,shader_image_load_store, GL300, GL420) // #115 _extension(GL,ARB,texture_storage, GL210, GL420) // #117 + _extension(GL,ARB,arrays_of_arrays, GL210, GL430) // #120 + _extension(GL,ARB,clear_buffer_object, GL210, GL430) // #121 + _extension(GL,ARB,compute_shader, GL420, GL430) // #122 + _extension(GL,ARB,copy_image, GL210, GL430) // #123 + _extension(GL,ARB,texture_view, GL210, GL430) // #124 + _extension(GL,ARB,vertex_attrib_binding, GL210, GL430) // #125 + _extension(GL,ARB,ES3_compatibility, GL330, GL430) // #127 + _extension(GL,ARB,explicit_uniform_location, GL210, GL430) // #128 + _extension(GL,ARB,fragment_layer_viewport, GL300, GL430) // #129 + _extension(GL,ARB,framebuffer_no_attachments, GL210, GL430) // #130 + _extension(GL,ARB,internalformat_query2, GL210, GL430) // #131 + _extension(GL,ARB,invalidate_subdata, GL210, GL430) // #132 + _extension(GL,ARB,multi_draw_indirect, GL310, GL430) // #133 + _extension(GL,ARB,program_interface_query, GL210, GL430) // #134 + _extension(GL,ARB,robust_buffer_access_behavior,GL210, GL430) // #135 + _extension(GL,ARB,shader_image_size, GL420, GL430) // #136 + _extension(GL,ARB,shader_storage_buffer_object, GL400, GL430) // #137 + _extension(GL,ARB,stencil_texturing, GL210, GL430) // #138 + _extension(GL,ARB,texture_buffer_range, GL210, GL430) // #139 + _extension(GL,ARB,texture_query_levels, GL300, GL430) // #140 + _extension(GL,ARB,texture_storage_multisample, GL210, GL430) // #141 } namespace EXT { _extension(GL,EXT,texture_filter_anisotropic, GL210, None) // #187 _extension(GL,EXT,framebuffer_object, GL210, GL300) // #310 @@ -142,6 +163,8 @@ namespace GL { _extension(GL,GREMEDY,string_marker, GL210, None) // #311 } namespace INTEL { /* INTEL_map_texture not supported */ // #429 + } namespace KHR { + _extension(GL,KHR,debug, GL210, GL430) // #119 } namespace NV { _extension(GL,NV,half_float, GL210, GL300) // #283 _extension(GL,NV,primitive_restart, GL210, GL310) // #285 @@ -150,6 +173,9 @@ namespace GL { /* NV_draw_texture not supported */ // #430 } } + +/* IMPORTANT: if this line is > 185 (54 + size), don't forget to update array size in Context.h */ + #undef _extension #endif #endif From 9f20c8bca4f0ee5463682b12f197709399c5f267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:12:34 +0100 Subject: [PATCH 026/567] Platform: forgot to rename *WindowContext -> *Application in some places. --- src/Platform/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index f441d40be..1e7b4e7bb 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -16,7 +16,7 @@ if(WITH_GLUTAPPLICATION) install(FILES GlutApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlutApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() - message(FATAL_ERROR "GLUT library, required by GlutApplication, was not found. Set WITH_GLUTWINDOWCONTEXT to OFF to skip building it.") + message(FATAL_ERROR "GLUT library, required by GlutApplication, was not found. Set WITH_GLUTAPPLICATION to OFF to skip building it.") endif() endif() @@ -31,7 +31,7 @@ if(WITH_SDL2APPLICATION) install(FILES Sdl2Application.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumSdl2Application DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) else() - message(FATAL_ERROR "SDL2 library, required by Sdl2Application, was not found. Set WITH_SDL2WINDOWCONTEXT to OFF to skip building it.") + message(FATAL_ERROR "SDL2 library, required by Sdl2Application, was not found. Set WITH_SDL2APPLICATION to OFF to skip building it.") endif() endif() @@ -59,8 +59,8 @@ if(WITH_GLXAPPLICATION) install(TARGETS MagnumGlxApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() -# X/EGL window context -if(WITH_XEGLWINDOWCONTEXT) +# X/EGL application +if(WITH_XEGLAPPLICATION) set(NEED_ABSTRACTXAPPLICATION 1) set(NEED_EGLCONTEXT 1) add_library(MagnumXEglApplication STATIC @@ -75,7 +75,7 @@ endif() if(NEED_ABSTRACTXAPPLICATION) find_package(X11) if(NOT X11_FOUND) - message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*WINDOWCONTEXT to OFF to skip building them.") + message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*APPLICATION to OFF to skip building them.") endif() add_library(MagnumAbstractXApplication OBJECT AbstractXApplication.cpp) # X11 macros are a mess, disable warnings for C-style casts @@ -95,7 +95,7 @@ endif() if(NEED_EGLCONTEXT) find_package(EGL) if(NOT EGL_FOUND) - message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*WINDOWCONTEXT to OFF to skip building them.") + message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*APPLICATION to OFF to skip building them.") endif() add_library(MagnumEglContextHandler OBJECT EglContextHandler.cpp) # X11 macros are a mess, disable warnings for C-style casts From f0764cac4e022d2bbd461777937a874b3ca7cb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:14:49 +0100 Subject: [PATCH 027/567] Doc++ How I could forgot @brief here?! --- src/Platform/AbstractXApplication.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index d26ddcc8b..8a91dcd86 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -297,6 +297,7 @@ class AbstractXApplication { }; /** @hideinitializer +@brief Entry point for X11-based applications @param className Class name Can be used as equivalent to the following code to achieve better portability, From ef75989178744f7c96a5a1f0a6b4db7bcb615400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:20:32 +0100 Subject: [PATCH 028/567] Platform: don't require any specific OpenGL version. We still want to target old Intel machines with OpenGL 2.1. Also moved important information from constructor documentation to class documentation. Who would look into constructor documentation for that? --- src/Platform/GlutApplication.h | 7 +++---- src/Platform/GlxApplication.h | 6 ++---- src/Platform/GlxContextHandler.cpp | 6 +----- src/Platform/GlxContextHandler.h | 6 ++---- src/Platform/NaClApplication.h | 5 ++--- src/Platform/XEglApplication.h | 5 ++--- 6 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 9d7e65c6a..d2fcca1af 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -35,8 +35,9 @@ namespace Platform { /** @nosubgrouping @brief GLUT application -Supports keyboard handling for limited subset of keys, mouse handling with -support for changing cursor and mouse tracking and warping. +Creates double-buffered RGBA window with depth and stencil buffers. Supports +keyboard handling for limited subset of keys, mouse handling with support for +changing cursor and mouse tracking and warping. @section GlutApplication-usage Usage @@ -58,8 +59,6 @@ class GlutApplication { * @param argv Arguments of `main()` function * @param title Window title * @param size Window size - * - * Creates double-buffered RGBA window with depth and stencil buffers. */ GlutApplication(int& argc, char** argv, const std::string& title = "Magnum GLUT application", const Vector2i& size = Vector2i(800, 600)); diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index fec492946..603ea41ae 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -27,7 +27,8 @@ namespace Magnum { namespace Platform { /** @brief GLX application -Uses GlxContextHandler. +Creates window with double-buffered OpenGL or OpenGL ES 2.0 context, if +targetting OpenGL ES. Uses GlxContextHandler. @section GlxApplication-usage Usage @@ -49,9 +50,6 @@ class GlxApplication: public AbstractXApplication { * @param argv Arguments of `main()` function * @param title Window title * @param size Window size - * - * Creates window with double-buffered OpenGL 3.2 core context or - * OpenGL ES 2.0 context, if targetting OpenGL ES. */ inline GlxApplication(int& argc, char** argv, const std::string& title = "Magnum GLX application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new GlxContextHandler, argc, argv, title, size) {} }; diff --git a/src/Platform/GlxContextHandler.cpp b/src/Platform/GlxContextHandler.cpp index f7915e98e..a7e2b810d 100644 --- a/src/Platform/GlxContextHandler.cpp +++ b/src/Platform/GlxContextHandler.cpp @@ -65,11 +65,7 @@ void GlxContextHandler::createContext(Window nativeWindow) { window = nativeWindow; GLint attributes[] = { - #ifndef MAGNUM_TARGET_GLES - GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 2, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, - #else + #ifdef MAGNUM_TARGET_GLES GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 0, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, diff --git a/src/Platform/GlxContextHandler.h b/src/Platform/GlxContextHandler.h index 8922f9bf5..136241466 100644 --- a/src/Platform/GlxContextHandler.h +++ b/src/Platform/GlxContextHandler.h @@ -34,10 +34,8 @@ namespace Magnum { namespace Platform { /** @brief GLX context -Creates OpenGL 3.2 core context or OpenGL ES 2.0 context, if targetting -OpenGL ES. - -Used in GlxApplication. +Creates OpenGL or OpenGL ES 2.0 context, if targetting OpenGL ES. Used in +GlxApplication. */ class GlxContextHandler: public AbstractContextHandler { public: diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 81d670603..13ed6e09b 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -44,7 +44,8 @@ namespace Magnum { namespace Platform { @brief NaCl application Application running in [Google Chrome Native Client](https://developers.google.com/native-client/). -Supports keyboard and mouse handling. +Creates double-buffered RGBA canvas with depth and stencil buffers. Supports +keyboard and mouse handling. @section NaClApplication-usage Usage @@ -69,8 +70,6 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public * @brief Constructor * @param instance Module instance * @param size Rendering size - * - * Creates double-buffered RGBA canvas with depth and stencil buffers. */ explicit NaClApplication(PP_Instance instance, const Vector2i& size = Vector2i(640, 480)); diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index c0a12317f..6ded61519 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -27,7 +27,8 @@ namespace Magnum { namespace Platform { /** @brief X/EGL application -Uses EglContextHandler. +Creates window with double-buffered OpenGL ES 2 context. Uses +EglContextHandler. @section XEglApplication-usage Usage @@ -49,8 +50,6 @@ class XEglApplication: public AbstractXApplication { * @param argv Arguments of `main()` function * @param title Window title * @param size Window size - * - * Creates window with double-buffered OpenGL ES 2 context. */ inline XEglApplication(int& argc, char** argv, const std::string& title = "Magnum X/EGL application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new EglContextHandler, argc, argv, title, size) {} }; From 8e947fbabb1e208e9b7a1bdb13a72cad5598e9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:29:15 +0100 Subject: [PATCH 029/567] Platform: Added WindowlessGlxApplication. Finally something that can be used for: * Unit tests * Resource compilation * Benchmarks * ... I also desperately need something similar for Windows (and Mac OS, too). --- CMakeLists.txt | 1 + modules/FindMagnum.cmake | 12 +++ src/Platform/CMakeLists.txt | 18 +++- src/Platform/WindowlessGlxApplication.cpp | 90 ++++++++++++++++++ src/Platform/WindowlessGlxApplication.h | 107 ++++++++++++++++++++++ 5 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 src/Platform/WindowlessGlxApplication.cpp create mode 100644 src/Platform/WindowlessGlxApplication.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c54c7c86..ce5298b43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_ cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF) +cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library" OFF "NOT WITH_MAGNUMINFO" ON) cmake_dependent_option(WITH_XEGLAPPLICATION "Build XEglApplication library" OFF "TARGET_GLES" OFF) cmake_dependent_option(WITH_GLUTAPPLICATION "Build GlutApplication library" OFF "NOT TARGET_GLES" OFF) option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 52d1bd474..1d031e8e2 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -23,6 +23,8 @@ # Shaders - Library with stock shaders # GlxApplication - GLX application (depends on X11 libraries) # XEglApplication - X/EGL application (depends on EGL and X11 libraries) +# WindowlessGlxApplication - Windowless GLX application (depends on X11 +# libraries) # GlutApplication - GLUT application (depends on GLUT library) # Sdl2Application - SDL2 application (depends on SDL2 library) # NaClApplication - NaCl application (only if targetting Google Chrome @@ -152,6 +154,16 @@ foreach(component ${Magnum_FIND_COMPONENTS}) unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() endif() + + # GLX application dependencies + if(${component} STREQUAL WindowlessGlxApplication) + find_package(X11) + if(X11_FOUND) + set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES} ${_WINDOWCONTEXT_MAGNUM_LIBRARY_DEPENDENCY}) + else() + unset(MAGNUM_${_COMPONENT}_LIBRARY) + endif() + endif() endif() # Mesh tools library diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 1e7b4e7bb..d3a6c2e7a 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -71,12 +71,26 @@ if(WITH_XEGLAPPLICATION) install(TARGETS MagnumXEglApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) endif() -# Abstract X application -if(NEED_ABSTRACTXAPPLICATION) +if(WITH_WINDOWLESSGLXAPPLICATION OR NEED_ABSTRACTXAPPLICATION) find_package(X11) if(NOT X11_FOUND) message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*APPLICATION to OFF to skip building them.") endif() +endif() + +# Windowless GLX application +if(WITH_WINDOWLESSGLXAPPLICATION) + add_library(MagnumWindowlessGlxApplication STATIC + WindowlessGlxApplication.cpp + $) + # X11 macros are a mess, disable warnings for C-style casts + set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") + install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) + install(TARGETS MagnumWindowlessGlxApplication DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +endif() + +# Abstract X application +if(NEED_ABSTRACTXAPPLICATION) add_library(MagnumAbstractXApplication OBJECT AbstractXApplication.cpp) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumAbstractXApplication PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp new file mode 100644 index 000000000..b109a7108 --- /dev/null +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -0,0 +1,90 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "WindowlessGlxApplication.h" + +#include + +#include "Context.h" + +#define None 0L // redef Xlib nonsense + +namespace Magnum { namespace Platform { + +WindowlessGlxApplication::WindowlessGlxApplication(int&, char**) { + display = XOpenDisplay(nullptr); + + /* Check version */ + int major, minor; + glXQueryVersion(display, &major, &minor); + if(major == 1 && minor < 4) { + Error() << "WindowlessGlxApplication: GLX version 1.4 or greater is required."; + std::exit(1); + } + + /* Choose config */ + int configCount = 0; + static const int fbAttributes[] = { None }; + GLXFBConfig* configs = glXChooseFBConfig(display, DefaultScreen(display), fbAttributes, &configCount); + if(!configCount) { + Error() << "WindowlessGlxApplication: no supported framebuffer configuration found."; + std::exit(1); + } + + GLint contextAttributes[] = { + #ifdef MAGNUM_TARGET_GLES + GLX_CONTEXT_MAJOR_VERSION_ARB, 2, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, + #endif + 0 + }; + + /** @todo Use some extension wrangler for this, not GLEW, as it apparently needs context to create context, yo dawg wtf. */ + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); + context = glXCreateContextAttribsARB(display, configs[0], 0, True, contextAttributes); + if(!context) { + Error() << "WindowlessGlxApplication: cannot create context."; + std::exit(1); + } + + /* Create pbuffer */ + int pbufferAttributes[] = { + GLX_PBUFFER_WIDTH, 32, + GLX_PBUFFER_HEIGHT, 32, + None + }; + pbuffer = glXCreatePbuffer(display, configs[0], pbufferAttributes); + + XFree(configs); + + /* Set OpenGL context as current */ + if(!glXMakeContextCurrent(display, pbuffer, pbuffer, context)) { + Error() << "WindowlessGlxApplication: cannot make context current"; + std::exit(1); + } + + /* Initialize extension wrangler */ + ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable); + + c = new Context; +} + +WindowlessGlxApplication::~WindowlessGlxApplication() { + glXMakeCurrent(display, None, nullptr); + glXDestroyContext(display, context); +} + +}} diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h new file mode 100644 index 000000000..9557d4718 --- /dev/null +++ b/src/Platform/WindowlessGlxApplication.h @@ -0,0 +1,107 @@ +#ifndef Magnum_Platform_WindowlessGlxApplication_h +#define Magnum_Platform_WindowlessGlxApplication_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Platform::WindowlessGlxApplication + */ + +#include "Magnum.h" +#include +#include +#include +/* undef Xlib nonsense to avoid conflicts */ +#undef None +#undef Always + +#include "AbstractContextHandler.h" + +namespace Magnum { namespace Platform { + +/** +@brief Windowless GLX application + +@section WindowlessGlxApplication-usage Usage + +Place your code into exec(). The subclass can be then used directly in +`main()` - see convenience macro MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(). +@code +class MyApplication: public Magnum::Platform::WindowlessGlxApplication { + // implement required methods... +}; +MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(MyApplication) +@endcode +*/ +class WindowlessGlxApplication { + public: + /** + * @brief Constructor + * @param argc Count of arguments of `main()` function + * @param argv Arguments of `main()` function + * + * Creates window with double-buffered OpenGL 3.2 core context or + * OpenGL ES 2.0 context, if targetting OpenGL ES. + */ + WindowlessGlxApplication(int& argc, char** argv); + + ~WindowlessGlxApplication(); + + /** + * @brief Execute application + * @return Value for returning from `main()`. + */ + virtual int exec() = 0; + + private: + Display* display; + GLXContext context; + GLXPbuffer pbuffer; + + Context* c; +}; + +/** @hideinitializer +@brief Entry point for windowless GLX application +@param className Class name + +Can be used as equivalent to the following code to achieve better portability, +see @ref portability-applications for more information. +@code +int main(int argc, char** argv) { + className app(argc, argv); + return app.exec(); +} +@endcode +When no other application header is included this macro is also aliased to +`MAGNUM_APPLICATION_MAIN()`. +*/ +#define MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(className) \ + int main(int argc, char** argv) { \ + className app(argc, argv); \ + return app.exec(); \ + } + +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_APPLICATION_MAIN +#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(className) +#else +#undef MAGNUM_APPLICATION_MAIN +#endif +#endif + +}} + +#endif From 14a5f1a8641e0cf9a56f5b7f5fbee005a24b6a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:37:38 +0100 Subject: [PATCH 030/567] Platform: added magnum-info utility. Similar to `glxinfo`, displays information about Magnum engine and OpenGL capabilities. Currently for Unix/X11 only, as I don't have windowless application implementation for other platforms. --- CMakeLists.txt | 3 + src/Platform/CMakeLists.txt | 11 ++++ src/Platform/magnum-info.cpp | 109 +++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/Platform/magnum-info.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ce5298b43..991605382 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_ cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) +cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) + option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF) cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library" OFF "NOT WITH_MAGNUMINFO" ON) cmake_dependent_option(WITH_XEGLAPPLICATION "Build XEglApplication library" OFF "TARGET_GLES" OFF) @@ -56,6 +58,7 @@ if(TARGET_GLES2) endif() # Installation paths +set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules) set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Magnum) diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index d3a6c2e7a..0e67226fa 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -116,3 +116,14 @@ if(NEED_EGLCONTEXT) set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") install(FILES EglContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) endif() + +# Magnum Info +if(WITH_MAGNUMINFO) + if(UNIX) + add_executable(magnum-info magnum-info.cpp) + target_link_libraries(magnum-info Magnum MagnumWindowlessGlxApplication ${X11_LIBRARIES}) + install(TARGETS magnum-info DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}) + else() + message(WARNING "magnum-info is currently available only on Unix. Set WITH_MAGNUMINFO to OFF to suppress this warning.") + endif() +endif() diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp new file mode 100644 index 000000000..edd30f322 --- /dev/null +++ b/src/Platform/magnum-info.cpp @@ -0,0 +1,109 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Context.h" +#include "Platform/WindowlessGlxApplication.h" + +namespace Magnum { + +class MagnumInfo: public Platform::WindowlessGlxApplication { + public: + MagnumInfo(int& argc, char** argv); + + inline int exec() override { return 0; } +}; + +MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, argv) { + Context* c = Context::current(); + + Debug() << ""; + Debug() << " +---------------------------------------------------------+"; + Debug() << " | Information about Magnum engine and OpenGL capabilities |"; + Debug() << " +---------------------------------------------------------+"; + Debug() << ""; + + Debug() << "Used application: Platform::WindowlessGlxApplication"; + { + Debug d; + d << "Compilation flags:"; + #ifdef MAGNUM_TARGET_GLES + d << "MAGNUM_TARGET_GLES"; + #endif + #ifdef MAGNUM_TARGET_GLES2 + d << "MAGNUM_TARGET_GLES2"; + #endif + #ifdef MAGNUM_TARGET_NACL + d << "MAGNUM_TARGET_NACL"; + #endif + #ifdef CORRADE_GCC46_COMPATIBILITY + d << "CORRADE_GCC46_COMPATIBILITY"; + #endif + } + Debug() << ""; + + Debug() << "Vendor:" << c->vendorString(); + Debug() << "Renderer:" << c->rendererString(); + Debug() << "OpenGL version:" << c->version() << '(' + c->versionString() + ')'; + Debug() << "GLSL version:" << c->version() << '(' + c->shadingLanguageVersionString() + ')'; + Debug() << ""; + + /* Get first future (not supported) version */ + std::vector versions{ + #ifndef MAGNUM_TARGET_GLES + Version::GL300, + Version::GL310, + Version::GL320, + Version::GL330, + Version::GL400, + Version::GL410, + Version::GL420, + Version::GL430, + #else + Version::GLES200, + Version::GLES300, + #endif + Version::None + }; + std::size_t future = 0; + while(versions[future] != Version::None && c->isVersionSupported(versions[future])) + ++future; + + /* Display supported OpenGL extensions from unsupported versions */ + for(std::size_t i = future; i != versions.size(); ++i) { + if(versions[i] != Version::None) + Debug() << versions[i] << "extension support:"; + else Debug() << "Vendor extension support:"; + + for(const auto& extension: Extension::extensions(versions[i])) { + std::string extensionName = extension.string(); + Debug d; + d << " " << extensionName << std::string(60-extensionName.size(), ' '); + if(c->isExtensionSupported(extension)) + d << "SUPPORTED"; + else if(c->isVersionSupported(extension.requiredVersion())) + d << " - "; + else + d << " --- "; + } + + Debug() << ""; + } +} + +} + +MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(Magnum::MagnumInfo) From 91a2798603dbd8e5045ffaf69855e678690e401c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 11 Dec 2012 17:54:25 +0100 Subject: [PATCH 031/567] Context initialization was not skipping surely supported extensions. On OpenGL 3.3 context it was checking for support of all 3.0, 3.1 and 3.2 extensions even if isExtensionSupported() didn't use that information at all. --- src/Context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context.cpp b/src/Context.cpp index 539a145a3..2e5d91007 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -239,7 +239,7 @@ Context::Context() { Version::None }; std::size_t future = 0; - while(versions[future] != Version::None && !isVersionSupported(_version)) + while(versions[future] != Version::None && isVersionSupported(versions[future])) ++future; /* List of extensions from future versions (extensions from current and From 7a894e97a0f18288503108b84b49d635c0073419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Dec 2012 19:26:58 +0100 Subject: [PATCH 032/567] Using ARB_explicit_uniform_location in shaders. The backwards compatibility fully kills the purpose, but at least I can test the feature somewhere :-) --- src/Shaders/FlatShader.cpp | 10 ++++++++-- src/Shaders/FlatShader.h | 4 ++-- src/Shaders/FlatShader2D.frag | 4 ++++ src/Shaders/FlatShader2D.vert | 4 ++++ src/Shaders/PhongShader.cpp | 24 +++++++++++++++--------- src/Shaders/PhongShader.frag | 19 ++++++++++++++----- src/Shaders/PhongShader.h | 18 +++++++++--------- src/Shaders/PhongShader.vert | 7 +++++++ src/Shaders/VertexColorShader.cpp | 8 +++++++- src/Shaders/VertexColorShader.h | 2 +- src/Shaders/VertexColorShader2D.vert | 4 ++++ src/Shaders/compatibility.glsl | 15 ++++++++++++--- 12 files changed, 87 insertions(+), 32 deletions(-) diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index d232e342b..aba54c0f3 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -65,8 +65,14 @@ template FlatShader::FlatShader() { link(); - transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); - colorUniform = uniformLocation("color"); + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + { + #endif + transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + colorUniform = uniformLocation("color"); + } } template class FlatShader<2>; diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index e8787cdd4..dc83f8d60 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -61,8 +61,8 @@ template class MAGNUM_SHADERS_EXPORT FlatShader: public } private: - GLint transformationProjectionMatrixUniform, - colorUniform; + GLint transformationProjectionMatrixUniform = 0, + colorUniform = 1; }; /** @brief 2D flat shader */ diff --git a/src/Shaders/FlatShader2D.frag b/src/Shaders/FlatShader2D.frag index 82c2d5a95..ce2c5867a 100644 --- a/src/Shaders/FlatShader2D.frag +++ b/src/Shaders/FlatShader2D.frag @@ -2,7 +2,11 @@ #define fragmentColor gl_FragColor #endif +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 1) uniform vec3 color; +#else uniform lowp vec3 color; +#endif #ifdef NEW_GLSL out lowp vec4 fragmentColor; diff --git a/src/Shaders/FlatShader2D.vert b/src/Shaders/FlatShader2D.vert index 78d041e8d..b976b595c 100644 --- a/src/Shaders/FlatShader2D.vert +++ b/src/Shaders/FlatShader2D.vert @@ -2,7 +2,11 @@ #define in attribute #endif +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat3 transformationProjectionMatrix; +#else uniform highp mat3 transformationProjectionMatrix; +#endif #ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in highp vec3 position; diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 8ca78b44d..638831d8e 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -52,15 +52,21 @@ PhongShader::PhongShader() { link(); - ambientColorUniform = uniformLocation("ambientColor"); - diffuseColorUniform = uniformLocation("diffuseColor"); - specularColorUniform = uniformLocation("specularColor"); - shininessUniform = uniformLocation("shininess"); - transformationMatrixUniform = uniformLocation("transformationMatrix"); - projectionMatrixUniform = uniformLocation("projectionMatrix"); - normalMatrixUniform = uniformLocation("normalMatrix"); - lightUniform = uniformLocation("light"); - lightColorUniform = uniformLocation("lightColor"); + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + { + #endif + transformationMatrixUniform = uniformLocation("transformationMatrix"); + projectionMatrixUniform = uniformLocation("projectionMatrix"); + normalMatrixUniform = uniformLocation("normalMatrix"); + lightUniform = uniformLocation("light"); + diffuseColorUniform = uniformLocation("diffuseColor"); + ambientColorUniform = uniformLocation("ambientColor"); + specularColorUniform = uniformLocation("specularColor"); + lightColorUniform = uniformLocation("lightColor"); + shininessUniform = uniformLocation("shininess"); + } /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ #ifdef MAGNUM_TARGET_GLES diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index 3bb1080ac..4b00f8cd5 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -3,13 +3,22 @@ #define color gl_FragColor #endif -uniform lowp vec3 diffuseColor; #ifndef GL_ES -uniform lowp vec3 ambientColor = vec3(0.0, 0.0, 0.0); -uniform lowp vec3 specularColor = vec3(1.0, 1.0, 1.0); -uniform lowp vec3 lightColor = vec3(1.0, 1.0, 1.0); -uniform mediump float shininess = 80.0; +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 4) uniform vec3 diffuseColor; +layout(location = 5) uniform vec3 ambientColor = vec3(0.0, 0.0, 0.0); +layout(location = 6) uniform vec3 specularColor = vec3(1.0, 1.0, 1.0); +layout(location = 7) uniform vec3 lightColor = vec3(1.0, 1.0, 1.0); +layout(location = 8) uniform float shininess = 80.0; +#else +uniform vec3 diffuseColor; +uniform vec3 ambientColor = vec3(0.0, 0.0, 0.0); +uniform vec3 specularColor = vec3(1.0, 1.0, 1.0); +uniform vec3 lightColor = vec3(1.0, 1.0, 1.0); +uniform float shininess = 80.0; +#endif #else +uniform lowp vec3 diffuseColor; uniform lowp vec3 ambientColor; uniform lowp vec3 specularColor; uniform lowp vec3 lightColor; diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 6be38d84c..cbfc4eba6 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -123,15 +123,15 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } private: - GLint ambientColorUniform, - diffuseColorUniform, - specularColorUniform, - shininessUniform, - transformationMatrixUniform, - projectionMatrixUniform, - normalMatrixUniform, - lightUniform, - lightColorUniform; + GLint transformationMatrixUniform = 0, + projectionMatrixUniform = 1, + normalMatrixUniform = 2, + lightUniform = 3, + diffuseColorUniform = 4, + ambientColorUniform = 5, + specularColorUniform = 6, + lightColorUniform = 7, + shininessUniform = 8; }; }} diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 066afd94d..99d3a3fe7 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -3,10 +3,17 @@ #define out varying #endif +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat4 transformationMatrix; +layout(location = 1) uniform mat4 projectionMatrix; +layout(location = 2) uniform mat3 normalMatrix; +layout(location = 3) uniform vec3 light; +#else uniform highp mat4 transformationMatrix; uniform highp mat4 projectionMatrix; uniform mediump mat3 normalMatrix; uniform highp vec3 light; +#endif #ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in highp vec4 position; diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 5313da38c..b2a93b8e5 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -66,7 +66,13 @@ template VertexColorShader::VertexColorShad link(); - transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + { + #endif + transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); + } } template class VertexColorShader<2>; diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 896fefdc6..c529521ff 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -55,7 +55,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: } private: - GLint transformationProjectionMatrixUniform; + GLint transformationProjectionMatrixUniform = 0; }; /** @brief 2D vertex color shader */ diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index 88c8fc9a5..ff300a5b1 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/src/Shaders/VertexColorShader2D.vert @@ -3,7 +3,11 @@ #define out varying #endif +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat3 transformationProjectionMatrix; +#else uniform highp mat3 transformationProjectionMatrix; +#endif #ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in highp vec3 position; diff --git a/src/Shaders/compatibility.glsl b/src/Shaders/compatibility.glsl index 70f4cd6ba..8c67705d5 100644 --- a/src/Shaders/compatibility.glsl +++ b/src/Shaders/compatibility.glsl @@ -4,13 +4,22 @@ /* On NVidia and GLSL 1.20 layout qualifiers result in parsing error, even if the extension is defined as supported */ -#if !defined(GL_ES) && __VERSION__ >= 120 && defined(GL_ARB_explicit_attrib_location) -#extension GL_ARB_explicit_attrib_location: enable -#define EXPLICIT_ATTRIB_LOCATION +#if !defined(GL_ES) && __VERSION__ >= 120 + +#ifdef GL_ARB_explicit_attrib_location + #extension GL_ARB_explicit_attrib_location: enable + #define EXPLICIT_ATTRIB_LOCATION +#endif +#ifdef GL_ARB_explicit_uniform_location + #extension GL_ARB_explicit_uniform_location: enable + #define EXPLICIT_UNIFORM_LOCATION +#endif + #endif #if defined(GL_ES) && __VERSION__ >= 300 #define EXPLICIT_ATTRIB_LOCATION +/* EXPLICIT_UNIFORM_LOCATION is not available in OpenGL ES */ #endif /* Precision qualifiers are not supported in GLSL 1.20 */ From dd8eb6bc02a858b9e021b5d1e9482a5b208389a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Dec 2012 20:08:29 +0100 Subject: [PATCH 033/567] Removed one swizzle() overload. It is less efficient because of all that runtime computation and can't be made to use SIMD operations so why bother with it at all. --- doc/matrix-vector.dox | 6 ++-- src/Swizzle.h | 64 ++-------------------------------------- src/Test/SwizzleTest.cpp | 30 +++---------------- 3 files changed, 9 insertions(+), 91 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 6b05b00c3..9faab0993 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -134,13 +134,11 @@ xyz.xy() *= 5; @endcode Color3 and Color4 name their components `rgba` instead of `xyzw`. -For more involved operations with components there are two swizzle() functions, -they have the same features, but one is guaranteed to do most of the work at -compile-time, while the second has more convenient syntax: +For more involved operations with components there is the swizzle() function: @code Vector4 original(-1, 2, 3, 4); Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } -Vector<6, int> a10rgb = swizzle(original, "a10rgb"); // { 4, 1, 0, -1, 2, 3 } +Vector<6, int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } @endcode @section matrix-vector-column-major Matrices are column-major and vectors are columns diff --git a/src/Swizzle.h b/src/Swizzle.h index 0805f6a9c..af2ff2186 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Functions Magnum::swizzle(const T&), Magnum::swizzle(const T&, const char(&)[]) + * @brief Function Magnum::swizzle() */ #include "Color.h" @@ -25,9 +25,6 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - using Math::Implementation::Sequence; - using Math::Implementation::GenerateSequence; - template struct ComponentAtPosition { static_assert(size > position, "Swizzle parameter out of range of base vector"); @@ -60,28 +57,6 @@ namespace Implementation { template struct TypeForSize<3, Color4> { typedef Color3 Type; }; template struct TypeForSize<4, Color3> { typedef Color4 Type; }; template struct TypeForSize<4, Color4> { typedef Color4 Type; }; - - template inline constexpr T componentAtPosition(const Math::Vector& vector, std::size_t position) { - return size > position ? vector[position] : throw; - } - - template inline constexpr T component(const Math::Vector& vector, char component) { - return component == 'x' ? componentAtPosition(vector, 0) : - component == 'y' ? componentAtPosition(vector, 1) : - component == 'z' ? componentAtPosition(vector, 2) : - component == 'w' ? componentAtPosition(vector, 3) : - component == 'r' ? componentAtPosition(vector, 0) : - component == 'g' ? componentAtPosition(vector, 1) : - component == 'b' ? componentAtPosition(vector, 2) : - component == 'a' ? componentAtPosition(vector, 3) : - component == '0' ? T(0) : - component == '1' ? T(1) : - throw; - } - - template inline constexpr Math::Vector swizzleFrom(Sequence, const Math::Vector& vector, const char(&components)[sizeof...(sequence)+1]) { - return {component(vector, components[sequence])...}; - } } #endif @@ -98,13 +73,8 @@ auto vec = swizzle<'a', '1', '0', 'r', 'g', 'b'>(original); You can use letters `x`, `y`, `z`, `w` and `r`, `g`, `b`, `a` for addressing components or letters `0` and `1` for zero and one. Count of elements is unlimited, but must be at least one. If the resulting vector is two, three or -four-component, corresponding Vector2, Vector3, Vector4, Color3 or Color4 -specialization is returned. - -@attention This function is less convenient to write than -swizzle(const T&, const char(&)[newSize]), but the evaluation of -the swizzling operation is guaranteed to be always done at compile time -instead of at runtime. +four-component, corresponding Math::Vector2, Math::Vector3, Math::Vector4, +Color3 or Color4 specialization is returned. @see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), Vector4::xy(), Vector3::xy() @@ -113,34 +83,6 @@ template inline constexpr typename Implementation:: return {Implementation::Component::value(vector)...}; } -/** -@brief Swizzle Vector components - -Creates new vector from given components. Example: -@code -Vector4i original(-1, 2, 3, 4); - -auto vec = swizzle(original, "a10rgb"); -// vec == { 4, 1, 0, -1, 2, 3 } -@endcode -You can use letters `x`, `y`, `z`, `w` and `r`, `g`, `b`, `a` for addressing -components or letters `0` and `1` for zero and one. Count of elements is -unlimited, but must be at least one. If the resulting vector is two, three or -four-component, corresponding Vector2, Vector3 or Vector4 specialization is -returned. - -@attention This function is more convenient to write than -swizzle(const T&), but unless the result is marked with -`constexpr`, the evaluation of the swizzling operation probably won't be -evaluated at compile time, but at runtime. - -@see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), - Vector4::xy(), Vector3::xy() -*/ -template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector, const char(&components)[newSize]) { - return Implementation::swizzleFrom(typename Implementation::GenerateSequence::Type(), vector, components); -} - } #endif diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 5da5a9bf3..627d302c2 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -31,61 +31,39 @@ SwizzleTest::SwizzleTest() { } void SwizzleTest::xyzw() { - Vector4i orig(2, 4, 5, 7); - Vector4i swizzled(5, 2, 7, 4); - CORRADE_COMPARE(swizzle(orig, "zxwy"), swizzled); - CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y'>(orig)), swizzled); + CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); } void SwizzleTest::rgba() { - Vector4i orig(2, 4, 5, 7); - Vector4i swizzled(5, 2, 7, 4); - CORRADE_COMPARE(swizzle(orig, "brag"), swizzled); - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g'>(orig)), swizzled); + CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); } void SwizzleTest::constants() { - Vector4i orig(2, 4, 5, 7); - Vector4i swizzled(1, 7, 0, 4); - CORRADE_COMPARE(swizzle(orig, "1w0g"), swizzled); - CORRADE_COMPARE((swizzle<'1', 'w', '0', 'g'>(orig)), swizzled); + CORRADE_COMPARE((swizzle<'1', 'w', '0', 'g'>(Vector4i(2, 4, 5, 7))), Vector4i(1, 7, 0, 4)); } void SwizzleTest::fromSmall() { - /* Force compile-time evaluation for both */ - constexpr Vector2i orig(1, 2); - constexpr Vector3i swizzled(swizzle(orig, "gxr")); - CORRADE_VERIFY((std::integral_constant::value)); - CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(orig)), Vector3i(2, 1, 1)); + CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(Vector2i(1, 2))), Vector3i(2, 1, 1)); } void SwizzleTest::type() { Vector4i orig; CORRADE_VERIFY((std::is_same(orig)), Vector2i>::value)); - CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same(orig)), Vector3i>::value)); - CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same(orig)), Vector4i>::value)); - CORRADE_VERIFY((std::is_same::value)); Color3 origColor3; Color4 origColor4; CORRADE_VERIFY((std::is_same(origColor3)), Color3<>>::value)); CORRADE_VERIFY((std::is_same(origColor4)), Color3>::value)); - CORRADE_VERIFY((std::is_same>::value)); - CORRADE_VERIFY((std::is_same>::value)); CORRADE_VERIFY((std::is_same(origColor3)), Color4<>>::value)); CORRADE_VERIFY((std::is_same(origColor4)), Color4>::value)); - CORRADE_VERIFY((std::is_same>::value)); - CORRADE_VERIFY((std::is_same>::value)); } void SwizzleTest::defaultType() { Vector4i orig(1, 2, 3, 4); CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, std::int32_t>(3))); - CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, std::int32_t>(3))); CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); - CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); } }} From ef779e50b24986de6b2663d70d8c64d920d05bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Dec 2012 20:44:37 +0100 Subject: [PATCH 034/567] Split out lightweight base of swizzle() function to Math namespace. Will make use of SIMD instructions and can be used elsewhere in Math. --- src/Math/CMakeLists.txt | 1 + src/Math/Swizzle.h | 74 +++++++++++++++++++++++++++++++++++ src/Math/Test/CMakeLists.txt | 2 + src/Math/Test/SwizzleTest.cpp | 49 +++++++++++++++++++++++ src/Math/Test/SwizzleTest.h | 33 ++++++++++++++++ src/Swizzle.h | 30 ++++---------- src/Test/SwizzleTest.cpp | 17 +------- src/Test/SwizzleTest.h | 3 -- 8 files changed, 168 insertions(+), 41 deletions(-) create mode 100644 src/Math/Swizzle.h create mode 100644 src/Math/Test/SwizzleTest.cpp create mode 100644 src/Math/Test/SwizzleTest.h diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index a92da34c4..ef962ab43 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -10,6 +10,7 @@ set(MagnumMath_HEADERS Point2D.h Point3D.h RectangularMatrix.h + Swizzle.h Vector.h Vector2.h Vector3.h diff --git a/src/Math/Swizzle.h b/src/Math/Swizzle.h new file mode 100644 index 000000000..482236d29 --- /dev/null +++ b/src/Math/Swizzle.h @@ -0,0 +1,74 @@ +#ifndef Magnum_Math_Swizzle_h +#define Magnum_Math_Swizzle_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::Math::swizzle() + */ + +#include "Vector.h" + +namespace Magnum { namespace Math { + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct ComponentAtPosition { + static_assert(size > position, "Swizzle parameter out of range of base vector"); + + template inline constexpr static T value(const Math::Vector& vector) { return vector[position]; } + }; + + template struct Component {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component: public ComponentAtPosition {}; + template struct Component { + template inline constexpr static T value(const Math::Vector&) { return T(0); } + }; + template struct Component { + template inline constexpr static T value(const Math::Vector&) { return T(1); } + }; +} +#endif + +/** +@brief Swizzle Vector components + +Creates new vector from given components. Example: +@code +Vector4 original(-1, 2, 3, 4); + +auto vec = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); +// vec == { 4, 1, 0, -1, 2, 3 } +@endcode +You can use letters `x`, `y`, `z`, `w` for addressing components or letters +`0` and `1` for zero and one. Count of elements is unlimited, but must be at +least one. + +See also Magnum::swizzle() which has some added convenience features not +present in this lightweight implementation for Math namespace. + +@see @ref matrix-vector-component-access, Vector4::xyz(), + Vector4::xy(), Vector3::xy() +*/ +template inline constexpr Vector swizzle(const Vector& vector) { + return {Implementation::Component::value(vector)...}; +} + +}} + +#endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index ad6385d3f..2d0739185 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -16,4 +16,6 @@ corrade_add_test(MathMatrixTest MatrixTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrix3Test Matrix3Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) + set_target_properties(MathVectorTest MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp new file mode 100644 index 000000000..78fc7a1dd --- /dev/null +++ b/src/Math/Test/SwizzleTest.cpp @@ -0,0 +1,49 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "SwizzleTest.h" + +#include "Math/Swizzle.h" + +CORRADE_TEST_MAIN(Magnum::Math::Test::SwizzleTest) + +namespace Magnum { namespace Math { namespace Test { + +typedef Vector<4, std::int32_t> Vector4i; + +SwizzleTest::SwizzleTest() { + addTests(&SwizzleTest::components, + &SwizzleTest::constants, + &SwizzleTest::sizes); +} + +void SwizzleTest::components() { + CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); +} + +void SwizzleTest::constants() { + CORRADE_COMPARE((swizzle<'1', 'w', '0', 'y'>(Vector4i(2, 4, 5, 7))), Vector4i(1, 7, 0, 4)); +} + +void SwizzleTest::sizes() { + CORRADE_COMPARE((swizzle<'y', 'x', 'x'>(Math::Vector<2, std::int32_t>(1, 2))), + (Math::Vector<3, std::int32_t>(2, 1, 1))); + CORRADE_COMPARE(swizzle<'z'>(Vector4i(1, 2, 3, 4)), + (Math::Vector<1, std::int32_t>(3))); + CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y', 'z', 'y', 'x'>(Vector4i(1, 2, 3, 4))), + (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); +} + +}}} diff --git a/src/Math/Test/SwizzleTest.h b/src/Math/Test/SwizzleTest.h new file mode 100644 index 000000000..a2d64fb2a --- /dev/null +++ b/src/Math/Test/SwizzleTest.h @@ -0,0 +1,33 @@ +#ifndef Magnum_Math_Test_SwizzleTest_h +#define Magnum_Math_Test_SwizzleTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Test { + +class SwizzleTest: public Corrade::TestSuite::Tester { + public: + SwizzleTest(); + + void components(); + void constants(); + void sizes(); +}; + +}}} + +#endif diff --git a/src/Swizzle.h b/src/Swizzle.h index af2ff2186..f3befdf78 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -15,38 +15,24 @@ GNU Lesser General Public License version 3 for more details. */ -/** @file +/** @file /Swizzle.h * @brief Function Magnum::swizzle() */ +#include "Math/Swizzle.h" #include "Color.h" namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - template struct ComponentAtPosition { - static_assert(size > position, "Swizzle parameter out of range of base vector"); - - template inline constexpr static T value(const Math::Vector& vector) { return vector[position]; } - }; - - template struct Component {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; - template struct Component: public ComponentAtPosition {}; +namespace Math { namespace Implementation { template struct Component: public ComponentAtPosition {}; template struct Component: public ComponentAtPosition {}; template struct Component: public ComponentAtPosition {}; template struct Component: public ComponentAtPosition {}; - template struct Component { - template inline constexpr static T value(const Math::Vector&) { return T(0); } - }; - template struct Component { - template inline constexpr static T value(const Math::Vector&) { return T(1); } - }; +}} +namespace Implementation { template struct TypeForSize { typedef Math::Vector Type; }; @@ -76,11 +62,11 @@ unlimited, but must be at least one. If the resulting vector is two, three or four-component, corresponding Math::Vector2, Math::Vector3, Math::Vector4, Color3 or Color4 specialization is returned. -@see @ref matrix-vector-component-access, Vector4::xyz(), Color4::rgb(), - Vector4::xy(), Vector3::xy() +@see @ref matrix-vector-component-access, Math::swizzle(), Vector4::xyz(), + Color4::rgb(), Vector4::xy(), Vector3::xy() */ template inline constexpr typename Implementation::TypeForSize::Type swizzle(const T& vector) { - return {Implementation::Component::value(vector)...}; + return {Math::Implementation::Component::value(vector)...}; } } diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 627d302c2..b07c4da34 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -22,30 +22,15 @@ CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) namespace Magnum { namespace Test { SwizzleTest::SwizzleTest() { - addTests(&SwizzleTest::xyzw, - &SwizzleTest::rgba, - &SwizzleTest::constants, - &SwizzleTest::fromSmall, + addTests(&SwizzleTest::rgba, &SwizzleTest::type, &SwizzleTest::defaultType); } -void SwizzleTest::xyzw() { - CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); -} - void SwizzleTest::rgba() { CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); } -void SwizzleTest::constants() { - CORRADE_COMPARE((swizzle<'1', 'w', '0', 'g'>(Vector4i(2, 4, 5, 7))), Vector4i(1, 7, 0, 4)); -} - -void SwizzleTest::fromSmall() { - CORRADE_COMPARE((swizzle<'g', 'x', 'r'>(Vector2i(1, 2))), Vector3i(2, 1, 1)); -} - void SwizzleTest::type() { Vector4i orig; CORRADE_VERIFY((std::is_same(orig)), Vector2i>::value)); diff --git a/src/Test/SwizzleTest.h b/src/Test/SwizzleTest.h index d9b581517..e432ed9ec 100644 --- a/src/Test/SwizzleTest.h +++ b/src/Test/SwizzleTest.h @@ -23,10 +23,7 @@ class SwizzleTest: public Corrade::TestSuite::Tester { public: SwizzleTest(); - void xyzw(); void rgba(); - void constants(); - void fromSmall(); void type(); void defaultType(); }; From b70b2777b38f2704b1f5eaa134d3413c30351cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Dec 2012 20:45:55 +0100 Subject: [PATCH 035/567] Using Math::swizzle() in Vector3::cross(). Inspired by http://stackoverflow.com/a/5150625 . --- src/Math/Vector3.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 84ff16050..88db8214b 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -20,6 +20,7 @@ */ #include "Vector2.h" +#include "Swizzle.h" namespace Magnum { namespace Math { @@ -98,9 +99,8 @@ template class Vector3: public Vector<3, T> { * @f] */ inline constexpr static Vector3 cross(const Vector3& a, const Vector3& b) { - return Vector3(a[1]*b[2]-a[2]*b[1], - a[2]*b[0]-a[0]*b[2], - a[0]*b[1]-a[1]*b[0]); + return swizzle<'y', 'z', 'x'>(a)*swizzle<'z', 'x', 'y'>(b) - + swizzle<'z', 'x', 'y'>(a)*swizzle<'y', 'z', 'x'>(b); } /** @copydoc Vector::Vector() */ From 9153bcd957d5c51f249fe6fcfa560023e2b57151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 17:39:28 +0100 Subject: [PATCH 036/567] Internal texture and renderbuffer format rework. Got rid of InternalFormat class, now it is all in one big enum, as each version (desktop, ES2, ES3) has different requirements and it can't be done that way anymore (moreover that was terribly ugly solution). --- src/AbstractTexture.cpp | 77 +--- src/AbstractTexture.h | 919 ++++++++++++++++++++++++++++------------ src/BufferedTexture.cpp | 36 +- src/BufferedTexture.h | 160 ++++--- src/Renderbuffer.cpp | 57 --- src/Renderbuffer.h | 516 +++++++++++++++++----- 6 files changed, 1154 insertions(+), 611 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index dedbd221c..9be1738fb 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -227,22 +227,22 @@ void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); - glTexImage1D(target, mipLevel, internalFormat, size[0], 0, static_cast(components), static_cast(type), data); + glTexImage1D(target, mipLevel, static_cast(internalFormat), size[0], 0, static_cast(components), static_cast(type), data); } void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureImage1DEXT(_id, target, mipLevel, internalFormat, size[0], 0, static_cast(components), static_cast(type), data); + glTextureImage1DEXT(_id, target, mipLevel, GLint(internalFormat), size[0], 0, static_cast(components), static_cast(type), data); } #endif void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { bindInternal(); - glTexImage2D(target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); + glTexImage2D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(components), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureImage2DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), 0, static_cast(components), static_cast(type), data); + glTextureImage2DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(components), static_cast(type), data); } #endif @@ -250,7 +250,7 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glTexImage3D(target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); + glTexImage3D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); #else static_cast(target); static_cast(mipLevel); @@ -264,7 +264,7 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, #ifndef MAGNUM_TARGET_GLES void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureImage3DEXT(_id, target, mipLevel, internalFormat, size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); + glTextureImage3DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); } #endif @@ -312,71 +312,6 @@ void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, c } #endif -#ifndef MAGNUM_TARGET_GLES2 -AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components components, AbstractTexture::ComponentType type) { - #ifndef MAGNUM_TARGET_GLES - #define internalFormatSwitch(c) switch(type) { \ - case ComponentType::UnsignedByte: \ - internalFormat = GL_##c##8UI; break; \ - case ComponentType::Byte: \ - internalFormat = GL_##c##8I; break; \ - case ComponentType::UnsignedShort: \ - internalFormat = GL_##c##16UI; break; \ - case ComponentType::Short: \ - internalFormat = GL_##c##16I; break; \ - case ComponentType::UnsignedInt: \ - internalFormat = GL_##c##32UI; break; \ - case ComponentType::Int: \ - internalFormat = GL_##c##32I; break; \ - case ComponentType::Half: \ - internalFormat = GL_##c##16F; break; \ - case ComponentType::Float: \ - internalFormat = GL_##c##32F; break; \ - case ComponentType::NormalizedUnsignedByte: \ - internalFormat = GL_##c##8; break; \ - case ComponentType::NormalizedByte: \ - internalFormat = GL_##c##8_SNORM; break; \ - case ComponentType::NormalizedUnsignedShort: \ - internalFormat = GL_##c##16; break; \ - case ComponentType::NormalizedShort: \ - internalFormat = GL_##c##16_SNORM; break; \ - } - #else - #define internalFormatSwitch(c) switch(type) { \ - case ComponentType::UnsignedByte: \ - internalFormat = GL_##c##8UI; break; \ - case ComponentType::Byte: \ - internalFormat = GL_##c##8I; break; \ - case ComponentType::UnsignedShort: \ - internalFormat = GL_##c##16UI; break; \ - case ComponentType::Short: \ - internalFormat = GL_##c##16I; break; \ - case ComponentType::UnsignedInt: \ - internalFormat = GL_##c##32UI; break; \ - case ComponentType::Int: \ - internalFormat = GL_##c##32I; break; \ - case ComponentType::Half: \ - internalFormat = GL_##c##16F; break; \ - case ComponentType::Float: \ - internalFormat = GL_##c##32F; break; \ - case ComponentType::NormalizedUnsignedByte: \ - internalFormat = GL_##c##8; break; \ - case ComponentType::NormalizedByte: \ - internalFormat = GL_##c##8_SNORM; break; \ - } - #endif - if(components == Components::Red) - internalFormatSwitch(R) - else if(components == Components::RedGreen) - internalFormatSwitch(RG) - else if(components == Components::RGB) - internalFormatSwitch(RGB) - else if(components == Components::RGBA) - internalFormatSwitch(RGBA) - #undef internalFormatSwitch -} -#endif - #ifndef DOXYGEN_GENERATING_OUTPUT void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D& wrapping) { #ifndef MAGNUM_TARGET_GLES diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 37d00b61b..d4627266d 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -126,440 +126,825 @@ class MAGNUM_EXPORT AbstractTexture { #endif }; - /** @{ @name Internal texture formats */ - - #ifndef MAGNUM_TARGET_GLES2 /** - * @brief Color components + * @brief Internal format * - * @requires_gles30 (no extension providing this functionality) + * @see @ref Texture::setData() "setData()" */ - enum class Components { + enum class InternalFormat: GLint { /** - * Red component only. Green and blue are set to `0`, alpha is set - * to `1`. - * @requires_gl30 Extension @extension{ARB,texture_rg} + * Red component, normalized unsigned, size implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::R8". + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gles30 %Extension @es_extension{EXT,texture_rg} */ - Red, + #ifndef MAGNUM_TARGET_GLES2 + Red = GL_RED, + #else + Red = GL_RED_EXT, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Red and green component. Blue is set to `0`, alpha is set to - * `1`. - * @requires_gl30 Extension @extension{ARB,texture_rg} + * Red component, normalized unsigned byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gles30 Use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::Red" + * in OpenGL ES 2.0 instead. */ - RedGreen, - - RGB, /**< Red, green and blue component. Alpha is set to `1`. */ - RGBA /**< Red, green, blue component and alpha. */ - }; + R8 = GL_R8, + #endif - /** - * @brief Type of data per each component - * - * `NormalizedUnsignedByte` and `NormalizedUnsignedShort` are the - * main ones for general usage. - * @requires_gles30 (no extension providing this functionality) - */ - enum class ComponentType { /** - * (Non-normalized) unsigned byte - * @requires_gl30 Extension @extension{EXT,texture_integer} + * Red and green component, normalized unsigned, size + * implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RG8". + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gles30 %Extension @es_extension{EXT,texture_rg} */ - UnsignedByte, + #ifndef MAGNUM_TARGET_GLES2 + RG = GL_RG, + #else + RG = GL_RG_EXT, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * (Non-normalized) byte - * @requires_gl30 Extension @extension{EXT,texture_integer} + * Red and green component, each normalized unsigned byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gles30 Use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RG" + * in OpenGL ES 2.0 instead. */ - Byte, + RG8 = GL_RG8, + #endif /** - * (Non-normalized) unsigned short - * @requires_gl30 Extension @extension{EXT,texture_integer} + * RGB, normalized unsigned, size implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RGB8". */ - UnsignedShort, + RGB = GL_RGB, /** - * (Non-normalized) short - * @requires_gl30 Extension @extension{EXT,texture_integer} + * RGB, each component normalized unsigned byte. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} */ - Short, + #ifndef MAGNUM_TARGET_GLES2 + RGB8 = GL_RGB8, + #else + RGB8 = GL_RGB8_OES, + #endif /** - * (Non-normalized) unsigned integer - * @requires_gl30 Extension @extension{EXT,texture_integer} + * RGBA, normalized unsigned, size implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RGBA8". */ - UnsignedInt, + RGBA = GL_RGBA, /** - * (Non-normalized) integer - * @requires_gl30 Extension @extension{EXT,texture_integer} + * RGBA, each component normalized unsigned byte. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} */ - Int, + #ifndef MAGNUM_TARGET_GLES2 + RGBA8 = GL_RGBA8, + #else + RGBA8 = GL_RGBA8_OES, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Half float (16 bit) - * @requires_gl30 Extension @extension{ARB,texture_float} + * Red component, normalized signed byte. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned formats are available in OpenGL + * ES 2.0. */ - Half, + R8Snorm = GL_R8_SNORM, /** - * Float (32 bit) - * @requires_gl30 Extension @extension{ARB,texture_float} + * Red and green component, each normalized signed byte. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned formats are available in OpenGL + * ES 2.0. */ - Float, + RG8Snorm = GL_RG8_SNORM, /** - * Normalized unsigned byte, i.e. values from range @f$ [0; 255] @f$ - * are converted to range @f$ [0.0; 1.0] @f$. + * RGB, each component normalized signed byte. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned formats are available in OpenGL + * ES 2.0. */ - NormalizedUnsignedByte, + RGB8Snorm = GL_RGB8_SNORM, /** - * Normalized signed byte, i.e. values from range @f$ [-128; 127] @f$ - * are converted to range @f$ [-1.0; 1.0] @f$. - * @requires_gl31 Extension @extension{EXT,texture_snorm} + * RGBA, each component normalized signed byte. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned formats are available in OpenGL + * ES 2.0. */ - NormalizedByte + RGBA8Snorm = GL_RGBA8_SNORM, #ifndef MAGNUM_TARGET_GLES - , + /** + * Red component, normalized unsigned short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. + */ + R16 = GL_R16, + + /** + * Red and green component, each normalized unsigned short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. + */ + RG16 = GL_RG16, /** - * Normalized unsigned short, i.e. values from range @f$ [0; 65536] @f$ - * are converted to range @f$ [0.0; 1.0] @f$. - * @requires_gl + * RGB, each component normalized unsigned short. + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. */ - NormalizedUnsignedShort, + RGB16 = GL_RGB16, /** - * Normalized signed short, i.e. values from range @f$ [-32768; 32767] @f$ - * are converted to range @f$ [-1.0; 1.0] @f$. - * @requires_gl - * @requires_gl31 Extension @extension{EXT,texture_snorm} + * RGBA, each component normalized unsigned short. + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. */ - NormalizedShort + RGBA16 = GL_RGBA16, #endif - }; - #endif - /** - * @brief Internal format - * - * For more information about default values for unused components and - * normalization see enums Components and ComponentType. - */ - enum class Format: GLenum { - #ifndef MAGNUM_TARGET_GLES2 /** - * One-component (red channel), unsigned normalized, probably - * 8bit. - * @requires_gl30 Extension @extension{ARB,texture_rg} - * @requires_gles30 (no extension providing this functionality) + * Red component, normalized signed short. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned normalized formats are available + * in OpenGL ES 2.0. */ - Red = GL_RED, + R16Snorm = GL_R16_SNORM, + + /** + * Red and green component, each normalized signed short. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned normalized formats are available + * in OpenGL ES 2.0. + */ + RG16Snorm = GL_RG16_SNORM, + + /** + * RGB, each component normalized signed short. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned normalized formats are available + * in OpenGL ES 2.0. + */ + RGB16Snorm = GL_RGB16_SNORM, + + /** + * RGBA, each component normalized signed short. + * @requires_gl31 %Extension @extension{EXT,texture_snorm} + * @requires_gles30 Only unsigned normalized formats are available + * in OpenGL ES 2.0. + */ + RGBA16Snorm = GL_RGBA16_SNORM, + + /** + * Red component, non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R8UI = GL_R8UI, + + /** + * Red and green component, each non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG8UI = GL_RG8UI, + + /** + * RGB, each component non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB8UI = GL_RGB8UI, + + /** + * RGBA, each component non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA8UI = GL_RGBA8UI, + + /** + * Red component, non-normalized signed byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R8I = GL_R8I, + + /** + * Red and green component, each non-normalized signed byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG8I = GL_RG8I, + + /** + * RGB, each component non-normalized signed byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB8I = GL_RGB8I, + + /** + * RGBA, each component non-normalized signed byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA8I = GL_RGBA8I, + + /** + * Red component, non-normalized unsigned short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R16UI = GL_R16UI, + + /** + * Red and green component, each non-normalized unsigned short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG16UI = GL_RG16UI, + + /** + * RGB, each component non-normalized unsigned short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB16UI = GL_RGB16UI, + + /** + * RGBA, each component non-normalized unsigned short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA16UI = GL_RGBA16UI, + + /** + * Red component, non-normalized signed short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R16I = GL_R16I, + + /** + * Red and green component, each non-normalized signed short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG16I = GL_RG16I, + + /** + * RGB, each component non-normalized signed short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB16I = GL_RGB16I, + + /** + * RGBA, each component non-normalized signed short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA16I = GL_RGBA16I, + + /** + * Red component, non-normalized unsigned int. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R32UI = GL_R32UI, + + /** + * Red and green component, each non-normalized unsigned int. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG32UI = GL_RG32UI, + + /** + * RGB, each component non-normalized unsigned int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB32UI = GL_RGB32UI, + + /** + * RGBA, each component non-normalized unsigned int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA32UI = GL_RGBA32UI, + + /** + * Red component, non-normalized signed int. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R32I = GL_R32I, + + /** + * Red and green component, each non-normalized signed int. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG32I = GL_RG32I, + + /** + * RGB, each component non-normalized signed int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB32I = GL_RGB32I, + + /** + * RGBA, each component non-normalized signed int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA32I = GL_RGBA32I, + + /** + * Red component, half float. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R16F = GL_R16F, + + /** + * Red and green component, each half float. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG16F = GL_RG16F, + + /** + * RGB, each component half float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB16F = GL_RGB16F, + + /** + * RGBA, each component half float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA16F = GL_RGBA16F, + + /** + * Red component, float. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R32F = GL_R32F, /** - * Two-component (red and green channel), unsigned normalized, - * each component probably 8bit, 16bit total. - * @requires_gl30 Extension @extension{ARB,texture_rg} - * @requires_gles30 (no extension providing this functionality) + * Red and green component, each float. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. */ - RedGreen = GL_RG, + RG32F = GL_RG32F, + + /** + * RGB, each component float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB32F = GL_RGB32F, + + /** + * RGBA, each component float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA32F = GL_RGBA32F, #endif + #ifndef MAGNUM_TARGET_GLES /** - * Three-component RGB, unsigned normalized, each component - * probably 8bit, 24bit total. - * - * Prefer to use the exactly specified version of this format, in - * this case `Components::RGB|ComponentType::%NormalizedUnsignedByte`. + * RGB, normalized unsigned, red and green component 3bit, blue + * 2bit. + * @requires_gl Packed 8bit types are not available in OpenGL ES. */ - RGB = GL_RGB, + R3B3G2 = GL_R3_G3_B2, /** - * Four-component RGBA, unsigned normalized, each component - * probably 8bit, 24bit total. - * - * Prefer to use the exactly specified version of this format, in - * this case `Components::RGBA|ComponentType::%NormalizedUnsignedByte`. + * RGB, each component normalized unsigned 4bit. + * @requires_gl Packed 12bit types are not available in OpenGL ES. */ - RGBA = GL_RGBA, + RGB4 = GL_RGB4, + + /** + * RGB, each component normalized unsigned 5bit. + * @requires_gl Use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RGB5A1" + * or @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RGB565" in OpenGL ES. + */ + RGB5 = GL_RGB5, + #endif + + /* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is + GL_ARB_ES2_compatibility */ + #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) + /** + * RGB, normalized unsigned, red and blue component 5bit, green 6bit. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} + */ + #ifndef MAGNUM_TARGET_GLES2 + RGB565 = GL_RGB565, + #else + RGB565 = GL_RGB565_OES, + #endif + #endif + + /** + * RGB, each component normalized unsigned 10bit. + * @requires_es_extension %Extension @es_extension{OES,required_internalformat} + */ + #ifndef MAGNUM_TARGET_GLES + RGB10 = GL_RGB10, + #else + RGB10 = GL_RGB10_EXT, + #endif #ifndef MAGNUM_TARGET_GLES /** - * Three-component BGR, unsigned normalized, each component - * probably 8bit, 24bit total. - * @requires_gl + * RGB, each component normalized unsigned 12bit. + * @requires_gl Packed 36bit types are not available in OpenGL ES. */ - BGR = GL_BGR, + RGB12 = GL_RGB12, /** - * Four-component BGRA, unsigned normalized, each component - * probably 8bit, 24bit total. - * @requires_gl + * RGBA, normalized unsigned, each component 2bit. + * @requires_gl Packed 8bit types are not available in OpenGL ES. */ - BGRA = GL_BGRA, + RGBA2 = GL_RGBA2, #endif + /** + * RGBA, normalized unsigned, each component 4bit. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} + */ #ifndef MAGNUM_TARGET_GLES2 + RGBA4 = GL_RGBA4, + #else + RGBA4 = GL_RGBA4_OES, + #endif + /** - * Four-component sRGBA, unsigned normalized, each component - * 8bit, 32bit total. - * @requires_gles30 (no extension providing this functionality) + * RGBA, normalized unsigned, each RGB component 5bit, alpha 1bit. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} */ - SRGBA8 = GL_SRGB8_ALPHA8, + #ifndef MAGNUM_TARGET_GLES2 + RGB5A1 = GL_RGB5_A1, + #else + RGB5A1 = GL_RGB5_A1_OES, + #endif /** - * Three-component sRGB, unsigned normalized, each component - * 8bit, 24bit total. - * @requires_gles30 (no extension providing this functionality) + * RGBA, normalized unsigned, each RGB component 10bit, alpha 2bit. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} + * and @es_extension{EXT,texture_type_2_10_10_10_REV} */ - SRGB8 = GL_SRGB8, + #ifndef MAGNUM_TARGET_GLES2 + RGB10A2 = GL_RGB10_A2, + #else + RGB10A2 = GL_RGB10_A2_EXT, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Four-component RGBA, unsigned normalized, each RGB component - * 10bit, alpha 2bit, 32bit total. - * @requires_gles30 (no extension providing this functionality) + * RGBA, non-normalized unsigned, each RGB component 10bit, alpha + * 2bit. + * @requires_gl33 %Extension @extension{ARB,texture_rgb10_a2ui} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. */ - RGB10Alpha2 = GL_RGB10_A2, + RGB10A2UI = GL_RGB10_A2UI, + #endif + #ifndef MAGNUM_TARGET_GLES /** - * Four-component RGBA, unsigned non-normalized, each RGB - * component 10bit, alpha channel 2bit, 32bit total. - * @requires_gl33 Extension @extension{ARB,texture_rgb10_a2ui} - * @requires_gles30 (no extension providing this functionality) + * RGBA, each component normalized unsigned 12bit. + * @requires_gl Packed 48bit types are not available in OpenGL ES. */ - RGB10Alpha2Unsigned = GL_RGB10_A2UI, + RGBA12 = GL_RGBA12, #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Four-component RGBA, unsigned normalized, each RGB component - * 5bit, alpha 1bit, 16bit total. + * RGB, float, red and green component 11bit, blue 10bit. + * @requires_gl30 %Extension @extension{EXT,packed_float} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. */ - RGB5Alpha1 = GL_RGB5_A1, + R11FG11FB10F = GL_R11F_G11F_B10F, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Four-component RGBA, unsigned normalized, each component 4bit, - * 16bit total. + * RGB, unsigned with exponent, each RGB component 9bit, exponent 5bit. + * @requires_gl30 %Extension @extension{EXT,texture_shared_exponent} + * @requires_gles30 Use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RGB" + * in OpenGL ES 2.0 instead. */ - RGBA4 = GL_RGBA4, + RGB9E5 = GL_RGB9_E5, + #endif + + /** + * sRGB, normalized unsigned, size implementation-dependent. + * @todo is this allowed in core? + * @deprecated Prefer to use the exactly specified version of this + * format, i.e. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::SRGB8". + * @requires_es_extension %Extension @es_extension{EXT,sRGB} in + * OpenGL ES 2.0, use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::SRGB8" + * in OpenGL ES 3.0 instead. + */ + #ifndef MAGNUM_TARGET_GLES + SRGB = GL_SRGB, + #else + SRGB = GL_SRGB_EXT, + #endif #ifndef MAGNUM_TARGET_GLES2 /** - * Three-component RGB, float, red and green 11bit, blue 10bit, - * 32bit total. - * @requires_gl30 Extension @extension{EXT,packed_float} - * @requires_gles30 (no extension providing this functionality) + * sRGB, each component normalized unsigned byte. + * @requires_gles30 Use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::SRGB" + * in OpenGL ES 2.0 instead. */ - RG11B10Float = GL_R11F_G11F_B10F, + SRGB8 = GL_SRGB8, #endif - /* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is - GL_ARB_ES2_compatibility */ - #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) /** - * Three-component RGB, unsigned normalized, red and blue 5bit, - * green 6bit, 16bit total. + * sRGBA, normalized unsigned, size implementation-dependent. + * @todo is this allowed in core? + * @deprecated Prefer to use the exactly specified version of this + * format, i.e. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::SRGB8Alpha8". + * @requires_es_extension %Extension @es_extension{EXT,sRGB} in + * OpenGL ES 2.0, use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::SRGB8Alpha8" + * in OpenGL ES 3.0 instead. */ - RGB565 = GL_RGB565 + #ifndef MAGNUM_TARGET_GLES + SRGBAlpha = GL_SRGB_ALPHA, + #else + SRGBAlpha = GL_SRGB_ALPHA_EXT, #endif #ifndef MAGNUM_TARGET_GLES2 - , /** - * Three-component RGB, unsigned with exponent, each component - * 9bit, exponent 5bit, 32bit total. - * @requires_gl30 Extension @extension{EXT,texture_shared_exponent} - * @requires_gles30 (no extension providing this functionality) + * sRGBA, each component normalized unsigned byte. + * @requires_gles30 Use @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::SRGBAlpha" + * in OpenGL ES 2.0 instead. */ - RGB9Exponent5 = GL_RGB9_E5, + SRGB8Alpha8 = GL_SRGB8_ALPHA8, #endif #ifndef MAGNUM_TARGET_GLES /** - * Compressed red channel, unsigned normalized. - * @requires_gl - * @requires_gl30 Extension @extension{ARB,texture_rg} + * Compressed red channel, normalized unsigned. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Generic texture compression is not available in + * OpenGL ES. */ CompressedRed = GL_COMPRESSED_RED, /** - * Compressed red and green channel, unsigned normalized. - * @requires_gl - * @requires_gl30 Extension @extension{ARB,texture_rg} + * Compressed red and green channel, normalized unsigned. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Generic texture compression is not available in + * OpenGL ES. */ - CompressedRedGreen = GL_COMPRESSED_RG, + CompressedRG = GL_COMPRESSED_RG, /** - * Compressed RGB, unsigned normalized. - * @requires_gl + * Compressed RGB, normalized unsigned. + * @requires_gl Generic texture compression is not available in + * OpenGL ES. */ CompressedRGB = GL_COMPRESSED_RGB, /** - * Compressed RGBA, unsigned normalized. - * @requires_gl + * Compressed RGBA, normalized unsigned. + * @requires_gl Generic texture compression is not available in + * OpenGL ES. */ CompressedRGBA = GL_COMPRESSED_RGBA, /** - * RTGC compressed red channel, unsigned normalized. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,texture_compression_rgtc} + * RTGC compressed red channel, normalized unsigned. + * @requires_gl30 %Extension @extension{EXT,texture_compression_rgtc} + * @requires_gl RGTC texture compression is not available in + * OpenGL ES. */ - CompressedRtgcRed = GL_COMPRESSED_RED_RGTC1, + CompressedRedRtgc1 = GL_COMPRESSED_RED_RGTC1, /** - * RTGC compressed red channel, signed normalized. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,texture_compression_rgtc} + * RTGC compressed red and green channel, normalized unsigned. + * @requires_gl30 %Extension @extension{EXT,texture_compression_rgtc} + * @requires_gl RGTC texture compression is not available in + * OpenGL ES. */ - CompressedRtgcSignedRed = GL_COMPRESSED_SIGNED_RED_RGTC1, + CompressedRGRgtc2 = GL_COMPRESSED_RG_RGTC2, /** - * RTGC compressed red and green channel, unsigned normalized. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,texture_compression_rgtc} + * RTGC compressed red channel, normalized signed. + * @requires_gl30 %Extension @extension{EXT,texture_compression_rgtc} + * @requires_gl RGTC texture compression is not available in + * OpenGL ES. */ - CompressedRtgcRedGreen = GL_COMPRESSED_RG_RGTC2, + CompressedSignedRedRgtc1 = GL_COMPRESSED_SIGNED_RED_RGTC1, /** - * RTGC compressed red and green channel, signed normalized. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,texture_compression_rgtc} + * RTGC compressed red and green channel, normalized signed. + * @requires_gl30 %Extension @extension{EXT,texture_compression_rgtc} + * @requires_gl RGTC texture compression is not available in + * OpenGL ES. */ - CompressedRtgcSignedRedGreen = GL_COMPRESSED_SIGNED_RG_RGTC2, + CompressedSignedRGRgtc2 = GL_COMPRESSED_SIGNED_RG_RGTC2, /* These are named with _ARB suffix, because glcorearb.h doesn't have suffixless version (?!) and GLEW has it without suffix as late as of 1.8.0 { */ /** - * BPTC compressed RGBA, unsigned normalized. - * @requires_gl - * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} + * BPTC compressed RGBA, normalized unsigned. + * @requires_gl42 %Extension @extension{ARB,texture_compression_bptc} + * @requires_gl BPTC texture compression is not available in + * OpenGL ES. */ - CompressedBptcRGBA = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, + CompressedRGBABtpcUnorm = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, /** - * BPTC compressed sRGBA, unsigned normalized. - * @requires_gl - * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} + * BPTC compressed sRGBA, normalized unsigned. + * @requires_gl42 %Extension @extension{ARB,texture_compression_bptc} + * @requires_gl BPTC texture compression is not available in + * OpenGL ES. */ - CompressedBptcSRGBA = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, + CompressedSRGBAlphaBtpcUnorm = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, /** - * BPTC compressed RGB, signed float. - * @requires_gl - * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} + * BPTC compressed RGB, unsigned float. + * @requires_gl42 %Extension @extension{ARB,texture_compression_bptc} + * @requires_gl BPTC texture compression is not available in + * OpenGL ES. */ - CompressedBptcRGBSignedFloat = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, + CompressedRGBBptcUnsignedFloat = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, /** - * BPTC compressed RGB, unsigned float. - * @requires_gl - * @requires_gl42 Extension @extension{ARB,texture_compression_bptc} + * BPTC compressed RGB, signed float. + * @requires_gl42 %Extension @extension{ARB,texture_compression_bptc} + * @requires_gl BPTC texture compression is not available in + * OpenGL ES. */ - CompressedBptcRGBUnsignedFloat = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, + CompressedRGBBptcSignedFloat = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, /*}*/ + #endif /** - * Depth component, at least 16bit. - * - * Prefer to use the exactly specified version of this format, in - * this case e.g. `Format::Depth16`. - * @requires_gl + * Depth component, size implementation-dependent. + * @deprecated Prefer to use exactly specified version of this + * format, e.g. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::DepthComponent16". + * @requires_gles30 %Extension @es_extension{OES,depth_texture} */ - Depth = GL_DEPTH_COMPONENT, + DepthComponent = GL_DEPTH_COMPONENT, /** - * Depth and stencil component, at least 24bit depth and 8bit - * stencil. - * - * Prefer to use the exactly specified version of this format, in - * this case e.g. `Format::Depth24Stencil8`. - * @requires_gl + * Depth and stencil component, size implementation-dependent. + * @deprecated Prefer to use exactly specified version of this + * format, e.g. @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::Depth24Stencil8". + * @requires_gles30 %Extension @es_extension{OES,packed_depth_stencil} */ + #ifndef MAGNUM_TARGET_GLES2 DepthStencil = GL_DEPTH_STENCIL, + #else + DepthStencil = GL_DEPTH_STENCIL_OES, #endif - #ifndef MAGNUM_TARGET_GLES2 /** - * 16bit depth component. - * @requires_gles30 (no extension providing this functionality) + * Depth component, 16bit. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} + * and @es_extension{OES,depth_texture} */ - Depth16 = GL_DEPTH_COMPONENT16, + DepthComponent16 = GL_DEPTH_COMPONENT16, /** - * 24bit depth component. - * @requires_gles30 (no extension providing this functionality) + * Depth component, 24bit. + * @requires_gles30 %Extension @es_extension{OES,required_internalformat}, + * @es_extension{OES,depth_texture} and @es_extension{OES,depth24} */ - Depth24 = GL_DEPTH_COMPONENT24, + #ifndef MAGNUM_TARGET_GLES2 + DepthComponent24 = GL_DEPTH_COMPONENT24, + #else + DepthComponent24 = GL_DEPTH_COMPONENT24_OES, + #endif /** - * 32bit float depth component. - * @requires_gl30 Extension @extension{ARB,depth_buffer_float} - * @requires_gles30 (no extension providing this functionality) + * Depth component, 32bit. + * @requires_es_extension %Extension @es_extension{OES,required_internalformat}, + * @es_extension{OES,depth_texture} and @es_extension{OES,depth24} */ - Depth32Float = GL_DEPTH_COMPONENT32F, + #ifndef MAGNUM_TARGET_GLES2 + DepthComponent32 = GL_DEPTH_COMPONENT32, + #else + DepthComponent32 = GL_DEPTH_COMPONENT32_OES, + #endif + + #ifndef MAGNUM_TARGET_GLES2 + /** + * Depth component, 32bit float. + * @requires_gl30 %Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 Only integral depth textures are available in + * OpenGL ES 2.0. + */ + DepthComponent32F = GL_DEPTH_COMPONENT32F, + #endif /** * 24bit depth and 8bit stencil component. - * @requires_gl30 Extension @extension{EXT,packed_depth_stencil} - * @requires_gles30 (no extension providing this functionality) + * @requires_gl30 %Extension @extension{EXT,packed_depth_stencil} + * @requires_gles30 %Extension @es_extension{OES,required_internalformat} + * and @es_extension{OES,packed_depth_stencil} */ + #ifdef MAGNUM_TARGET_GLES2 + Depth24Stencil8 = GL_DEPTH24_STENCIL8_OES + #else Depth24Stencil8 = GL_DEPTH24_STENCIL8, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** * 32bit float depth component and 8bit stencil component. - * @requires_gl30 Extension @extension{ARB,depth_buffer_float} - * @requires_gles30 (no extension providing this functionality) + * @requires_gl30 %Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 Only integral depth textures are available in + * OpenGL ES 2.0. */ - Depth32FloatStencil8 = GL_DEPTH32F_STENCIL8 + Depth32FStencil8 = GL_DEPTH32F_STENCIL8 #endif }; - /** - * @brief Internal format - * - * When specifying internal format, you can either specify as binary - * OR of component count (using Component enum) and data type per - * component (value from ComponentType enum), or using one of named - * internal formats from Format enum, e.g.: - * @code - * InternalFormat fmt1 = Format::RGBA; - * InternalFormat fmt2 = Components::RGBA|ComponentType::NormalizedUnsignedByte; - * @endcode - * You can also use the constructor directly instead of binary OR: - * @code - * InternalFormat fmt2(Components::RGBA, ComponentType::NormalizedUnsignedByte); - * @endcode - */ - class MAGNUM_EXPORT InternalFormat { - public: - #ifndef MAGNUM_TARGET_GLES2 - /** - * @brief Constructor from component count and data type per component - * - * @requires_gles30 (no extension providing this functionality) - */ - InternalFormat(Components components, ComponentType type); - #endif - - /** @brief Constructor from named internal format */ - inline constexpr InternalFormat(Format format): internalFormat(static_cast(format)) {} - - /** @brief OpenGL internal format ID */ - inline constexpr operator GLint() const { return internalFormat; } - - private: - GLint internalFormat; - }; - - /*@}*/ - /** * @brief Max supported layer count * @@ -713,7 +1098,7 @@ class MAGNUM_EXPORT AbstractTexture { * @see setMinificationFilter(), @fn_gl{ActiveTexture}, * @fn_gl{BindTexture} and @fn_gl{GenerateMipmap} or * @fn_gl_extension{GenerateTextureMipmap,EXT,direct_state_access} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @requires_gl30 %Extension @extension{EXT,framebuffer_object} */ AbstractTexture* generateMipmap(); @@ -802,24 +1187,6 @@ class MAGNUM_EXPORT AbstractTexture { GLuint _id; }; -#ifndef MAGNUM_TARGET_GLES2 -/** @relates AbstractTexture -@brief Convertor of component count and data type to InternalFormat - -@requires_gles30 (no extension providing this functionality) -*/ -inline AbstractTexture::InternalFormat operator|(AbstractTexture::Components components, AbstractTexture::ComponentType type) { - return AbstractTexture::InternalFormat(components, type); -} - -/** @relates AbstractTexture - * @overload - */ -inline AbstractTexture::InternalFormat operator|(AbstractTexture::ComponentType type, AbstractTexture::Components components) { - return AbstractTexture::InternalFormat(components, type); -} -#endif - #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_TARGET_GLES template<> struct AbstractTexture::DataHelper<1> { diff --git a/src/BufferedTexture.cpp b/src/BufferedTexture.cpp index 862f1f97a..83327903b 100644 --- a/src/BufferedTexture.cpp +++ b/src/BufferedTexture.cpp @@ -34,43 +34,11 @@ void BufferedTexture::initializeContextBasedFunctionality(Context* context) { void BufferedTexture::setBufferImplementationDefault(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { bindInternal(); - glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id()); + glTexBuffer(GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); } void BufferedTexture::setBufferImplementationDSA(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { - glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, internalFormat, buffer->id()); -} - -BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) { - #define internalFormatSwitch(c) switch(type) { \ - case ComponentType::UnsignedByte: \ - internalFormat = GL_##c##8UI; break; \ - case ComponentType::Byte: \ - internalFormat = GL_##c##8I; break; \ - case ComponentType::UnsignedShort: \ - internalFormat = GL_##c##16UI; break; \ - case ComponentType::Short: \ - internalFormat = GL_##c##16I; break; \ - case ComponentType::UnsignedInt: \ - internalFormat = GL_##c##32UI; break; \ - case ComponentType::Int: \ - internalFormat = GL_##c##32I; break; \ - case ComponentType::Half: \ - internalFormat = GL_##c##16F; break; \ - case ComponentType::Float: \ - internalFormat = GL_##c##32F; break; \ - case ComponentType::NormalizedUnsignedByte: \ - internalFormat = GL_##c##8; break; \ - case ComponentType::NormalizedUnsignedShort: \ - internalFormat = GL_##c##16; break; \ - } - if(components == Components::Red) - internalFormatSwitch(R) - else if(components == Components::RedGreen) - internalFormatSwitch(RG) - else if(components == Components::RGBA) - internalFormatSwitch(RGBA) - #undef internalFormatSwitch + glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); } } diff --git a/src/BufferedTexture.h b/src/BufferedTexture.h index ba2e5e4f8..cd02eff5d 100644 --- a/src/BufferedTexture.h +++ b/src/BufferedTexture.h @@ -79,75 +79,120 @@ class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { BufferedTexture& operator=(BufferedTexture&& other) = delete; public: - /** @{ @name Internal buffered texture formats */ - /** - * @copybrief AbstractTexture::Components + * @brief Internal format * - * Like AbstractTexture::Components, without three-component RGB. + * @see setBuffer() */ - enum class Components { - Red, RedGreen, RGBA - }; + enum class InternalFormat: GLenum { + /** Red component, normalized unsigned byte. */ + R8 = GL_R8, - /** - * @copybrief AbstractTexture::ComponentType - * - * Like AbstractTexture::ComponentType, without normalized signed - * types. - */ - enum class ComponentType { - UnsignedByte, Byte, UnsignedShort, Short, UnsignedInt, Int, Half, - Float, NormalizedUnsignedByte, NormalizedUnsignedShort - }; + /** Red and green component, each normalized unsigned byte. */ + RG8 = GL_RG8, - /** @copybrief AbstractTexture::Format */ - enum class Format: GLenum { - /** - * Three-component RGB, float, each component 32bit, 96bit total. - * - * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} - */ - RGB32Float = GL_RGB32F, + /** RGBA, each component normalized unsigned byte. */ + RGBA8 = GL_RGBA8, + + /** Red component, normalized unsigned short. */ + R16 = GL_R16, + + /** Red and green component, each normalized unsigned short. */ + RG16 = GL_RG16, + + /** RGBA, each component normalized unsigned short. */ + RGBA16 = GL_RGBA16, + + /** Red component, non-normalized unsigned byte. */ + R8UI = GL_R8UI, + + /** Red and green component, each non-normalized unsigned byte. */ + RG8UI = GL_RG8UI, + + /** RGBA, each component non-normalized unsigned byte. */ + RGBA8UI = GL_RGBA8UI, + + /** Red component, non-normalized signed byte. */ + R8I = GL_R8I, + + /** Red and green component, each non-normalized signed byte. */ + RG8I = GL_RG8I, + + /** RGBA, each component non-normalized signed byte. */ + RGBA8I = GL_RGBA8I, + + /** Red component, non-normalized unsigned short. */ + R16UI = GL_R16UI, + + /** Red and green component, each non-normalized unsigned short. */ + RG16UI = GL_RG16UI, + + /** RGBA, each component non-normalized unsigned short. */ + RGBA16UI = GL_RGBA16UI, + + /** Red component, non-normalized signed short. */ + R16I = GL_R16I, + + /** Red and green component, each non-normalized signed short. */ + RG16I = GL_RG16I, + + /** RGBA, each component non-normalized signed short. */ + RGBA16I = GL_RGBA16I, + + /** Red component, non-normalized unsigned int. */ + R32UI = GL_R32UI, + + /** Red and green component, each non-normalized unsigned int. */ + RG32UI = GL_RG32UI, /** - * Three-component RGB, unsigned non-normalized, each component - * 32bit, 96bit total. - * + * RGB, each component non-normalized unsigned int. * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} */ - RGB32UnsignedInt = GL_RGB32UI, + RGB32UI = GL_RGB32UI, + + /** RGBA, each component non-normalized unsigned int. */ + RGBA32UI = GL_RGBA32UI, + + /** Red component, non-normalized signed int. */ + R32I = GL_R32I, + + /** Red and green component, each non-normalized signed int. */ + RG32I = GL_RG32I, /** - * Three-component RGB, signed non-normalized, each component - * 32bit, 96bit total. - * + * RGB, each component non-normalized signed int. * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} */ - RGB32Int = GL_RGB32I - }; + RGB32I = GL_RGB32I, - /** @copydoc AbstractTexture::InternalFormat */ - class MAGNUM_EXPORT InternalFormat { - public: - /** @copybrief AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components, AbstractTexture::ComponentType) */ - InternalFormat(Components components, ComponentType type); + /** RGBA, each component non-normalized signed int. */ + RGBA32I = GL_RGBA32I, - /** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Format) */ - inline constexpr InternalFormat(Format format): internalFormat(static_cast(format)) {} + /** Red component, half float. */ + R16F = GL_R16F, - /** - * @brief OpenGL internal format ID - * - * @todoc Remove workaround when Doxygen supports \@copydoc for conversion operators - */ - inline constexpr operator GLint() const { return internalFormat; } + /** Red and green component, each half float. */ + RG16F = GL_RG16F, - private: - GLint internalFormat; - }; + /** RGBA, each component half float. */ + RGBA16F = GL_RGBA16F, - /*@}*/ + /** Red component, float. */ + R32F = GL_R32F, + + /** Red and green component, each float. */ + RG32F = GL_RG32F, + + /** + * RGB, each component float. + * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} + */ + RGB32F = GL_RGB32F, + + /** RGBA, each component float. */ + RGBA32F = GL_RGBA32F + }; inline BufferedTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} @@ -178,19 +223,6 @@ class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { static SetBufferImplementation setBufferImplementation; }; -/** @relates BufferedTexture -@brief Convertor of component count and data type to InternalFormat -*/ -inline BufferedTexture::InternalFormat operator|(BufferedTexture::Components components, BufferedTexture::ComponentType type) { - return BufferedTexture::InternalFormat(components, type); -} -/** @relates BufferedTexture - * @overload - */ -inline BufferedTexture::InternalFormat operator|(BufferedTexture::ComponentType type, BufferedTexture::Components components) { - return BufferedTexture::InternalFormat(components, type); -} - } #endif diff --git a/src/Renderbuffer.cpp b/src/Renderbuffer.cpp index bb5be459b..6e3cb17ee 100644 --- a/src/Renderbuffer.cpp +++ b/src/Renderbuffer.cpp @@ -17,61 +17,4 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES2 -Renderbuffer::InternalFormat::InternalFormat(Components components, ComponentType type) { - #ifndef MAGNUM_TARGET_GLES - #define internalFormatSwitch(c) switch(type) { \ - case ComponentType::UnsignedByte: \ - internalFormat = GL_##c##8UI; break; \ - case ComponentType::Byte: \ - internalFormat = GL_##c##8I; break; \ - case ComponentType::UnsignedShort: \ - internalFormat = GL_##c##16UI; break; \ - case ComponentType::Short: \ - internalFormat = GL_##c##16I; break; \ - case ComponentType::UnsignedInt: \ - internalFormat = GL_##c##32UI; break; \ - case ComponentType::Int: \ - internalFormat = GL_##c##32I; break; \ - case ComponentType::Half: \ - internalFormat = GL_##c##16F; break; \ - case ComponentType::Float: \ - internalFormat = GL_##c##32F; break; \ - case ComponentType::NormalizedUnsignedByte: \ - internalFormat = GL_##c##8; break; \ - case ComponentType::NormalizedUnsignedShort: \ - internalFormat = GL_##c##16; break; \ - } - #else - #define internalFormatSwitch(c) switch(type) { \ - case ComponentType::UnsignedByte: \ - internalFormat = GL_##c##8UI; break; \ - case ComponentType::Byte: \ - internalFormat = GL_##c##8I; break; \ - case ComponentType::UnsignedShort: \ - internalFormat = GL_##c##16UI; break; \ - case ComponentType::Short: \ - internalFormat = GL_##c##16I; break; \ - case ComponentType::UnsignedInt: \ - internalFormat = GL_##c##32UI; break; \ - case ComponentType::Int: \ - internalFormat = GL_##c##32I; break; \ - case ComponentType::Half: \ - internalFormat = GL_##c##16F; break; \ - case ComponentType::Float: \ - internalFormat = GL_##c##32F; break; \ - case ComponentType::NormalizedUnsignedByte: \ - internalFormat = GL_##c##8; break; \ - } - #endif - if(components == Components::Red) - internalFormatSwitch(R) - else if(components == Components::RedGreen) - internalFormatSwitch(RG) - else if(components == Components::RGBA) - internalFormatSwitch(RGBA) - #undef internalFormatSwitch -} -#endif - } diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 2ee87b8bc..42bd27bac 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -40,156 +40,471 @@ class Renderbuffer { Renderbuffer& operator=(Renderbuffer&& other) = delete; public: - /** @{ @name Internal renderbuffer formats */ - - #ifndef MAGNUM_TARGET_GLES2 /** - * @copybrief AbstractTexture::Components + * @brief Internal format * - * Like AbstractTexture::Components, without three-component RGB. - * @requires_gles30 (no extension providing this functionality) + * @see @ref Texture::setData() "setData()" + * @todo RGB, RGB8 ES only (ES3 + @es_extension{OES,rgb8_rgba8}) */ - enum class Components { - Red, RedGreen, RGBA - }; + enum class InternalFormat: GLenum { + #ifndef MAGNUM_TARGET_GLES + /** + * Red component, normalized unsigned, size implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::Renderbuffer::InternalFormat "InternalFormat::R8". + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Use exactly specified format in OpenGL ES instead. + */ + Red = GL_RED, + #endif - /** - * @copybrief AbstractTexture::ComponentType - * - * Like AbstractTexture::ComponentType, without normalized signed - * types. - * @requires_gles30 (no extension providing this functionality) - */ - enum class ComponentType { - UnsignedByte, Byte, UnsignedShort, Short, UnsignedInt, Int, Half, - Float, NormalizedUnsignedByte + /** + * Red component, normalized unsigned byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gles30 %Extension @es_extension{EXT,texture_rg} + */ + #ifndef MAGNUM_TARGET_GLES2 + R8 = GL_R8, + #else + R8 = GL_R8_EXT, + #endif #ifndef MAGNUM_TARGET_GLES - , NormalizedUnsignedShort + /** + * Red and green component, normalized unsigned, size + * implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::Renderbuffer::InternalFormat "InternalFormat::RG8". + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Use exactly specified format in OpenGL ES instead. + */ + RG = GL_RG, #endif - }; - #endif - /** - * @copybrief AbstractTexture::Format - * - * Like AbstractTexture::Format without - * AbstractTexture::Format::RGB9Intensity5, three-component and - * compressed formats, but with added separate stencil index. - */ - enum class Format: GLenum { + /** + * Red and green component, each normalized unsigned byte. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gles30 %Extension @es_extension{EXT,texture_rg} + */ #ifndef MAGNUM_TARGET_GLES2 - Red = GL_RED, RedGreen = GL_RG, + RG8 = GL_RG8, + #else + RG8 = GL_RG8_EXT, #endif + #ifndef MAGNUM_TARGET_GLES + /** + * RGBA, normalized unsigned, size implementation-dependent. + * @deprecated Prefer to use the exactly specified version of this + * format, e.g. @ref Magnum::Renderbuffer::InternalFormat "InternalFormat::RGBA8". + * @requires_gl Use exactly specified format in OpenGL ES 2.0 + * instead. + */ RGBA = GL_RGBA, + #endif + + /** + * RGBA, each component normalized unsigned byte. + * @requires_gles30 %Extension @es_extension{ARM,rgba8} or + * @es_extension{OES,required_internalformat} and @es_extension{OES,rgb8_rgba8} + */ + #ifndef MAGNUM_TARGET_GLES2 + RGBA8 = GL_RGBA8, + #else + RGBA8 = GL_RGBA8_OES, + #endif #ifndef MAGNUM_TARGET_GLES - BGRA = GL_BGRA, + /** + * Red component, normalized unsigned short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. + */ + R16 = GL_R16, + + /** + * Red and green component, each normalized unsigned short. + * @requires_gl30 %Extension @extension{ARB,texture_rg} + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. + */ + RG16 = GL_RG16, + + /** + * RGB, each component normalized unsigned short. + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. + */ + RGB16 = GL_RGB16, + + /** + * RGBA, each component normalized unsigned short. + * @requires_gl Only byte-sized normalized formats are available + * in OpenGL ES. + */ + RGBA16 = GL_RGBA16, #endif #ifndef MAGNUM_TARGET_GLES2 - SRGBA = GL_SRGB8_ALPHA8, RGB10Alpha2 = GL_RGB10_A2, - RGB10AlphaUnsigned2 = GL_RGB10_A2UI, + /** + * Red component, non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R8UI = GL_R8UI, + + /** + * Red and green component, each non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG8UI = GL_RG8UI, + + /** + * RGBA, each component non-normalized unsigned byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA8UI = GL_RGBA8UI, + + /** + * Red component, non-normalized signed byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R8I = GL_R8I, + + /** + * Red and green component, each non-normalized signed byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG8I = GL_RG8I, + + /** + * RGBA, each component non-normalized signed byte. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA8I = GL_RGBA8I, + + /** + * Red component, non-normalized unsigned short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R16UI = GL_R16UI, + + /** + * Red and green component, each non-normalized unsigned short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG16UI = GL_RG16UI, + + /** + * RGBA, each component non-normalized unsigned short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA16UI = GL_RGBA16UI, + + /** + * Red component, non-normalized signed short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R16I = GL_R16I, + + /** + * Red and green component, each non-normalized signed short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG16I = GL_RG16I, + + /** + * RGBA, each component non-normalized signed short. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA16I = GL_RGBA16I, + + /** + * Red component, non-normalized unsigned int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R32UI = GL_R32UI, + + /** + * Red and green component, each non-normalized unsigned int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG32UI = GL_RG32UI, + + /** + * RGBA, each component non-normalized unsigned int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA32UI = GL_RGBA32UI, + + /** + * Red component, non-normalized signed int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + R32I = GL_R32I, + + /** + * Red and green component, each non-normalized signed int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RG32I = GL_RG32I, + + /** + * RGBA, each component non-normalized signed int. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGBA32I = GL_RGBA32I, #endif - RGB5Alpha1 = GL_RGB5_A1, - RGBA4 = GL_RGBA4, + #ifndef MAGNUM_TARGET_GLES + /** + * Red component, half float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gl Only (non)normalized integral formats are + * available in OpenGL ES. + */ + R16F = GL_R16F, + + /** + * Red and green component, each half float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gl Only (non)normalized integral formats are + * available in OpenGL ES. + */ + RG16F = GL_RG16F, + + /** + * RGBA, each component half float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gl Only (non)normalized integral formats are + * available in OpenGL ES. + */ + RGBA16F = GL_RGBA16F, + + /** + * Red component, float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gl Only (non)normalized integral formats are + * available in OpenGL ES. + */ + R32F = GL_R32F, + + /** + * Red and green component, each float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gl Only (non)normalized integral formats are + * available in OpenGL ES. + */ + RG32F = GL_RG32F, + + /** + * RGBA, each component float. + * @requires_gl30 %Extension @extension{ARB,texture_float} + * @requires_gl Only (non)normalized integral formats are + * available in OpenGL ES. + */ + RGBA32F = GL_RGBA32F, + #endif #ifndef MAGNUM_TARGET_GLES2 - RFloat11GFloat11BFloat10 = GL_R11F_G11F_B10F, + /** + * RGBA, normalized unsigned, each RGB component 10bit, alpha 2bit. + * @requires_gles30 Usable only as internal texture format in OpenGL + * ES 2.0, see @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::RGB10A2". + */ + RGB10A2 = GL_RGB10_A2, + + /** + * RGBA, non-normalized unsigned, each RGB component 10bit, alpha 2bit. + * @requires_gl33 %Extension @extension{ARB,texture_rgb10_a2ui} + * @requires_gles30 Only normalized integral formats are available + * in OpenGL ES 2.0. + */ + RGB10A2UI = GL_RGB10_A2UI, + #endif + + /** RGBA, normalized unsigned, each RGB component 5bit, alpha 1bit. */ + RGB5A1 = GL_RGB5_A1, + + /** RGBA, normalized unsigned, each component 4bit. */ + RGBA4 = GL_RGBA4, + + #ifndef MAGNUM_TARGET_GLES + /** + * RGB, float, red and green 11bit, blue 10bit. + * @requires_gl30 %Extension @extension{EXT,packed_float} + * @requires_gl Usable only as internal texture format in OpenGL + * ES, see @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::R11FG11FB10F". + */ + R11FG11FB10F = GL_R11F_G11F_B10F, #endif /* 1.5.6 <= GLEW < 1.8.0 doesn't have this, even if there is GL_ARB_ES2_compatibility */ #if defined(GL_RGB565) || defined(DOXYGEN_GENERATING_OUTPUT) + /** RGB, normalized unsigned, red and blue 5bit, green 6bit. */ RGB565 = GL_RGB565, #endif - #ifndef MAGNUM_TARGET_GLES /** - * Depth component, at least 16bit. - * - * Prefer to use the exactly specified version of this format, in - * this case e.g. `Format::%Depth16`. - * @requires_gl Use exactly specified format Format::%Depth16 instead. + * sRGBA, each component normalized unsigned byte. + * @requires_gles30 %Extension @es_extension{EXT,sRGB} */ - Depth = GL_DEPTH_COMPONENT, + #ifndef MAGNUM_TARGET_GLES2 + SRGB8Alpha8 = GL_SRGB8_ALPHA8, + #else + SRGB8Alpha8 = GL_SRGB8_ALPHA8_EXT, + #endif - DepthStencil = GL_DEPTH_STENCIL, + #ifndef MAGNUM_TARGET_GLES + /** + * Depth component, size implementation-dependent. + * @todo is this allowed in core? + * @deprecated Prefer to use exactly specified version of this + * format, e.g. @ref Magnum::Renderbuffer::InternalFormat "InternalFormat::DepthComponent16". + * @requires_gl Use exactly specified format in OpenGL ES instead. + */ + DepthComponent = GL_DEPTH_COMPONENT, #endif - Depth16 = GL_DEPTH_COMPONENT16, + /** Depth component, 16bit. */ + DepthComponent16 = GL_DEPTH_COMPONENT16, + /** + * Depth component, 24bit. + * @requires_gles30 %Extension @es_extension{OES,depth24} + */ + #ifndef MAGNUM_TARGET_GLES2 + DepthComponent24 = GL_DEPTH_COMPONENT24, + #else + DepthComponent24 = GL_DEPTH_COMPONENT24_OES, + #endif + + /** + * Depth component, 32bit. + * @requires_es_extension %Extension @es_extension{OES,depth32} + */ #ifndef MAGNUM_TARGET_GLES - Depth24 = GL_DEPTH_COMPONENT24, - DepthFloat = GL_DEPTH_COMPONENT32F, + DepthComponent32 = GL_DEPTH_COMPONENT32, + #else + DepthComponent32 = GL_DEPTH_COMPONENT32_OES, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Stencil index (unspecified size). - * - * Prefer to use the exactly specified version of this format, in - * this case e.g. `Format::%Stencil8`. - * @requires_gl Use exactly specified format Format::%Stencil8 instead. + * Depth component, 32bit float. + * @requires_gl30 %Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 Only integral depth textures are available in + * OpenGL ES 2.0. */ - Stencil = GL_STENCIL_INDEX, + DepthComponent32F = GL_DEPTH_COMPONENT32F, + #endif + + #ifndef MAGNUM_TARGET_GLES + /** + * Stencil index, size implementation-dependent. + * @deprecated Prefer to use exactly specified version of this + * format, e.g. @ref Magnum::Renderbuffer::InternalFormat "InternalFormat::StencilIndex8". + * @requires_gl Use exactly specified format in OpenGL ES instead. + */ + StencilIndex = GL_STENCIL_INDEX, + #endif /** * 1-bit stencil index. - * - * @requires_gl Use Format::%Stencil8 instead. + * @requires_es_extension %Extension @es_extension{OES,stencil1} */ - Stencil1 = GL_STENCIL_INDEX1, + #ifndef MAGNUM_TARGET_GLES + StencilIndex1 = GL_STENCIL_INDEX1, + #else + StencilIndex1 = GL_STENCIL_INDEX1_OES, + #endif /** * 4-bit stencil index. - * - * @requires_gl Use Format::%Stencil8 instead. + * @requires_es_extension %Extension @es_extension{OES,stencil4} */ - Stencil4 = GL_STENCIL_INDEX4, + #ifndef MAGNUM_TARGET_GLES + StencilIndex4 = GL_STENCIL_INDEX4, + #else + StencilIndex4 = GL_STENCIL_INDEX4_OES, #endif /** 8-bit stencil index. */ - Stencil8 = GL_STENCIL_INDEX8 + StencilIndex8 = GL_STENCIL_INDEX8, #ifndef MAGNUM_TARGET_GLES - , - /** * 16-bit stencil index. - * - * @requires_gl Use Format::%Stencil8 instead. + * @requires_gl At most 8bit stencil index is available in OpenGL + * ES. */ - Stencil16 = GL_STENCIL_INDEX1, + StencilIndex16 = GL_STENCIL_INDEX16, - Depth24Stencil8 = GL_DEPTH24_STENCIL8, - DepthFloatStencil8 = GL_DEPTH32F_STENCIL8 + /** + * Depth and stencil component, size implementation-dependent. + * @deprecated Prefer to use exactly specified version of this + * format, e.g. @ref Magnum::Renderbuffer::InternalFormat "InternalFormat::Depth24Stencil8". + * @requires_gl Use exactly specified format in OpenGL ES instead. + */ + DepthStencil = GL_DEPTH_STENCIL, #endif - }; - /** @copydoc AbstractTexture::InternalFormat */ - class MAGNUM_EXPORT InternalFormat { - public: - #ifndef MAGNUM_TARGET_GLES2 - /** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components, AbstractTexture::ComponentType) */ - InternalFormat(Components components, ComponentType type); - #endif - - /** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Format) */ - inline constexpr InternalFormat(Format format): internalFormat(static_cast(format)) {} - - /** - * @brief OpenGL internal format ID - * - * @todoc Remove workaround when Doxygen supports \@copydoc for conversion operators - */ - inline constexpr operator GLenum() const { return internalFormat; } - - private: - GLenum internalFormat; - }; + /** + * 24bit depth and 8bit stencil component. + * @requires_gl30 %Extension @extension{EXT,packed_depth_stencil} + * @requires_gles30 %Extension @es_extension{OES,packed_depth_stencil} + */ + #ifdef MAGNUM_TARGET_GLES2 + Depth24Stencil8 = GL_DEPTH24_STENCIL8_OES, + #else + Depth24Stencil8 = GL_DEPTH24_STENCIL8, - /*@}*/ + /** + * 32bit float depth component and 8bit stencil component. + * @requires_gl30 %Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 Only integral depth textures are available in + * OpenGL ES 2.0. + */ + Depth32FStencil8 = GL_DEPTH32F_STENCIL8, + #endif + }; /** * @brief Constructor @@ -232,30 +547,13 @@ class Renderbuffer { */ inline void setStorage(InternalFormat internalFormat, const Vector2i& size) { bind(); - glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, size.x(), size.y()); + glRenderbufferStorage(GL_RENDERBUFFER, GLenum(internalFormat), size.x(), size.y()); } private: GLuint renderbuffer; }; -#ifndef MAGNUM_TARGET_GLES2 -/** @relates Renderbuffer -@brief Convertor of component count and data type to InternalFormat - -@requires_gles30 (no extension providing this functionality) -*/ -inline Renderbuffer::InternalFormat operator|(Renderbuffer::Components components, Renderbuffer::ComponentType type) { - return Renderbuffer::InternalFormat(components, type); -} -/** @relates Renderbuffer - * @overload - */ -inline Renderbuffer::InternalFormat operator|(Renderbuffer::ComponentType type, Renderbuffer::Components components) { - return Renderbuffer::InternalFormat(components, type); -} -#endif - } #endif From 90ed04dc7a951913071173f8542d8a46dd7d0f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 2 Nov 2012 17:31:55 +0100 Subject: [PATCH 037/567] Image formats rework. Renamed the enums and enum values to be consistent with OpenGL, added integer types, fixed OpenGL ES compatibility. --- src/AbstractImage.cpp | 114 ++++++----- src/AbstractImage.h | 411 ++++++++++++++++++++++++++++------------ src/AbstractTexture.cpp | 52 ++--- src/AbstractTexture.h | 52 ++--- src/BufferedImage.cpp | 6 +- src/BufferedImage.h | 31 ++- src/Framebuffer.cpp | 16 +- src/Framebuffer.h | 12 +- src/Image.cpp | 4 +- src/Image.h | 43 ++--- src/ImageWrapper.h | 27 +-- src/Trade/ImageData.h | 17 +- src/TypeTraits.h | 24 ++- 13 files changed, 499 insertions(+), 310 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 00e2fcbd8..97599c3de 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -21,80 +21,100 @@ namespace Magnum { -std::size_t AbstractImage::pixelSize(Components format, ComponentType type) { +std::size_t AbstractImage::pixelSize(Format format, Type type) { std::size_t size = 0; switch(type) { - #ifndef MAGNUM_TARGET_GLES - case ComponentType::RGB332: - case ComponentType::BGR233: - return 1; + case Type::UnsignedByte: + #ifndef MAGNUM_TARGET_GLES2 + case Type::Byte: #endif - case ComponentType::RGB565: - #ifndef MAGNUM_TARGET_GLES - case ComponentType::BGR565: + size = 1; break; + case Type::UnsignedShort: + #ifndef MAGNUM_TARGET_GLES2 + case Type::Short: + #endif + case Type::HalfFloat: + size = 2; break; + case Type::UnsignedInt: + #ifndef MAGNUM_TARGET_GLES2 + case Type::Int: #endif - case ComponentType::RGBA4: + case Type::Float: + size = 4; break; + #ifndef MAGNUM_TARGET_GLES - case ComponentType::ABGR4: + case Type::UnsignedByte332: + case Type::UnsignedByte233Rev: + return 1; #endif - case ComponentType::RGB5Alpha1: + case Type::UnsignedShort565: #ifndef MAGNUM_TARGET_GLES - case ComponentType::Alpha1BGR5: + case Type::UnsignedShort565Rev: #endif + case Type::UnsignedShort4444: + case Type::UnsignedShort4444Rev: + case Type::UnsignedShort5551: + case Type::UnsignedShort1555Rev: return 2; #ifndef MAGNUM_TARGET_GLES - case ComponentType::RGBA8: - case ComponentType::ABGR8: - case ComponentType::RGB10Alpha2: - case ComponentType::Alpha2RGB10: - case ComponentType::Depth24Stencil8: - case ComponentType::B10GR11Float: - case ComponentType::Exponent5RGB9: + case Type::UnsignedInt8888: + case Type::UnsignedInt8888Rev: + case Type::UnsignedInt1010102: + #endif + case Type::UnsignedInt2101010Rev: + #ifndef MAGNUM_TARGET_GLES2 + case Type::UnsignedInt10F11F11FRev: + case Type::UnsignedInt5999Rev: + #endif + case Type::UnsignedInt248: return 4; - case ComponentType::Depth32FloatStencil8: + #ifndef MAGNUM_TARGET_GLES2 + case Type::Float32UnsignedInt248Rev: return 8; #endif - case ComponentType::UnsignedByte: - case ComponentType::Byte: - size = 1; break; - case ComponentType::UnsignedShort: - case ComponentType::Short: - #ifndef MAGNUM_TARGET_GLES - case ComponentType::HalfFloat: - size = 2; break; - #endif - case ComponentType::UnsignedInt: - case ComponentType::Int: - case ComponentType::Float: - size = 4; break; } switch(format) { + case Format::Red: + #ifndef MAGNUM_TARGET_GLES2 + case Format::RedInteger: + #endif #ifndef MAGNUM_TARGET_GLES - case Components::Red: - case Components::Green: - case Components::Blue: + case Format::Green: + case Format::Blue: + case Format::GreenInteger: + case Format::BlueInteger: + #endif return 1*size; - case Components::RedGreen: + case Format::RG: + #ifndef MAGNUM_TARGET_GLES2 + case Format::RGInteger: + #endif return 2*size; + case Format::RGB: + #ifndef MAGNUM_TARGET_GLES2 + case Format::RGBInteger: #endif - case Components::RGB: #ifndef MAGNUM_TARGET_GLES - case Components::BGR: + case Format::BGR: + case Format::BGRInteger: #endif return 3*size; - case Components::RGBA: - #ifndef MAGNUM_TARGET_GLES - case Components::BGRA: + case Format::RGBA: + #ifndef MAGNUM_TARGET_GLES2 + case Format::RGBAInteger: + #endif + case Format::BGRA: + #ifndef MAGNUM_TARGET_GLES2 + case Format::BGRAInteger: #endif return 4*size; - #ifndef MAGNUM_TARGET_GLES - case Components::Depth: - case Components::StencilIndex: - case Components::DepthStencil: + /* Handled above */ + case Format::DepthComponent: + case Format::StencilIndex: + case Format::DepthStencil: CORRADE_INTERNAL_ASSERT(false); - #endif } return 0; diff --git a/src/AbstractImage.h b/src/AbstractImage.h index e310ff00a..3be1c7007 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -30,7 +30,8 @@ namespace Magnum { /** @brief Non-templated base for one-, two- or three-dimensional images -See Image, BufferedImage, Trade::ImageData documentation for more information. +See Image, ImageWrapper, BufferedImage, Trade::ImageData documentation for +more information. */ class MAGNUM_EXPORT AbstractImage { AbstractImage(const AbstractImage& other) = delete; @@ -47,217 +48,377 @@ class MAGNUM_EXPORT AbstractImage { * Texture::setData() and others). */ - /** @brief Color components */ - /** @todo Support *_INTEGER types */ - enum class Components: GLenum { - #ifndef MAGNUM_TARGET_GLES + /** + * @brief Format of pixel data + * + * @todo What is allowed for FB reading and what for image + * specification? + * @see pixelSize() + */ + enum class Format: GLenum { /** - * One-component (red channel) - * @requires_gl + * Floating-point red channel. + * @requires_gles30 %Extension @es_extension{EXT,texture_rg} */ + #ifndef MAGNUM_TARGET_GLES2 Red = GL_RED, + #else + Red = GL_RED_EXT, + #endif + #ifndef MAGNUM_TARGET_GLES /** - * One-component (green channel). For framebuffer reading only. - * @requires_gl + * Floating-point green channel. For framebuffer reading only. + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::Red" + * is available in OpenGL ES. */ Green = GL_GREEN, /** - * One-component (green channel). For framebuffer reading only. - * @requires_gl + * Floating-point blue channel. For framebuffer reading only. + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::Red" + * is available in OpenGL ES. */ Blue = GL_BLUE, + #endif /** - * Two-component (red and green channel). For texture data only. - * @requires_gl + * Floating-point red and green channel. For texture data only. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 %Extension @es_extension{EXT,texture_rg} */ - RedGreen = GL_RG, + #ifndef MAGNUM_TARGET_GLES2 + RG = GL_RG, + #else + RG = GL_RG_EXT, #endif - RGB = GL_RGB, /**< Three-component RGB */ - RGBA = GL_RGBA /**< Four-component RGBA */ + /** Floating-point RGB. */ + RGB = GL_RGB, - #ifndef MAGNUM_TARGET_GLES - , + /** Floating-point RGBA. */ + RGBA = GL_RGBA, + #ifndef MAGNUM_TARGET_GLES /** - * Three-component BGR - * @requires_gl + * Floating-point BGR. + * @requires_gl Only RGB component ordering is available in OpenGL + * ES. */ BGR = GL_BGR, + #endif /** - * Four-component BGRA - * @requires_gl + * Floating-point BGRA. + * @requires_es_extension %Extension @es_extension{EXT,read_format_bgra}, + * for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888} + * for texture data. */ + #ifndef MAGNUM_TARGET_GLES BGRA = GL_BGRA, + #else + BGRA = GL_BGRA_EXT, + #endif + + #ifndef MAGNUM_TARGET_GLES2 + /** + * Integer red channel. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + RedInteger = GL_RED_INTEGER, + + /** + * Integer green channel. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + GreenInteger = GL_GREEN_INTEGER, + + /** + * Integer blue channel. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + BlueInteger = GL_BLUE_INTEGER, + + /** + * Integer red and green channel. + * @requires_gl30 %Extension @extension{ARB,texture_rg} and + * @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + RGInteger = GL_RG_INTEGER, + + /** + * Integer RGB. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + RGBInteger = GL_RGB_INTEGER, + + /** + * Integer RGBA. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + RGBAInteger = GL_RGBA_INTEGER, + + /** + * Integer BGR. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + BGRInteger = GL_BGR_INTEGER, + + /** + * Integer BGRA. + * @requires_gl30 %Extension @extension{EXT,texture_integer} + * @requires_gles30 Only floating-point image data are available + * in OpenGL ES 2.0. + */ + BGRAInteger = GL_BGRA_INTEGER, + #endif /** * Depth component. For framebuffer reading only. - * @requires_gl + * @requires_gles30 %Extension @es_extension2{NV,read_depth,GL_NV_read_depth_stencil} */ - Depth = GL_DEPTH_COMPONENT, + DepthComponent = GL_DEPTH_COMPONENT, /** * Stencil index. For framebuffer reading only. - * @requires_gl + * @requires_es_extension %Extension @es_extension2{NV,read_stencil,GL_NV_read_depth_stencil} + * @todo Where to get GL_STENCIL_INDEX in ES? */ + #ifndef MAGNUM_TARGET_GLES StencilIndex = GL_STENCIL_INDEX, + #else + StencilIndex = 0x1901, + #endif /** - * Depth and stencil component. For framebuffer reading only. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,packed_depth_stencil} + * Depth and stencil. For framebuffer reading only. + * @requires_gl30 %Extension @extension{EXT,packed_depth_stencil} + * @requires_gles30 %Extension @es_extension2{NV,read_depth_stencil,GL_NV_read_depth_stencil} */ + #ifndef MAGNUM_TARGET_GLES2 DepthStencil = GL_DEPTH_STENCIL + #else + DepthStencil = GL_DEPTH_STENCIL_OES #endif }; - /** @brief Data type */ - enum class ComponentType: GLenum { - UnsignedByte = GL_UNSIGNED_BYTE, /**< Each component unsigned byte */ - Byte = GL_BYTE, /**< Each component byte */ - UnsignedShort = GL_UNSIGNED_SHORT, /**< Each component unsigned short */ - Short = GL_SHORT, /**< Each component short */ - UnsignedInt = GL_UNSIGNED_INT, /**< Each component unsigned int */ - Int = GL_INT, /**< Each component int */ + /** + * @brief Data type of pixel data + * + * @see pixelSize() + */ + enum class Type: GLenum { + /** Each component unsigned byte. */ + UnsignedByte = GL_UNSIGNED_BYTE, - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 /** - * Each component half float (16bit). For framebuffer reading only. - * - * @requires_gl - * @requires_gl30 Extension @extension{NV,half_float} / @extension{ARB,half_float_pixel} + * Each component signed byte. + * @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedByte" + * is available in OpenGL ES 2.0. */ - HalfFloat = GL_HALF_FLOAT, + Byte = GL_BYTE, #endif - Float = GL_FLOAT, /**< Each component float (32bit) */ - - #ifndef MAGNUM_TARGET_GLES /** - * Three-component RGB, unsigned normalized, red and green 3bit, - * blue 2bit, 8bit total. - * @requires_gl + * Each component unsigned short. + * @requires_gles30 %Extension @es_extension{OES,depth_texture} */ - RGB332 = GL_UNSIGNED_BYTE_3_3_2, + UnsignedShort = GL_UNSIGNED_SHORT, + #ifndef MAGNUM_TARGET_GLES2 /** - * Three-component BGR, unsigned normalized, red and green 3bit, - * blue 2bit, 8bit total. - * @requires_gl + * Each component signed short. + * @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedShort" + * is available in OpenGL ES 2.0. */ - BGR233 = GL_UNSIGNED_BYTE_2_3_3_REV, + Short = GL_SHORT, #endif /** - * Three-component RGB, unsigned normalized, red and blue 5bit, - * green 6bit, 16bit total. + * Each component unsigned int. + * @requires_gles30 %Extension @es_extension{OES,depth_texture} */ - RGB565 = GL_UNSIGNED_SHORT_5_6_5, + UnsignedInt = GL_UNSIGNED_INT, - #ifndef MAGNUM_TARGET_GLES + #ifndef MAGNUM_TARGET_GLES2 /** - * Three-component BGR, unsigned normalized, red and blue 5bit, - * green 6bit, 16bit total. - * @requires_gl + * Each component signed int. + * @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedInt" + * is available in OpenGL ES 2.0. */ - BGR565 = GL_UNSIGNED_SHORT_5_6_5_REV, + Int = GL_INT, #endif /** - * Four-component RGBA, unsigned normalized, each component 4bit, - * 16bit total. + * Each component half float. For framebuffer reading only. + * @requires_gl30 %Extension @extension{NV,half_float} / @extension{ARB,half_float_pixel} + * @requires_gles30 %Extension @es_extension{OES,texture_float}, + * for texture data only. */ - RGBA4 = GL_UNSIGNED_SHORT_4_4_4_4, + #ifndef MAGNUM_TARGET_GLES2 + HalfFloat = GL_HALF_FLOAT, + #else + HalfFloat = GL_HALF_FLOAT_OES, + #endif + + /** + * Each component float. + * @requires_gles30 %Extension @es_extension{OES,texture_float} + */ + Float = GL_FLOAT, #ifndef MAGNUM_TARGET_GLES /** - * Four-component ABGR, unsigned normalized, each component 4bit, - * 16bit total. - * @requires_gl + * RGB, unsigned byte, red and green component 3bit, blue + * component 2bit. + * @requires_gl Packed 12bit types are not available in OpenGL ES. + */ + UnsignedByte332 = GL_UNSIGNED_BYTE_3_3_2, + + /** + * BGR, unsigned byte, red and green component 3bit, blue + * component 2bit. + * @requires_gl Packed 12bit types are not available in OpenGL ES. */ - ABGR4 = GL_UNSIGNED_SHORT_4_4_4_4_REV, + UnsignedByte233Rev = GL_UNSIGNED_BYTE_2_3_3_REV, #endif + /** RGB, unsigned byte, red and blue component 5bit, green 6bit. */ + UnsignedShort565 = GL_UNSIGNED_SHORT_5_6_5, + + #ifndef MAGNUM_TARGET_GLES /** - * Four-component RGBA, unsigned normalized, each RGB component - * 5bit, alpha 1bit, 16bit total. + * BGR, unsigned short, red and blue 5bit, green 6bit. + * @requires_gl Only @ref Magnum::AbstractImage::Type "Type::RGB565" + * is available in OpenGL ES. */ - RGB5Alpha1 = GL_UNSIGNED_SHORT_5_5_5_1 + UnsignedShort565Rev = GL_UNSIGNED_SHORT_5_6_5_REV, + #endif + + /** RGBA, unsigned short, each component 4bit. */ + UnsignedShort4444 = GL_UNSIGNED_SHORT_4_4_4_4, + /** + * ABGR, unsigned short, each component 4bit. + * @requires_es_extension %Extension @es_extension{EXT,read_format_bgra}, + * for framebuffer reading only. + */ #ifndef MAGNUM_TARGET_GLES - , + UnsignedShort4444Rev = GL_UNSIGNED_SHORT_4_4_4_4_REV, + #else + UnsignedShort4444Rev = GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, + #endif + + /** + * RGBA, unsigned short, each RGB component 5bit, alpha component + * 1bit. + */ + UnsignedShort5551 = GL_UNSIGNED_SHORT_5_5_5_1, /** - * Four-component ABGR, unsigned normalized, each RGB component - * 5bit, alpha 1bit, 16bit total. - * @requires_gl + * ABGR, unsigned short, each RGB component 5bit, alpha component + * 1bit. + * @requires_es_extension %Extension @es_extension{EXT,read_format_bgra}, + * for framebuffer reading only. */ - Alpha1BGR5 = GL_UNSIGNED_SHORT_1_5_5_5_REV, + #ifndef MAGNUM_TARGET_GLES + UnsignedShort1555Rev = GL_UNSIGNED_SHORT_1_5_5_5_REV, + #else + UnsignedShort1555Rev = GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, + #endif + #ifndef MAGNUM_TARGET_GLES /** - * Four-component RGBA, unsigned normalized, each component 8bit, - * 32bit total. - * @requires_gl + * RGBA, unsigned int, each component 8bit. + * @requires_gl Use @ref Magnum::AbstractImage::Type "Type::UnsignedByte" + * in OpenGL ES instead. */ - RGBA8 = GL_UNSIGNED_INT_8_8_8_8, + UnsignedInt8888 = GL_UNSIGNED_INT_8_8_8_8, /** - * Four-component ABGR, unsigned normalized, each component 8bit, - * 32bit total. - * @requires_gl + * ABGR, unsigned int, each component 8bit. + * @requires_gl Only RGBA component ordering is available in + * OpenGL ES, see @ref Magnum::AbstractImage::Format "Format::UnsignedInt8888" + * for more information. */ - ABGR8 = GL_UNSIGNED_INT_8_8_8_8_REV, + UnsignedInt8888Rev = GL_UNSIGNED_INT_8_8_8_8_REV, /** - * Four-component RGBA, unsigned normalized, each RGB component - * 10bit, alpha 2bit, 32bit total. - * @requires_gl + * RGBA, unsigned int, each RGB component 10bit, alpha component + * 2bit. + * @requires_gl Only @ref Magnum::AbstractImage::Type "Type::UnsignedInt2101010Rev" + * is available in OpenGL ES. */ - RGB10Alpha2 = GL_UNSIGNED_INT_10_10_10_2, + UnsignedInt1010102 = GL_UNSIGNED_INT_10_10_10_2, + #endif /** - * Four-component ABGR, unsigned normalized, each RGB component - * 10bit, alpha 2bit, 32bit total. - * @requires_gl + * ABGR, unsigned int, each RGB component 10bit, alpha component + * 2bit. + * @requires_gles30 %Extension @es_extension{EXT,texture_type_2_10_10_10_REV}, + * for texture data only. */ - Alpha2RGB10 = GL_UNSIGNED_INT_2_10_10_10_REV, + #ifndef MAGNUM_TARGET_GLES2 + UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, + #else + UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV_EXT, + #endif + #ifndef MAGNUM_TARGET_GLES2 /** - * Three-component BGR, float, red and green 11bit, blue 10bit, - * 32bit total. For framebuffer reading only. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,packed_float} + * BGR, unsigned int, red and green 11bit float, blue 10bit float. + * For framebuffer reading only. + * @requires_gl30 %Extension @extension{EXT,packed_float} + * @requires_gles30 Floating-point types are not available in + * OpenGL ES 2.0. */ - B10GR11Float = GL_UNSIGNED_INT_10F_11F_11F_REV, + UnsignedInt10F11F11FRev = GL_UNSIGNED_INT_10F_11F_11F_REV, /** - * Three-component BGR, unsigned integers with exponent, each - * component 9bit, exponent 5bit, 32bit total. For framebuffer - * reading only. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,texture_shared_exponent} + * BGR, unsigned int, each component 9bit + 5bit exponent. For + * framebuffer reading only. + * @requires_gl30 %Extension @extension{EXT,texture_shared_exponent} + * @requires_gles30 Only 8bit and 16bit types are available in + * OpenGL ES 2.0. */ - Exponent5RGB9 = GL_UNSIGNED_INT_5_9_9_9_REV, + UnsignedInt5999Rev = GL_UNSIGNED_INT_5_9_9_9_REV, + #endif /** - * 24bit depth and 8bit stencil component, 32bit total. For + * Unsigned int, depth component 24bit, stencil index 8bit. For * framebuffer reading only. - * @requires_gl - * @requires_gl30 Extension @extension{EXT,packed_depth_stencil} + * @requires_gl30 %Extension @extension{EXT,packed_depth_stencil} + * @requires_gles30 %Extension @es_extension{OES,packed_depth_stencil} */ - Depth24Stencil8 = GL_UNSIGNED_INT_24_8, + #ifdef MAGNUM_TARGET_GLES2 + UnsignedInt248 = GL_UNSIGNED_INT_24_8_OES, + #else + UnsignedInt248 = GL_UNSIGNED_INT_24_8, /** - * 32bit float depth component and 8bit stencil component, 64bit - * total. For framebuffer reading only. - * @requires_gl - * @requires_gl30 Extension @extension{ARB,depth_buffer_float} + * Float + unsigned int, depth component 32bit float, 24bit gap, + * stencil index 8bit. For framebuffer reading only. + * @requires_gl30 %Extension @extension{ARB,depth_buffer_float} + * @requires_gles30 Only @ref Magnum::AbstractImage::Type "Type::UnsignedInt248" + * is available in OpenGL ES 2.0. */ - Depth32FloatStencil8 = GL_FLOAT_32_UNSIGNED_INT_24_8_REV + Float32UnsignedInt248Rev = GL_FLOAT_32_UNSIGNED_INT_24_8_REV #endif }; @@ -265,30 +426,32 @@ class MAGNUM_EXPORT AbstractImage { /** * @brief Pixel size (in bytes) - * @param components Color components - * @param type Data type + * @param format Format of the pixel + * @param type Data type of the pixel */ - static std::size_t pixelSize(Components components, ComponentType type); + static std::size_t pixelSize(Format format, Type type); /** * @brief Constructor - * @param components Color components of passed data - * @param type %Image data type + * @param format Format of pixel data + * @param type Data type of pixel data */ - inline AbstractImage(Components components, ComponentType type): _components(components), _type(type) {} + inline AbstractImage(Format format, Type type): _format(format), _type(type) {} /** @brief Destructor */ virtual ~AbstractImage() = 0; - /** @brief Color components */ - inline Components components() const { return _components; } + /** @brief Format of pixel data */ + inline Format format() const { return _format; } - /** @brief Data type */ - inline ComponentType type() const { return _type; } + /** @brief Data type of pixel data */ + inline Type type() const { return _type; } + #ifndef DOXYGEN_GENERATING_OUTPUT protected: - Components _components; /**< @brief Color components */ - ComponentType _type; /**< @brief Data type */ + Format _format; + Type _type; + #endif }; inline AbstractImage::~AbstractImage() {} diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 9be1738fb..1e14bf5d6 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -225,90 +225,90 @@ void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat glTextureParameterfvEXT(_id, _target, parameter, values); } -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexImage1D(target, mipLevel, static_cast(internalFormat), size[0], 0, static_cast(components), static_cast(type), data); + glTexImage1D(target, mipLevel, static_cast(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); } -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureImage1DEXT(_id, target, mipLevel, GLint(internalFormat), size[0], 0, static_cast(components), static_cast(type), data); +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureImage1DEXT(_id, target, mipLevel, GLint(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexImage2D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(components), static_cast(type), data); + glTexImage2D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(format), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureImage2DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(components), static_cast(type), data); +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureImage2DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glTexImage3D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); + glTexImage3D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(format), static_cast(type), data); #else static_cast(target); static_cast(mipLevel); static_cast(internalFormat); static_cast(size); - static_cast(components); + static_cast(format); static_cast(type); static_cast(data); #endif } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureImage3DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(components), static_cast(type), data); +void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureImage3DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(format), static_cast(type), data); } #endif #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast(components), static_cast(type), data); + glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast(format), static_cast(type), data); } -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast(components), static_cast(type), data); +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); + glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexSubImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); + glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(format), static_cast(type), data); #else static_cast(target); static_cast(mipLevel); static_cast(offset); static_cast(size); - static_cast(components); + static_cast(format); static_cast(type); static_cast(data); #endif } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data) { - glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(components), static_cast(type), data); +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(format), static_cast(type), data); } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index d4627266d..9145e8119 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1151,37 +1151,37 @@ class MAGNUM_EXPORT AbstractTexture { static MAGNUM_LOCAL MipmapImplementation mipmapImplementation; #ifndef MAGNUM_TARGET_GLES - typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static Image1DImplementation image1DImplementation; #endif - typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static Image2DImplementation image2DImplementation; - typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static Image3DImplementation image3DImplementation; #ifndef MAGNUM_TARGET_GLES - typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage1DImplementation subImage1DImplementation; #endif - typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage2DImplementation subImage2DImplementation; - typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Components, AbstractImage::ComponentType, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Components components, AbstractImage::ComponentType type, const GLvoid* data); + typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage3DImplementation subImage3DImplementation; GLuint _id; @@ -1201,11 +1201,11 @@ template<> struct AbstractTexture::DataHelper<1> { } template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - (texture->*image1DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); + (texture->*image1DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data()); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { - (texture->*subImage1DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); + (texture->*subImage1DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data()); } }; #endif @@ -1224,15 +1224,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { static void setWrapping(AbstractTexture* texture, const Array2D& wrapping); template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - (texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); + (texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data()); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) { - (texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); + (texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data()); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) { - (texture->*subImage2DImplementation)(target, mipLevel, offset, Vector2i(image->size(), 1), image->components(), image->type(), image->data()); + (texture->*subImage2DImplementation)(target, mipLevel, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data()); } }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { @@ -1250,15 +1250,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { static void setWrapping(AbstractTexture* texture, const Array3D& wrapping); template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - (texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->components(), image->type(), image->data()); + (texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data()); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) { - (texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->components(), image->type(), image->data()); + (texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data()); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) { - (texture->*subImage3DImplementation)(target, mipLevel, offset, Vector3i(image->size(), 1), image->components(), image->type(), image->data()); + (texture->*subImage3DImplementation)(target, mipLevel, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data()); } }; #endif diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index f75688054..95781fdce 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -18,11 +18,11 @@ namespace Magnum { #ifndef MAGNUM_TARGET_GLES2 -template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { - _components = components; +template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) { + _format = format; _type = type; _size = size; - _buffer.setData(pixelSize(_components, _type)*size.product(), data, usage); + _buffer.setData(pixelSize(format, type)*size.product(), data, usage); } template class BufferedImage<1>; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index bcc10c985..b87756e09 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -33,8 +33,7 @@ namespace Magnum { /** @brief %Buffered image -Class for storing image data in GPU memory. Can be replaced with Image, which -stores image data in client memory, ImageWrapper, or for example with +Stores image data in GPU memory. Interchangeable with Image, ImageWrapper or Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. @@ -45,13 +44,13 @@ template class MAGNUM_EXPORT BufferedImage: public Abst /** * @brief Constructor - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * * Dimensions and buffer are empty, call setData() to fill the image * with data. */ - inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type) { + inline BufferedImage(Format format, Type type): AbstractImage(format, type) { _buffer.setTargetHint(Buffer::Target::PixelPack); } @@ -78,25 +77,25 @@ template class MAGNUM_EXPORT BufferedImage: public Abst /** * @brief Set image data * @param size %Image size - * @param components Color components. Data type is detected - * from passed data array. + * @param format Format of pixel data. Data type is + * detected from passed data array. * @param data %Image data * @param usage %Image buffer usage * * Updates the image buffer with given data. The data are not deleted * after filling the buffer. * - * @see setData(const Math::Vector&, Components, ComponentType, const GLvoid*, Buffer::Usage) + * @see setData(const Math::Vector&, Format, Type, const GLvoid*, Buffer::Usage) */ - template inline void setData(const typename DimensionTraits::VectorType& size, Components components, const T* data, Buffer::Usage usage) { - setData(size, components, TypeTraits::imageType(), data, usage); + template inline void setData(const typename DimensionTraits::VectorType& size, Format format, const T* data, Buffer::Usage usage) { + setData(size, format, TypeTraits::imageType(), data, usage); } /** * @brief Set image data * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param data %Image data * @param usage %Image buffer usage * @@ -105,11 +104,11 @@ template class MAGNUM_EXPORT BufferedImage: public Abst * * @see Buffer::setData() */ - void setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); + void setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage); - protected: - Math::Vector _size; /**< @brief %Image size */ - Buffer _buffer; /**< @brief %Image buffer */ + private: + Math::Vector _size; + Buffer _buffer; }; /** @brief One-dimensional buffered image */ diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index cec234536..c9324bfbf 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -45,21 +45,21 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments delete[] attachments; } -void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image) { - char* data = new char[AbstractImage::pixelSize(components, type)*size.product()]; - glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), data); - image->setData(size, components, type, data); +void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { + char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); + image->setData(size, format, type, data); } #ifndef MAGNUM_TARGET_GLES2 -void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage) { +void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferedImage2D* image, Buffer::Usage usage) { /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ - if(image->size() != size || image->components() != components || image->type() != type) - image->setData(size, components, type, nullptr, usage); + if(image->size() != size || image->format() != format || image->type() != type) + image->setData(size, format, type, nullptr, usage); image->buffer()->bind(Buffer::Target::PixelPack); - glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(components), static_cast(type), nullptr); + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), nullptr); } #endif diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 67ae17619..2737dbcc7 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -677,22 +677,22 @@ class MAGNUM_EXPORT Framebuffer { * @brief Read block of pixels from framebuffer to image * @param offset Offset in the framebuffer * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param image %Image where to put the data * * @see @fn_gl{ReadPixels} * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ - static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, Image2D* image); + static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); #ifndef MAGNUM_TARGET_GLES2 /** * @brief Read block of pixels from framebuffer to buffered image * @param offset Offset in the framebuffer * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param image Buffered image where to put the data * @param usage %Buffer usage * @@ -700,7 +700,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ - static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Components components, AbstractImage::ComponentType type, BufferedImage2D* image, Buffer::Usage usage); + static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferedImage2D* image, Buffer::Usage usage); #endif /*@}*/ diff --git a/src/Image.cpp b/src/Image.cpp index 637001733..2e04ce74f 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,9 +17,9 @@ namespace Magnum { -template void Image::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data) { +template void Image::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data) { delete[] _data; - _components = components; + _format = format; _type = type; _size = size; _data = reinterpret_cast(data); diff --git a/src/Image.h b/src/Image.h index 8613ebc5c..a28ac8863 100644 --- a/src/Image.h +++ b/src/Image.h @@ -29,9 +29,8 @@ namespace Magnum { /** @brief %Image -Class for storing image data on client memory. Can be replaced with -ImageWrapper, BufferedImage, which stores image data in GPU memory, or for -example with Trade::ImageData. +Stores image data on client memory. Interchangeable with ImageWrapper, +BufferedImage or Trade::ImageData. @see Image1D, Image2D, Image3D */ template class Image: public AbstractImage { @@ -41,36 +40,36 @@ template class Image: public AbstractImage { /** * @brief Constructor * @param size %Image size - * @param components Color components. Data type is detected - * from passed data array. + * @param format Format of pixel data. Data type is + * detected from passed data array. * @param data %Image data with proper size * * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline Image(const typename DimensionTraits::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} + template inline Image(const typename DimensionTraits::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param data %Image data * * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline Image(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} + inline Image(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline Image(Components components, ComponentType type): AbstractImage(components, type), _data(nullptr) {} + inline Image(Format format, Type type): AbstractImage(format, type), _data(nullptr) {} /** @brief Destructor */ inline ~Image() { delete[] _data; } @@ -85,32 +84,32 @@ template class Image: public AbstractImage { /** * @brief Set image data * @param size %Image size - * @param components Color components. Data type is detected - * from passed data array. + * @param format Format of pixel data. Data type is + * detected from passed data array. * @param data %Image data * * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - template inline void setData(const typename DimensionTraits::VectorType& size, Components components, T* data) { - setData(size, components, TypeTraits::imageType(), data); + template inline void setData(const typename DimensionTraits::VectorType& size, Format format, T* data) { + setData(size, format, TypeTraits::imageType(), data); } /** * @brief Set image data * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param data %Image data * * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - void setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data); + void setData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data); - protected: - Math::Vector _size; /**< @brief %Image size */ - char* _data; /**< @brief %Image data */ + private: + Math::Vector _size; + char* _data; }; #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 68aabd58f..59b4e3508 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -38,7 +38,8 @@ targeted for wrapping data which are either stored in stack/constant memory same properties for each frame, such as video stream. Thus it is not possible to change image properties, only data pointer. -See also Image, BufferedImage and Trade::ImageData. +Interchangeable with Image, BufferedImage or Trade::ImageData. +@see ImageWrapper1D, ImageWrapper2D, ImageWrapper3D */ template class ImageWrapper: public AbstractImage { public: @@ -47,37 +48,37 @@ template class ImageWrapper: public AbstractImage { /** * @brief Constructor * @param size %Image size - * @param components Color components. Data type is detected - * from passed data array. + * @param format Format of pixel data. Data type is + * detected from passed data array. * @param data %Image data with proper size * * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _size(size), _data(data) {} + template inline ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits::imageType()), _size(size), _data(data) {} /** * @brief Constructor * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param data %Image data * * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _size(size), _data(reinterpret_cast(data)) {} + inline ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline ImageWrapper(const typename DimensionTraits::VectorType& size, Components components, ComponentType type): AbstractImage(components, type), _size(size), _data(nullptr) {} + inline ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type): AbstractImage(format, type), _size(size), _data(nullptr) {} /** @brief %Image size */ inline typename DimensionTraits::VectorType size() const { return _size; } @@ -98,9 +99,9 @@ template class ImageWrapper: public AbstractImage { _data = reinterpret_cast(data); } - protected: - Math::Vector _size; /**< @brief %Image size */ - char* _data; /**< @brief %Image data */ + private: + Math::Vector _size; + char* _data; }; /** @brief One-dimensional image wrapper */ diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index cb6ca2690..eaa9e052b 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -29,8 +29,9 @@ namespace Magnum { namespace Trade { /** @brief %Image data -Provides access to image data and additional information about data type and -dimensions. Can be used in the same situations as Image and BufferedImage. +Access to image data provided by AbstractImporter subclasses. Interchangeable +with Image, ImageWrapper or BufferedImage. +@see ImageData1D, ImageData2D, ImageData3D */ template class ImageData: public AbstractImage { public: @@ -40,27 +41,27 @@ template class ImageData: public AbstractImage { * @brief Constructor * @param name %Image name * @param size %Image size - * @param components Color components. Data type is detected - * from passed data array. + * @param format Format of pixel data. Data type is + * detected from passed data array. * @param data %Image data * * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - template inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Components components, T* data): AbstractImage(components, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} + template inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor * @param name %Image name * @param size %Image size - * @param components Color components - * @param type Data type + * @param format Format of pixel data + * @param type Data type of pixel data * @param data %Image data * * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} + inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline ~ImageData() { delete[] _data; } diff --git a/src/TypeTraits.h b/src/TypeTraits.h index c6f878e61..d1f1f4cae 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -69,13 +69,13 @@ template struct TypeTraits: Math::MathTypeTraits { inline constexpr static Type indexType(); /** - * @brief OpenGL type ID for images + * @brief OpenGL type ID for pixel data * * Implemented only in types which can be used for image data, like * GLubyte. This function is not present for types unusable for image data, * like GLdouble and Matrix3. */ - inline constexpr static AbstractImage::ComponentType imageType(); + inline constexpr static AbstractImage::Type imageType(); /** * @brief Size of plain OpenGL type @@ -182,7 +182,7 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ 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; } + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedByte; } inline constexpr static std::size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t count() { return 1; } }; @@ -191,7 +191,9 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ - inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; } + #ifndef MAGNUM_TARGET_GLES2 + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Byte; } + #endif inline constexpr static std::size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t count() { return 1; } }; @@ -200,7 +202,7 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ 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; } + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedShort; } inline constexpr static std::size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t count() { return 1; } }; @@ -209,7 +211,9 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ - inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; } + #ifndef MAGNUM_TARGET_GLES2 + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Short; } + #endif inline constexpr static std::size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t count() { return 1; } }; @@ -218,7 +222,7 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; 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; } + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedInt; } inline constexpr static std::size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t count() { return 1; } }; @@ -227,7 +231,9 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ - inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; } + #ifndef MAGNUM_TARGET_GLES2 + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Int; } + #endif inline constexpr static std::size_t size() { return sizeof(GLint); } inline constexpr static std::size_t count() { return 1; } }; @@ -236,7 +242,7 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; inline constexpr static Type type() { return Type::Float; } /* Can not be used for indices */ - inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Float; } + inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Float; } inline constexpr static std::size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t count() { return 1; } }; From 33a36c9dc6c06c4e1a970135ee18a3bdc3b937de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Dec 2012 21:08:04 +0100 Subject: [PATCH 038/567] Make cube primitive indexed. Saves 300 bytes if using uncompressed vertex and normal data. --- src/Primitives/Cube.cpp | 36 +++++++++--------------------------- src/Primitives/Cube.h | 2 +- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index f3fd4f44e..993200ebb 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -19,91 +19,73 @@ namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new std::vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new std::vector{ + 0, 1, 2, 0, 2, 3, /* +Z */ + 4, 5, 6, 4, 6, 7, /* +X */ + 8, 9, 10, 8, 10, 11, /* +Y */ + 12, 13, 14, 12, 14, 15, /* -Z */ + 16, 17, 18, 16, 18, 19, /* -Y */ + 20, 21, 22, 20, 22, 23 /* -X */ +}, {new std::vector{ {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, /* +Z */ - {-1.0f, -1.0f, 1.0f}, - { 1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, -1.0f}, { 1.0f, 1.0f, -1.0f}, /* +X */ - { 1.0f, -1.0f, 1.0f}, - { 1.0f, 1.0f, -1.0f}, { 1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, { 1.0f, 1.0f, -1.0f}, /* +Y */ - {-1.0f, 1.0f, 1.0f}, - { 1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, { 1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, /* -Z */ - { 1.0f, -1.0f, -1.0f}, - {-1.0f, 1.0f, -1.0f}, { 1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, -1.0f}, { 1.0f, -1.0f, 1.0f}, /* -Y */ - {-1.0f, -1.0f, -1.0f}, - { 1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, /* -X */ - {-1.0f, -1.0f, -1.0f}, - {-1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, -1.0f} }}, {new std::vector{ { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, 1.0f}, /* +Z */ { 0.0f, 0.0f, 1.0f}, - { 0.0f, 0.0f, 1.0f}, - { 0.0f, 0.0f, 1.0f}, { 1.0f, 0.0f, 0.0f}, { 1.0f, 0.0f, 0.0f}, { 1.0f, 0.0f, 0.0f}, /* +X */ { 1.0f, 0.0f, 0.0f}, - { 1.0f, 0.0f, 0.0f}, - { 1.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, /* +Y */ { 0.0f, 1.0f, 0.0f}, - { 0.0f, 1.0f, 0.0f}, - { 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, -1.0f}, { 0.0f, 0.0f, -1.0f}, { 0.0f, 0.0f, -1.0f}, /* -Z */ { 0.0f, 0.0f, -1.0f}, - { 0.0f, 0.0f, -1.0f}, - { 0.0f, 0.0f, -1.0f}, { 0.0f, -1.0f, 0.0f}, { 0.0f, -1.0f, 0.0f}, { 0.0f, -1.0f, 0.0f}, /* -Y */ { 0.0f, -1.0f, 0.0f}, - { 0.0f, -1.0f, 0.0f}, - { 0.0f, -1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, /* -X */ - {-1.0f, 0.0f, 0.0f}, - {-1.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} -}}, {}) { -} +}}, {}) {} }} diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index cf390389f..fd329c4a8 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D cube primitive -2x2x2 cube. Non-indexed triangle mesh with flat normals. +2x2x2 cube. Indexed triangle mesh with flat normals. */ class Cube: public Trade::MeshData3D { public: From ac90cd8a4517841448aa367ae0fcef210475719d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Dec 2012 22:03:02 +0100 Subject: [PATCH 039/567] Removed TypeTraits::imageType() and related function in *Image* classes. It is now ambiguous whether data passed as `std::int8_t` are of Type::Byte, Type::ByteInteger or whatnot. The user now must explicitly specify both format and type. --- src/BufferedImage.h | 18 ------------------ src/Image.h | 27 --------------------------- src/ImageWrapper.h | 14 -------------- src/Trade/ImageData.h | 14 -------------- src/TypeTraits.h | 29 +++-------------------------- 5 files changed, 3 insertions(+), 99 deletions(-) diff --git a/src/BufferedImage.h b/src/BufferedImage.h index b87756e09..9cbe3a119 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -25,7 +25,6 @@ #include "AbstractImage.h" #include "Buffer.h" #include "DimensionTraits.h" -#include "TypeTraits.h" namespace Magnum { @@ -74,23 +73,6 @@ template class MAGNUM_EXPORT BufferedImage: public Abst /** @brief %Image buffer */ inline Buffer* buffer() { return &_buffer; } - /** - * @brief Set image data - * @param size %Image size - * @param format Format of pixel data. Data type is - * detected from passed data array. - * @param data %Image data - * @param usage %Image buffer usage - * - * Updates the image buffer with given data. The data are not deleted - * after filling the buffer. - * - * @see setData(const Math::Vector&, Format, Type, const GLvoid*, Buffer::Usage) - */ - template inline void setData(const typename DimensionTraits::VectorType& size, Format format, const T* data, Buffer::Usage usage) { - setData(size, format, TypeTraits::imageType(), data, usage); - } - /** * @brief Set image data * @param size %Image size diff --git a/src/Image.h b/src/Image.h index a28ac8863..e447c2c9f 100644 --- a/src/Image.h +++ b/src/Image.h @@ -22,7 +22,6 @@ #include "Math/Vector3.h" #include "AbstractImage.h" #include "DimensionTraits.h" -#include "TypeTraits.h" namespace Magnum { @@ -37,18 +36,6 @@ template class Image: public AbstractImage { public: const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ - /** - * @brief Constructor - * @param size %Image size - * @param format Format of pixel data. Data type is - * detected from passed data array. - * @param data %Image data with proper size - * - * Note that the image data are not copied on construction, but they - * are deleted on class destruction. - */ - template inline Image(const typename DimensionTraits::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits::imageType()), _size(size), _data(data) {} - /** * @brief Constructor * @param size %Image size @@ -81,20 +68,6 @@ template class Image: public AbstractImage { inline void* data() { return _data; } inline const void* data() const { return _data; } /**< @overload */ - /** - * @brief Set image data - * @param size %Image size - * @param format Format of pixel data. Data type is - * detected from passed data array. - * @param data %Image data - * - * Deletes previous data and replaces them with new. Note that the - * data are not copied, but they are deleted on destruction. - */ - template inline void setData(const typename DimensionTraits::VectorType& size, Format format, T* data) { - setData(size, format, TypeTraits::imageType(), data); - } - /** * @brief Set image data * @param size %Image size diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 59b4e3508..f02b79667 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -22,7 +22,6 @@ #include "Math/Vector3.h" #include "AbstractImage.h" #include "DimensionTraits.h" -#include "TypeTraits.h" namespace Magnum { @@ -44,19 +43,6 @@ Interchangeable with Image, BufferedImage or Trade::ImageData. template class ImageWrapper: public AbstractImage { public: const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ - - /** - * @brief Constructor - * @param size %Image size - * @param format Format of pixel data. Data type is - * detected from passed data array. - * @param data %Image data with proper size - * - * Note that the image data are not copied on construction, but they - * are deleted on class destruction. - */ - template inline ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits::imageType()), _size(size), _data(data) {} - /** * @brief Constructor * @param size %Image size diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index eaa9e052b..b1d250ab7 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -22,7 +22,6 @@ #include "Math/Vector3.h" #include "AbstractImage.h" #include "DimensionTraits.h" -#include "TypeTraits.h" namespace Magnum { namespace Trade { @@ -37,19 +36,6 @@ template class ImageData: public AbstractImage { public: const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ - /** - * @brief Constructor - * @param name %Image name - * @param size %Image size - * @param format Format of pixel data. Data type is - * detected from passed data array. - * @param data %Image data - * - * Note that the image data are not copied on construction, but they - * are deleted on class destruction. - */ - template inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Format format, T* data): AbstractImage(format, TypeTraits::imageType()), _name(name), _size(size), _data(reinterpret_cast(data)) {} - /** * @brief Constructor * @param name %Image name diff --git a/src/TypeTraits.h b/src/TypeTraits.h index d1f1f4cae..be2d5fc81 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -22,7 +22,9 @@ #include #include "Math/MathTypeTraits.h" -#include "AbstractImage.h" +#include "Magnum.h" + +#include "magnumVisibility.h" namespace Magnum { @@ -68,15 +70,6 @@ template struct TypeTraits: Math::MathTypeTraits { */ inline constexpr static Type indexType(); - /** - * @brief OpenGL type ID for pixel data - * - * Implemented only in types which can be used for image data, like - * GLubyte. This function is not present for types unusable for image data, - * like GLdouble and Matrix3. - */ - inline constexpr static AbstractImage::Type imageType(); - /** * @brief Size of plain OpenGL type * @@ -182,7 +175,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static Type indexType() { return Type::UnsignedByte; } - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedByte; } inline constexpr static std::size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t count() { return 1; } }; @@ -191,9 +183,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ - #ifndef MAGNUM_TARGET_GLES2 - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Byte; } - #endif inline constexpr static std::size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t count() { return 1; } }; @@ -202,7 +191,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; } - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedShort; } inline constexpr static std::size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t count() { return 1; } }; @@ -211,9 +199,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ - #ifndef MAGNUM_TARGET_GLES2 - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Short; } - #endif inline constexpr static std::size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t count() { return 1; } }; @@ -222,7 +207,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::UnsignedInt; } inline constexpr static std::size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t count() { return 1; } }; @@ -231,9 +215,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ - #ifndef MAGNUM_TARGET_GLES2 - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Int; } - #endif inline constexpr static std::size_t size() { return sizeof(GLint); } inline constexpr static std::size_t count() { return 1; } }; @@ -242,7 +223,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; inline constexpr static Type type() { return Type::Float; } /* Can not be used for indices */ - inline constexpr static AbstractImage::Type imageType() { return AbstractImage::Type::Float; } inline constexpr static std::size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t count() { return 1; } }; @@ -252,7 +232,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { typedef GLdouble AttributeType; inline constexpr static Type type() { return Type::Double; } /* Can not be used for indices */ - /* Can not be used for images */ inline constexpr static std::size_t size() { return sizeof(GLdouble); } inline constexpr static std::size_t count() { return 1; } }; @@ -264,7 +243,6 @@ namespace Implementation { inline constexpr static Type type() { return TypeTraits::type(); } /* Might be used for attributes, see below */ /* Can not be used for indices */ - /* Can not be used for images */ inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return vectorSize; } }; @@ -311,7 +289,6 @@ namespace Implementation { inline constexpr static Type type() { return TypeTraits::type(); } /* Might be used for attributes, see below */ /* Can not be used for indices */ - /* Can not be used for images */ inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return rows; } inline constexpr static std::size_t vectors() { return cols; } From 2acbd49e9c53318f370297b4386507fbe1af6c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 14 Dec 2012 22:12:11 +0100 Subject: [PATCH 040/567] Renamed Buffered{Image,Texture} to Buffer{Image,Texture}. Buffered* hinted that it has something to do with caching, streaming or whatever. "Buffer texture" is now also consistent with naming in specification. --- src/AbstractImage.h | 2 +- src/Buffer.h | 2 +- src/{BufferedImage.cpp => BufferImage.cpp} | 10 +++--- src/{BufferedImage.h => BufferImage.h} | 26 +++++++-------- ...{BufferedTexture.cpp => BufferTexture.cpp} | 14 ++++---- src/{BufferedTexture.h => BufferTexture.h} | 32 +++++++++---------- src/CMakeLists.txt | 8 ++--- src/Context.cpp | 4 +-- src/CubeMapTextureArray.h | 8 ++--- src/Framebuffer.cpp | 4 +-- src/Framebuffer.h | 2 +- src/Image.h | 2 +- src/ImageWrapper.h | 2 +- src/Magnum.h | 10 +++--- src/Texture.h | 6 ++-- src/Trade/ImageData.h | 2 +- 16 files changed, 67 insertions(+), 67 deletions(-) rename src/{BufferedImage.cpp => BufferImage.cpp} (69%) rename src/{BufferedImage.h => BufferImage.h} (79%) rename src/{BufferedTexture.cpp => BufferTexture.cpp} (62%) rename src/{BufferedTexture.h => BufferTexture.h} (88%) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 3be1c7007..594d43cd5 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -30,7 +30,7 @@ namespace Magnum { /** @brief Non-templated base for one-, two- or three-dimensional images -See Image, ImageWrapper, BufferedImage, Trade::ImageData documentation for +See Image, ImageWrapper, BufferImage, Trade::ImageData documentation for more information. */ class MAGNUM_EXPORT AbstractImage { diff --git a/src/Buffer.h b/src/Buffer.h index ff7dcc1a4..790a8db70 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -167,7 +167,7 @@ class MAGNUM_EXPORT Buffer { ShaderStorage = GL_SHADER_STORAGE_BUFFER, /** - * Source for texel fetches. See BufferedTexture. + * Source for texel fetches. See BufferTexture. * @requires_gl31 Extension @extension{ARB,texture_buffer_object} * @requires_gl Texture buffers are not available in OpenGL ES. */ diff --git a/src/BufferedImage.cpp b/src/BufferImage.cpp similarity index 69% rename from src/BufferedImage.cpp rename to src/BufferImage.cpp index 95781fdce..377b28e8b 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferImage.cpp @@ -13,21 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "BufferedImage.h" +#include "BufferImage.h" namespace Magnum { #ifndef MAGNUM_TARGET_GLES2 -template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) { +template void BufferImage::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) { _format = format; _type = type; _size = size; _buffer.setData(pixelSize(format, type)*size.product(), data, usage); } -template class BufferedImage<1>; -template class BufferedImage<2>; -template class BufferedImage<3>; +template class BufferImage<1>; +template class BufferImage<2>; +template class BufferImage<3>; #endif } diff --git a/src/BufferedImage.h b/src/BufferImage.h similarity index 79% rename from src/BufferedImage.h rename to src/BufferImage.h index 9cbe3a119..a9c35abcf 100644 --- a/src/BufferedImage.h +++ b/src/BufferImage.h @@ -1,5 +1,5 @@ -#ifndef Magnum_BufferedImage_h -#define Magnum_BufferedImage_h +#ifndef Magnum_BufferImage_h +#define Magnum_BufferImage_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,7 +17,7 @@ #ifndef MAGNUM_TARGET_GLES2 /** @file - * @brief Class Magnum::BufferedImage, typedef Magnum::BufferedImage1D, Magnum::BufferedImage2D, Magnum::BufferedImage3D + * @brief Class Magnum::BufferImage, typedef Magnum::BufferImage1D, Magnum::BufferImage2D, Magnum::BufferImage3D */ #endif @@ -30,14 +30,14 @@ namespace Magnum { #ifndef MAGNUM_TARGET_GLES2 /** -@brief %Buffered image +@brief %Buffer image Stores image data in GPU memory. Interchangeable with Image, ImageWrapper or Trade::ImageData. -@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer +@see BufferImage1D, BufferImage2D, BufferImage3D, Buffer @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ -template class MAGNUM_EXPORT BufferedImage: public AbstractImage { +template class MAGNUM_EXPORT BufferImage: public AbstractImage { public: const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ @@ -49,7 +49,7 @@ template class MAGNUM_EXPORT BufferedImage: public Abst * Dimensions and buffer are empty, call setData() to fill the image * with data. */ - inline BufferedImage(Format format, Type type): AbstractImage(format, type) { + inline BufferImage(Format format, Type type): AbstractImage(format, type) { _buffer.setTargetHint(Buffer::Target::PixelPack); } @@ -93,14 +93,14 @@ template class MAGNUM_EXPORT BufferedImage: public Abst Buffer _buffer; }; -/** @brief One-dimensional buffered image */ -typedef BufferedImage<1> BufferedImage1D; +/** @brief One-dimensional buffer image */ +typedef BufferImage<1> BufferImage1D; -/** @brief Two-dimensional buffered image */ -typedef BufferedImage<2> BufferedImage2D; +/** @brief Two-dimensional buffer image */ +typedef BufferImage<2> BufferImage2D; -/** @brief Three-dimensional buffered image */ -typedef BufferedImage<3> BufferedImage3D; +/** @brief Three-dimensional buffer image */ +typedef BufferImage<3> BufferImage3D; #endif } diff --git a/src/BufferedTexture.cpp b/src/BufferTexture.cpp similarity index 62% rename from src/BufferedTexture.cpp rename to src/BufferTexture.cpp index 83327903b..7fd4f6d50 100644 --- a/src/BufferedTexture.cpp +++ b/src/BufferTexture.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "BufferedTexture.h" +#include "BufferTexture.h" #ifndef MAGNUM_TARGET_GLES #include "Buffer.h" @@ -22,22 +22,22 @@ namespace Magnum { -BufferedTexture::SetBufferImplementation BufferedTexture::setBufferImplementation = &BufferedTexture::setBufferImplementationDefault; +BufferTexture::SetBufferImplementation BufferTexture::setBufferImplementation = &BufferTexture::setBufferImplementationDefault; -void BufferedTexture::initializeContextBasedFunctionality(Context* context) { +void BufferTexture::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { - Debug() << "BufferedTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + Debug() << "BufferTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; - setBufferImplementation = &BufferedTexture::setBufferImplementationDSA; + setBufferImplementation = &BufferTexture::setBufferImplementationDSA; } } -void BufferedTexture::setBufferImplementationDefault(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { +void BufferTexture::setBufferImplementationDefault(BufferTexture::InternalFormat internalFormat, Buffer* buffer) { bindInternal(); glTexBuffer(GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); } -void BufferedTexture::setBufferImplementationDSA(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { +void BufferTexture::setBufferImplementationDSA(BufferTexture::InternalFormat internalFormat, Buffer* buffer) { glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); } diff --git a/src/BufferedTexture.h b/src/BufferTexture.h similarity index 88% rename from src/BufferedTexture.h rename to src/BufferTexture.h index cd02eff5d..548206247 100644 --- a/src/BufferedTexture.h +++ b/src/BufferTexture.h @@ -1,5 +1,5 @@ -#ifndef Magnum_BufferedTexture_h -#define Magnum_BufferedTexture_h +#ifndef Magnum_BufferTexture_h +#define Magnum_BufferTexture_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,7 +17,7 @@ #ifndef MAGNUM_TARGET_GLES /** @file - * @brief Class Magnum::BufferedTexture + * @brief Class Magnum::BufferTexture */ #endif @@ -27,13 +27,13 @@ namespace Magnum { /** -@brief Buffered texture +@brief %Buffer texture This texture is, unlike classic textures such as Texture or CubeMapTexture, used as simple data source, without any unnecessary interpolation and wrapping methods. -@section BufferedTexture-usage Usage +@section BufferTexture-usage Usage %Texture data are stored in buffer and after binding the buffer to the texture using setBuffer(), you can fill the buffer at any time using data setting @@ -46,7 +46,7 @@ to use one buffer for more textures or store more than one data in it. Example usage: @code Buffer* buffer; -BufferedTexture texture; +BufferTexture texture; texture.setBuffer(buffer); constexpr static Vector3 data[] = { @@ -57,10 +57,10 @@ buffer.setData(data, Buffer::Usage::StaticDraw); The texture is bound to layer specified by shader via bind(). In shader, the texture is used via `samplerBuffer`. Unlike in classic textures, coordinates -for buffered textures are integer coordinates passed to `texelFetch()`. See -also AbstractShaderProgram documentation for more information. +for buffer textures are integer coordinates passed to `texelFetch()`. See also +AbstractShaderProgram documentation for more information. -@section BufferedTexture-performance-optimization Performance optimizations +@section BufferTexture-performance-optimization Performance optimizations If extension @extension{EXT,direct_state_access} is available, setBuffer() uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and @fn_gl{BindTexture}. See @ref AbstractTexture-performance-optimization @@ -70,13 +70,13 @@ documentation for more information. @requires_gl31 Extension @extension{ARB,texture_buffer_object} @requires_gl Texture buffers are not available in OpenGL ES. */ -class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { +class MAGNUM_EXPORT BufferTexture: private AbstractTexture { friend class Context; - BufferedTexture(const BufferedTexture& other) = delete; - BufferedTexture(BufferedTexture&& other) = delete; - BufferedTexture& operator=(const BufferedTexture& other) = delete; - BufferedTexture& operator=(BufferedTexture&& other) = delete; + BufferTexture(const BufferTexture& other) = delete; + BufferTexture(BufferTexture&& other) = delete; + BufferTexture& operator=(const BufferTexture& other) = delete; + BufferTexture& operator=(BufferTexture&& other) = delete; public: /** @@ -194,7 +194,7 @@ class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { RGBA32F = GL_RGBA32F }; - inline BufferedTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} + inline BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} /** @copydoc AbstractTexture::bind() */ inline void bind(GLint layer) { AbstractTexture::bind(layer); } @@ -217,7 +217,7 @@ class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); - typedef void(BufferedTexture::*SetBufferImplementation)(InternalFormat, Buffer*); + typedef void(BufferTexture::*SetBufferImplementation)(InternalFormat, Buffer*); void MAGNUM_LOCAL setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer); void MAGNUM_LOCAL setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer); static SetBufferImplementation setBufferImplementation; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a65f447a9..c521a9e31 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,13 +40,13 @@ set(Magnum_SRCS # Desktop-only code if(NOT TARGET_GLES) set(Magnum_SRCS ${Magnum_SRCS} - BufferedTexture.cpp) + BufferTexture.cpp) endif() # Not-ES2 code if(NOT TARGET_GLES2) set(Magnum_SRCS ${Magnum_SRCS} - BufferedImage.cpp) + BufferImage.cpp) endif() set(Magnum_HEADERS @@ -86,14 +86,14 @@ set(Magnum_HEADERS # Desktop-only headers if(NOT TARGET_GLES) set(Magnum_HEADERS ${Magnum_HEADERS} - BufferedTexture.h + BufferTexture.h CubeMapTextureArray.h) endif() # Not-ES2 headers if(NOT TARGET_GLES2) set(Magnum_HEADERS ${Magnum_HEADERS} - BufferedImage.h) + BufferImage.h) endif() add_library(MagnumObjects OBJECT ${Magnum_SRCS}) diff --git a/src/Context.cpp b/src/Context.cpp index 2e5d91007..46fad8b8c 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -23,7 +23,7 @@ #include "AbstractShaderProgram.h" #include "AbstractTexture.h" #include "Buffer.h" -#include "BufferedTexture.h" +#include "BufferTexture.h" #include "Extensions.h" #include "IndexedMesh.h" #include "Mesh.h" @@ -296,7 +296,7 @@ Context::Context() { AbstractTexture::initializeContextBasedFunctionality(this); Buffer::initializeContextBasedFunctionality(this); #ifndef MAGNUM_TARGET_GLES - BufferedTexture::initializeContextBasedFunctionality(this); + BufferTexture::initializeContextBasedFunctionality(this); #endif DebugMarker::initializeContextBasedFunctionality(this); IndexedMesh::initializeContextBasedFunctionality(this); diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 06824978f..9dcbf0e3f 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -113,8 +113,8 @@ class CubeMapTextureArray: public AbstractTexture { * @brief Set texture subdata from 3D image * @param mipLevel Mip level * @param offset Offset where to put data in the texture - * @param image Three-dimensional Image, BufferedImage or for - * example Trade::ImageData + * @param image Image3D, ImageWrapper3D, BufferImage3D or + * Trade::ImageData3D * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted @@ -138,8 +138,8 @@ class CubeMapTextureArray: public AbstractTexture { * @param coordinate Coordinate * @param mipLevel Mip level * @param offset Offset where to put data in the texture - * @param image Two-dimensional Image, BufferedImage or for - * example Trade::ImageData + * @param image Image2D, ImageWrapper2D, BufferImage2D or + * Trade::ImageData2D * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index c9324bfbf..238c2f7a1 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -15,7 +15,7 @@ #include "Framebuffer.h" -#include "BufferedImage.h" +#include "BufferImage.h" #include "Image.h" namespace Magnum { @@ -52,7 +52,7 @@ void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractIma } #ifndef MAGNUM_TARGET_GLES2 -void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferedImage2D* image, Buffer::Usage usage) { +void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ if(image->size() != size || image->format() != format || image->type() != type) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 2737dbcc7..74e7a4dca 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -700,7 +700,7 @@ class MAGNUM_EXPORT Framebuffer { * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ - static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferedImage2D* image, Buffer::Usage usage); + static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); #endif /*@}*/ diff --git a/src/Image.h b/src/Image.h index e447c2c9f..8146ce13b 100644 --- a/src/Image.h +++ b/src/Image.h @@ -29,7 +29,7 @@ namespace Magnum { @brief %Image Stores image data on client memory. Interchangeable with ImageWrapper, -BufferedImage or Trade::ImageData. +BufferImage or Trade::ImageData. @see Image1D, Image2D, Image3D */ template class Image: public AbstractImage { diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index f02b79667..6deb82bc2 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -37,7 +37,7 @@ targeted for wrapping data which are either stored in stack/constant memory same properties for each frame, such as video stream. Thus it is not possible to change image properties, only data pointer. -Interchangeable with Image, BufferedImage or Trade::ImageData. +Interchangeable with Image, BufferImage or Trade::ImageData. @see ImageWrapper1D, ImageWrapper2D, ImageWrapper3D */ template class ImageWrapper: public AbstractImage { diff --git a/src/Magnum.h b/src/Magnum.h index bc0b133f3..41010a193 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -134,14 +134,14 @@ template class Array3D; class Buffer; #ifndef MAGNUM_TARGET_GLES2 -template class BufferedImage; -typedef BufferedImage<1> BufferedImage1D; -typedef BufferedImage<2> BufferedImage2D; -typedef BufferedImage<3> BufferedImage3D; +template class BufferImage; +typedef BufferImage<1> BufferImage1D; +typedef BufferImage<2> BufferImage2D; +typedef BufferImage<3> BufferImage3D; #endif #ifndef MAGNUM_TARGET_GLES -class BufferedTexture; +class BufferTexture; #endif template class Color3; diff --git a/src/Texture.h b/src/Texture.h index 6b55d1303..012618b4e 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -200,7 +200,7 @@ template class Texture: public AbstractTexture { * @brief Set texture data * @param mipLevel Mip level * @param internalFormat Internal texture format - * @param image Image, BufferedImage or for example + * @param image Image, ImageWrapper, BufferImage or * Trade::ImageData of the same dimension count * @return Pointer to self (for method chaining) * @@ -222,8 +222,8 @@ template class Texture: public AbstractTexture { * @brief Set texture subdata * @param mipLevel Mip level * @param offset Offset where to put data in the texture - * @param image Image, BufferedImage or for example - * Trade::ImageData + * @param image Image, ImageWrapper, BufferImage or + * Trade::ImageData of the same or one less dimension count * @return Pointer to self (for method chaining) * * Sets texture subdata from given image. The image is not deleted diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index b1d250ab7..b92c5039c 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Trade { @brief %Image data Access to image data provided by AbstractImporter subclasses. Interchangeable -with Image, ImageWrapper or BufferedImage. +with Image, ImageWrapper or BufferImage. @see ImageData1D, ImageData2D, ImageData3D */ template class ImageData: public AbstractImage { From 9e24d0cb06d0fc3a6a41ca86e7a644d489dacda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Dec 2012 00:47:08 +0100 Subject: [PATCH 041/567] Cleaned up #includes. --- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/Framebuffer.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index d0efe7677..a0622d252 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -19,7 +19,7 @@ * @brief Class Magnum::CubeMapTexture */ -#include "Texture.h" +#include "AbstractTexture.h" namespace Magnum { diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 9dcbf0e3f..0bf226684 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -21,7 +21,7 @@ */ #endif -#include "Texture.h" +#include "AbstractTexture.h" #ifndef MAGNUM_TARGET_GLES namespace Magnum { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 74e7a4dca..18664f319 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -24,7 +24,7 @@ #include "AbstractImage.h" #include "Buffer.h" #include "CubeMapTexture.h" -#include "Color.h" +#include "Texture.h" #include "Renderbuffer.h" namespace Magnum { From 5f84edf73d9e708739ecfdc9c4ad97a1033a9177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Dec 2012 18:56:57 +0100 Subject: [PATCH 042/567] Split Framebuffer into default and named framebuffers. Default framebuffer is now accessible throught defaultFramebuffer global variable, named framebuffers are handled the same way as before. All operations (clear, setViewport, blit, read) now are member functions so they cannot be mistakenly used when unwanted framebuffer is bound. Further rework (DSA, state tracking...) is on the way. --- src/AbstractFramebuffer.cpp | 43 ++++ src/AbstractFramebuffer.h | 270 +++++++++++++++++++++ src/CMakeLists.txt | 4 + src/DefaultFramebuffer.cpp | 36 +++ src/DefaultFramebuffer.h | 204 ++++++++++++++++ src/Framebuffer.cpp | 30 --- src/Framebuffer.h | 458 +----------------------------------- src/Magnum.h | 2 + src/Renderbuffer.h | 2 +- 9 files changed, 569 insertions(+), 480 deletions(-) create mode 100644 src/AbstractFramebuffer.cpp create mode 100644 src/AbstractFramebuffer.h create mode 100644 src/DefaultFramebuffer.cpp create mode 100644 src/DefaultFramebuffer.h diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp new file mode 100644 index 000000000..5e8099db0 --- /dev/null +++ b/src/AbstractFramebuffer.cpp @@ -0,0 +1,43 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AbstractFramebuffer.h" + +#include "BufferImage.h" +#include "Image.h" + +namespace Magnum { + +void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { + bind(Target::ReadDraw); + char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); + image->setData(size, format, type, data); +} + +#ifndef MAGNUM_TARGET_GLES2 +void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { + bind(Target::ReadDraw); + /* If the buffer doesn't have sufficient size, resize it */ + /** @todo Explicitly reset also when buffer usage changes */ + if(image->size() != size || image->format() != format || image->type() != type) + image->setData(size, format, type, nullptr, usage); + + image->buffer()->bind(Buffer::Target::PixelPack); + glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), nullptr); +} +#endif + +} diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h new file mode 100644 index 000000000..d0774aefa --- /dev/null +++ b/src/AbstractFramebuffer.h @@ -0,0 +1,270 @@ +#ifndef Magnum_AbstractFramebuffer_h +#define Magnum_AbstractFramebuffer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::AbstractFramebuffer + */ + +#include + +#include "Math/Vector2.h" +#include "AbstractImage.h" +#include "Buffer.h" + +namespace Magnum { + +/** +@brief Base for default and named framebuffers + +See DefaultFramebuffer and Framebuffer for more information. +@todo @extension{ARB,viewport_array} +*/ +class MAGNUM_EXPORT AbstractFramebuffer { + AbstractFramebuffer(const AbstractFramebuffer& other) = delete; + AbstractFramebuffer(AbstractFramebuffer&& other) = delete; + AbstractFramebuffer& operator=(const AbstractFramebuffer& other) = delete; + AbstractFramebuffer& operator=(AbstractFramebuffer&& other) = delete; + + public: + /** + * @brief Mask for clearing + * + * @see ClearMask + */ + enum class Clear: GLbitfield { + Color = GL_COLOR_BUFFER_BIT, /**< Color */ + Depth = GL_DEPTH_BUFFER_BIT, /**< Depth value */ + Stencil = GL_STENCIL_BUFFER_BIT /**< Stencil value */ + }; + + /** + * @brief Mask for clearing + * + * @see clear() + */ + typedef Corrade::Containers::EnumSet ClearMask; + + /** + * @brief Mask for blitting + * + * @see BlitMask + * @requires_gl30 %Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} + */ + enum class Blit: GLbitfield { + ColorBuffer = GL_COLOR_BUFFER_BIT, /**< Color buffer */ + DepthBuffer = GL_DEPTH_BUFFER_BIT, /**< Depth buffer */ + StencilBuffer = GL_STENCIL_BUFFER_BIT /**< Stencil buffer */ + }; + + /** + * @brief Mask for blitting + * + * @see blit() + * @requires_gl30 %Extension @extension{EXT,framebuffer_object} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} + */ + typedef Corrade::Containers::EnumSet BlitMask; + + /** + * @brief Blit filtering + * + * @see blit() + */ + enum class BlitFilter: GLenum { + NearestNeighbor = GL_NEAREST, /**< Nearest neighbor filtering */ + LinearInterpolation = GL_LINEAR /**< Linear interpolation filtering */ + }; + + /** + * @brief Target for binding framebuffer + * + * @see DefaultFramebuffer::bind(), Framebuffer::bind() + * @requires_gl30 %Extension @extension{EXT,framebuffer_object} + */ + enum class Target: GLenum { + /** + * For reading only. + * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} + * or @es_extension{ANGLE,framebuffer_blit} + */ + #ifndef MAGNUM_TARGET_GLES2 + Read = GL_READ_FRAMEBUFFER, + #else + Read = GL_READ_FRAMEBUFFER_APPLE, + #endif + + /** + * For drawing only. + * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} + * or @es_extension{ANGLE,framebuffer_blit} + */ + #ifndef MAGNUM_TARGET_GLES2 + Draw = GL_DRAW_FRAMEBUFFER, + #else + Draw = GL_DRAW_FRAMEBUFFER_APPLE, + #endif + + ReadDraw = GL_FRAMEBUFFER /**< For both reading and drawing. */ + }; + + /** + * @brief Copy block of pixels + * @param source Source framebuffer + * @param destination Destination framebuffer + * @param sourceBottomLeft Bottom left coordinates of source rectangle + * @param sourceTopRight Top right coordinates of source rectangle + * @param destinationBottomLeft Bottom left coordinates of destination rectangle + * @param destinationTopRight Top right coordinates of destination + * rectangle + * @param mask Which buffers to perform blit operation on + * @param filter Interpolation filter + * + * Binds @p source framebuffer to @ref Target "Target::Read" and + * @p destination framebuffer to @ref Target "Target::Draw" and + * performs blitting operation. See DefaultFramebuffer::mapForRead(), + * Framebuffer::mapForRead(), DefaultFramebuffer::mapForDraw() and + * Framebuffer::mapForDraw() for specifying particular buffers for + * blitting operation. + * @see @fn_gl{BlitFramebuffer} + * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} + */ + inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask mask, BlitFilter filter) { + source.bind(AbstractFramebuffer::Target::Read); + destination.bind(AbstractFramebuffer::Target::Draw); + /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glBlitFramebuffer(sourceBottomLeft.x(), sourceBottomLeft.y(), sourceTopRight.x(), sourceTopRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(mask), static_cast(filter)); + #else + static_cast(sourceBottomLeft); + static_cast(sourceTopRight); + static_cast(destinationBottomLeft); + static_cast(destinationTopRight); + static_cast(mask); + static_cast(filter); + #endif + } + + /** + * @brief Copy block of pixels + * @param source Source framebuffer + * @param destination Destination framebuffer + * @param bottomLeft Bottom left coordinates of source and + * destination rectangle + * @param topRight Top right coordinates of source and + * destination rectangle + * @param mask Which buffers to perform blit operation on + * + * Convenience alternative to above function when source rectangle is + * the same as destination rectangle. As the image is copied + * pixel-by-pixel, no interpolation is needed and thus + * @ref BlitFilter "BlitFilter::NearestNeighbor" filtering is used by + * default. + * @see @fn_gl{BlitFramebuffer} + * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} + * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} + */ + inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& bottomLeft, const Vector2i& topRight, BlitMask mask) { + blit(source, destination, bottomLeft, topRight, bottomLeft, topRight, mask, BlitFilter::NearestNeighbor); + } + + AbstractFramebuffer() = default; + virtual ~AbstractFramebuffer() = 0; + + /** + * @brief Bind framebuffer + * + * @see DefaultFramebuffer::mapForRead(), Framebuffer::mapForRead(), + * DefaultFramebuffer::mapForDraw(), Framebuffer::mapForDraw(), + * @fn_gl{BindFramebuffer} + */ + inline void bind(Target target) { + glBindFramebuffer(static_cast(target), _id); + } + + /** + * @brief Set viewport size + * + * Call when window size changes. + * @see @fn_gl{Viewport} + */ + inline void setViewport(const Vector2i& position, const Vector2i& size) { + bind(Target::ReadDraw); + glViewport(position.x(), position.y(), size.x(), size.y()); + } + + /** + * @brief Clear specified buffers in framebuffer + * @param mask Which buffers to clear + * + * @see Renderer::setClearColor(), Renderer::setClearDepth(), + * Renderer::setClearStencil(), @fn_gl{Clear} + */ + inline void clear(ClearMask mask) { + bind(Target::ReadDraw); + glClear(static_cast(mask)); + } + + /** + * @brief Read block of pixels from framebuffer to image + * @param offset Offset in the framebuffer + * @param size %Image size + * @param format Format of pixel data + * @param type Data type of pixel data + * @param image %Image where to put the data + * + * @see @fn_gl{ReadPixels} + */ + void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); + + #ifndef MAGNUM_TARGET_GLES2 + /** + * @brief Read block of pixels from framebuffer to buffer image + * @param offset Offset in the framebuffer + * @param size %Image size + * @param format Format of pixel data + * @param type Data type of pixel data + * @param image %Buffer image where to put the data + * @param usage %Buffer usage + * + * @see Buffer::bind(Target), @fn_gl{ReadPixels} + * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. + */ + void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); + #endif + + #ifndef DOXYGEN_GENERATING_OUTPUT + protected: + GLuint _id; + #endif +}; + +inline AbstractFramebuffer::~AbstractFramebuffer() {} + +CORRADE_ENUMSET_OPERATORS(AbstractFramebuffer::ClearMask) +#ifndef MAGNUM_TARGET_GLES +CORRADE_ENUMSET_OPERATORS(AbstractFramebuffer::BlitMask) +#endif + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c521a9e31..eb5732e97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,12 +11,14 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CO # Files shared between main library and unit test library set(Magnum_SRCS + AbstractFramebuffer.cpp AbstractImage.cpp AbstractTexture.cpp AbstractShaderProgram.cpp Buffer.cpp Context.cpp DebugMarker.cpp + DefaultFramebuffer.cpp Framebuffer.cpp Image.cpp IndexedMesh.cpp @@ -50,6 +52,7 @@ if(NOT TARGET_GLES2) endif() set(Magnum_HEADERS + AbstractFramebuffer.h AbstractImage.h AbstractResourceLoader.h AbstractShaderProgram.h @@ -60,6 +63,7 @@ set(Magnum_HEADERS Context.h CubeMapTexture.h DebugMarker.h + DefaultFramebuffer.h DimensionTraits.h Extensions.h Framebuffer.h diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp new file mode 100644 index 000000000..7d12c9715 --- /dev/null +++ b/src/DefaultFramebuffer.cpp @@ -0,0 +1,36 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "DefaultFramebuffer.h" + +namespace Magnum { + +DefaultFramebuffer defaultFramebuffer; + +DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } + +#ifndef MAGNUM_TARGET_GLES2 +void DefaultFramebuffer::mapForDraw(std::initializer_list attachments) { + GLenum* _attachments = new GLenum[attachments.size()]; + for(auto it = attachments.begin(); it != attachments.end(); ++it) + _attachments[it-attachments.begin()] = static_cast(*it); + + bind(Target::Draw); + glDrawBuffers(attachments.size(), _attachments); + delete[] _attachments; +} +#endif + +} diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h new file mode 100644 index 000000000..0afa8e432 --- /dev/null +++ b/src/DefaultFramebuffer.h @@ -0,0 +1,204 @@ +#ifndef Magnum_DefaultFramebuffer_h +#define Magnum_DefaultFramebuffer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::DefaultFramebuffer + */ + +#include "AbstractFramebuffer.h" + +namespace Magnum { + +/** +@brief Default framebuffer + +@see @ref defaultFramebuffer, Framebuffer +*/ +class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { + public: + #ifndef MAGNUM_TARGET_GLES2 + /** + * @brief Draw attachment + * + * @see mapForDraw() + * @requires_gles30 Draw attachments for default framebuffer are + * available only in OpenGL ES 3.0. + */ + enum class DrawAttachment: GLenum { + /** Don't use the output. */ + None = GL_NONE, + + #ifndef MAGNUM_TARGET_GLES + /** + * Write output to back left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackLeft = GL_BACK_LEFT, + + /** + * Write output to back right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackRight = GL_BACK_RIGHT, + + /** + * Write output to front left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontLeft = GL_FRONT_LEFT, + + /** + * Write output to front right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontRight = GL_FRONT_RIGHT, + #endif + + /** + * Write output to back framebuffer. + * + * On desktop OpenGL, this is equal to @ref DrawAttachment "DrawAttachment::BackLeft". + */ + #ifdef MAGNUM_TARGET_GLES + Back = GL_BACK, + #else + Back = GL_BACK_LEFT, + #endif + + /** + * Write output to front framebuffer. + * + * On desktop OpenGL, this is equal to @ref DrawAttachment "DrawAttachment::FrontLeft". + */ + #ifdef MAGNUM_TARGET_GLES + Front = GL_FRONT + #else + Front = GL_FRONT_LEFT + #endif + }; + #endif + + /** + * @brief Read attachment + * + * @see mapForRead() + * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} + */ + enum class ReadAttachment: GLenum { + /** Don't read from any framebuffer */ + None = GL_NONE, + + #ifndef MAGNUM_TARGET_GLES + /** + * Read from back left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackLeft = GL_BACK_LEFT, + + /** + * Read from back right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackRight = GL_BACK_RIGHT, + + /** + * Read from front left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontLeft = GL_FRONT_LEFT, + + /** + * Read from front right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontRight = GL_FRONT_RIGHT, + + /** + * Read from left framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + Left = GL_LEFT, + + /** + * Read from right framebuffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + Right = GL_RIGHT, + #endif + + /** Read from back framebuffer. */ + Back = GL_BACK, + + /** + * Read from front framebuffer. + * @requires_es_extension %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} + */ + Front = GL_FRONT + + #ifndef MAGNUM_TARGET_GLES + , + + /** + * Read from front and back framebuffer. + * @requires_gl In OpenGL ES you must specify either + * @ref Magnum::DefaultFramebuffer::ReadAttachment "ReadAttachment::Front" + * or @ref Magnum::DefaultFramebuffer::ReadAttachment "ReadAttachment::Back". + */ + FrontAndBack = GL_FRONT_AND_BACK + #endif + }; + + MAGNUM_LOCAL DefaultFramebuffer(); + + #ifndef MAGNUM_TARGET_GLES2 + /** + * @brief Map given attachments for drawing + * @param attachments Attachments. If any value is + * @ref DrawAttachment "Attachment::None", given output is not + * used. + * + * @see mapForRead(), bind(), @fn_gl{DrawBuffers} + * @requires_gles30 Draw attachments for default framebuffer are + * available only in OpenGL ES 3.0. + */ + void mapForDraw(std::initializer_list attachments); + #endif + + /** + * @brief Map given attachment for reading + * @param attachment Attachment + * + * @see mapForDraw(), bind(), @fn_gl{ReadBuffer} + * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} + */ + inline void mapForRead(ReadAttachment attachment) { + bind(Target::Read); + /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glReadBuffer(static_cast(attachment)); + #else + static_cast(attachment); + #endif + } +}; + +/** @brief Default framebuffer instance */ +extern DefaultFramebuffer MAGNUM_EXPORT defaultFramebuffer; + +} + +#endif diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 238c2f7a1..d37dbe064 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -20,18 +20,6 @@ namespace Magnum { -#ifndef MAGNUM_TARGET_GLES2 -void Framebuffer::mapDefaultForDraw(std::initializer_list attachments) { - GLenum* _attachments = new GLenum[attachments.size()]; - for(auto it = attachments.begin(); it != attachments.end(); ++it) - _attachments[it-attachments.begin()] = static_cast(*it); - - bindDefault(Target::Draw); - glDrawBuffers(attachments.size(), _attachments); - delete[] _attachments; -} -#endif - void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { GLenum* attachments = new GLenum[colorAttachments.size()]; for(auto it = colorAttachments.begin(); it != colorAttachments.end(); ++it) @@ -45,22 +33,4 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments delete[] attachments; } -void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { - char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; - glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); - image->setData(size, format, type, data); -} - -#ifndef MAGNUM_TARGET_GLES2 -void Framebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { - /* If the buffer doesn't have sufficient size, resize it */ - /** @todo Explicitly reset also when buffer usage changes */ - if(image->size() != size || image->format() != format || image->type() != type) - image->setData(size, format, type, nullptr, usage); - - image->buffer()->bind(Buffer::Target::PixelPack); - glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), nullptr); -} -#endif - } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 18664f319..54167b9ee 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -19,242 +19,26 @@ * @brief Class Magnum::Framebuffer */ -#include - -#include "AbstractImage.h" -#include "Buffer.h" +#include "AbstractFramebuffer.h" #include "CubeMapTexture.h" #include "Texture.h" #include "Renderbuffer.h" namespace Magnum { -/** @nosubgrouping +/** @brief %Framebuffer -Provides operations with framebuffers (configuring, clearing, blitting...) and -creation and attaching of named framebuffers. -@todo @extension{ARB,viewport_array} +@see DefaultFramebuffer +@requires_gl30 %Extension @extension{EXT,framebuffer_object} */ -class MAGNUM_EXPORT Framebuffer { - Framebuffer(const Framebuffer& other) = delete; - Framebuffer(Framebuffer&& other) = delete; - Framebuffer& operator=(const Framebuffer& other) = delete; - Framebuffer& operator=(Framebuffer&& other) = delete; - +class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { public: - /** - * @brief Set viewport size - * - * Call when window size changes. - * @see @fn_gl{Viewport} - */ - inline static void setViewport(const Vector2i& position, const Vector2i& size) { - glViewport(position.x(), position.y(), size.x(), size.y()); - } - - /** - * @brief Mask for clearing - * - * @see ClearMask, clear(), clear(ClearMask) - */ - enum class Clear: GLbitfield { - Color = GL_COLOR_BUFFER_BIT, /**< Color */ - Depth = GL_DEPTH_BUFFER_BIT, /**< Depth value */ - Stencil = GL_STENCIL_BUFFER_BIT /**< Stencil value */ - }; - - /** @brief Mask for clearing */ - typedef Corrade::Containers::EnumSet ClearMask; - - /** - * @brief Clear specified buffers in framebuffer - * - * @see clear(), Renderer::setClearColor(), Renderer::setClearDepth(), - * Renderer::setClearStencil(), @fn_gl{Clear} - * @todo Clearing only given draw buffer - */ - inline static void clear(ClearMask mask) { glClear(static_cast(mask)); } - - /** @{ @name Framebuffer creation and binding */ - - /** - * @brief %Framebuffer target - * - * @see bind(), bindDefault() - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - */ - enum class Target: GLenum { - /** - * For reading only. - * @requires_gl30 Extension @extension{EXT,framebuffer_blit} - * @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} - * or @es_extension{ANGLE,framebuffer_blit} - */ - #ifndef MAGNUM_TARGET_GLES2 - Read = GL_READ_FRAMEBUFFER, - #else - Read = GL_READ_FRAMEBUFFER_APPLE, - #endif - - /** - * For drawing only. - * @requires_gl30 Extension @extension{EXT,framebuffer_blit} - * @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} - * or @es_extension{ANGLE,framebuffer_blit} - */ - #ifndef MAGNUM_TARGET_GLES2 - Draw = GL_DRAW_FRAMEBUFFER, - #else - Draw = GL_DRAW_FRAMEBUFFER_APPLE, - #endif - - ReadDraw = GL_FRAMEBUFFER /**< For both reading and drawing. */ - }; - - #ifndef MAGNUM_TARGET_GLES2 - /** - * @brief Draw attachment for default framebuffer - * - * @see mapDefaultForDraw() - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - * @requires_gles30 Draw attachments for default framebuffer are - * available only in OpenGL ES 3.0. - */ - enum class DefaultDrawAttachment: GLenum { - /** Don't use the output. */ - None = GL_NONE, - - #ifndef MAGNUM_TARGET_GLES - /** - * Write output to back left framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - BackLeft = GL_BACK_LEFT, - - /** - * Write output to back right framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - BackRight = GL_BACK_RIGHT, - - /** - * Write output to front left framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - FrontLeft = GL_FRONT_LEFT, - - /** - * Write output to front right framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - FrontRight = GL_FRONT_RIGHT, - #endif - - /** - * Write output to back framebuffer. - * - * On desktop OpenGL, this is equal to - * @ref Magnum::Framebuffer::DefaultDrawAttachment "DefaultDrawAttachment::BackLeft". - */ - #ifdef MAGNUM_TARGET_GLES - Back = GL_BACK, - #else - Back = GL_BACK_LEFT, - #endif - - /** - * Write output to front framebuffer. - * - * On desktop OpenGL, this is equal to - * @ref Magnum::Framebuffer::DefaultDrawAttachment "DefaultDrawAttachment::FrontLeft". - */ - #ifdef MAGNUM_TARGET_GLES - Front = GL_FRONT - #else - Front = GL_FRONT_LEFT - #endif - }; - #endif - - /** - * @brief Read attachment for default framebuffer - * - * @see mapDefaultForRead() - * @requires_gl30 %Extension @extension{EXT,framebuffer_object} - * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} - */ - enum class DefaultReadAttachment: GLenum { - /** Don't read from any framebuffer */ - None = GL_NONE, - - #ifndef MAGNUM_TARGET_GLES - /** - * Read from back left framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - BackLeft = GL_BACK_LEFT, - - /** - * Read from back right framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - BackRight = GL_BACK_RIGHT, - - /** - * Read from front left framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - FrontLeft = GL_FRONT_LEFT, - - /** - * Read from front right framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - FrontRight = GL_FRONT_RIGHT, - - /** - * Read from left framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - Left = GL_LEFT, - - /** - * Read from right framebuffer. - * @requires_gl Stereo rendering is not available in OpenGL ES. - */ - Right = GL_RIGHT, - #endif - - /** Read from back framebuffer. */ - Back = GL_BACK, - - /** - * Read from front framebuffer. - * @requires_es_extension %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} - */ - Front = GL_FRONT - - #ifndef MAGNUM_TARGET_GLES - , - - /** - * Read from front and back framebuffer. - * @requires_gl In OpenGL ES you must specify either - * @ref Magnum::Framebuffer::DefaultReadAttachment "DefaultReadAttachment::Front" - * or @ref Magnum::Framebuffer::DefaultReadAttachment "DefaultReadAttachment::Back". - */ - FrontAndBack = GL_FRONT_AND_BACK - #endif - }; - /** * @brief Constructor * * Generates new OpenGL framebuffer. * @see @fn_gl{GenFramebuffers} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline Framebuffer() { glGenFramebuffers(1, &_id); } @@ -263,94 +47,24 @@ class MAGNUM_EXPORT Framebuffer { * * Deletes associated OpenGL framebuffer. * @see @fn_gl{DeleteFramebuffers} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline ~Framebuffer() { glDeleteFramebuffers(1, &_id); } - /** - * @brief Bind default framebuffer to given target - * @param target %Target - * - * @see @fn_gl{BindFramebuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - */ - inline static void bindDefault(Target target) { - glBindFramebuffer(static_cast(target), 0); - } - - /** - * @brief Bind framebuffer - * - * @see @fn_gl{BindFramebuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - */ - inline void bind(Target target) { - glBindFramebuffer(static_cast(target), _id); - } - - #ifndef MAGNUM_TARGET_GLES2 - /** - * @brief Map given attachments of default framebuffer for drawing - * @param attachments Default attachments. If any value is - * DefaultAttachment::None, given output is not used. - * - * If used for mapping output of fragment shader, the order must be as - * specified by the shader (see AbstractShaderProgram documentation). - * If used for blit(), the order is not important. Each used attachment - * should have either renderbuffer or texture attached for writing to - * work properly. - * @see mapForDraw(), mapDefaultForRead(), bindDefault(), @fn_gl{DrawBuffers} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - * @requires_gles30 Draw attachments for default framebuffer are - * available only in OpenGL ES 3.0. - */ - static void mapDefaultForDraw(std::initializer_list attachments); - #endif - /** * @brief Map given color attachments of current framebuffer for drawing * @param colorAttachments Color attachment IDs. If any value is -1, * given output is not used. * - * If used for mapping output of fragment shader, the order must be as - * specified by the shader (see AbstractShaderProgram documentation). - * If used for blit(), the order is not important. Each used attachment - * should have either renderbuffer or texture attached for writing to - * work properly. - * @see mapDefaultForDraw(), mapForRead(), bind(), @fn_gl{DrawBuffers} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @see mapForRead(), bind(), @fn_gl{DrawBuffers} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ void mapForDraw(std::initializer_list colorAttachments); - /** - * @brief Map given attachment of default framebuffer for reading - * @param attachment Default attachment - * - * Each used attachment should have either renderbuffer or texture - * attached to work properly. - * @see mapForRead(), mapDefaultForDraw(), bindDefault(), @fn_gl{ReadBuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} - */ - inline static void mapDefaultForRead(DefaultReadAttachment attachment) { - bindDefault(Target::Read); - /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glReadBuffer(static_cast(attachment)); - #else - static_cast(attachment); - #endif - } - /** * @brief Map given color attachment of current framebuffer for reading * @param colorAttachment Color attachment ID * - * The color attachment should have either renderbuffer or texture - * attached for reading to work properly. - * @see mapDefaultForRead(), mapForDraw(), bind(), @fn_gl{ReadBuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @see mapForDraw(), bind(), @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ inline void mapForRead(std::uint8_t colorAttachment) { @@ -363,19 +77,11 @@ class MAGNUM_EXPORT Framebuffer { #endif } - /*@}*/ - - /** @{ @name Attaching textures and renderbuffers */ - /** * @brief Attachment for depth/stencil part of fragment shader output * - * @see attachRenderbuffer(Target, DepthStencilAttachment, Renderbuffer*), - * attachTexture1D(Target, DepthStencilAttachment, Texture1D*, GLint), - * attachTexture2D(Target, DepthStencilAttachment, Texture2D*, GLint), - * attachCubeMapTexture(Target, DepthStencilAttachment, CubeMapTexture*, CubeMapTexture::Coordinate, GLint), - * attachTexture3D(Target, DepthStencilAttachment, Texture3D*, GLint, GLint) - * @requires_gl30 Extension @extension{EXT,framebuffer_object} + * @see attachRenderbuffer(), attachTexture1D(), attachTexture2D(), + * attachCubeMapTexture(), attachTexture3D() */ enum class DepthStencilAttachment: GLenum { Depth = GL_DEPTH_ATTACHMENT, /**< Depth output only. */ @@ -400,10 +106,8 @@ class MAGNUM_EXPORT Framebuffer { * @param renderbuffer %Renderbuffer * * @see bind(), @fn_gl{FramebufferRenderbuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { - /** @todo Check for internal format compatibility */ bind(target); glFramebufferRenderbuffer(static_cast(target), static_cast(depthStencilAttachment), GL_RENDERBUFFER, renderbuffer->id()); } @@ -415,10 +119,8 @@ class MAGNUM_EXPORT Framebuffer { * @param renderbuffer %Renderbuffer * * @see bind(), @fn_gl{FramebufferRenderbuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { - /** @todo Check for internal format compatibility */ bind(target); glFramebufferRenderbuffer(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, GL_RENDERBUFFER, renderbuffer->id()); } @@ -432,11 +134,9 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); glFramebufferTexture1D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); @@ -450,11 +150,9 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); glFramebufferTexture1D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); @@ -470,10 +168,8 @@ class MAGNUM_EXPORT Framebuffer { * should be always 0. * * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); @@ -488,10 +184,8 @@ class MAGNUM_EXPORT Framebuffer { * should be always 0. * * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); @@ -506,7 +200,6 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { /** @todo Check for internal format compatibility */ @@ -523,7 +216,6 @@ class MAGNUM_EXPORT Framebuffer { * @param mipLevel Mip level * * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} */ inline void attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { /** @todo Check for internal format compatibility */ @@ -540,11 +232,9 @@ class MAGNUM_EXPORT Framebuffer { * @param layer Layer of 2D image within a 3D texture * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ inline void attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { - /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ @@ -567,11 +257,9 @@ class MAGNUM_EXPORT Framebuffer { * @param layer Layer of 2D image within a 3D texture. * * @see bind(), @fn_gl{FramebufferTexture} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ inline void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { - /** @todo Check for internal format compatibility */ /** @todo Check for texture target compatibility */ bind(target); /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ @@ -584,136 +272,8 @@ class MAGNUM_EXPORT Framebuffer { static_cast(layer); #endif } - - /*@}*/ - - /** @{ @name Framebuffer blitting and reading */ - - /** - * @brief Output mask for blitting - * - * Specifies which data are copied when performing blit operation - * using blit(). - * @see BlitMask - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} - */ - enum class Blit: GLbitfield { - Color = GL_COLOR_BUFFER_BIT, /**< Color */ - Depth = GL_DEPTH_BUFFER_BIT, /**< Depth value */ - Stencil = GL_STENCIL_BUFFER_BIT /**< Stencil value */ - }; - - /** - * @brief Output mask for blitting - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} - */ - typedef Corrade::Containers::EnumSet BlitMask; - - /** - * @brief Copy block of pixels from read to draw framebuffer - * @param bottomLeft Bottom left coordinates of source rectangle - * @param topRight Top right coordinates of source rectangle - * @param destinationBottomLeft Bottom left coordinates of destination rectangle - * @param destinationTopRight Top right coordinates of destination - * rectangle - * @param blitMask Blit mask - * @param filter Interpolation applied if the image is - * stretched - * - * See mapForRead() / mapDefaultForRead() and mapForDraw() / - * mapDefaultForDraw() for binding particular framebuffer for reading - * and drawing. If multiple attachments are specified in mapForDraw() - * / mapDefaultForDraw(), the data are written to each of them. - * @see @fn_gl{BlitFramebuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_blit} - * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} - */ - inline static void blit(const Vector2i& bottomLeft, const Vector2i& topRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask blitMask, AbstractTexture::Filter filter) { - /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glBlitFramebuffer(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(blitMask), static_cast(filter)); - #else - static_cast(bottomLeft); - static_cast(topRight); - static_cast(destinationBottomLeft); - static_cast(destinationTopRight); - static_cast(blitMask); - static_cast(filter); - #endif - } - - /** - * @brief Copy block of pixels from read to draw framebuffer - * @param bottomLeft Bottom left coordinates of source and - * destination rectangle - * @param topRight Top right coordinates of source and - * destination rectangle - * @param blitMask Blit mask - * - * Convenience function when source rectangle is the same as - * destination rectangle. As the image is copied pixel-by-pixel, - * no interpolation is needed and thus - * AbstractTexture::Filter::NearestNeighbor filtering is used by - * default. - * @see @fn_gl{BlitFramebuffer} - * @requires_gl30 Extension @extension{EXT,framebuffer_blit} - * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} - */ - inline static void blit(const Vector2i& bottomLeft, const Vector2i& topRight, BlitMask blitMask) { - /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glBlitFramebuffer(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y(), static_cast(blitMask), static_cast(AbstractTexture::Filter::NearestNeighbor)); - #else - static_cast(bottomLeft); - static_cast(topRight); - static_cast(blitMask); - #endif - } - - /** - * @brief Read block of pixels from framebuffer to image - * @param offset Offset in the framebuffer - * @param size %Image size - * @param format Format of pixel data - * @param type Data type of pixel data - * @param image %Image where to put the data - * - * @see @fn_gl{ReadPixels} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - */ - static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); - - #ifndef MAGNUM_TARGET_GLES2 - /** - * @brief Read block of pixels from framebuffer to buffered image - * @param offset Offset in the framebuffer - * @param size %Image size - * @param format Format of pixel data - * @param type Data type of pixel data - * @param image Buffered image where to put the data - * @param usage %Buffer usage - * - * @see Buffer::bind(Target), @fn_gl{ReadPixels} - * @requires_gl30 Extension @extension{EXT,framebuffer_object} - * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. - */ - static void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); - #endif - - /*@}*/ - - private: - GLuint _id; }; -CORRADE_ENUMSET_OPERATORS(Framebuffer::ClearMask) -#ifndef MAGNUM_TARGET_GLES -CORRADE_ENUMSET_OPERATORS(Framebuffer::BlitMask) -#endif - } #endif diff --git a/src/Magnum.h b/src/Magnum.h index 41010a193..6e4cf7ee2 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -122,6 +122,7 @@ using Math::deg; using Math::rad; /* Forward declarations for all types in root namespace */ +class AbstractFramebuffer; class AbstractImage; class AbstractShaderProgram; class AbstractTexture; @@ -156,6 +157,7 @@ class CubeMapTextureArray; #endif /* DebugMarker forward declaration is not needed */ +/* DefaultFramebuffer is available only through global instance */ /* DimensionTraits forward declaration is not needed */ class Extension; diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 42bd27bac..0d687fe48 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -31,7 +31,7 @@ namespace Magnum { Attachable to Framebuffer as render target. -@requires_gl30 Extension @extension{EXT,framebuffer_object} +@requires_gl30 %Extension @extension{EXT,framebuffer_object} */ class Renderbuffer { Renderbuffer(const Renderbuffer& other) = delete; From 6ffa8eac51ff79e3b278f9f891ffaafe4c4007e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Dec 2012 22:56:13 +0100 Subject: [PATCH 043/567] Using old framebuffer binding internally if new is not supported. --- src/AbstractFramebuffer.cpp | 24 ++++++++++++++++++++++-- src/AbstractFramebuffer.h | 11 +++++++++-- src/Context.cpp | 2 ++ src/DefaultFramebuffer.cpp | 2 +- src/DefaultFramebuffer.h | 2 +- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 5e8099db0..ee78c5395 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -16,12 +16,19 @@ #include "AbstractFramebuffer.h" #include "BufferImage.h" +#include "Context.h" +#include "Extensions.h" #include "Image.h" namespace Magnum { +#ifndef DOXYGEN_GENERATING_OUTPUT +AbstractFramebuffer::Target AbstractFramebuffer::readTarget = AbstractFramebuffer::Target::ReadDraw; +AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffer::Target::ReadDraw; +#endif + void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { - bind(Target::ReadDraw); + bind(readTarget); char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); image->setData(size, format, type, data); @@ -29,7 +36,7 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Abs #ifndef MAGNUM_TARGET_GLES2 void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { - bind(Target::ReadDraw); + bind(readTarget); /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ if(image->size() != size || image->format() != format || image->type() != type) @@ -40,4 +47,17 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Abs } #endif +void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context) { + #ifndef MAGNUM_TARGET_GLES + if(context->isExtensionSupported()) { + Debug() << "AbstractFramebuffer: using" << Extensions::GL::EXT::framebuffer_blit::string() << "features"; + + readTarget = Target::Read; + drawTarget = Target::Draw; + } + #else + static_cast(context); + #endif +} + } diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index d0774aefa..e751c08e1 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -34,6 +34,8 @@ See DefaultFramebuffer and Framebuffer for more information. @todo @extension{ARB,viewport_array} */ class MAGNUM_EXPORT AbstractFramebuffer { + friend class Context; + AbstractFramebuffer(const AbstractFramebuffer& other) = delete; AbstractFramebuffer(AbstractFramebuffer&& other) = delete; AbstractFramebuffer& operator=(const AbstractFramebuffer& other) = delete; @@ -208,7 +210,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @see @fn_gl{Viewport} */ inline void setViewport(const Vector2i& position, const Vector2i& size) { - bind(Target::ReadDraw); + bind(drawTarget); glViewport(position.x(), position.y(), size.x(), size.y()); } @@ -220,7 +222,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * Renderer::setClearStencil(), @fn_gl{Clear} */ inline void clear(ClearMask mask) { - bind(Target::ReadDraw); + bind(drawTarget); glClear(static_cast(mask)); } @@ -254,8 +256,13 @@ class MAGNUM_EXPORT AbstractFramebuffer { #ifndef DOXYGEN_GENERATING_OUTPUT protected: + static Target readTarget, drawTarget; + GLuint _id; #endif + + private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); }; inline AbstractFramebuffer::~AbstractFramebuffer() {} diff --git a/src/Context.cpp b/src/Context.cpp index 46fad8b8c..ff45c6d71 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -20,6 +20,7 @@ #include #include +#include "AbstractFramebuffer.h" #include "AbstractShaderProgram.h" #include "AbstractTexture.h" #include "Buffer.h" @@ -292,6 +293,7 @@ Context::Context() { _state = new Implementation::State; /* Initialize functionality based on current OpenGL version and extensions */ + AbstractFramebuffer::initializeContextBasedFunctionality(this); AbstractShaderProgram::initializeContextBasedFunctionality(this); AbstractTexture::initializeContextBasedFunctionality(this); Buffer::initializeContextBasedFunctionality(this); diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 7d12c9715..07f8a392d 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -27,7 +27,7 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list attach for(auto it = attachments.begin(); it != attachments.end(); ++it) _attachments[it-attachments.begin()] = static_cast(*it); - bind(Target::Draw); + bind(drawTarget); glDrawBuffers(attachments.size(), _attachments); delete[] _attachments; } diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 0afa8e432..6acebc3ae 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -186,7 +186,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ inline void mapForRead(ReadAttachment attachment) { - bind(Target::Read); + bind(readTarget); /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 glReadBuffer(static_cast(attachment)); From 52675473738200cfd5927dc2c86ef0b24f026878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 10:18:09 +0100 Subject: [PATCH 044/567] Tracking framebuffer binding. --- src/AbstractFramebuffer.cpp | 21 +++++++++++++++++++ src/AbstractFramebuffer.h | 19 ++++++++++------- src/DefaultFramebuffer.h | 4 ++-- src/Framebuffer.cpp | 13 ++++++++++++ src/Framebuffer.h | 30 +++++++++++++++------------ src/Implementation/FramebufferState.h | 30 +++++++++++++++++++++++++++ src/Implementation/State.cpp | 9 +++++++- src/Implementation/State.h | 2 ++ 8 files changed, 105 insertions(+), 23 deletions(-) create mode 100644 src/Implementation/FramebufferState.h diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index ee78c5395..9f2f1904b 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -20,6 +20,9 @@ #include "Extensions.h" #include "Image.h" +#include "Implementation/FramebufferState.h" +#include "Implementation/State.h" + namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -27,6 +30,24 @@ AbstractFramebuffer::Target AbstractFramebuffer::readTarget = AbstractFramebuffe AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffer::Target::ReadDraw; #endif +void AbstractFramebuffer::bind(Target target) { + Implementation::FramebufferState* state = Context::current()->state()->framebuffer; + + /* If already bound, done, otherwise update tracked state */ + if(target == Target::Read) { + if(state->readBinding == _id) return; + state->readBinding = _id; + } else if(target == Target::Draw) { + if(state->drawBinding == _id) return; + state->drawBinding = _id; + } else if(target == Target::ReadDraw) { + if(state->readBinding == _id && state->drawBinding == _id) return; + state->readBinding = state->drawBinding = _id; + } else CORRADE_INTERNAL_ASSERT(false); + + glBindFramebuffer(static_cast(target), _id); +} + void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { bind(readTarget); char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index e751c08e1..28a8d307c 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -31,6 +31,12 @@ namespace Magnum { @brief Base for default and named framebuffers See DefaultFramebuffer and Framebuffer for more information. + +@section AbstractFramebuffer-performance-optimization Performance optimizations + +The engine tracks currently bound framebuffer to avoid unnecessary calls to +@fn_gl{BindFramebuffer}. + @todo @extension{ARB,viewport_array} */ class MAGNUM_EXPORT AbstractFramebuffer { @@ -199,15 +205,13 @@ class MAGNUM_EXPORT AbstractFramebuffer { * DefaultFramebuffer::mapForDraw(), Framebuffer::mapForDraw(), * @fn_gl{BindFramebuffer} */ - inline void bind(Target target) { - glBindFramebuffer(static_cast(target), _id); - } + void bind(Target target); /** * @brief Set viewport size * * Call when window size changes. - * @see @fn_gl{Viewport} + * @see @fn_gl{BindFramebuffer}, @fn_gl{Viewport} */ inline void setViewport(const Vector2i& position, const Vector2i& size) { bind(drawTarget); @@ -219,7 +223,8 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @param mask Which buffers to clear * * @see Renderer::setClearColor(), Renderer::setClearDepth(), - * Renderer::setClearStencil(), @fn_gl{Clear} + * Renderer::setClearStencil(), @fn_gl{BindFramebuffer}, + * @fn_gl{Clear} */ inline void clear(ClearMask mask) { bind(drawTarget); @@ -234,7 +239,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @param type Data type of pixel data * @param image %Image where to put the data * - * @see @fn_gl{ReadPixels} + * @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} */ void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); @@ -248,7 +253,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @param image %Buffer image where to put the data * @param usage %Buffer usage * - * @see Buffer::bind(Target), @fn_gl{ReadPixels} + * @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 6acebc3ae..6e5b478d4 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -171,7 +171,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @ref DrawAttachment "Attachment::None", given output is not * used. * - * @see mapForRead(), bind(), @fn_gl{DrawBuffers} + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ @@ -182,7 +182,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @brief Map given attachment for reading * @param attachment Attachment * - * @see mapForDraw(), bind(), @fn_gl{ReadBuffer} + * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ inline void mapForRead(ReadAttachment attachment) { diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index d37dbe064..2aff2474a 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -16,10 +16,23 @@ #include "Framebuffer.h" #include "BufferImage.h" +#include "Context.h" #include "Image.h" +#include "Implementation/State.h" +#include "Implementation/FramebufferState.h" + namespace Magnum { +Framebuffer::~Framebuffer() { + /* If bound, remove itself from state */ + Implementation::FramebufferState* state = Context::current()->state()->framebuffer; + if(state->readBinding == _id) state->readBinding = 0; + if(state->drawBinding == _id) state->drawBinding = 0; + + glDeleteFramebuffers(1, &_id); +} + void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { GLenum* attachments = new GLenum[colorAttachments.size()]; for(auto it = colorAttachments.begin(); it != colorAttachments.end(); ++it) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 54167b9ee..781596363 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -48,14 +48,14 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * Deletes associated OpenGL framebuffer. * @see @fn_gl{DeleteFramebuffers} */ - inline ~Framebuffer() { glDeleteFramebuffers(1, &_id); } + ~Framebuffer(); /** * @brief Map given color attachments of current framebuffer for drawing * @param colorAttachments Color attachment IDs. If any value is -1, * given output is not used. * - * @see mapForRead(), bind(), @fn_gl{DrawBuffers} + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ void mapForDraw(std::initializer_list colorAttachments); @@ -64,7 +64,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @brief Map given color attachment of current framebuffer for reading * @param colorAttachment Color attachment ID * - * @see mapForDraw(), bind(), @fn_gl{ReadBuffer} + * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ inline void mapForRead(std::uint8_t colorAttachment) { @@ -105,7 +105,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param depthStencilAttachment Depth/stencil attachment * @param renderbuffer %Renderbuffer * - * @see bind(), @fn_gl{FramebufferRenderbuffer} + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} */ inline void attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { bind(target); @@ -118,7 +118,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param colorAttachment Color attachment ID (number between 0 and 15) * @param renderbuffer %Renderbuffer * - * @see bind(), @fn_gl{FramebufferRenderbuffer} + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} */ inline void attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { bind(target); @@ -133,7 +133,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param texture 1D texture * @param mipLevel Mip level * - * @see bind(), @fn_gl{FramebufferTexture} + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { @@ -149,7 +149,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param texture 1D texture * @param mipLevel Mip level * - * @see bind(), @fn_gl{FramebufferTexture} + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { @@ -167,7 +167,8 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param mipLevel Mip level. For rectangle textures it * should be always 0. * - * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} + * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, + * @fn_gl{FramebufferTexture} */ inline void attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { /** @todo Check for texture target compatibility */ @@ -183,7 +184,8 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param mipLevel Mip level. For rectangle textures it * should be always 0. * - * @see attachCubeMapTexture(), bind(), @fn_gl{FramebufferTexture} + * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, + * @fn_gl{FramebufferTexture} */ inline void attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { /** @todo Check for texture target compatibility */ @@ -199,7 +201,8 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param coordinate Cube map coordinate * @param mipLevel Mip level * - * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} + * @see attachTexture2D(), @fn_gl{BindFramebuffer}, + * @fn_gl{FramebufferTexture} */ inline void attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { /** @todo Check for internal format compatibility */ @@ -215,7 +218,8 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param coordinate Cube map coordinate * @param mipLevel Mip level * - * @see attachTexture2D(), bind(), @fn_gl{FramebufferTexture} + * @see attachTexture2D(), @fn_gl{BindFramebuffer}, + * @fn_gl{FramebufferTexture} */ inline void attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { /** @todo Check for internal format compatibility */ @@ -231,7 +235,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param mipLevel Mip level * @param layer Layer of 2D image within a 3D texture * - * @see bind(), @fn_gl{FramebufferTexture} + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ inline void attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { @@ -256,7 +260,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param mipLevel Mip level * @param layer Layer of 2D image within a 3D texture. * - * @see bind(), @fn_gl{FramebufferTexture} + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ inline void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { diff --git a/src/Implementation/FramebufferState.h b/src/Implementation/FramebufferState.h new file mode 100644 index 000000000..43e496040 --- /dev/null +++ b/src/Implementation/FramebufferState.h @@ -0,0 +1,30 @@ +#ifndef Magnum_Implementation_FramebufferState_h +#define Magnum_Implementation_FramebufferState_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Magnum.h" + +namespace Magnum { namespace Implementation { + +struct FramebufferState { + inline FramebufferState(): readBinding(0), drawBinding(0) {} + + GLuint readBinding, drawBinding; +}; + +}} + +#endif diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp index 062a98a8c..152e02450 100644 --- a/src/Implementation/State.cpp +++ b/src/Implementation/State.cpp @@ -16,18 +16,25 @@ #include "State.h" #include "BufferState.h" +#include "FramebufferState.h" #include "MeshState.h" #include "ShaderProgramState.h" #include "TextureState.h" namespace Magnum { namespace Implementation { -State::State(): buffer(new BufferState), mesh(new MeshState), shaderProgram(new ShaderProgramState), texture(new TextureState) {} +State::State(): + buffer(new BufferState), + framebuffer(new FramebufferState), + mesh(new MeshState), + shaderProgram(new ShaderProgramState), + texture(new TextureState) {} State::~State() { delete texture; delete shaderProgram; delete mesh; + delete framebuffer; delete buffer; } diff --git a/src/Implementation/State.h b/src/Implementation/State.h index a264247d7..dd02d6823 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -20,6 +20,7 @@ namespace Magnum { namespace Implementation { struct BufferState; +struct FramebufferState; struct MeshState; struct ShaderProgramState; struct TextureState; @@ -29,6 +30,7 @@ struct State { ~State(); BufferState* const buffer; + FramebufferState* const framebuffer; MeshState* const mesh; ShaderProgramState* const shaderProgram; TextureState* const texture; From 19029d97c6fa5df28af5e5e4a99946a50067a8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 17:05:03 +0100 Subject: [PATCH 045/567] Tracking viewport state in Framebuffer. Viewport position and size is managed separately for each framebuffer and glViewport() is called in bind() (and also from setViewport(), if the framebuffer is currently bound) if the viewport differs from current state. If used only one framebuffer size through whole application lifetime, glViewport() doesn't need to be called at all. --- src/AbstractFramebuffer.cpp | 58 +++++++++++++++- src/AbstractFramebuffer.h | 57 +++++++--------- src/Context.cpp | 5 +- src/DefaultFramebuffer.cpp | 27 +++++++- src/DefaultFramebuffer.h | 15 ++--- src/Framebuffer.cpp | 97 ++++++++++++++++++++++++++- src/Framebuffer.h | 88 ++++-------------------- src/Implementation/FramebufferState.h | 2 + 8 files changed, 228 insertions(+), 121 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 9f2f1904b..079d9321f 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -31,6 +31,12 @@ AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffe #endif void AbstractFramebuffer::bind(Target target) { + bindInternal(target); + setViewportInternal(); +} + +#ifndef DOXYGEN_GENERATING_OUTPUT +void AbstractFramebuffer::bindInternal(Target target) { Implementation::FramebufferState* state = Context::current()->state()->framebuffer; /* If already bound, done, otherwise update tracked state */ @@ -47,9 +53,57 @@ void AbstractFramebuffer::bind(Target target) { glBindFramebuffer(static_cast(target), _id); } +#endif + +void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) { + source.bindInternal(AbstractFramebuffer::Target::Read); + destination.bindInternal(AbstractFramebuffer::Target::Draw); + /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glBlitFramebuffer(sourceBottomLeft.x(), sourceBottomLeft.y(), sourceTopRight.x(), sourceTopRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(mask), static_cast(filter)); + #else + static_cast(sourceBottomLeft); + static_cast(sourceTopRight); + static_cast(destinationBottomLeft); + static_cast(destinationTopRight); + static_cast(mask); + static_cast(filter); + #endif +} + +void AbstractFramebuffer::setViewport(const Vector2i& position, const Vector2i& size) { + _viewportPosition = position; + _viewportSize = size; + + /* Update the viewport if the framebuffer is currently bound */ + if(Context::current()->state()->framebuffer->drawBinding == _id) + setViewportInternal(); +} + +#ifndef DOXYGEN_GENERATING_OUTPUT +void AbstractFramebuffer::setViewportInternal() { + Implementation::FramebufferState* state = Context::current()->state()->framebuffer; + + CORRADE_INTERNAL_ASSERT(state->drawBinding == _id); + + /* Already up-to-date, nothing to do */ + if(state->viewportPosition == _viewportPosition && state->viewportSize == _viewportSize) + return; + + /* Update the state and viewport */ + state->viewportPosition = _viewportPosition; + state->viewportSize = _viewportSize; + glViewport(_viewportPosition.x(), _viewportPosition.y(), _viewportSize.x(), _viewportSize.y()); +} +#endif + +void AbstractFramebuffer::clear(ClearMask mask) { + bindInternal(drawTarget); + glClear(static_cast(mask)); +} void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { - bind(readTarget); + bindInternal(readTarget); char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); image->setData(size, format, type, data); @@ -57,7 +111,7 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Abs #ifndef MAGNUM_TARGET_GLES2 void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { - bind(readTarget); + bindInternal(readTarget); /* If the buffer doesn't have sufficient size, resize it */ /** @todo Explicitly reset also when buffer usage changes */ if(image->size() != size || image->format() != format || image->type() != type) diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 28a8d307c..a18b1f303 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -34,8 +34,9 @@ See DefaultFramebuffer and Framebuffer for more information. @section AbstractFramebuffer-performance-optimization Performance optimizations -The engine tracks currently bound framebuffer to avoid unnecessary calls to -@fn_gl{BindFramebuffer}. +The engine tracks currently bound framebuffer and current viewport to avoid +unnecessary calls to @fn_gl{BindFramebuffer} and @fn_gl{Viewport} when +switching framebuffers. @todo @extension{ARB,viewport_array} */ @@ -156,21 +157,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ - inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask mask, BlitFilter filter) { - source.bind(AbstractFramebuffer::Target::Read); - destination.bind(AbstractFramebuffer::Target::Draw); - /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glBlitFramebuffer(sourceBottomLeft.x(), sourceBottomLeft.y(), sourceTopRight.x(), sourceTopRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(mask), static_cast(filter)); - #else - static_cast(sourceBottomLeft); - static_cast(sourceTopRight); - static_cast(destinationBottomLeft); - static_cast(destinationTopRight); - static_cast(mask); - static_cast(filter); - #endif - } + static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask mask, BlitFilter filter); /** * @brief Copy block of pixels @@ -199,24 +186,31 @@ class MAGNUM_EXPORT AbstractFramebuffer { virtual ~AbstractFramebuffer() = 0; /** - * @brief Bind framebuffer + * @brief Bind framebuffer for rendering * - * @see DefaultFramebuffer::mapForRead(), Framebuffer::mapForRead(), - * DefaultFramebuffer::mapForDraw(), Framebuffer::mapForDraw(), - * @fn_gl{BindFramebuffer} + * Binds the framebuffer and updates viewport to saved dimensions. + * @see setViewport(), DefaultFramebuffer::mapForRead(), + * Framebuffer::mapForRead(), DefaultFramebuffer::mapForDraw(), + * Framebuffer::mapForDraw(), @fn_gl{BindFramebuffer}, + * @fn_gl{Viewport} */ void bind(Target target); + /** @brief Viewport position */ + inline Vector2i viewportPosition() const { return _viewportPosition; } + + /** @brief Viewport size */ + inline Vector2i viewportSize() const { return _viewportSize; } + /** * @brief Set viewport size * - * Call when window size changes. - * @see @fn_gl{BindFramebuffer}, @fn_gl{Viewport} + * Saves the viewport size to be used at later time in bind(). If the + * framebuffer is currently bound, updates the viewport to given + * dimensions. + * @see @fn_gl{Viewport} */ - inline void setViewport(const Vector2i& position, const Vector2i& size) { - bind(drawTarget); - glViewport(position.x(), position.y(), size.x(), size.y()); - } + void setViewport(const Vector2i& position, const Vector2i& size); /** * @brief Clear specified buffers in framebuffer @@ -226,10 +220,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * Renderer::setClearStencil(), @fn_gl{BindFramebuffer}, * @fn_gl{Clear} */ - inline void clear(ClearMask mask) { - bind(drawTarget); - glClear(static_cast(mask)); - } + void clear(ClearMask mask); /** * @brief Read block of pixels from framebuffer to image @@ -261,9 +252,13 @@ class MAGNUM_EXPORT AbstractFramebuffer { #ifndef DOXYGEN_GENERATING_OUTPUT protected: + void MAGNUM_LOCAL bindInternal(Target target); + void MAGNUM_LOCAL setViewportInternal(); + static Target readTarget, drawTarget; GLuint _id; + Vector2i _viewportPosition, _viewportSize; #endif private: diff --git a/src/Context.cpp b/src/Context.cpp index ff45c6d71..8aaaf98ed 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -25,11 +25,13 @@ #include "AbstractTexture.h" #include "Buffer.h" #include "BufferTexture.h" +#include "DebugMarker.h" +#include "DefaultFramebuffer.h" #include "Extensions.h" #include "IndexedMesh.h" #include "Mesh.h" + #include "Implementation/State.h" -#include "DebugMarker.h" namespace Magnum { @@ -301,6 +303,7 @@ Context::Context() { BufferTexture::initializeContextBasedFunctionality(this); #endif DebugMarker::initializeContextBasedFunctionality(this); + DefaultFramebuffer::initializeContextBasedFunctionality(this); IndexedMesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this); } diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 07f8a392d..d4a267f54 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -15,6 +15,11 @@ #include "DefaultFramebuffer.h" +#include "Context.h" + +#include "Implementation/State.h" +#include "Implementation/FramebufferState.h" + namespace Magnum { DefaultFramebuffer defaultFramebuffer; @@ -27,10 +32,30 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list attach for(auto it = attachments.begin(); it != attachments.end(); ++it) _attachments[it-attachments.begin()] = static_cast(*it); - bind(drawTarget); + bindInternal(drawTarget); glDrawBuffers(attachments.size(), _attachments); delete[] _attachments; } #endif +void DefaultFramebuffer::mapForRead(ReadAttachment attachment) { + bindInternal(readTarget); + /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glReadBuffer(static_cast(attachment)); + #else + static_cast(attachment); + #endif +} + +void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) { + Implementation::FramebufferState* state = context->state()->framebuffer; + + /* Initial framebuffer size */ + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + defaultFramebuffer._viewportPosition = state->viewportPosition = {viewport[0], viewport[1]}; + defaultFramebuffer._viewportSize = state->viewportSize = {viewport[2], viewport[3]}; +} + } diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 6e5b478d4..1798c4138 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -29,6 +29,8 @@ namespace Magnum { @see @ref defaultFramebuffer, Framebuffer */ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { + friend class Context; + public: #ifndef MAGNUM_TARGET_GLES2 /** @@ -185,15 +187,10 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - inline void mapForRead(ReadAttachment attachment) { - bind(readTarget); - /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glReadBuffer(static_cast(attachment)); - #else - static_cast(attachment); - #endif - } + void mapForRead(ReadAttachment attachment); + + private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); }; /** @brief Default framebuffer instance */ diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 2aff2474a..ebb0d175d 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -18,12 +18,21 @@ #include "BufferImage.h" #include "Context.h" #include "Image.h" +#include "Renderbuffer.h" +#include "Texture.h" #include "Implementation/State.h" #include "Implementation/FramebufferState.h" namespace Magnum { +Framebuffer::Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize) { + _viewportPosition = viewportPosition; + _viewportSize = viewportSize; + + glGenFramebuffers(1, &_id); +} + Framebuffer::~Framebuffer() { /* If bound, remove itself from state */ Implementation::FramebufferState* state = Context::current()->state()->framebuffer; @@ -38,7 +47,7 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments for(auto it = colorAttachments.begin(); it != colorAttachments.end(); ++it) attachments[it-colorAttachments.begin()] = *it + GL_COLOR_ATTACHMENT0; - bind(Target::Draw); + bindInternal(Target::Draw); /** @todo Re-enable when extension wrangler is available for ES2 */ #ifndef MAGNUM_TARGET_GLES2 glDrawBuffers(colorAttachments.size(), attachments); @@ -46,4 +55,90 @@ void Framebuffer::mapForDraw(std::initializer_list colorAttachments delete[] attachments; } +void Framebuffer::mapForRead(std::uint8_t colorAttachment) { + bindInternal(Target::Read); + /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glReadBuffer(GL_COLOR_ATTACHMENT0 + colorAttachment); + #else + static_cast(colorAttachment); + #endif +} + +void Framebuffer::attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { + bindInternal(target); + glFramebufferRenderbuffer(static_cast(target), static_cast(depthStencilAttachment), GL_RENDERBUFFER, renderbuffer->id()); +} + +void Framebuffer::attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { + bindInternal(target); + glFramebufferRenderbuffer(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, GL_RENDERBUFFER, renderbuffer->id()); +} + +#ifndef MAGNUM_TARGET_GLES +void Framebuffer::attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + bindInternal(target); + glFramebufferTexture1D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); +} + +void Framebuffer::attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + bindInternal(target); + glFramebufferTexture1D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); +} +#endif + +void Framebuffer::attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + bindInternal(target); + glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); +} + +void Framebuffer::attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + bindInternal(target); + glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); +} + +void Framebuffer::attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { + /** @todo Check for internal format compatibility */ + bindInternal(target); + glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(coordinate), texture->id(), mipLevel); +} + +void Framebuffer::attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { + /** @todo Check for internal format compatibility */ + bindInternal(target); + glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(coordinate), texture->id(), mipLevel); +} + +void Framebuffer::attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { + /** @todo Check for texture target compatibility */ + bindInternal(target); + /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ + #ifndef MAGNUM_TARGET_GLES + glFramebufferTexture3D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel, layer); + #else + static_cast(depthStencilAttachment); + static_cast(texture); + static_cast(mipLevel); + static_cast(layer); + #endif +} + +void Framebuffer::attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { + /** @todo Check for texture target compatibility */ + bindInternal(target); + /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ + #ifndef MAGNUM_TARGET_GLES + glFramebufferTexture3D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel, layer); + #else + static_cast(colorAttachment); + static_cast(texture); + static_cast(mipLevel); + static_cast(layer); + #endif +} + } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 781596363..6ab19eec1 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -21,8 +21,6 @@ #include "AbstractFramebuffer.h" #include "CubeMapTexture.h" -#include "Texture.h" -#include "Renderbuffer.h" namespace Magnum { @@ -40,7 +38,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * Generates new OpenGL framebuffer. * @see @fn_gl{GenFramebuffers} */ - inline Framebuffer() { glGenFramebuffers(1, &_id); } + Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize); /** * @brief Destructor @@ -67,15 +65,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - inline void mapForRead(std::uint8_t colorAttachment) { - bind(Target::Read); - /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glReadBuffer(GL_COLOR_ATTACHMENT0 + colorAttachment); - #else - static_cast(colorAttachment); - #endif - } + void mapForRead(std::uint8_t colorAttachment); /** * @brief Attachment for depth/stencil part of fragment shader output @@ -107,10 +97,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} */ - inline void attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { - bind(target); - glFramebufferRenderbuffer(static_cast(target), static_cast(depthStencilAttachment), GL_RENDERBUFFER, renderbuffer->id()); - } + void attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer); /** * @brief Attach renderbuffer to given framebuffer color attachment @@ -120,10 +107,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} */ - inline void attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { - bind(target); - glFramebufferRenderbuffer(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, GL_RENDERBUFFER, renderbuffer->id()); - } + void attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer); #ifndef MAGNUM_TARGET_GLES /** @@ -136,11 +120,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - inline void attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bind(target); - glFramebufferTexture1D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); - } + void attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel); /** * @brief Attach 1D texture to given framebuffer color attachment @@ -152,11 +132,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - inline void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bind(target); - glFramebufferTexture1D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); - } + void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel); #endif /** @@ -170,11 +146,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, * @fn_gl{FramebufferTexture} */ - inline void attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bind(target); - glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); - } + void attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel); /** * @brief Attach 2D texture to given framebuffer color attachment @@ -187,11 +159,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, * @fn_gl{FramebufferTexture} */ - inline void attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bind(target); - glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); - } + void attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel); /** * @brief Attach cube map texture to given framebuffer depth/stencil attachment @@ -204,11 +172,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, * @fn_gl{FramebufferTexture} */ - inline void attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { - /** @todo Check for internal format compatibility */ - bind(target); - glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(coordinate), texture->id(), mipLevel); - } + void attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel); /** * @brief Attach cube map texture to given framebuffer color attachment @@ -221,11 +185,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, * @fn_gl{FramebufferTexture} */ - inline void attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { - /** @todo Check for internal format compatibility */ - bind(target); - glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(coordinate), texture->id(), mipLevel); - } + void attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel); /** * @brief Attach 3D texture to given framebuffer depth/stencil attachment @@ -238,19 +198,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - inline void attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { - /** @todo Check for texture target compatibility */ - bind(target); - /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ - #ifndef MAGNUM_TARGET_GLES - glFramebufferTexture3D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel, layer); - #else - static_cast(depthStencilAttachment); - static_cast(texture); - static_cast(mipLevel); - static_cast(layer); - #endif - } + void attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer); /** * @brief Attach 3D texture to given framebuffer color attachment @@ -263,19 +211,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - inline void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { - /** @todo Check for texture target compatibility */ - bind(target); - /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ - #ifndef MAGNUM_TARGET_GLES - glFramebufferTexture3D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel, layer); - #else - static_cast(colorAttachment); - static_cast(texture); - static_cast(mipLevel); - static_cast(layer); - #endif - } + void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer); }; } diff --git a/src/Implementation/FramebufferState.h b/src/Implementation/FramebufferState.h index 43e496040..f6c0b5a19 100644 --- a/src/Implementation/FramebufferState.h +++ b/src/Implementation/FramebufferState.h @@ -15,6 +15,7 @@ GNU Lesser General Public License version 3 for more details. */ +#include "Math/Vector2.h" #include "Magnum.h" namespace Magnum { namespace Implementation { @@ -23,6 +24,7 @@ struct FramebufferState { inline FramebufferState(): readBinding(0), drawBinding(0) {} GLuint readBinding, drawBinding; + Vector2i viewportPosition, viewportSize; }; }} From dc1ab80cdaab790c6888af20699cc717e113b135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 17:26:31 +0100 Subject: [PATCH 046/567] Doc++ --- src/AbstractShaderProgram.h | 46 ++++++++++++++++---------------- src/Buffer.h | 20 +++++++------- src/BufferTexture.h | 8 +++--- src/Context.h | 3 +++ src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/Extensions.h | 2 +- src/Mesh.h | 10 +++---- src/Platform/ExtensionWrangler.h | 2 +- src/Query.h | 19 ++++++------- src/Renderer.h | 12 ++++----- src/Shader.h | 8 +++--- src/Texture.h | 9 ++++--- 13 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 4f506270a..1f6f60d60 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -168,7 +168,7 @@ GLint transformationUniform = uniformLocation("transformation"); GLint projectionUniform = uniformLocation("projection"); @endcode -@requires_gl43 Extension @extension{ARB,explicit_uniform_location} for +@requires_gl43 %Extension @extension{ARB,explicit_uniform_location} for explicit uniform location instead of using uniformLocation(). @requires_gl Explicit uniform location is not supported in OpenGL ES. Use uniformLocation() instead. @@ -191,7 +191,7 @@ setUniform(DiffuseTextureUniform, DiffuseTextureLayer); setUniform(SpecularTextureUniform, SpecularTextureLayer); @endcode -@requires_gl42 Extension @extension{ARB,shading_language_420pack} for explicit +@requires_gl42 %Extension @extension{ARB,shading_language_420pack} for explicit texture layer binding instead of using setUniform(GLint, GLint). @requires_gl Explicit texture layer binding is not supported in OpenGL ES. Use setUniform(GLint, GLint) instead. @@ -485,7 +485,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @note This function should be called after attachShader() calls and * before link(). * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_BINARY_RETRIEVABLE_HINT} - * @requires_gl41 Extension @extension{ARB,get_program_binary} + * @requires_gl41 %Extension @extension{ARB,get_program_binary} * @requires_gles30 Always allowed in OpenGL ES 2.0. */ inline void setRetrievableBinary(bool enabled) { @@ -500,7 +500,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @note This function should be called after attachShader() calls and * before link(). * @see @fn_gl{ProgramParameter} with @def_gl{PROGRAM_SEPARABLE} - * @requires_gl41 Extension @extension{ARB,separate_shader_objects} + * @requires_gl41 %Extension @extension{ARB,separate_shader_objects} * @requires_es_extension %Extension @es_extension{EXT,separate_shader_objects} */ inline void setSeparable(bool enabled) { @@ -562,7 +562,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @ref AbstractShaderProgram-attribute-location "class documentation" * for more information. * @see @fn_gl{BindFragDataLocationIndexed} - * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl33 %Extension @extension{ARB,blend_func_extended} * @requires_gl Multiple blend function inputs are not available in * OpenGL ES. */ @@ -576,7 +576,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * The same as bindFragmentDataLocationIndexed(), but with `index` set * to `0`. * @see @fn_gl{BindFragDataLocation} - * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gl Use explicit location specification in OpenGL ES 3.0 * instead. */ @@ -659,7 +659,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { #ifndef MAGNUM_TARGET_GLES2 /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, GLuint value) { @@ -668,7 +668,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::Vector<2, GLuint>& value) { @@ -677,7 +677,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::Vector<3, GLuint>& value) { @@ -686,7 +686,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl30 Extension @extension{EXT,gpu_shader4} + * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ inline void setUniform(GLint location, const Math::Vector<4, GLuint>& value) { @@ -697,7 +697,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { #ifndef MAGNUM_TARGET_GLES /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, GLdouble value) { @@ -706,7 +706,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::Vector<2, GLdouble>& value) { @@ -715,7 +715,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::Vector<3, GLdouble>& value) { @@ -724,7 +724,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::Vector<4, GLdouble>& value) { @@ -800,7 +800,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { #ifndef MAGNUM_TARGET_GLES /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::Matrix<2, GLdouble>& value) { @@ -809,7 +809,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::Matrix<3, GLdouble>& value) { @@ -818,7 +818,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::Matrix<4, GLdouble>& value) { @@ -827,7 +827,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value) { @@ -836,7 +836,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value) { @@ -845,7 +845,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value) { @@ -854,7 +854,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value) { @@ -863,7 +863,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value) { @@ -872,7 +872,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @copydoc setUniform(GLint, GLfloat) - * @requires_gl40 Extension @extension{ARB,gpu_shader_fp64} + * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value) { diff --git a/src/Buffer.h b/src/Buffer.h index 790a8db70..2e22375e9 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -97,7 +97,7 @@ class MAGNUM_EXPORT Buffer { #ifndef MAGNUM_TARGET_GLES /** * Used for storing atomic counters. - * @requires_gl42 Extension @extension{ARB,shader_atomic_counters} + * @requires_gl42 %Extension @extension{ARB,shader_atomic_counters} * @requires_gl Atomic counters are not available in OpenGL ES. */ AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, @@ -106,7 +106,7 @@ class MAGNUM_EXPORT Buffer { #ifndef MAGNUM_TARGET_GLES2 /** * Source for copies. See copy(). - * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gl31 %Extension @extension{ARB,copy_buffer} * @requires_gles30 Buffer copying is not available in OpenGL ES * 2.0. */ @@ -114,7 +114,7 @@ class MAGNUM_EXPORT Buffer { /** * Target for copies. See copy(). - * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gl31 %Extension @extension{ARB,copy_buffer} * @requires_gles30 Buffer copying is not available in OpenGL ES * 2.0. */ @@ -124,14 +124,14 @@ class MAGNUM_EXPORT Buffer { #ifndef MAGNUM_TARGET_GLES /** * Indirect compute dispatch commands. - * @requires_gl43 Extension @extension{ARB,compute_shader} + * @requires_gl43 %Extension @extension{ARB,compute_shader} * @requires_gl Compute shaders are not available in OpenGL ES. */ DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER, /** * Used for supplying arguments for indirect drawing. - * @requires_gl40 Extension @extension{ARB,draw_indirect} + * @requires_gl40 %Extension @extension{ARB,draw_indirect} * @requires_gl Indirect drawing not available in OpenGL ES. */ DrawIndirect = GL_DRAW_INDIRECT_BUFFER, @@ -161,14 +161,14 @@ class MAGNUM_EXPORT Buffer { #ifndef MAGNUM_TARGET_GLES /** * Used for shader storage. - * @requires_gl43 Extension @extension{ARB,shader_storage_buffer_object} + * @requires_gl43 %Extension @extension{ARB,shader_storage_buffer_object} * @requires_gl Shader storage is not available in OpenGL ES. */ ShaderStorage = GL_SHADER_STORAGE_BUFFER, /** * Source for texel fetches. See BufferTexture. - * @requires_gl31 Extension @extension{ARB,texture_buffer_object} + * @requires_gl31 %Extension @extension{ARB,texture_buffer_object} * @requires_gl Texture buffers are not available in OpenGL ES. */ Texture = GL_TEXTURE_BUFFER, @@ -177,7 +177,7 @@ class MAGNUM_EXPORT Buffer { #ifndef MAGNUM_TARGET_GLES2 /** * Target for transform feedback. - * @requires_gl30 Extension @extension{EXT,transform_feedback} + * @requires_gl30 %Extension @extension{EXT,transform_feedback} * @requires_gles30 Transform feedback is not available in OpenGL * ES 2.0. */ @@ -185,7 +185,7 @@ class MAGNUM_EXPORT Buffer { /** * Used for storing uniforms. - * @requires_gl31 Extension @extension{ARB,uniform_buffer_object} + * @requires_gl31 %Extension @extension{ARB,uniform_buffer_object} * @requires_gles30 Uniform buffers are not available in OpenGL ES * 2.0. */ @@ -293,7 +293,7 @@ class MAGNUM_EXPORT Buffer { * buffers aren't already bound somewhere, they are bound to * `Target::CopyRead` and `Target::CopyWrite` before the copy is * performed. - * @requires_gl31 Extension @extension{ARB,copy_buffer} + * @requires_gl31 %Extension @extension{ARB,copy_buffer} * @requires_gles30 Buffer copying is not available in OpenGL ES 2.0. * @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or * @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} diff --git a/src/BufferTexture.h b/src/BufferTexture.h index 548206247..bdb98656e 100644 --- a/src/BufferTexture.h +++ b/src/BufferTexture.h @@ -67,7 +67,7 @@ uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and "relevant section in AbstractTexture documentation" and respective function documentation for more information. -@requires_gl31 Extension @extension{ARB,texture_buffer_object} +@requires_gl31 %Extension @extension{ARB,texture_buffer_object} @requires_gl Texture buffers are not available in OpenGL ES. */ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { @@ -147,7 +147,7 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { /** * RGB, each component non-normalized unsigned int. - * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} + * @requires_gl40 %Extension @extension{ARB,texture_buffer_object_rgb32} */ RGB32UI = GL_RGB32UI, @@ -162,7 +162,7 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { /** * RGB, each component non-normalized signed int. - * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} + * @requires_gl40 %Extension @extension{ARB,texture_buffer_object_rgb32} */ RGB32I = GL_RGB32I, @@ -186,7 +186,7 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { /** * RGB, each component float. - * @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} + * @requires_gl40 %Extension @extension{ARB,texture_buffer_object_rgb32} */ RGB32F = GL_RGB32F, diff --git a/src/Context.h b/src/Context.h index ccc5ddbd4..b2bf161c8 100644 --- a/src/Context.h +++ b/src/Context.h @@ -138,10 +138,13 @@ class MAGNUM_EXPORT Context { /** * @brief Constructor * + * Constructed automatically, see class documentation for more + * information. * @see @fn_gl{Get} with @def_gl{MAJOR_VERSION}, @def_gl{MINOR_VERSION}, * @fn_gl{GetString} with @def_gl{EXTENSIONS} */ Context(); + ~Context(); /** @brief Current context */ diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index a0622d252..c6d2da991 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -82,7 +82,7 @@ class CubeMapTexture: public AbstractTexture { * * Initially disabled on desktop OpenGL. * @see @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS} - * @requires_gl32 Extension @extension{ARB,seamless_cube_map} + * @requires_gl32 %Extension @extension{ARB,seamless_cube_map} * @requires_gl Not available in OpenGL ES 2.0, always enabled in * OpenGL ES 3.0. */ diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 0bf226684..abda57b71 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -66,7 +66,7 @@ one of the six sides of the cube map, fourth part is layer in the array. See also AbstractShaderProgram for more information. @see CubeMapTexture::setSeamless() -@requires_gl40 Extension @extension{ARB,texture_cube_map_array} +@requires_gl40 %Extension @extension{ARB,texture_cube_map_array} @requires_gl Cube map texture arrays are not available in OpenGL ES. */ class CubeMapTextureArray: public AbstractTexture { diff --git a/src/Extensions.h b/src/Extensions.h index cd805c12e..068f84b22 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -30,7 +30,7 @@ Each extension is `struct` named hierarchically by prefix, vendor and extension name, for example `GL::APPLE::vertex_array_object`. Each struct has the same public methods as Extension class (requiredVersion(), coreVersion() and string(), but these structs are better suited for compile-time decisions -rather than Extension instances. See Context::isExtensionSupported() for +rather than %Extension instances. See Context::isExtensionSupported() for example usage. @see MAGNUM_ASSERT_EXTENSION_SUPPORTED() diff --git a/src/Mesh.h b/src/Mesh.h index 6909bfe59..100b343fb 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -155,11 +155,11 @@ class MAGNUM_EXPORT Mesh { * @brief Provoking vertex * * @see setProvokingVertex() - * @requires_gl OpenGL ES behaves always like - * ProvokingMode::%LastVertexConvention. - * @requires_gl32 Extension @extension{ARB,provoking_vertex}. Older + * @requires_gl32 %Extension @extension{ARB,provoking_vertex}. Older * versions behave always like * ProvokingMode::%LastVertexConvention. + * @requires_gl OpenGL ES behaves always like + * ProvokingMode::%LastVertexConvention. */ enum class ProvokingVertex: GLenum { /** @brief Use first vertex of each polygon. */ @@ -174,9 +174,9 @@ class MAGNUM_EXPORT Mesh { * * Initial value is ProvokingMode::%LastVertexConvention. * @see @fn_gl{ProvokingVertex} - * @requires_gl OpenGL ES behaves always like the default. - * @requires_gl32 Extension @extension{ARB,provoking_vertex}. Older + * @requires_gl32 %Extension @extension{ARB,provoking_vertex}. Older * versions behave always like the default. + * @requires_gl OpenGL ES behaves always like the default. */ inline static void setProvokingVertex(ProvokingVertex mode) { glProvokingVertex(static_cast(mode)); diff --git a/src/Platform/ExtensionWrangler.h b/src/Platform/ExtensionWrangler.h index f9353b3fc..536a8c11b 100644 --- a/src/Platform/ExtensionWrangler.h +++ b/src/Platform/ExtensionWrangler.h @@ -21,7 +21,7 @@ namespace Magnum { namespace Platform { -/** @brief Extension wrangler interface */ +/** @brief %Extension wrangler interface */ class ExtensionWrangler { public: /** @brief Whether to enable or disable experimental features */ diff --git a/src/Query.h b/src/Query.h index 723826ddc..d548e2100 100644 --- a/src/Query.h +++ b/src/Query.h @@ -78,7 +78,8 @@ class MAGNUM_EXPORT AbstractQuery { * Note that this function is blocking until the result is available. * See resultAvailable(). * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} - * @requires_gl33 Extension @extension{ARB,timer_query} (result type `GLuint64` and `GLint64`) + * @requires_gl33 %Extension @extension{ARB,timer_query} (result + * type `GLuint64` and `GLint64`) * @requires_gl Result types @c GLint, @c GLuint64 and @c GLint64 are * not available in OpenGL ES. */ @@ -119,7 +120,7 @@ if(!q.resultAvailable()) { // ...or block until the result is available GLuint primitiveCount = q.result(); @endcode -@requires_gl30 Extension @extension{EXT,transform_feedback} +@requires_gl30 %Extension @extension{EXT,transform_feedback} @requires_gles30 Only sample queries are available on OpenGL ES 2.0. */ class MAGNUM_EXPORT Query: public AbstractQuery { @@ -144,7 +145,7 @@ class MAGNUM_EXPORT Query: public AbstractQuery { /** * Elapsed time - * @requires_gl33 Extension @extension{ARB,timer_query} + * @requires_gl33 %Extension @extension{ARB,timer_query} * @requires_gl Only transform feedback query is available in * OpenGL ES. */ @@ -227,7 +228,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { /** * Whether any samples passed from fragment shader - * @requires_gl33 Extension @extension{ARB,occlusion_query2} + * @requires_gl33 %Extension @extension{ARB,occlusion_query2} */ #ifndef MAGNUM_TARGET_GLES2 AnySamplesPassed = GL_ANY_SAMPLES_PASSED, @@ -240,7 +241,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { * * An implementation may choose a less precise version of the * test at the expense of some false positives. - * @requires_gl43 Extension @extension{ARB,ES3_compatibility} + * @requires_gl43 %Extension @extension{ARB,ES3_compatibility} */ #ifndef MAGNUM_TARGET_GLES2 AnySamplesPassedConservative = GL_ANY_SAMPLES_PASSED_CONSERVATIVE @@ -253,7 +254,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { /** * @brief Conditional render mode * - * @requires_gl30 Extension @extension{NV,conditional_render} + * @requires_gl30 %Extension @extension{NV,conditional_render} * @requires_gl Conditional rendering is not available in OpenGL ES. */ enum class ConditionalRenderMode: GLenum { @@ -298,7 +299,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { * @brief Begin conditional rendering based on result value * * @see @fn_gl{BeginConditionalRender} - * @requires_gl30 Extension @extension{NV,conditional_render} + * @requires_gl30 %Extension @extension{NV,conditional_render} * @requires_gl Conditional rendering is not available in OpenGL ES. */ inline void beginConditionalRender(ConditionalRenderMode mode) { @@ -309,7 +310,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { * @brief End conditional render * * @see @fn_gl{EndConditionalRender} - * @requires_gl30 Extension @extension{NV,conditional_render} + * @requires_gl30 %Extension @extension{NV,conditional_render} * @requires_gl Conditional rendering is not available in OpenGL ES. */ inline void endConditionalRender() { @@ -352,7 +353,7 @@ GLuint timeElapsed1 = tmp-q1.result(); GLuint timeElapsed2 = q3.result()-tmp; @endcode Using this query results in fewer OpenGL calls when doing more measures. -@requires_gl33 Extension @extension{ARB,timer_query} +@requires_gl33 %Extension @extension{ARB,timer_query} @requires_gl Timer query is not available in OpenGL ES. */ class TimeQuery: public AbstractQuery { diff --git a/src/Renderer.h b/src/Renderer.h index d4b319676..420c29cf9 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -79,7 +79,7 @@ class MAGNUM_EXPORT Renderer { /** * Depth clamping. If enabled, ignores near and far clipping plane. - * @requires_gl32 Extension @extension{ARB,depth_clamp} + * @requires_gl32 %Extension @extension{ARB,depth_clamp} * @requires_gl Depth clamping is not available in OpenGL ES. */ DepthClamp = GL_DEPTH_CLAMP, @@ -146,7 +146,7 @@ class MAGNUM_EXPORT Renderer { * @overload * * @see @fn_gl{ClearDepth} - * @requires_gl41 Extension @extension{ARB,ES2_compatibility} + * @requires_gl41 %Extension @extension{ARB,ES2_compatibility} * @todo Call double version if the extension is not available */ inline static void setClearDepth(GLfloat depth) { glClearDepthf(depth); } @@ -451,7 +451,7 @@ class MAGNUM_EXPORT Renderer { * Second source color (@f$ RGB = (R_{s1}, G_{s1}, B_{s1}); A = A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl33 %Extension @extension{ARB,blend_func_extended} * @requires_gl Multiple blending inputs are not available in * OpenGL ES. */ @@ -468,7 +468,7 @@ class MAGNUM_EXPORT Renderer { * One minus second source color (@f$ RGB = (1.0 - R_{s1}, 1.0 - G_{s1}, 1.0 - B_{s1}); A = 1.0 - A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl33 %Extension @extension{ARB,blend_func_extended} * @requires_gl Multiple blending inputs are not available in * OpenGL ES. */ @@ -490,7 +490,7 @@ class MAGNUM_EXPORT Renderer { * Second source alpha (@f$ RGB = (A_{s1}, A_{s1}, A_{s1}); A = A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl33 %Extension @extension{ARB,blend_func_extended} * @requires_gl Multiple blending inputs are not available in * OpenGL ES. */ @@ -507,7 +507,7 @@ class MAGNUM_EXPORT Renderer { * One minus second source alpha (@f$ RGB = (1.0 - A_{s1}, 1.0 - A_{s1}, 1.0 - A_{s1}); A = 1.0 - A_{s1} @f$) * * @see AbstractShaderProgram::bindFragmentDataLocationIndexed() - * @requires_gl33 Extension @extension{ARB,blend_func_extended} + * @requires_gl33 %Extension @extension{ARB,blend_func_extended} * @requires_gl Multiple blending inputs are not available in * OpenGL ES. */ diff --git a/src/Shader.h b/src/Shader.h index 566cadb68..798a6c223 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -47,28 +47,28 @@ class MAGNUM_EXPORT Shader { #ifndef MAGNUM_TARGET_GLES /** * Tessellation control shader - * @requires_gl40 Extension @extension{ARB,tessellation_shader} + * @requires_gl40 %Extension @extension{ARB,tessellation_shader} * @requires_gl Tessellation shaders are not available in OpenGL ES. */ TessellationControl = GL_TESS_CONTROL_SHADER, /** * Tessellation evaluation shader - * @requires_gl40 Extension @extension{ARB,tessellation_shader} + * @requires_gl40 %Extension @extension{ARB,tessellation_shader} * @requires_gl Tessellation shaders are not available in OpenGL ES. */ TessellationEvaluation = GL_TESS_EVALUATION_SHADER, /** * Geometry shader - * @requires_gl32 Extension @extension{ARB,geometry_shader4} + * @requires_gl32 %Extension @extension{ARB,geometry_shader4} * @requires_gl Geometry shaders are not available in OpenGL ES. */ Geometry = GL_GEOMETRY_SHADER, /** * Compute shader - * @requires_gl43 Extension @extension{ARB,compute_shader} + * @requires_gl43 %Extension @extension{ARB,compute_shader} * @requires_gl Compute shaders are not available in OpenGL ES. */ Compute = GL_COMPUTE_SHADER, diff --git a/src/Texture.h b/src/Texture.h index 012618b4e..cc7ec7ff5 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -102,7 +102,8 @@ rectangle textures don't support mipmapping and repeating wrapping modes, see generateMipmap() documentation for more information. @requires_gl Rectangle textures are not available in OpenGL ES. -@requires_gl31 Extension @extension{ARB,texture_rectangle} (rectangle textures) +@requires_gl31 %Extension @extension{ARB,texture_rectangle} (rectangle + textures) @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @todo @extension{AMD,sparse_texture} @@ -135,7 +136,7 @@ template class Texture: public AbstractTexture { /** * One-dimensional texture array (i.e. two dimensions in total) - * @requires_gl30 Extension @extension{EXT,texture_array} + * @requires_gl30 %Extension @extension{EXT,texture_array} * @requires_gl Only 2D and 3D textures are available in OpenGL * ES. */ @@ -143,7 +144,7 @@ template class Texture: public AbstractTexture { /** * Two-dimensional texture array (i.e. three dimensions in total) - * @requires_gl30 Extension @extension{EXT,texture_array} + * @requires_gl30 %Extension @extension{EXT,texture_array} * @requires_gles30 Array textures are not available in OpenGL ES * 2.0. */ @@ -151,7 +152,7 @@ template class Texture: public AbstractTexture { /** * Rectangle texture (i.e. two dimensions) - * @requires_gl31 Extension @extension{ARB,texture_rectangle} + * @requires_gl31 %Extension @extension{ARB,texture_rectangle} * @requires_gl Rectangle textures are not available in OpenGL ES. */ Rectangle = GL_TEXTURE_RECTANGLE From 3b37dfa6b8e09927ef5ab8e332edcb5eecfc853b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 18:14:29 +0100 Subject: [PATCH 047/567] Deleted constructors of classes with only static members. They shouldn't be instantiated, prevent mistakes with this. --- src/DebugMarker.h | 2 ++ src/DimensionTraits.h | 16 +++++++++ src/Math/Algorithms/GaussJordan.h | 2 ++ src/Math/Constants.h | 6 ++++ src/Math/Geometry/Distance.h | 2 ++ src/Math/Geometry/Intersection.h | 2 ++ src/Math/MathTypeTraits.h | 6 ++++ src/Math/RectangularMatrix.h | 2 ++ src/Mesh.h | 2 ++ src/Platform/ExtensionWrangler.h | 2 ++ src/Renderer.h | 4 +-- src/SizeTraits.h | 17 ++++++++-- src/TypeTraits.h | 54 +++++++++++++++++++++++++------ 13 files changed, 104 insertions(+), 13 deletions(-) diff --git a/src/DebugMarker.h b/src/DebugMarker.h index 942c38dad..54e1e1479 100644 --- a/src/DebugMarker.h +++ b/src/DebugMarker.h @@ -41,6 +41,8 @@ class MAGNUM_EXPORT DebugMarker { friend class Context; public: + DebugMarker() = delete; + /** @brief Put string mark into OpenGL command stream */ inline static void mark(const std::string& string) { markImplementation(string); diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index 016fc1ee0..ad3975501 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -37,6 +37,8 @@ namespace Math { /** @brief Matrix, point and vector specializations for given dimension count */ template struct DimensionTraits { + DimensionTraits() = delete; + #ifdef DOXYGEN_GENERATING_OUTPUT /** * @brief Vector type @@ -66,21 +68,29 @@ template struct DimensionTraits { #ifndef DOXYGEN_GENERATING_OUTPUT /* One dimension */ template struct DimensionTraits<1, T> { + DimensionTraits() = delete; + typedef Math::Vector<1, T> VectorType; }; /* Two dimensions - integral */ template struct DimensionTraits<2, T> { + DimensionTraits() = delete; + typedef Math::Vector2 VectorType; }; /* Two dimensions - floating-point */ template<> struct DimensionTraits<2, float> { + DimensionTraits() = delete; + typedef Math::Vector2 VectorType; typedef Math::Point2D PointType; typedef Math::Matrix3 MatrixType; }; template<> struct DimensionTraits<2, double> { + DimensionTraits() = delete; + typedef Math::Vector2 VectorType; typedef Math::Point2D PointType; typedef Math::Matrix3 MatrixType; @@ -88,16 +98,22 @@ template<> struct DimensionTraits<2, double> { /* Three dimensions - integral */ template struct DimensionTraits<3, T> { + DimensionTraits() = delete; + typedef Math::Vector3 VectorType; }; /* Three dimensions - floating-point */ template<> struct DimensionTraits<3, float> { + DimensionTraits() = delete; + typedef Math::Vector3 VectorType; typedef Math::Point3D PointType; typedef Math::Matrix4 MatrixType; }; template<> struct DimensionTraits<3, double> { + DimensionTraits() = delete; + typedef Math::Vector3 VectorType; typedef Math::Point3D PointType; typedef Math::Matrix4 MatrixType; diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index 2778fa5c2..30154fbab 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -31,6 +31,8 @@ http://elonen.iki.fi/code/misc-notes/python-gaussj/index.html. */ class GaussJordan { public: + GaussJordan() = delete; + /** * @brief Eliminate transposed matrices in place * @param a Transposed left side of augmented matrix diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 0b27ae947..5e8e70e9b 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -27,6 +27,8 @@ namespace Magnum { namespace Math { @see Magnum::Constants */ template struct Constants { + Constants() = delete; + /* See MathTypeTraits for answer why these are functions and not constants. */ #ifdef DOXYGEN_GENERATING_OUTPUT /** @@ -43,11 +45,15 @@ template struct Constants { #ifndef DOXYGEN_GENERATING_OUTPUT template<> struct Constants { + Constants() = delete; + static inline constexpr double pi() { return 3.141592653589793; } static inline constexpr double sqrt2() { return 1.414213562373095; } static inline constexpr double sqrt3() { return 1.732050807568877; } }; template<> struct Constants { + Constants() = delete; + static inline constexpr float pi() { return 3.141592654f; } static inline constexpr float sqrt2() { return 1.414213562f; } static inline constexpr float sqrt3() { return 1.732050808f; } diff --git a/src/Math/Geometry/Distance.h b/src/Math/Geometry/Distance.h index 9073520a8..48fe043a1 100644 --- a/src/Math/Geometry/Distance.h +++ b/src/Math/Geometry/Distance.h @@ -28,6 +28,8 @@ namespace Magnum { namespace Math { namespace Geometry { /** @brief Functions for computing distances */ class Distance { public: + Distance() = delete; + /** * @brief %Distance of line and point in 2D * @param a First point of the line diff --git a/src/Math/Geometry/Intersection.h b/src/Math/Geometry/Intersection.h index 6eeba75bc..c3b13785c 100644 --- a/src/Math/Geometry/Intersection.h +++ b/src/Math/Geometry/Intersection.h @@ -26,6 +26,8 @@ namespace Magnum { namespace Math { namespace Geometry { /** @brief Functions for computing intersections */ class Intersection { public: + Intersection() = delete; + /** * @brief %Intersection of a plane and line * @param planePosition Plane position diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index a0b9f591d..7b4693cf6 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -46,6 +46,8 @@ sense, it has empty implementation for unknown types or types which don't support given feature, thus forcing the compilation stop with an error. */ template struct MathTypeTraits { + MathTypeTraits() = delete; + /* * The following values are implemented as inline functions, not as * static const variables, because the compiler will inline the return @@ -101,6 +103,8 @@ template struct MathTypeTraits { namespace Implementation { template struct MathTypeTraitsIntegral { + MathTypeTraitsIntegral() = delete; + inline constexpr static T epsilon() { return 1; } inline constexpr static bool equals(T a, T b) { @@ -109,6 +113,8 @@ template struct MathTypeTraitsIntegral { }; template struct MathTypeTraitsFloatingPoint { + MathTypeTraitsFloatingPoint() = delete; + inline static bool equals(T a, T b) { return std::abs(a - b) < MathTypeTraits::epsilon(); } diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 014eebbf3..d4a2bb7e0 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -517,6 +517,8 @@ namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Math::RectangularMatrix} */ template struct ConfigurationValue> { + ConfigurationValue() = delete; + /** @brief Writes elements separated with spaces */ static std::string toString(const Magnum::Math::RectangularMatrix& value, ConfigurationValueFlags flags) { std::string output; diff --git a/src/Mesh.h b/src/Mesh.h index 100b343fb..f4cf516ad 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -754,6 +754,8 @@ namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Mesh} */ template<> struct MAGNUM_EXPORT ConfigurationValue { + ConfigurationValue() = delete; + /** * @brief Writes enum value as string * diff --git a/src/Platform/ExtensionWrangler.h b/src/Platform/ExtensionWrangler.h index 536a8c11b..5dc8d8147 100644 --- a/src/Platform/ExtensionWrangler.h +++ b/src/Platform/ExtensionWrangler.h @@ -24,6 +24,8 @@ namespace Magnum { namespace Platform { /** @brief %Extension wrangler interface */ class ExtensionWrangler { public: + ExtensionWrangler() = delete; + /** @brief Whether to enable or disable experimental features */ enum class ExperimentalFeatures { Disable, diff --git a/src/Renderer.h b/src/Renderer.h index 420c29cf9..e2274fc61 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -36,9 +36,9 @@ Access to global renderer configuration. @todo @extension{ARB,viewport_array} */ class MAGNUM_EXPORT Renderer { - Renderer() = delete; - public: + Renderer() = delete; + /** * @brief Affected polygon facing for culling, stencil operations and masks * diff --git a/src/SizeTraits.h b/src/SizeTraits.h index b2001f5ce..d221fcada 100644 --- a/src/SizeTraits.h +++ b/src/SizeTraits.h @@ -51,20 +51,26 @@ template struct SizeTraits { typedef T SizeType; }; #else -template struct SizeTraits: public SizeTraits {}; +template struct SizeTraits: public SizeTraits { + SizeTraits() = delete; +}; #endif #ifndef DOXYGEN_GENERATING_OUTPUT template<> struct SizeTraits<0> { + SizeTraits() = delete; typedef GLubyte SizeType; }; template<> struct SizeTraits<1> { + SizeTraits() = delete; typedef GLushort SizeType; }; template<> struct SizeTraits<2> { + SizeTraits() = delete; typedef GLuint SizeType; }; template<> struct SizeTraits<4> { + SizeTraits() = delete; /* We don't have size type to store 2^32 values */ }; #endif @@ -146,6 +152,8 @@ Useful mainly for computing template parameter value, e.g. in conjunction with SizeTraits class. */ template struct Pow { + Pow() = delete; + /** @brief Value of the power */ enum: std::uint32_t { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -158,6 +166,8 @@ template struct Pow { #ifndef DOXYGEN_GENERATING_OUTPUT template struct Pow { + Pow() = delete; + enum: std::uint32_t { value = 1 }; }; #endif @@ -171,6 +181,8 @@ Useful mainly for computing template parameter value, e.g. in conjunction with SizeTraits class. */ template struct Log { + Log() = delete; + /** @brief Value of the logarithm */ enum: std::uint32_t { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -182,10 +194,11 @@ template struct Log { }; #ifndef DOXYGEN_GENERATING_OUTPUT -template struct Log: public Log {}; template struct Log { + Log() = delete; enum: std::uint32_t { value = 0 }; }; +template struct Log: public Log {}; #endif } diff --git a/src/TypeTraits.h b/src/TypeTraits.h index be2d5fc81..9366bd872 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -86,7 +86,9 @@ template struct TypeTraits: Math::MathTypeTraits { inline constexpr static std::size_t count(); }; #else -template struct TypeTraits {}; +template struct TypeTraits { + TypeTraits() = delete; +}; #endif /** @brief OpenGL plain types */ @@ -124,6 +126,8 @@ type = TypeTraits::imageType(); @endcode */ template class TypeOf { + TypeOf() = delete; + #ifdef DOXYGEN_GENERATING_OUTPUT typedef U Type; /**< @brief Type */ #endif @@ -137,6 +141,8 @@ time, this class alows to get some information also at runtime with tiny performance loss. */ struct MAGNUM_EXPORT TypeInfo { + TypeInfo() = delete; + /** * @brief Size of given type * @@ -160,15 +166,39 @@ struct MAGNUM_EXPORT TypeInfo { /** @todo Using Vector3 for textures? */ #ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct TypeOf { typedef GLubyte Type; }; -template<> struct TypeOf { typedef GLbyte Type; }; -template<> struct TypeOf { typedef GLushort Type; }; -template<> struct TypeOf { typedef GLshort Type; }; -template<> struct TypeOf { typedef GLuint Type; }; -template<> struct TypeOf { typedef GLint Type; }; -template<> struct TypeOf { typedef GLfloat Type; }; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLubyte Type; +}; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLbyte Type; +}; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLushort Type; +}; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLshort Type; +}; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLuint Type; +}; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLint Type; +}; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLfloat Type; +}; #ifndef MAGNUM_TARGET_GLES -template<> struct TypeOf { typedef GLdouble Type; }; +template<> struct TypeOf { + TypeOf() = delete; + typedef GLdouble Type; +}; #endif template<> struct TypeTraits: Math::MathTypeTraits { @@ -239,6 +269,8 @@ template<> struct TypeTraits: Math::MathTypeTraits { namespace Implementation { template struct VectorTypeTraits { + VectorTypeTraits() = delete; + /* Might be used for attributes, see below */ inline constexpr static Type type() { return TypeTraits::type(); } /* Might be used for attributes, see below */ @@ -286,6 +318,8 @@ template struct TypeTraits>: TypeTraits> { namespace Implementation { template struct MatrixTypeTraits { + MatrixTypeTraits() = delete; + inline constexpr static Type type() { return TypeTraits::type(); } /* Might be used for attributes, see below */ /* Can not be used for indices */ @@ -332,6 +366,8 @@ namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::TypeInfo} */ template<> struct MAGNUM_EXPORT ConfigurationValue { + ConfigurationValue() = delete; + /** * @brief Writes enum value as string * From 7e66a09461bc851b8e73e0c36fcca4b151765594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 18:17:44 +0100 Subject: [PATCH 048/567] Marking all constructors explicit, except for matrix and vector classes. It prevents unwanted implicit conversions from e.g. nullptr to Camera, Vector2 to Physics::Point etc. By making all the constructors explicit it is easier to routinely add the keyword to all new classes instead of thinking about cases when to add and when not to. --- src/AbstractFramebuffer.h | 2 +- src/AbstractImage.h | 2 +- src/AbstractResourceLoader.h | 2 +- src/AbstractShaderProgram.h | 2 +- src/AbstractTexture.h | 2 +- src/Array.h | 26 +++++++++---------- src/Buffer.h | 2 +- src/BufferImage.h | 2 +- src/BufferTexture.h | 2 +- src/Color.h | 22 ++++++++-------- src/Context.h | 2 +- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/DefaultFramebuffer.h | 2 +- src/Framebuffer.h | 2 +- src/Image.h | 4 +-- src/ImageWrapper.h | 4 +-- src/IndexedMesh.h | 2 +- src/Math/Matrix.h | 6 ++--- src/Math/Matrix3.h | 6 ++--- src/Math/Matrix4.h | 6 ++--- src/Math/Point2D.h | 12 ++++----- src/Math/Point3D.h | 12 ++++----- src/Math/RectangularMatrix.h | 4 +-- src/Math/Vector.h | 6 ++--- src/Math/Vector2.h | 10 +++---- src/Math/Vector3.h | 12 ++++----- src/Math/Vector4.h | 12 ++++----- src/Mesh.h | 2 +- src/Physics/AbstractShape.h | 2 +- src/Physics/AxisAlignedBox.h | 2 +- src/Physics/Box.h | 2 +- src/Physics/Capsule.h | 2 +- src/Physics/DebugDrawResourceManager.h | 2 +- src/Physics/Line.h | 2 +- src/Physics/LineSegment.h | 2 +- src/Physics/ObjectShape.h | 2 +- src/Physics/ObjectShapeGroup.h | 2 +- src/Physics/Plane.h | 2 +- src/Physics/Point.h | 2 +- src/Physics/ShapeGroup.h | 2 +- src/Physics/Sphere.h | 2 +- src/Platform/AbstractContextHandler.h | 2 ++ src/Platform/AbstractXApplication.h | 2 +- src/Platform/EglContextHandler.h | 1 + src/Platform/GlutApplication.h | 2 +- src/Platform/GlxApplication.h | 2 +- src/Platform/GlxContextHandler.h | 1 + src/Platform/Sdl2Application.h | 2 +- src/Platform/WindowlessGlxApplication.h | 2 +- src/Platform/XEglApplication.h | 2 +- src/Primitives/Capsule.h | 2 +- src/Primitives/Cube.h | 2 +- src/Primitives/Cylinder.h | 2 +- src/Primitives/Icosphere.h | 4 +-- src/Primitives/Plane.h | 2 +- src/Primitives/Square.h | 2 +- src/Primitives/UVSphere.h | 2 +- src/Profiler.h | 2 +- src/Query.h | 8 +++--- src/Renderbuffer.h | 2 +- src/Resource.h | 2 +- src/SceneGraph/AbstractCamera.h | 2 +- src/SceneGraph/AbstractFeature.h | 2 +- src/SceneGraph/AbstractGroupedFeature.h | 2 +- src/SceneGraph/AbstractObject.h | 1 + src/SceneGraph/AbstractTransformation.h | 1 + .../AbstractTranslationRotation2D.h | 2 ++ .../AbstractTranslationRotation3D.h | 2 ++ .../AbstractTranslationRotationScaling2D.h | 2 ++ .../AbstractTranslationRotationScaling3D.h | 2 ++ src/SceneGraph/Animable.h | 2 +- src/SceneGraph/AnimableGroup.h | 2 +- src/SceneGraph/Camera2D.h | 2 +- src/SceneGraph/Camera3D.h | 2 +- src/SceneGraph/Drawable.h | 2 +- src/SceneGraph/FeatureGroup.h | 2 ++ src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/MatrixTransformation3D.h | 2 +- src/SceneGraph/Object.h | 2 +- src/SceneGraph/Scene.h | 2 ++ src/Shader.h | 2 +- src/Shaders/FlatShader.h | 2 +- src/Shaders/PhongShader.h | 2 +- src/Shaders/VertexColorShader.h | 2 +- src/SizeTraits.h | 2 +- src/Texture.h | 2 +- src/Timeline.h | 2 +- src/Trade/AbstractImporter.h | 2 +- 89 files changed, 158 insertions(+), 138 deletions(-) diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index a18b1f303..542e00a12 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -182,7 +182,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { blit(source, destination, bottomLeft, topRight, bottomLeft, topRight, mask, BlitFilter::NearestNeighbor); } - AbstractFramebuffer() = default; + explicit AbstractFramebuffer() = default; virtual ~AbstractFramebuffer() = 0; /** diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 594d43cd5..8eb821569 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -436,7 +436,7 @@ class MAGNUM_EXPORT AbstractImage { * @param format Format of pixel data * @param type Data type of pixel data */ - inline AbstractImage(Format format, Type type): _format(format), _type(type) {} + inline explicit AbstractImage(Format format, Type type): _format(format), _type(type) {} /** @brief Destructor */ virtual ~AbstractImage() = 0; diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h index 01c68a2b5..e1d358215 100644 --- a/src/AbstractResourceLoader.h +++ b/src/AbstractResourceLoader.h @@ -91,7 +91,7 @@ template class AbstractResourceLoader { friend class Implementation::ResourceManagerData; public: - inline AbstractResourceLoader(): manager(nullptr), _requestedCount(0), _loadedCount(0), _notFoundCount(0) {} + inline explicit AbstractResourceLoader(): manager(nullptr), _requestedCount(0), _loadedCount(0), _notFoundCount(0) {} inline virtual ~AbstractResourceLoader() { if(manager) manager->_loader = nullptr; diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 1f6f60d60..10d48afe0 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -455,7 +455,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Creates one OpenGL shader program. * @see @fn_gl{CreateProgram} */ - inline AbstractShaderProgram(): state(Initialized) { + inline explicit AbstractShaderProgram(): state(Initialized) { _id = glCreateProgram(); } diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 9145e8119..31d8f916c 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -974,7 +974,7 @@ class MAGNUM_EXPORT AbstractTexture { * Creates one OpenGL texture. * @see @fn_gl{GenTextures} */ - inline AbstractTexture(GLenum target): _target(target) { + inline explicit AbstractTexture(GLenum target): _target(target) { glGenTextures(1, &_id); } diff --git a/src/Array.h b/src/Array.h index fc940fc7e..e761dde90 100644 --- a/src/Array.h +++ b/src/Array.h @@ -45,7 +45,7 @@ template class Array { * * Sets all components to their default-constructed values */ - inline constexpr Array(): _data() {} + inline constexpr /*implicit*/ Array(): _data() {} /** * @brief Initializer-list constructor @@ -53,19 +53,19 @@ template class Array { * @param next Next values */ #ifndef DOXYGEN_GENERATING_OUTPUT - template inline constexpr Array(T first, T second, U... next): _data{first, second, next...} { + template inline constexpr /*implicit*/ Array(T first, T second, U... next): _data{first, second, next...} { static_assert(sizeof...(next)+2 == dimensions, "Improper number of arguments passed to Array constructor"); } - template inline constexpr Array(typename std::enable_if::value && dimensions == 1, U>::type first): _data{first} {} + template inline constexpr /*implicit*/ Array(typename std::enable_if::value && dimensions == 1, U>::type first): _data{first} {} #else - template inline constexpr Array(T first, U... next); + template inline constexpr /*implicit*/ Array(T first, U... next); #endif /** * @brief Constructor * @param value Value for all fields */ - template::value && dimensions != 1, U>::type> inline Array(U value) { + template::value && dimensions != 1, U>::type> inline /*implicit*/ Array(U value) { for(std::uint8_t i = 0; i != dimensions; ++i) _data[i] = value; } @@ -104,13 +104,13 @@ template class Array { template class Array1D: public Array<1, T> { public: /** @copydoc Array::Array() */ - inline constexpr Array1D() = default; + inline constexpr /*implicit*/ Array1D() = default; /** * @brief Constructor * @param x X component */ - inline constexpr Array1D(T x): Array<1, T>(x) {} + inline constexpr /*implicit*/ Array1D(T x): Array<1, T>(x) {} /** @brief Copy constructor */ inline constexpr Array1D(const Array<1, T>& other): Array<1, T>(other) {} @@ -126,17 +126,17 @@ template class Array1D: public Array<1, T> { template class Array2D: public Array<2, T> { public: /** @copydoc Array::Array() */ - inline constexpr Array2D() = default; + inline constexpr /*implicit*/ Array2D() = default; /** * @brief Constructor * @param x X component * @param y Y component */ - inline constexpr Array2D(T x, T y): Array<2, T>(x, y) {} + inline constexpr /*implicit*/ Array2D(T x, T y): Array<2, T>(x, y) {} /** @copydoc Array::Array(U) */ - inline constexpr Array2D(T value): Array<2, T>(value, value) {} + inline constexpr /*implicit*/ Array2D(T value): Array<2, T>(value, value) {} /** @brief Copy constructor */ inline constexpr Array2D(const Array<2, T>& other): Array<2, T>(other) {} @@ -154,7 +154,7 @@ template class Array2D: public Array<2, T> { template class Array3D: public Array<3, T> { public: /** @copydoc Array::Array() */ - inline constexpr Array3D() {} + inline constexpr /*implicit*/ Array3D() {} /** * @brief Constructor @@ -162,10 +162,10 @@ template class Array3D: public Array<3, T> { * @param y Y component * @param z Z component */ - inline constexpr Array3D(T x, T y, T z): Array<3, T>(x, y, z) {} + inline constexpr /*implicit*/ Array3D(T x, T y, T z): Array<3, T>(x, y, z) {} /** @copydoc Array::Array(U) */ - inline constexpr Array3D(T value): Array<3, T>(value, value, value) {} + inline constexpr /*implicit*/ Array3D(T value): Array<3, T>(value, value, value) {} /** @brief Copy constructor */ inline constexpr Array3D(const Array<3, T>& other): Array<3, T>(other) {} diff --git a/src/Buffer.h b/src/Buffer.h index 2e22375e9..91ca36587 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -311,7 +311,7 @@ class MAGNUM_EXPORT Buffer { * Generates new OpenGL buffer. * @see @fn_gl{GenBuffers} */ - inline Buffer(Target targetHint = Target::Array): _targetHint(targetHint) { + inline explicit Buffer(Target targetHint = Target::Array): _targetHint(targetHint) { glGenBuffers(1, &_id); } diff --git a/src/BufferImage.h b/src/BufferImage.h index a9c35abcf..63911d2b8 100644 --- a/src/BufferImage.h +++ b/src/BufferImage.h @@ -49,7 +49,7 @@ template class MAGNUM_EXPORT BufferImage: public Abstra * Dimensions and buffer are empty, call setData() to fill the image * with data. */ - inline BufferImage(Format format, Type type): AbstractImage(format, type) { + inline explicit BufferImage(Format format, Type type): AbstractImage(format, type) { _buffer.setTargetHint(Buffer::Target::PixelPack); } diff --git a/src/BufferTexture.h b/src/BufferTexture.h index bdb98656e..37cc3c9a1 100644 --- a/src/BufferTexture.h +++ b/src/BufferTexture.h @@ -194,7 +194,7 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { RGBA32F = GL_RGBA32F }; - inline BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} + inline explicit BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} /** @copydoc AbstractTexture::bind() */ inline void bind(GLint layer) { AbstractTexture::bind(layer); } diff --git a/src/Color.h b/src/Color.h index 5b8bb83aa..23fabeb99 100644 --- a/src/Color.h +++ b/src/Color.h @@ -211,7 +211,7 @@ class Color3: public Math::Vector3 { * * All components are set to zero. */ - inline constexpr Color3() {} + inline constexpr /*implicit*/ Color3() {} /** * @brief Gray constructor @@ -219,16 +219,16 @@ class Color3: public Math::Vector3 { */ inline constexpr explicit Color3(T rgb): Math::Vector3(rgb) {} - /** @brief Copy constructor */ - inline constexpr Color3(const Math::RectangularMatrix<1, 3, T>& other): Math::Vector3(other) {} - /** * @brief Constructor * @param r R value * @param g G value * @param b B value */ - inline constexpr Color3(T r, T g, T b): Math::Vector3(r, g, b) {} + inline constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3(r, g, b) {} + + /** @brief Copy constructor */ + inline constexpr Color3(const Math::RectangularMatrix<1, 3, T>& other): Math::Vector3(other) {} inline T& r() { return Math::Vector3::x(); } /**< @brief R component */ inline constexpr T r() const { return Math::Vector3::x(); } /**< @overload */ @@ -343,7 +343,7 @@ class Color4: public Math::Vector4 { * RGB components are set to zero, A component is set to 1.0 for * floating-point types and maximum positive value for integral types. */ - inline constexpr Color4(): Math::Vector4(T(0), T(0), T(0), Implementation::defaultAlpha()) {} + inline constexpr /*implicit*/ Color4(): Math::Vector4(T(0), T(0), T(0), Implementation::defaultAlpha()) {} /** * @copydoc Color3::Color3(T) @@ -352,9 +352,6 @@ class Color4: public Math::Vector4 { */ inline constexpr explicit Color4(T rgb, T alpha = Implementation::defaultAlpha()): Math::Vector4(rgb, rgb, rgb, alpha) {} - /** @brief Copy constructor */ - inline constexpr Color4(const Math::RectangularMatrix<1, 4, T>& other): Math::Vector4(other) {} - /** * @brief Constructor * @param r R value @@ -363,7 +360,7 @@ class Color4: public Math::Vector4 { * @param a A value, defaults to 1.0 for floating-point types and * maximum positive value for integral types. */ - inline constexpr Color4(T r, T g, T b, T a = Implementation::defaultAlpha()): Math::Vector4(r, g, b, a) {} + inline constexpr /*implicit*/ Color4(T r, T g, T b, T a = Implementation::defaultAlpha()): Math::Vector4(r, g, b, a) {} /** * @brief Constructor @@ -372,7 +369,10 @@ class Color4: public Math::Vector4 { */ /* Not marked as explicit, because conversion from Color3 to Color4 is fairly common, nearly always with A set to 1 */ - inline constexpr Color4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} + inline constexpr /*implicit*/ Color4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} + + /** @brief Copy constructor */ + inline constexpr Color4(const Math::RectangularMatrix<1, 4, T>& other): Math::Vector4(other) {} inline T& r() { return Math::Vector4::x(); } /**< @brief R component */ inline constexpr T r() const { return Math::Vector4::x(); } /**< @overload */ diff --git a/src/Context.h b/src/Context.h index b2bf161c8..53c8b7896 100644 --- a/src/Context.h +++ b/src/Context.h @@ -143,7 +143,7 @@ class MAGNUM_EXPORT Context { * @see @fn_gl{Get} with @def_gl{MAJOR_VERSION}, @def_gl{MINOR_VERSION}, * @fn_gl{GetString} with @def_gl{EXTENSIONS} */ - Context(); + explicit Context(); ~Context(); diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index c6d2da991..e53fa92ba 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -97,7 +97,7 @@ class CubeMapTexture: public AbstractTexture { * Creates one cube map OpenGL texture. * @see @def_gl{TEXTURE_CUBE_MAP} */ - inline CubeMapTexture(): AbstractTexture(GL_TEXTURE_CUBE_MAP) {} + inline explicit CubeMapTexture(): AbstractTexture(GL_TEXTURE_CUBE_MAP) {} /** * @copydoc Texture::setWrapping() diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index abda57b71..ef5fe0124 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -87,7 +87,7 @@ class CubeMapTextureArray: public AbstractTexture { * Creates one cube map OpenGL texture. * @see @def_gl{TEXTURE_CUBE_MAP_ARRAY} */ - inline CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {} + inline explicit CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {} /** * @copydoc Texture::setWrapping() diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 1798c4138..4578d6200 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -164,7 +164,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #endif }; - MAGNUM_LOCAL DefaultFramebuffer(); + explicit MAGNUM_LOCAL DefaultFramebuffer(); #ifndef MAGNUM_TARGET_GLES2 /** diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 6ab19eec1..a146dd6dc 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -38,7 +38,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * Generates new OpenGL framebuffer. * @see @fn_gl{GenFramebuffers} */ - Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize); + explicit Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize); /** * @brief Destructor diff --git a/src/Image.h b/src/Image.h index 8146ce13b..111a748f7 100644 --- a/src/Image.h +++ b/src/Image.h @@ -46,7 +46,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline Image(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} + inline explicit Image(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -56,7 +56,7 @@ template class Image: public AbstractImage { * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline Image(Format format, Type type): AbstractImage(format, type), _data(nullptr) {} + inline explicit Image(Format format, Type type): AbstractImage(format, type), _data(nullptr) {} /** @brief Destructor */ inline ~Image() { delete[] _data; } diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 6deb82bc2..c3a5046b5 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -53,7 +53,7 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} + inline explicit ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -64,7 +64,7 @@ template class ImageWrapper: public AbstractImage { * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type): AbstractImage(format, type), _size(size), _data(nullptr) {} + inline explicit ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type): AbstractImage(format, type), _size(size), _data(nullptr) {} /** @brief %Image size */ inline typename DimensionTraits::VectorType size() const { return _size; } diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 9e6e3f6b3..d801255e6 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -80,7 +80,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @see setPrimitive(), setVertexCount(), setIndexBuffer(), * setIndexCount(), setIndexType() */ - inline IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(Type::UnsignedShort) {} + inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(Type::UnsignedShort) {} /** * @brief Set index buffer diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index a773af055..66235ef99 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -62,7 +62,7 @@ template class Matrix: public RectangularMatrix class Matrix: public RectangularMatrix inline constexpr Matrix(T first, U... next): RectangularMatrix(first, next...) {} + template inline constexpr /*implicit*/ Matrix(T first, U... next): RectangularMatrix(first, next...) {} #else - template inline constexpr Matrix(T first, U... next); + template inline constexpr /*implicit*/ Matrix(T first, U... next); #endif /** @brief Copy constructor */ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 59ba6b48c..20910638d 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -87,7 +87,7 @@ template class Matrix3: public Matrix<3, T> { inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {} /** @copydoc Matrix::Matrix(IdentityType, T) */ - inline constexpr Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( + inline constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( value, T(0), T(0), T(0), value, T(0), T(0), T(0), value @@ -95,9 +95,9 @@ template class Matrix3: public Matrix<3, T> { /** @copydoc Matrix::Matrix */ #ifndef DOXYGEN_GENERATING_OUTPUT - template inline constexpr Matrix3(T first, U... next): Matrix<3, T>(first, next...) {} + template inline constexpr /*implicit*/ Matrix3(T first, U... next): Matrix<3, T>(first, next...) {} #else - template inline constexpr Matrix3(T first, U... next) {} + template inline constexpr /*implicit*/ Matrix3(T first, U... next) {} #endif /** @brief Copy constructor */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 9e01c2104..899374fa7 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -177,7 +177,7 @@ template class Matrix4: public Matrix<4, T> { inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} /** @copydoc Matrix::Matrix(IdentityType, T) */ - inline constexpr Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( + inline constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( value, T(0), T(0), T(0), T(0), value, T(0), T(0), T(0), T(0), value, T(0), @@ -186,9 +186,9 @@ template class Matrix4: public Matrix<4, T> { /** @copydoc Matrix::Matrix */ #ifndef DOXYGEN_GENERATING_OUTPUT - template inline constexpr Matrix4(T first, U... next): Matrix<4, T>(first, next...) {} + template inline constexpr /*implicit*/ Matrix4(T first, U... next): Matrix<4, T>(first, next...) {} #else - template inline constexpr Matrix4(T first, U... next) {} + template inline constexpr /*implicit*/ Matrix4(T first, U... next) {} #endif /** @brief Copy constructor */ diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index f26552d77..93adf7d9f 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -39,10 +39,7 @@ template class Point2D: public Vector3 { * * X and Y components are set to zero, Z is set to one. */ - inline constexpr Point2D(): Vector3(T(0), T(0), T(1)) {} - - /** @brief Copy constructor */ - inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3(other) {} + inline constexpr /*implicit*/ Point2D(): Vector3(T(0), T(0), T(1)) {} /** * @brief Constructor @@ -50,14 +47,17 @@ template class Point2D: public Vector3 { * @param y Y component * @param z Z component */ - inline constexpr Point2D(T x, T y, T z = T(1)): Vector3(x, y, z) {} + inline constexpr /*implicit*/ Point2D(T x, T y, T z = T(1)): Vector3(x, y, z) {} /** * @brief Constructor * @param xy Two-component vector * @param z Z component */ - inline constexpr Point2D(const Vector2& xy, T z = T(1)): Vector3(xy, z) {} + inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z = T(1)): Vector3(xy, z) {} + + /** @brief Copy constructor */ + inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3(other) {} /** * @brief Vector part of the point diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 339822217..959b7e745 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -39,10 +39,7 @@ template class Point3D: public Vector4 { * * X, Y and Z components are set to zero, W is set to one. */ - inline constexpr Point3D(): Vector4(T(0), T(0), T(0), T(1)) {} - - /** @brief Copy constructor */ - inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4(other) {} + inline constexpr /*implicit*/ Point3D(): Vector4(T(0), T(0), T(0), T(1)) {} /** * @brief Constructor @@ -51,14 +48,17 @@ template class Point3D: public Vector4 { * @param z Z component * @param w W component */ - inline constexpr Point3D(T x, T y, T z, T w = T(1)): Vector4(x, y, z, w) {} + inline constexpr /*implicit*/ Point3D(T x, T y, T z, T w = T(1)): Vector4(x, y, z, w) {} /** * @brief Constructor * @param xyz Three-component vector * @param w W component */ - inline constexpr Point3D(const Vector3& xyz, T w = T(1)): Vector4(xyz, w) {} + inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w = T(1)): Vector4(xyz, w) {} + + /** @brief Copy constructor */ + inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4(other) {} /** * @brief Vector part of the point diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index d4a2bb7e0..7ff919cb2 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -116,7 +116,7 @@ template class RectangularMatrix { } /** @brief Zero-filled matrix constructor */ - inline constexpr RectangularMatrix(): _data() {} + inline constexpr /*implicit*/ RectangularMatrix(): _data() {} /** * @brief Initializer-list constructor @@ -127,7 +127,7 @@ template class RectangularMatrix { * @todoc Remove workaround when Doxygen supports uniform initialization */ #ifndef DOXYGEN_GENERATING_OUTPUT - template inline constexpr RectangularMatrix(T first, U... next): _data{first, next...} { + template inline constexpr /*implicit*/ RectangularMatrix(T first, U... next): _data{first, next...} { static_assert(sizeof...(next)+1 == cols*rows, "Improper number of arguments passed to RectangularMatrix constructor"); } #else diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 1f315d9fd..99b0bc32b 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -69,7 +69,7 @@ template class Vector: public RectangularMatrix<1, si } /** @brief Default constructor */ - inline constexpr Vector() {} + inline constexpr /*implicit*/ Vector() {} /** @todo Creating Vector from combination of vector and scalar types */ @@ -79,9 +79,9 @@ template class Vector: public RectangularMatrix<1, si * @param next Next values */ #ifndef DOXYGEN_GENERATING_OUTPUT - template inline constexpr Vector(T first, U... next): RectangularMatrix<1, size, T>(first, next...) {} + template inline constexpr /*implicit*/ Vector(T first, U... next): RectangularMatrix<1, size, T>(first, next...) {} #else - template inline constexpr Vector(T first, U... next); + template inline constexpr /*implicit*/ Vector(T first, U... next); #endif /** diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 61534e2a8..24297213a 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -72,20 +72,20 @@ template class Vector2: public Vector<2, T> { inline constexpr static Vector2 yScale(T scale) { return Vector2(T(1), scale); } /** @copydoc Vector::Vector() */ - inline constexpr Vector2() {} + inline constexpr /*implicit*/ Vector2() {} /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector2(T value): Vector<2, T>(value, value) {} - /** @brief Copy constructor */ - inline constexpr Vector2(const RectangularMatrix<1, 2, T>& other): Vector<2, T>(other) {} - /** * @brief Constructor * @param x X component * @param y Y component */ - inline constexpr Vector2(T x, T y): Vector<2, T>(x, y) {} + inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} + + /** @brief Copy constructor */ + inline constexpr Vector2(const RectangularMatrix<1, 2, T>& other): Vector<2, T>(other) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 88db8214b..52250101b 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -104,28 +104,28 @@ template class Vector3: public Vector<3, T> { } /** @copydoc Vector::Vector() */ - inline constexpr Vector3() {} + inline constexpr /*implicit*/ Vector3() {} /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector3(T value): Vector<3, T>(value, value, value) {} - /** @brief Copy constructor */ - inline constexpr Vector3(const RectangularMatrix<1, 3, T>& other): Vector<3, T>(other) {} - /** * @brief Constructor * @param x X component * @param y Y component * @param z Z component */ - inline constexpr Vector3(T x, T y, T z): Vector<3, T>(x, y, z) {} + inline constexpr /*implicit*/ Vector3(T x, T y, T z): Vector<3, T>(x, y, z) {} /** * @brief Constructor * @param xy Two-component vector * @param z Z component */ - inline constexpr Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} + inline constexpr /*implicit*/ Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} + + /** @brief Copy constructor */ + inline constexpr Vector3(const RectangularMatrix<1, 3, T>& other): Vector<3, T>(other) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 94a680fac..206b5a8aa 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -35,14 +35,11 @@ homogeneous three-dimensional coordinates. template class Vector4: public Vector<4, T> { public: /** @copydoc Vector::Vector() */ - inline constexpr Vector4() {} + inline constexpr /*implicit*/ Vector4() {} /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {} - /** @brief Copy constructor */ - inline constexpr Vector4(const RectangularMatrix<1, 4, T>& other): Vector<4, T>(other) {} - /** * @brief Constructor * @param x X component @@ -50,14 +47,17 @@ template class Vector4: public Vector<4, T> { * @param z Z component * @param w W component */ - inline constexpr Vector4(T x, T y, T z, T w): Vector<4, T>(x, y, z, w) {} + inline constexpr /*implicit*/ Vector4(T x, T y, T z, T w): Vector<4, T>(x, y, z, w) {} /** * @brief Constructor * @param xyz Three-component vector * @param w W component */ - inline constexpr Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} + inline constexpr /*implicit*/ Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} + + /** @brief Copy constructor */ + inline constexpr Vector4(const RectangularMatrix<1, 4, T>& other): Vector<4, T>(other) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ diff --git a/src/Mesh.h b/src/Mesh.h index f4cf516ad..931e5140b 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -365,7 +365,7 @@ class MAGNUM_EXPORT Mesh { * @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if * @extension{APPLE,vertex_array_object} is available) */ - inline Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0) { + inline explicit Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0) { (this->*createImplementation)(); } diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index cebb5f61e..84fc07a25 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -93,7 +93,7 @@ template class MAGNUM_PHYSICS_EXPORT AbstractShape { typedef typename Implementation::ShapeDimensionTraits::Type Type; #endif - /** @brief Destructor */ + explicit AbstractShape() = default; virtual inline ~AbstractShape() {} /** @brief Shape type */ diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 15f96d1c3..ed642b966 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Physics { template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ - inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} + inline explicit AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::AxisAlignedBox; diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 272236540..67c0b80a0 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -36,7 +36,7 @@ namespace Magnum { namespace Physics { template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ - inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} + inline explicit Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Box; diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index e2ff9da69..9fd8e15d8 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -37,7 +37,7 @@ applying transformation, the scale factor is averaged from all axes. template class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ - inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline explicit Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Capsule; diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h index ffabe9350..9381ac3f7 100644 --- a/src/Physics/DebugDrawResourceManager.h +++ b/src/Physics/DebugDrawResourceManager.h @@ -104,7 +104,7 @@ class MAGNUM_PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager static SceneGraph::Drawable* createDebugRenderer(ObjectShape* shape, ResourceKey options = ResourceKey()); - DebugDrawResourceManager(); + explicit DebugDrawResourceManager(); ~DebugDrawResourceManager(); private: diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 9230be376..79c721d09 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -35,7 +35,7 @@ namespace Magnum { namespace Physics { template class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ - inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} + inline explicit Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Line; diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index 4ed4b9449..f36c878f7 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { template class LineSegment: public Line { public: /** @brief Constructor */ - inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} + inline explicit LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::LineSegment; diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index b1d04e1fd..259ee93ef 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -42,7 +42,7 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShape: publi * Creates empty object shape. * @see setShape() */ - ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group = nullptr); + explicit ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group = nullptr); /** * @brief Destructor diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 4e2c1a188..6747704e0 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -43,7 +43,7 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: * * Marks the group as dirty. */ - inline ObjectShapeGroup(): dirty(true) {} + inline explicit ObjectShapeGroup(): dirty(true) {} /** * @brief Whether the group is dirty diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 07cc7ad68..38dca5670 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { class MAGNUM_PHYSICS_EXPORT Plane: public AbstractShape<3> { public: /** @brief Constructor */ - inline Plane(const Vector3& position, const Vector3& normal): _position(position), _transformedPosition(position), _normal(normal), _transformedNormal(normal) {} + inline explicit Plane(const Vector3& position, const Vector3& normal): _position(position), _transformedPosition(position), _normal(normal), _transformedNormal(normal) {} inline Type type() const override { return Type::Plane; } diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 741874ad6..10ebf9583 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Physics { template class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ - inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} + inline explicit Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Point; diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 0c89901a7..fde6d895a 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -91,7 +91,7 @@ template class MAGNUM_PHYSICS_EXPORT ShapeGroup: public public: /** @brief Default constructor */ - inline ShapeGroup(): operation(Implementation::GroupOperation::AlwaysFalse), a(nullptr), b(nullptr) {} + inline explicit ShapeGroup(): operation(Implementation::GroupOperation::AlwaysFalse), a(nullptr), b(nullptr) {} /** @brief Move constructor */ ShapeGroup(ShapeGroup&& other); diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 24b4dd074..8d95f2512 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -37,7 +37,7 @@ applying transformation, the scale factor is averaged from all axes. template class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ - inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline explicit Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Sphere; diff --git a/src/Platform/AbstractContextHandler.h b/src/Platform/AbstractContextHandler.h index 81adb561b..fd342ca7c 100644 --- a/src/Platform/AbstractContextHandler.h +++ b/src/Platform/AbstractContextHandler.h @@ -33,6 +33,8 @@ template class AbstractContextHandl */ virtual VisualId getVisualId(Display nativeDisplay) = 0; + explicit AbstractContextHandler() = default; + /** * @brief Destructor * diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 8a91dcd86..4b6d4d836 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -57,7 +57,7 @@ class AbstractXApplication { * * Creates window with double-buffered OpenGL ES 2 context. */ - AbstractXApplication(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X application", const Vector2i& size = Vector2i(800, 600)); + explicit AbstractXApplication(AbstractContextHandler* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X application", const Vector2i& size = Vector2i(800, 600)); /** * @brief Destructor diff --git a/src/Platform/EglContextHandler.h b/src/Platform/EglContextHandler.h index 878e5d3ab..26d12ba1a 100644 --- a/src/Platform/EglContextHandler.h +++ b/src/Platform/EglContextHandler.h @@ -51,6 +51,7 @@ Used in XEglApplication. */ class EglContextHandler: public AbstractContextHandler { public: + explicit EglContextHandler() = default; ~EglContextHandler(); VisualId getVisualId(EGLNativeDisplayType nativeDisplay) override; diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index d2fcca1af..6b7fafee0 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -60,7 +60,7 @@ class GlutApplication { * @param title Window title * @param size Window size */ - GlutApplication(int& argc, char** argv, const std::string& title = "Magnum GLUT application", const Vector2i& size = Vector2i(800, 600)); + explicit GlutApplication(int& argc, char** argv, const std::string& title = "Magnum GLUT application", const Vector2i& size = Vector2i(800, 600)); virtual ~GlutApplication(); diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index 603ea41ae..919fc7dea 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -51,7 +51,7 @@ class GlxApplication: public AbstractXApplication { * @param title Window title * @param size Window size */ - inline GlxApplication(int& argc, char** argv, const std::string& title = "Magnum GLX application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new GlxContextHandler, argc, argv, title, size) {} + inline explicit GlxApplication(int& argc, char** argv, const std::string& title = "Magnum GLX application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new GlxContextHandler, argc, argv, title, size) {} }; }} diff --git a/src/Platform/GlxContextHandler.h b/src/Platform/GlxContextHandler.h index 136241466..1a8f7b85f 100644 --- a/src/Platform/GlxContextHandler.h +++ b/src/Platform/GlxContextHandler.h @@ -39,6 +39,7 @@ GlxApplication. */ class GlxContextHandler: public AbstractContextHandler { public: + explicit GlxContextHandler() = default; ~GlxContextHandler(); VisualID getVisualId(Display* nativeDisplay) override; diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index ac1265881..82f2b377e 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -65,7 +65,7 @@ class Sdl2Application { * @param title Window title * @param size Window size */ - Sdl2Application(int argc, char** argv, const std::string& title = "Magnum SDL2 application", const Vector2i& size = Vector2i(800, 600)); + explicit Sdl2Application(int argc, char** argv, const std::string& title = "Magnum SDL2 application", const Vector2i& size = Vector2i(800, 600)); /** * @brief Destructor diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 9557d4718..e3e2d2e39 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -55,7 +55,7 @@ class WindowlessGlxApplication { * Creates window with double-buffered OpenGL 3.2 core context or * OpenGL ES 2.0 context, if targetting OpenGL ES. */ - WindowlessGlxApplication(int& argc, char** argv); + explicit WindowlessGlxApplication(int& argc, char** argv); ~WindowlessGlxApplication(); diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index 6ded61519..fab076393 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -51,7 +51,7 @@ class XEglApplication: public AbstractXApplication { * @param title Window title * @param size Window size */ - inline XEglApplication(int& argc, char** argv, const std::string& title = "Magnum X/EGL application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new EglContextHandler, argc, argv, title, size) {} + inline explicit XEglApplication(int& argc, char** argv, const std::string& title = "Magnum X/EGL application", const Vector2i& size = Vector2i(800, 600)): AbstractXApplication(new EglContextHandler, argc, argv, title, size) {} }; }} diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 1d9e118a6..94650a039 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -53,7 +53,7 @@ class Capsule: public Trade::MeshData3D { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); + explicit Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: Capsule(std::uint32_t segments, TextureCoords textureCoords); diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index fd329c4a8..b62606c16 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Primitives { class Cube: public Trade::MeshData3D { public: /** @brief Constructor */ - Cube(); + explicit Cube(); }; }} diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index 29da7a73b..542d3c8c5 100644 --- a/src/Primitives/Cylinder.h +++ b/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(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); + explicit Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); private: void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal); diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 3f938ba84..9e1b275ba 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -38,7 +38,7 @@ from Blender. template<> class Icosphere<0>: public Trade::MeshData3D { public: /** @brief Constructor */ - Icosphere(); + explicit Icosphere(); }; /** @@ -54,7 +54,7 @@ template class Icosphere { #endif public: /** @brief Constructor */ - Icosphere() { + explicit Icosphere() { for(std::size_t i = 0; i != subdivisions; ++i) MeshTools::subdivide(*indices(), *normals(0), [](const Vector3& a, const Vector3& b) { return (a+b).normalized(); diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index 1cdb6f104..9de4f9a2b 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Primitives { class Plane: public Trade::MeshData3D { public: /** @brief Constructor */ - Plane(); + explicit Plane(); }; }} diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index d83520580..7d3f96754 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Primitives { class Square: public Trade::MeshData2D { public: /** @brief Constructor */ - Square(); + explicit Square(); }; }} diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index 8d2f01054..5a55cda1d 100644 --- a/src/Primitives/UVSphere.h +++ b/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(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); + explicit UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); }; }} diff --git a/src/Profiler.h b/src/Profiler.h index db2e94f0c..173b00b17 100644 --- a/src/Profiler.h +++ b/src/Profiler.h @@ -105,7 +105,7 @@ class MAGNUM_EXPORT Profiler { static const Section otherSection = 0; #ifndef DOXYGEN_GENERATING_OUTPUT - Profiler(): enabled(false), measureDuration(60), currentFrame(0), frameCount(0), sections{"Other"}, currentSection(otherSection) {} + explicit Profiler(): enabled(false), measureDuration(60), currentFrame(0), frameCount(0), sections{"Other"}, currentSection(otherSection) {} #endif /** diff --git a/src/Query.h b/src/Query.h index d548e2100..ff3f9ca22 100644 --- a/src/Query.h +++ b/src/Query.h @@ -40,7 +40,7 @@ class MAGNUM_EXPORT AbstractQuery { * Generates one OpenGL query. * @see @fn_gl{GenQueries} */ - inline AbstractQuery() { + inline explicit AbstractQuery() { /** @todo Get some extension wrangler instead to avoid undeclared glGenQueries() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 glGenQueries(1, &_id); @@ -153,7 +153,7 @@ class MAGNUM_EXPORT Query: public AbstractQuery { #endif }; - inline Query(): target(nullptr) {} + inline explicit Query(): target(nullptr) {} inline ~Query() { delete target; } @@ -284,7 +284,7 @@ class MAGNUM_EXPORT SampleQuery: public AbstractQuery { }; #endif - inline SampleQuery(): target(nullptr) {} + inline explicit SampleQuery(): target(nullptr) {} inline ~SampleQuery() { delete target; } @@ -358,6 +358,8 @@ Using this query results in fewer OpenGL calls when doing more measures. */ class TimeQuery: public AbstractQuery { public: + explicit TimeQuery() = default; + /** * @brief Query timestamp * diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 0d687fe48..7016db189 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -512,7 +512,7 @@ class Renderbuffer { * Generates new OpenGL renderbuffer. * @see @fn_gl{GenRenderbuffers} */ - inline Renderbuffer() { + inline explicit Renderbuffer() { glGenRenderbuffers(1, &renderbuffer); } diff --git a/src/Resource.h b/src/Resource.h index 4084aebfb..7b94a491e 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -120,7 +120,7 @@ class Resource { * Creates empty resource. Resources are acquired from the manager by * calling ResourceManager::get(). */ - inline Resource(): manager(nullptr), lastCheck(0), _state(ResourceState::Final), data(nullptr) {} + inline explicit Resource(): manager(nullptr), lastCheck(0), _state(ResourceState::Final), data(nullptr) {} /** @brief Copy constructor */ inline Resource(const Resource& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index b66369436..9b24759fb 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -75,7 +75,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature* object): AbstractFeature(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) { + inline explicit AbstractCamera(AbstractObject* object): AbstractFeature(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) { AbstractFeature::setCachedTransformations(AbstractFeature::CachedTransformation::InvertedAbsolute); } diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 4506c2d4f..4d48312f2 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -132,7 +132,7 @@ template class AbstractFeature * @brief Constructor * @param object %Object holding this feature */ - inline AbstractFeature(AbstractObject* object) { + inline explicit AbstractFeature(AbstractObject* object) { object->Corrade::Containers::LinkedList>::insert(this); } diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index 9e6aaf5f2..5998895c7 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -64,7 +64,7 @@ class AbstractGroupedFeature: public AbstractFeature { * Adds the feature to the object and to group, if specified. * @see FeatureGroup::add() */ - inline AbstractGroupedFeature(AbstractObject* object, FeatureGroup* group = nullptr): AbstractFeature(object), _group(nullptr) { + inline explicit AbstractGroupedFeature(AbstractObject* object, FeatureGroup* group = nullptr): AbstractFeature(object), _group(nullptr) { if(group) group->add(static_cast(this)); } diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 08f9a4ac5..64ef2aeff 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -59,6 +59,7 @@ template class AbstractObject /** @brief Feature object type */ typedef AbstractFeature FeatureType; + explicit AbstractObject() = default; inline virtual ~AbstractObject() {} /** @brief Whether this object has features */ diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index d3fc55f99..4fed38811 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -54,6 +54,7 @@ class AbstractTransformation { /** @brief Dimension count */ static const std::uint8_t Dimensions = dimensions; + explicit AbstractTransformation() = default; virtual ~AbstractTransformation() = 0; #ifdef DOXYGEN_GENERATING_OUTPUT diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index 62be8ef0e..215be0d49 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -35,6 +35,8 @@ template #endif class AbstractTranslationRotation2D: public AbstractTransformation<2, T> { public: + explicit AbstractTranslationRotation2D() = default; + /** * @brief Translate object * @param vector Translation vector diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index 1bd1ff6b3..bfc63943d 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -36,6 +36,8 @@ template #endif class AbstractTranslationRotation3D: public AbstractTransformation<3, T> { public: + explicit AbstractTranslationRotation3D() = default; + /** * @brief Translate object * @param vector Translation vector diff --git a/src/SceneGraph/AbstractTranslationRotationScaling2D.h b/src/SceneGraph/AbstractTranslationRotationScaling2D.h index 269aada69..45476a17d 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling2D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling2D.h @@ -35,6 +35,8 @@ template #endif class AbstractTranslationRotationScaling2D: public AbstractTranslationRotation2D { public: + explicit AbstractTranslationRotationScaling2D() = default; + /** * @brief Scale object * @param vector Scaling vector diff --git a/src/SceneGraph/AbstractTranslationRotationScaling3D.h b/src/SceneGraph/AbstractTranslationRotationScaling3D.h index 30cebf0ad..a2a1fb3de 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling3D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling3D.h @@ -35,6 +35,8 @@ template #endif class AbstractTranslationRotationScaling3D: public AbstractTranslationRotation3D { public: + explicit AbstractTranslationRotationScaling3D() = default; + /** * @brief Scale object * @param vector Scaling vector diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 9bb2b3ac8..48a7915fc 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -148,7 +148,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* object, GLfloat duration, AnimableGroup* group = nullptr); + explicit Animable(AbstractObject* object, GLfloat duration, AnimableGroup* group = nullptr); /** @brief Animation duration */ inline GLfloat duration() const { return _duration; } diff --git a/src/SceneGraph/AnimableGroup.h b/src/SceneGraph/AnimableGroup.h index 243dfb5a7..6c86b3b6f 100644 --- a/src/SceneGraph/AnimableGroup.h +++ b/src/SceneGraph/AnimableGroup.h @@ -43,7 +43,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup: public FeatureGroup { * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). * @see setOrthographic() */ - inline Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} + inline explicit Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} /** * @brief Set projection diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 688a5ce9b..ea0aca366 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -65,7 +65,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { * (range @f$ [-1; 1] @f$ in all directions). * @see setOrthographic(), setPerspective() */ - inline Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} + inline explicit Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} /** * @brief Set orthographic projection diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 99148d2f2..36ee9fa75 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -115,7 +115,7 @@ template class Drawable: public AbstractGroupedFeature, T> { public: /** @copydoc AbstractGroupedFeature::AbstractGroupedFeature() */ - inline Drawable(AbstractObject* object, DrawableGroup* group = nullptr): AbstractGroupedFeature, T>(object, group) {} + inline explicit Drawable(AbstractObject* object, DrawableGroup* group = nullptr): AbstractGroupedFeature, T>(object, group) {} /** * @brief Draw the object using given camera diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 293942eb6..3aecc66d1 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -42,6 +42,8 @@ class FeatureGroup { friend class AbstractGroupedFeature; public: + explicit FeatureGroup() = default; + /** * @brief Destructor * diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index ceeab86fc..e797fba84 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -131,7 +131,7 @@ class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { protected: /* Allow construction only from Object */ - inline MatrixTransformation2D() {} + inline explicit MatrixTransformation2D() = default; private: Math::Matrix3 _transformation; diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 7eabf1938..4afc360c0 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -162,7 +162,7 @@ class MatrixTransformation3D: public AbstractTranslationRotationScaling3D { protected: /* Allow construction only from Object */ - inline MatrixTransformation3D() {} + inline explicit MatrixTransformation3D() = default; private: Math::Matrix4 _transformation; diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 5c87c5a47..b6f06696d 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -105,7 +105,7 @@ template class Object: public AbstractObject* parent = nullptr): counter(0xFFFFu), flags(Flag::Dirty) { + inline explicit Object(Object* parent = nullptr): counter(0xFFFFu), flags(Flag::Dirty) { setParent(parent); } diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index eecc231f0..9f06d3f8a 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -31,6 +31,8 @@ See @ref scenegraph for introduction. */ template class Scene: public Object { public: + explicit Scene() = default; + inline bool isScene() const { return true; } }; diff --git a/src/Shader.h b/src/Shader.h index 798a6c223..3fb8d6c3d 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -135,7 +135,7 @@ class MAGNUM_EXPORT Shader { * beginning. Sources can be added with addSource() or addFile(). * @see fromData(), fromFile(), @fn_gl{CreateShader} */ - Shader(Version version, Type type); + explicit Shader(Version version, Type type); /** * @brief Destructor diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index dc83f8d60..33ee62607 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -40,7 +40,7 @@ template class MAGNUM_SHADERS_EXPORT FlatShader: public /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::PointType> Position; - FlatShader(); + explicit FlatShader(); /** * @brief Set transformation and projection matrix diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index cbfc4eba6..ff0d483cf 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -38,7 +38,7 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ - PhongShader(); + explicit PhongShader(); /** * @brief Set ambient color diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index c529521ff..061022a91 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -43,7 +43,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: /** @brief Vertex color */ typedef Attribute<1, Color3<>> Color; - VertexColorShader(); + explicit VertexColorShader(); /** * @brief Set transformation and projection matrix diff --git a/src/SizeTraits.h b/src/SizeTraits.h index d221fcada..f007d5e4c 100644 --- a/src/SizeTraits.h +++ b/src/SizeTraits.h @@ -113,7 +113,7 @@ template struct SizeBasedCall: public Base { * @brief Constructor * @param size Data size */ - SizeBasedCall(std::size_t size): size(size) {} + explicit SizeBasedCall(std::size_t size): size(size) {} /** * @brief Functor diff --git a/src/Texture.h b/src/Texture.h index cc7ec7ff5..c3da55f57 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -169,7 +169,7 @@ template class Texture: public AbstractTexture { * * Creates one OpenGL texture. */ - inline Texture(Target target = DataHelper::target()): AbstractTexture(static_cast(target)) {} + inline explicit Texture(Target target = DataHelper::target()): AbstractTexture(static_cast(target)) {} /** @brief %Texture target */ inline constexpr Target target() const { return static_cast(_target); } diff --git a/src/Timeline.h b/src/Timeline.h index 42c22249e..581f2ba2b 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -78,7 +78,7 @@ class MAGNUM_EXPORT Timeline { * Creates stopped timeline. * @see start() */ - inline constexpr Timeline(): _minimalFrameTime(0), _previousFrameDuration(0), running(false) {} + inline constexpr explicit Timeline(): _minimalFrameTime(0), _previousFrameDuration(0), running(false) {} /** @brief Minimal frame time (in seconds) */ inline constexpr GLfloat minimalFrameTime() const { diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 23cef208c..2d2557661 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -75,7 +75,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { typedef Corrade::Containers::EnumSet Features; /** @brief Constructor */ - inline AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = ""): Plugin(manager, plugin) {} + inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = ""): Plugin(manager, plugin) {} /** @brief Features supported by this importer */ virtual Features features() const = 0; From 6e6e53886d35288e773cf84d307ce1b58d5f978f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 18:50:29 +0100 Subject: [PATCH 049/567] Removed dead code. --- src/Math/MathTypeTraits.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 7b4693cf6..2b54f8e3a 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -120,18 +120,6 @@ template struct MathTypeTraitsFloatingPoint { } }; -template struct MathTypeTraitsLong {}; - -template<> struct MathTypeTraitsLong<4> { - typedef std::uint32_t UnsignedType; - typedef std::int32_t Type; -}; - -template<> struct MathTypeTraitsLong<8> { - typedef std::uint64_t UnsignedType; - typedef std::int64_t Type; -}; - } template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { From 72d48ac3e736a6886781fa503eb197f33e39588b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 23:26:06 +0100 Subject: [PATCH 050/567] More intuitive framebuffer attachment mapping. --- src/DefaultFramebuffer.cpp | 22 +++++++++++++++++----- src/DefaultFramebuffer.h | 29 +++++++++++++++++++++++------ src/Framebuffer.cpp | 28 ++++++++++++++++++++-------- src/Framebuffer.h | 31 ++++++++++++++++++++++++------- 4 files changed, 84 insertions(+), 26 deletions(-) diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index d4a267f54..64c71c118 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -27,15 +27,27 @@ DefaultFramebuffer defaultFramebuffer; DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } #ifndef MAGNUM_TARGET_GLES2 -void DefaultFramebuffer::mapForDraw(std::initializer_list attachments) { - GLenum* _attachments = new GLenum[attachments.size()]; - for(auto it = attachments.begin(); it != attachments.end(); ++it) - _attachments[it-attachments.begin()] = static_cast(*it); +void DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { + /* Max attachment location */ + std::size_t max = 0; + for(const auto& attachment: attachments) + if(attachment.first > max) max = attachment.first; + + /* Create linear array from associative */ + GLenum* _attachments = new GLenum[max+1]; + std::fill_n(_attachments, max, GL_NONE); + for(const auto& attachment: attachments) + _attachments[attachment.first] = static_cast(attachment.second); bindInternal(drawTarget); - glDrawBuffers(attachments.size(), _attachments); + glDrawBuffers(max+1, _attachments); delete[] _attachments; } + +void DefaultFramebuffer::mapForDraw(DrawAttachment attachment) { + bindInternal(drawTarget); + glDrawBuffer(static_cast(attachment)); +} #endif void DefaultFramebuffer::mapForRead(ReadAttachment attachment) { diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 4578d6200..7781b1e37 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -168,21 +168,38 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #ifndef MAGNUM_TARGET_GLES2 /** - * @brief Map given attachments for drawing - * @param attachments Attachments. If any value is - * @ref DrawAttachment "Attachment::None", given output is not - * used. + * @brief Map shader outputs to buffer attachment * + * @p attachments is list of shader outputs mapped to framebuffer + * buffer attachments. Shader outputs which are not listed are not + * used, you can achieve the same by passing @ref DrawAttachment "DrawAttachment::None" + * as attachment. Example usage: + * @code + * framebuffer.mapForDraw({{MyShader::ColorOutput, DefaultFramebuffer::DrawAttachment::BackLeft}, + * {MyShader::NormalOutput, DefaultFramebuffer::DrawAttachment::None}}); + * @endcode * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - void mapForDraw(std::initializer_list attachments); + void mapForDraw(std::initializer_list> attachments); + + /** + * @brief Map shader output to buffer attachment + * @param attachment Buffer attachment + * + * Similar to above function, can be used in cases when shader has + * only one (unnamed) output. + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} + * @requires_gles30 Draw attachments for default framebuffer are + * available only in OpenGL ES 3.0. + */ + void mapForDraw(DrawAttachment attachment); #endif /** * @brief Map given attachment for reading - * @param attachment Attachment + * @param attachment Buffer attachment * * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index ebb0d175d..398bd34e8 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -42,17 +42,29 @@ Framebuffer::~Framebuffer() { glDeleteFramebuffers(1, &_id); } -void Framebuffer::mapForDraw(std::initializer_list colorAttachments) { - GLenum* attachments = new GLenum[colorAttachments.size()]; - for(auto it = colorAttachments.begin(); it != colorAttachments.end(); ++it) - attachments[it-colorAttachments.begin()] = *it + GL_COLOR_ATTACHMENT0; - - bindInternal(Target::Draw); +void Framebuffer::mapForDraw(std::initializer_list> attachments) { + /* Max attachment location */ + std::size_t max = 0; + for(const auto& attachment: attachments) + if(attachment.first > max) max = attachment.first; + + /* Create linear array from associative */ + GLenum* _attachments = new GLenum[max+1]; + std::fill_n(_attachments, max, GL_NONE); + for(const auto& attachment: attachments) + _attachments[attachment.first] = attachment.second < 0 ? GL_NONE : GL_COLOR_ATTACHMENT0 + attachment.second; + + bindInternal(drawTarget); /** @todo Re-enable when extension wrangler is available for ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glDrawBuffers(colorAttachments.size(), attachments); + glDrawBuffers(max+1, _attachments); #endif - delete[] attachments; + delete[] _attachments; +} + +void Framebuffer::mapForDraw(std::int8_t attachment) { + bindInternal(drawTarget); + glDrawBuffer(static_cast(attachment)); } void Framebuffer::mapForRead(std::uint8_t colorAttachment) { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index a146dd6dc..062fed400 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -49,23 +49,40 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { ~Framebuffer(); /** - * @brief Map given color attachments of current framebuffer for drawing - * @param colorAttachments Color attachment IDs. If any value is -1, - * given output is not used. + * @brief Map shader output to color attachment * + * @p attachments is list of shader outputs mapped to framebuffer + * color attachment IDs. Shader outputs which are not listed are not + * used, you can achieve the same by passing `-1` as color attachment + * ID. Example usage: + * @code + * framebuffer.mapForDraw({{MyShader::ColorOutput, 0}, + * {MyShader::NormalOutput, 1}}); + * @endcode * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - void mapForDraw(std::initializer_list colorAttachments); + void mapForDraw(std::initializer_list> attachments); /** - * @brief Map given color attachment of current framebuffer for reading - * @param colorAttachment Color attachment ID + * @brief Map shader output to color attachment + * @param attachment Color attachment ID + * + * Similar to above function, can be used in cases when shader has + * only one (unnamed) output. + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} + * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} + */ + void mapForDraw(std::int8_t attachment); + + /** + * @brief Map given color attachment for reading + * @param attachment Color attachment ID * * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - void mapForRead(std::uint8_t colorAttachment); + void mapForRead(std::uint8_t attachment); /** * @brief Attachment for depth/stencil part of fragment shader output From 7d04b7d51145fd7d9389e7acafb19bcb179c0c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 23:26:36 +0100 Subject: [PATCH 051/567] Doc++ Basic framebuffer usage, mentioned framebuffer attachments in shader documentation. --- src/AbstractShaderProgram.h | 46 ++++++++++++++++++++-------------- src/DefaultFramebuffer.h | 32 +++++++++++++++++++++++- src/Framebuffer.h | 49 ++++++++++++++++++++++++++++++++++++- src/Mesh.h | 3 ++- src/Renderbuffer.h | 4 +-- 5 files changed, 111 insertions(+), 23 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 10d48afe0..ed646d079 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -57,22 +57,28 @@ typedef Attribute<0, Point3D> Position; typedef Attribute<1, Vector3> Normal; typedef Attribute<2, Vector2> TextureCoordinates; @endcode - @todoc Output attribute location (for bindFragmentDataLocationIndexed(), - referenced also from Framebuffer::mapDefaultForDraw() / Framebuffer::mapForDraw()) - + - **Output attribute locations**, if desired, for example: +@code +enum: GLuint { + ColorOutput = 0, + NormalOutput = 1 +}; +@endcode - **Layers for texture uniforms** to which the textures will be bound before rendering, for example: @code -static const GLint DiffuseTextureLayer = 0; -static const GLint SpecularTextureLayer = 1; +enum: GLint { + DiffuseTextureLayer = 0, + SpecularTextureLayer = 1 +}; @endcode - **Uniform locations** for setting uniform data (see below) (private - constants), for example: + variables), for example: @code -static const GLint TransformationUniform = 0; -static const GLint ProjectionUniform = 1; -static const GLint DiffuseTextureUniform = 2; -static const GLint SpecularTextureUniform = 3; +GLint TransformationUniform = 0, + ProjectionUniform = 1, + DiffuseTextureUniform = 2, + SpecularTextureUniform = 3; @endcode - **Constructor**, which attaches particular shaders, links the program and gets uniform locations, for example: @@ -112,12 +118,13 @@ layout(location = 0) in vec4 position; layout(location = 1) in vec3 normal; layout(location = 2) in vec2 textureCoordinates; @endcode + Similarly for ouput attributes, you can also specify blend equation color index for them (see Framebuffer::BlendFunction for more information about using color input index): @code layout(location = 0, index = 0) out vec4 color; -layout(location = 1, index = 1) out vec4 ambient; +layout(location = 1, index = 1) out vec3 normal; @endcode If you don't have the required extension, you can use functions @@ -131,8 +138,8 @@ bindAttributeLocation(Position::Location, "position"); bindAttributeLocation(Normal::Location, "normal"); bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); -bindFragmentDataLocationIndexed(0, 0, "color"); -bindFragmentDataLocationIndexed(1, 1, "ambient"); +bindFragmentDataLocationIndexed(ColorOutput, 0, "color"); +bindFragmentDataLocationIndexed(NormalOutput, 1, "normal"); // Link... @endcode @@ -198,11 +205,14 @@ setUniform(SpecularTextureUniform, SpecularTextureLayer); @section AbstractShaderProgram-rendering-workflow Rendering workflow -Basic workflow with %AbstractShaderProgram subclasses is to instance the class -and configuring attribute binding in meshes (see @ref Mesh-configuration "Mesh documentation" -for more information) at the beginning, then in draw event setting uniforms -and marking the shader for use, binding required textures to their respective -layers using AbstractTexture::bind(GLint) and calling Mesh::draw(). Example: +Basic workflow with %AbstractShaderProgram subclasses is: instance shader +class, configure attribute binding in meshes (see @ref Mesh-configuration "Mesh documentation" +for more information) and map shader outputs to framebuffer attachments if +needed (see @ref Framebuffer-usage "Framebuffer documentation" for more +information). In each draw event set uniforms, mark the shader for use, bind +specific framebuffer (if needed) and bind required textures to their +respective layers using AbstractTexture::bind(GLint). Then call Mesh::draw(). +Example: @code shader->setTransformation(transformation) ->setProjection(projection) diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 7781b1e37..92a6486c7 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -26,7 +26,37 @@ namespace Magnum { /** @brief Default framebuffer -@see @ref defaultFramebuffer, Framebuffer +Default framebuffer, i.e. the actual screen surface. It is automatically +created when Context is created and it is available through global variable +@ref defaultFramebuffer. It is by default mapped to whole screen surface. + +@section DefaultFramebuffer-usage Usage + +When you are using only the default framebuffer, the usage is simple. You +must ensure that it is properly resized when application surface is resized, +i.e. you must pass the new size in your @ref Platform::GlutApplication::viewportEvent() "viewportEvent()" +implementation, for example: +@code +void viewportEvent(const Vector2i& size) { + defaultFramebuffer.setViewport({}, size); + + // ... +} +@endcode + +Next thing you probably want is to clear all used buffers before performing +any drawing in your @ref Platform::GlutApplication::drawEvent() "drawEvent()" +implementation, for example: +@code +void drawEvent() { + defaultFramebuffer.clear(AbstractFramebuffer::Clear::Color|AbstractFramebuffer::Clear::Depth); + + // ... +} +@endcode + +See Framebuffer documentation for more involved usage, usage of non-default or +multiple framebuffers. */ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { friend class Context; diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 062fed400..f755e9ef7 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -27,7 +27,54 @@ namespace Magnum { /** @brief %Framebuffer -@see DefaultFramebuffer +Unlike DefaultFramebuffer, which is used for on-screen rendering, this class +is used for off-screen rendering, usable either in windowless applications, +texture generation or for various post-processing effects. + +@section Framebuffer-usage Example usage + +See @ref DefaultFramebuffer-usage "DefaultFramebuffer documentation" for +introduction. Imagine you have shader with multiple outputs (e.g. for deferred +rendering). You want to render them off-screen to textures and then use the +textures for actual on-screen rendering. First you need to create the +framebuffer with the same viewport as default framebuffer and attach textures +and renderbuffers to desired outputs: +@code +Framebuffer framebuffer(defaultFramebuffer.viewportPosition(), defaultFramebuffer.viewportSize()); +Texture2D color, normal; +Renderbuffer depthStencil; + +// configure the textures and allocate texture memory... + +framebuffer.attachTexture2D(Framebuffer::Target::Draw, 0, &color); +framebuffer.attachTexture2D(Framebuffer::Target::Draw, 1, &normal); +framebuffer.attachRenderbuffer(Framebuffer::Target::Draw, Framebuffer::DepthStencilAttachment::DepthStencil, &depthStencil); +@endcode + +Then you need to map outputs of your shader to color attachments in the +framebuffer: +@code +framebuffer.mapForDraw({{MyShader::ColorOutput, 0}, + {MyShader::NormalOutput, 1}}); +@endcode + +The actual @ref Platform::GlutApplication::drawEvent() "drawEvent()" might +look like this. First you clear all buffers you need, perform drawing to +off-screen framebuffer, then bind the default and render the textures on +screen: +@code +void drawEvent() { + defaultFramebuffer.clear(AbstractFramebuffer::Clear::Color) + framebuffer.clear(AbstractFramebuffer::Clear::Color|AbstractFramebuffer::Clear::Depth|AbstractFramebuffer::Clear::Stencil); + + framebuffer.bind(AbstractFramebuffer::Target::Draw); + // ... + + defaultFramebuffer.bind(AbstractFramebuffer::Target::Draw); + // ... +} +@endcode + @requires_gl30 %Extension @extension{EXT,framebuffer_object} */ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { diff --git a/src/Mesh.h b/src/Mesh.h index 931e5140b..a7df32fe1 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -95,7 +95,8 @@ mesh->addVertexBuffer(buffer, MyShader::Color(Type::UsignedByte, MyShader::Color @section Mesh-drawing Rendering meshes -Basic workflow is to set up respective shader (see +Basic workflow is: bind specific framebuffer for drawing (if needed), set up +respective shader and bind required textures (see @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" for more infromation) and call Mesh::draw(). diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 7016db189..f96b1de2e 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -29,8 +29,8 @@ namespace Magnum { /** @brief %Renderbuffer -Attachable to Framebuffer as render target. - +Attachable to framebuffer as render target, see Framebuffer documentation +for more information. @requires_gl30 %Extension @extension{EXT,framebuffer_object} */ class Renderbuffer { From 4b2551bbb57ade4b20e6229dcd161c6bf9a466d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Dec 2012 23:28:26 +0100 Subject: [PATCH 052/567] No trailing whitespace in magnum-info utility. --- src/Platform/magnum-info.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index edd30f322..01912273b 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -95,9 +95,9 @@ MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, a if(c->isExtensionSupported(extension)) d << "SUPPORTED"; else if(c->isVersionSupported(extension.requiredVersion())) - d << " - "; + d << " -"; else - d << " --- "; + d << " ---"; } Debug() << ""; From 1a7c30cdde6a9e700b87ceb6173fc5342defdc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 00:04:29 +0100 Subject: [PATCH 053/567] Tracking currently bound renderbuffer. --- src/Implementation/FramebufferState.h | 4 +-- src/Renderbuffer.cpp | 27 ++++++++++++++++++++ src/Renderbuffer.h | 36 +++++++++++---------------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/Implementation/FramebufferState.h b/src/Implementation/FramebufferState.h index f6c0b5a19..93b83f1ad 100644 --- a/src/Implementation/FramebufferState.h +++ b/src/Implementation/FramebufferState.h @@ -21,9 +21,9 @@ namespace Magnum { namespace Implementation { struct FramebufferState { - inline FramebufferState(): readBinding(0), drawBinding(0) {} + inline FramebufferState(): readBinding(0), drawBinding(0), renderbufferBinding(0) {} - GLuint readBinding, drawBinding; + GLuint readBinding, drawBinding, renderbufferBinding; Vector2i viewportPosition, viewportSize; }; diff --git a/src/Renderbuffer.cpp b/src/Renderbuffer.cpp index 6e3cb17ee..100ac550e 100644 --- a/src/Renderbuffer.cpp +++ b/src/Renderbuffer.cpp @@ -15,6 +15,33 @@ #include "Renderbuffer.h" +#include "Context.h" + +#include "Implementation/State.h" +#include "Implementation/FramebufferState.h" + namespace Magnum { +Renderbuffer::~Renderbuffer() { + /* If bound, remove itself from state */ + GLuint& binding = Context::current()->state()->framebuffer->renderbufferBinding; + if(binding == _id) binding = 0; + + glDeleteRenderbuffers(1, &_id); +} + +void Renderbuffer::setStorage(Renderbuffer::InternalFormat internalFormat, const Vector2i& size) { + bind(); + glRenderbufferStorage(GL_RENDERBUFFER, GLenum(internalFormat), size.x(), size.y()); +} + +void Renderbuffer::bind() { + GLuint& binding = Context::current()->state()->framebuffer->renderbufferBinding; + + if(binding == _id) return; + + binding = _id; + glBindRenderbuffer(GL_RENDERBUFFER, _id); +} + } diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index f96b1de2e..d61c260a1 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -31,9 +31,15 @@ namespace Magnum { Attachable to framebuffer as render target, see Framebuffer documentation for more information. + +@section Renderbuffer-performance-optimization Performance optimizations + +The engine tracks currently bound renderbuffer to avoid unnecessary calls to +@fn_gl{BindRenderbuffer} in setStorage(). + @requires_gl30 %Extension @extension{EXT,framebuffer_object} */ -class Renderbuffer { +class MAGNUM_EXPORT Renderbuffer { Renderbuffer(const Renderbuffer& other) = delete; Renderbuffer(Renderbuffer&& other) = delete; Renderbuffer& operator=(const Renderbuffer& other) = delete; @@ -513,7 +519,7 @@ class Renderbuffer { * @see @fn_gl{GenRenderbuffers} */ inline explicit Renderbuffer() { - glGenRenderbuffers(1, &renderbuffer); + glGenRenderbuffers(1, &_id); } /** @@ -522,36 +528,24 @@ class Renderbuffer { * Deletes associated OpenGL renderbuffer. * @see @fn_gl{DeleteRenderbuffers} */ - inline ~Renderbuffer() { - glDeleteRenderbuffers(1, &renderbuffer); - } + ~Renderbuffer(); /** @brief OpenGL internal renderbuffer ID */ - inline GLuint id() const { return renderbuffer; } - - /** - * @brief Bind renderbuffer - * - * @see @fn_gl{BindRenderbuffer} - */ - inline void bind() { - glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); - } + inline GLuint id() const { return _id; } /** * @brief Set renderbuffer storage * @param internalFormat Internal format * @param size Renderbuffer size * - * @see bind(), @fn_gl{RenderbufferStorage} + * @see @fn_gl{BindRenderbuffer}, @fn_gl{RenderbufferStorage} */ - inline void setStorage(InternalFormat internalFormat, const Vector2i& size) { - bind(); - glRenderbufferStorage(GL_RENDERBUFFER, GLenum(internalFormat), size.x(), size.y()); - } + void setStorage(InternalFormat internalFormat, const Vector2i& size); private: - GLuint renderbuffer; + void MAGNUM_LOCAL bind(); + + GLuint _id; }; } From 7d6b7a4b6bc20d26c86b52c5d8f1ba0aa653ca69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 12:41:54 +0100 Subject: [PATCH 054/567] Using EXT_direct_state_access in framebuffers. Framebuffer::attach*() doesn't need the target at all (meaning the attachment will be used for both reading and drawing), another misunderstanding on my side. Now the extension is used on all places where it can be used (except for unimplemented features). --- src/AbstractFramebuffer.cpp | 61 ++++++++++++ src/AbstractFramebuffer.h | 27 ++++- src/Context.cpp | 4 + src/DefaultFramebuffer.cpp | 18 +--- src/DefaultFramebuffer.h | 37 ++++++- src/Framebuffer.cpp | 119 ++++++++++------------ src/Framebuffer.h | 191 ++++++++++++++++++++++++++++-------- src/Renderbuffer.cpp | 31 +++++- src/Renderbuffer.h | 26 ++++- 9 files changed, 376 insertions(+), 138 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 079d9321f..9e7147c8e 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -25,6 +25,10 @@ namespace Magnum { +AbstractFramebuffer::DrawBuffersImplementation AbstractFramebuffer::drawBuffersImplementation = &AbstractFramebuffer::drawBuffersImplementationDefault; +AbstractFramebuffer::DrawBufferImplementation AbstractFramebuffer::drawBufferImplementation = &AbstractFramebuffer::drawBufferImplementationDefault; +AbstractFramebuffer::ReadBufferImplementation AbstractFramebuffer::readBufferImplementation = &AbstractFramebuffer::readBufferImplementationDefault; + #ifndef DOXYGEN_GENERATING_OUTPUT AbstractFramebuffer::Target AbstractFramebuffer::readTarget = AbstractFramebuffer::Target::ReadDraw; AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffer::Target::ReadDraw; @@ -130,9 +134,66 @@ void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context) readTarget = Target::Read; drawTarget = Target::Draw; } + + if(context->isExtensionSupported()) { + Debug() << "AbstractFramebuffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + + drawBuffersImplementation = &AbstractFramebuffer::drawBuffersImplementationDSA; + drawBufferImplementation = &AbstractFramebuffer::drawBufferImplementationDSA; + readBufferImplementation = &AbstractFramebuffer::readBufferImplementationDSA; + } #else static_cast(context); #endif } +void AbstractFramebuffer::drawBuffersImplementationDefault(GLsizei count, const GLenum* buffers) { + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + bindInternal(drawTarget); + glDrawBuffers(count, buffers); + #else + static_cast(count); + static_cast(buffers); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractFramebuffer::drawBuffersImplementationDSA(GLsizei count, const GLenum* buffers) { + glFramebufferDrawBuffersEXT(_id, count, buffers); +} +#endif + +void AbstractFramebuffer::drawBufferImplementationDefault(GLenum buffer) { + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + bindInternal(drawTarget); + glDrawBuffer(buffer); + #else + static_cast(buffer); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractFramebuffer::drawBufferImplementationDSA(GLenum buffer) { + glFramebufferDrawBufferEXT(_id, buffer); +} +#endif + +void AbstractFramebuffer::readBufferImplementationDefault(GLenum buffer) { + /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + bindInternal(readTarget); + glReadBuffer(buffer); + #else + static_cast(buffer); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractFramebuffer::readBufferImplementationDSA(GLenum buffer) { + glFramebufferReadBufferEXT(_id, buffer); +} +#endif + } diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 542e00a12..777ed7dc6 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -255,7 +255,17 @@ class MAGNUM_EXPORT AbstractFramebuffer { void MAGNUM_LOCAL bindInternal(Target target); void MAGNUM_LOCAL setViewportInternal(); - static Target readTarget, drawTarget; + static MAGNUM_LOCAL Target readTarget; + static MAGNUM_LOCAL Target drawTarget; + + typedef void(AbstractFramebuffer::*DrawBuffersImplementation)(GLsizei, const GLenum*); + static MAGNUM_LOCAL DrawBuffersImplementation drawBuffersImplementation; + + typedef void(AbstractFramebuffer::*DrawBufferImplementation)(GLenum); + static DrawBufferImplementation drawBufferImplementation; + + typedef void(AbstractFramebuffer::*ReadBufferImplementation)(GLenum); + static ReadBufferImplementation readBufferImplementation; GLuint _id; Vector2i _viewportPosition, _viewportSize; @@ -263,6 +273,21 @@ class MAGNUM_EXPORT AbstractFramebuffer { private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + + void MAGNUM_LOCAL drawBuffersImplementationDefault(GLsizei count, const GLenum* buffers); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL drawBuffersImplementationDSA(GLsizei count, const GLenum* buffers); + #endif + + void MAGNUM_LOCAL drawBufferImplementationDefault(GLenum buffer); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL drawBufferImplementationDSA(GLenum buffer); + #endif + + void MAGNUM_LOCAL readBufferImplementationDefault(GLenum buffer); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL readBufferImplementationDSA(GLenum buffer); + #endif }; inline AbstractFramebuffer::~AbstractFramebuffer() {} diff --git a/src/Context.cpp b/src/Context.cpp index 8aaaf98ed..d1ac1e884 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -28,8 +28,10 @@ #include "DebugMarker.h" #include "DefaultFramebuffer.h" #include "Extensions.h" +#include "Framebuffer.h" #include "IndexedMesh.h" #include "Mesh.h" +#include "Renderbuffer.h" #include "Implementation/State.h" @@ -304,8 +306,10 @@ Context::Context() { #endif DebugMarker::initializeContextBasedFunctionality(this); DefaultFramebuffer::initializeContextBasedFunctionality(this); + Framebuffer::initializeContextBasedFunctionality(this); IndexedMesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this); + Renderbuffer::initializeContextBasedFunctionality(this); } Context::~Context() { diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 64c71c118..38081e96b 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -39,27 +39,11 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list(attachment.second); - bindInternal(drawTarget); - glDrawBuffers(max+1, _attachments); + (this->*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; } - -void DefaultFramebuffer::mapForDraw(DrawAttachment attachment) { - bindInternal(drawTarget); - glDrawBuffer(static_cast(attachment)); -} #endif -void DefaultFramebuffer::mapForRead(ReadAttachment attachment) { - bindInternal(readTarget); - /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glReadBuffer(static_cast(attachment)); - #else - static_cast(attachment); - #endif -} - void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) { Implementation::FramebufferState* state = context->state()->framebuffer; diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 92a6486c7..4262fe6a4 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -57,6 +57,15 @@ void drawEvent() { See Framebuffer documentation for more involved usage, usage of non-default or multiple framebuffers. + +@section DefaultFramebuffer-performance-optimization Performance optimizations + +See also @ref AbstractFramebuffer-performance-optimization "relevant section in AbstractFramebuffer". + +If extension @extension{EXT,direct_state_access} is available, functions +mapForDraw() and mapForRead() use DSA to avoid unnecessary calls to +@fn_gl{BindFramebuffer}. See their respective documentation for more +information. */ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { friend class Context; @@ -208,7 +217,12 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * framebuffer.mapForDraw({{MyShader::ColorOutput, DefaultFramebuffer::DrawAttachment::BackLeft}, * {MyShader::NormalOutput, DefaultFramebuffer::DrawAttachment::None}}); * @endcode - * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} + * + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} or + * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ @@ -220,21 +234,34 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. - * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} + * + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} or + * @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - void mapForDraw(DrawAttachment attachment); + inline void mapForDraw(DrawAttachment attachment) { + (this->*drawBufferImplementation)(static_cast(attachment)); + } #endif /** * @brief Map given attachment for reading * @param attachment Buffer attachment * - * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} or + * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - void mapForRead(ReadAttachment attachment); + inline void mapForRead(ReadAttachment attachment) { + (this->*readBufferImplementation)(static_cast(attachment)); + } private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 398bd34e8..def6ea157 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -17,6 +17,7 @@ #include "BufferImage.h" #include "Context.h" +#include "Extensions.h" #include "Image.h" #include "Renderbuffer.h" #include "Texture.h" @@ -26,6 +27,13 @@ namespace Magnum { +Framebuffer::RenderbufferImplementation Framebuffer::renderbufferImplementation = &Framebuffer::renderbufferImplementationDefault; +#ifndef MAGNUM_TARGET_GLES +Framebuffer::Texture1DImplementation Framebuffer::texture1DImplementation = &Framebuffer::texture1DImplementationDefault; +#endif +Framebuffer::Texture2DImplementation Framebuffer::texture2DImplementation = &Framebuffer::texture2DImplementationDefault; +Framebuffer::Texture3DImplementation Framebuffer::texture3DImplementation = &Framebuffer::texture3DImplementationDefault; + Framebuffer::Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize) { _viewportPosition = viewportPosition; _viewportSize = viewportSize; @@ -54,103 +62,84 @@ void Framebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; } -void Framebuffer::mapForDraw(std::int8_t attachment) { - bindInternal(drawTarget); - glDrawBuffer(static_cast(attachment)); +void Framebuffer::attachTexture2D(DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + (this->*texture2DImplementation)(GLenum(depthStencilAttachment), GLenum(texture->target()), texture->id(), mipLevel); } -void Framebuffer::mapForRead(std::uint8_t colorAttachment) { - bindInternal(Target::Read); - /** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ - #ifndef MAGNUM_TARGET_GLES2 - glReadBuffer(GL_COLOR_ATTACHMENT0 + colorAttachment); - #else - static_cast(colorAttachment); - #endif +void Framebuffer::attachTexture2D(std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + (this->*texture2DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, GLenum(texture->target()), texture->id(), mipLevel); } -void Framebuffer::attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { - bindInternal(target); - glFramebufferRenderbuffer(static_cast(target), static_cast(depthStencilAttachment), GL_RENDERBUFFER, renderbuffer->id()); +void Framebuffer::initializeContextBasedFunctionality(Context* context) { + #ifndef MAGNUM_TARGET_GLES + if(context->isExtensionSupported()) { + Debug() << "Framebuffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + + renderbufferImplementation = &Framebuffer::renderbufferImplementationDSA; + texture1DImplementation = &Framebuffer::texture1DImplementationDSA; + texture2DImplementation = &Framebuffer::texture2DImplementationDSA; + texture3DImplementation = &Framebuffer::texture3DImplementationDSA; + } + #else + static_cast(context); + #endif } -void Framebuffer::attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { - bindInternal(target); - glFramebufferRenderbuffer(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, GL_RENDERBUFFER, renderbuffer->id()); +void Framebuffer::renderbufferImplementationDefault(GLenum attachment, Renderbuffer* renderbuffer) { + bindInternal(drawTarget); + glFramebufferRenderbuffer(static_cast(drawTarget), attachment, GL_RENDERBUFFER, renderbuffer->id()); } #ifndef MAGNUM_TARGET_GLES -void Framebuffer::attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bindInternal(target); - glFramebufferTexture1D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); +void Framebuffer::renderbufferImplementationDSA(GLenum attachment, Renderbuffer* renderbuffer) { + glNamedFramebufferRenderbufferEXT(_id, attachment, GL_RENDERBUFFER, renderbuffer->id()); } -void Framebuffer::attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bindInternal(target); - glFramebufferTexture1D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); -} -#endif - -void Framebuffer::attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bindInternal(target); - glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel); +void Framebuffer::texture1DImplementationDefault(GLenum attachment, Texture1D* texture, GLint mipLevel) { + bindInternal(drawTarget); + glFramebufferTexture1D(static_cast(drawTarget), attachment, static_cast(texture->target()), texture->id(), mipLevel); } -void Framebuffer::attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - bindInternal(target); - glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel); +void Framebuffer::texture1DImplementationDSA(GLenum attachment, Texture1D* texture, GLint mipLevel) { + glNamedFramebufferTexture1DEXT(_id, attachment, GLenum(texture->target()), texture->id(), mipLevel); } +#endif -void Framebuffer::attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { - /** @todo Check for internal format compatibility */ - bindInternal(target); - glFramebufferTexture2D(static_cast(target), static_cast(depthStencilAttachment), static_cast(coordinate), texture->id(), mipLevel); +void Framebuffer::texture2DImplementationDefault(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { + bindInternal(drawTarget); + glFramebufferTexture2D(static_cast(drawTarget), attachment, textureTarget, textureId, mipLevel); } -void Framebuffer::attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { - /** @todo Check for internal format compatibility */ - bindInternal(target); - glFramebufferTexture2D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(coordinate), texture->id(), mipLevel); +#ifndef MAGNUM_TARGET_GLES +void Framebuffer::texture2DImplementationDSA(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { + glNamedFramebufferTexture2DEXT(_id, attachment, textureTarget, textureId, mipLevel); } +#endif -void Framebuffer::attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { +void Framebuffer::texture3DImplementationDefault(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer) { /** @todo Check for texture target compatibility */ - bindInternal(target); + bindInternal(drawTarget); /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ #ifndef MAGNUM_TARGET_GLES - glFramebufferTexture3D(static_cast(target), static_cast(depthStencilAttachment), static_cast(texture->target()), texture->id(), mipLevel, layer); + glFramebufferTexture3D(static_cast(drawTarget), attachment, static_cast(texture->target()), texture->id(), mipLevel, layer); #else - static_cast(depthStencilAttachment); + static_cast(attachment); static_cast(texture); static_cast(mipLevel); static_cast(layer); #endif } -void Framebuffer::attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { - /** @todo Check for texture target compatibility */ - bindInternal(target); - /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ - #ifndef MAGNUM_TARGET_GLES - glFramebufferTexture3D(static_cast(target), GL_COLOR_ATTACHMENT0 + colorAttachment, static_cast(texture->target()), texture->id(), mipLevel, layer); - #else - static_cast(colorAttachment); - static_cast(texture); - static_cast(mipLevel); - static_cast(layer); - #endif +#ifndef MAGNUM_TARGET_GLES +void Framebuffer::texture3DImplementationDSA(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer) { + glNamedFramebufferTexture3DEXT(_id, attachment, GLenum(texture->target()), texture->id(), mipLevel, layer); } +#endif } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index f755e9ef7..6bc7104a0 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -46,9 +46,9 @@ Renderbuffer depthStencil; // configure the textures and allocate texture memory... -framebuffer.attachTexture2D(Framebuffer::Target::Draw, 0, &color); -framebuffer.attachTexture2D(Framebuffer::Target::Draw, 1, &normal); -framebuffer.attachRenderbuffer(Framebuffer::Target::Draw, Framebuffer::DepthStencilAttachment::DepthStencil, &depthStencil); +framebuffer.attachTexture2D(0, &color); +framebuffer.attachTexture2D(1, &normal); +framebuffer.attachRenderbuffer(Framebuffer::DepthStencilAttachment::DepthStencil, &depthStencil); @endcode Then you need to map outputs of your shader to color attachments in the @@ -75,9 +75,21 @@ void drawEvent() { } @endcode +@section Framebuffer-performance-optimization Performance optimizations + +See also @ref AbstractFramebuffer-performance-optimization "relevant section in AbstractFramebuffer". + +If extension @extension{EXT,direct_state_access} is available, functions +mapForDraw(), mapForRead(), attachRenderbuffer(), attachTexture1D(), +attachTexture2D(), attachCubeMapTexture() and attachTexture3D() use DSA +to avoid unnecessary calls to @fn_gl{BindFramebuffer}. See their respective +documentation for more information. + @requires_gl30 %Extension @extension{EXT,framebuffer_object} */ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { + friend class Context; + public: /** * @brief Constructor @@ -106,7 +118,12 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * framebuffer.mapForDraw({{MyShader::ColorOutput, 0}, * {MyShader::NormalOutput, 1}}); * @endcode - * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} + * + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} or + * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ void mapForDraw(std::initializer_list> attachments); @@ -117,19 +134,32 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. - * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} + * + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} or + * @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - void mapForDraw(std::int8_t attachment); + inline void mapForDraw(std::int8_t attachment) { + (this->*drawBufferImplementation)(static_cast(GL_COLOR_ATTACHMENT0 + attachment)); + } /** * @brief Map given color attachment for reading * @param attachment Color attachment ID * - * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} or + * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - void mapForRead(std::uint8_t attachment); + inline void mapForRead(std::uint8_t attachment) { + (this->*readBufferImplementation)(GL_COLOR_ATTACHMENT0 + attachment); + } /** * @brief Attachment for depth/stencil part of fragment shader output @@ -155,127 +185,204 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { /** * @brief Attach renderbuffer to given framebuffer depth/stencil attachment - * @param target %Target * @param depthStencilAttachment Depth/stencil attachment * @param renderbuffer %Renderbuffer * - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or + * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} */ - void attachRenderbuffer(Target target, DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer); + inline void attachRenderbuffer(DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { + (this->*renderbufferImplementation)(GLenum(depthStencilAttachment), renderbuffer); + } /** * @brief Attach renderbuffer to given framebuffer color attachment - * @param target %Target * @param colorAttachment Color attachment ID (number between 0 and 15) * @param renderbuffer %Renderbuffer * - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or + * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} */ - void attachRenderbuffer(Target target, std::uint8_t colorAttachment, Renderbuffer* renderbuffer); + inline void attachRenderbuffer(std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { + (this->*renderbufferImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, renderbuffer); + } #ifndef MAGNUM_TARGET_GLES /** * @brief Attach 1D texture to given framebuffer depth/stencil attachment - * @param target %Target * @param depthStencilAttachment Depth/stencil attachment * @param texture 1D texture * @param mipLevel Mip level * - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} or + * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - void attachTexture1D(Target target, DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel); + inline void attachTexture1D(DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + (this->*texture1DImplementation)(GLenum(depthStencilAttachment), texture, mipLevel); + } /** * @brief Attach 1D texture to given framebuffer color attachment - * @param target %Target * @param colorAttachment Color attachment ID (number between 0 and 15) * @param texture 1D texture * @param mipLevel Mip level * - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} or + * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - void attachTexture1D(Target target, std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel); + inline void attachTexture1D(std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { + /** @todo Check for texture target compatibility */ + (this->*texture1DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, texture, mipLevel); + } #endif /** * @brief Attach 2D texture to given framebuffer depth/stencil attachment - * @param target %Target * @param depthStencilAttachment Depth/stencil attachment * @param texture 2D texture * @param mipLevel Mip level. For rectangle textures it * should be always 0. * - * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, - * @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachTexture2D(Target target, DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel); + void attachTexture2D(DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel); /** * @brief Attach 2D texture to given framebuffer color attachment - * @param target %Target * @param colorAttachment Color attachment ID (number between 0 and 15) * @param texture 2D texture * @param mipLevel Mip level. For rectangle textures it * should be always 0. * - * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, - * @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachTexture2D(Target target, std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel); + void attachTexture2D(std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel); /** * @brief Attach cube map texture to given framebuffer depth/stencil attachment - * @param target %Target * @param depthStencilAttachment Depth/stencil attachment * @param texture Cube map texture * @param coordinate Cube map coordinate * @param mipLevel Mip level * - * @see attachTexture2D(), @fn_gl{BindFramebuffer}, - * @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachCubeMapTexture(Target target, DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel); + inline void attachCubeMapTexture(DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { + (this->*texture2DImplementation)(GLenum(depthStencilAttachment), GLenum(coordinate), texture->id(), mipLevel); + } /** * @brief Attach cube map texture to given framebuffer color attachment - * @param target %Target * @param colorAttachment Color attachment ID (number between 0 and 15) * @param texture Cube map texture * @param coordinate Cube map coordinate * @param mipLevel Mip level * - * @see attachTexture2D(), @fn_gl{BindFramebuffer}, - * @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachCubeMapTexture(Target target, std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel); + inline void attachCubeMapTexture(std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { + (this->*texture2DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, GLenum(coordinate), texture->id(), mipLevel); + } /** * @brief Attach 3D texture to given framebuffer depth/stencil attachment - * @param target %Target * @param depthStencilAttachment Depth/stencil attachment * @param texture 3D texture * @param mipLevel Mip level * @param layer Layer of 2D image within a 3D texture * - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} or + * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - void attachTexture3D(Target target, DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer); + inline void attachTexture3D(DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { + /** @todo Check for texture target compatibility */ + (this->*texture3DImplementation)(GLenum(depthStencilAttachment), texture, mipLevel, layer); + } /** * @brief Attach 3D texture to given framebuffer color attachment - * @param target %Target * @param colorAttachment Color attachment ID (number between 0 and 15) * @param texture 3D texture * @param mipLevel Mip level * @param layer Layer of 2D image within a 3D texture. * - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} or + * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - void attachTexture3D(Target target, std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer); + inline void attachTexture3D(std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { + /** @todo Check for texture target compatibility */ + (this->*texture3DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, texture, mipLevel, layer); + } + + private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + + typedef void(Framebuffer::*RenderbufferImplementation)(GLenum, Renderbuffer*); + void MAGNUM_LOCAL renderbufferImplementationDefault(GLenum attachment, Renderbuffer* renderbuffer); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL renderbufferImplementationDSA(GLenum attachment, Renderbuffer* renderbuffer); + #endif + static RenderbufferImplementation renderbufferImplementation; + + #ifndef MAGNUM_TARGET_GLES + typedef void(Framebuffer::*Texture1DImplementation)(GLenum, Texture1D*, GLint); + void MAGNUM_LOCAL texture1DImplementationDefault(GLenum attachment, Texture1D* texture, GLint mipLevel); + void MAGNUM_LOCAL texture1DImplementationDSA(GLenum attachment, Texture1D* texture, GLint mipLevel); + static Texture1DImplementation texture1DImplementation; + #endif + + typedef void(Framebuffer::*Texture2DImplementation)(GLenum, GLenum, GLuint, GLint); + void MAGNUM_LOCAL texture2DImplementationDefault(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL texture2DImplementationDSA(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel); + #endif + static MAGNUM_LOCAL Texture2DImplementation texture2DImplementation; + + typedef void(Framebuffer::*Texture3DImplementation)(GLenum, Texture3D*, GLint, GLint); + void MAGNUM_LOCAL texture3DImplementationDefault(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL texture3DImplementationDSA(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer); + #endif + static Texture3DImplementation texture3DImplementation; }; } diff --git a/src/Renderbuffer.cpp b/src/Renderbuffer.cpp index 100ac550e..afb9d1f26 100644 --- a/src/Renderbuffer.cpp +++ b/src/Renderbuffer.cpp @@ -16,12 +16,15 @@ #include "Renderbuffer.h" #include "Context.h" +#include "Extensions.h" #include "Implementation/State.h" #include "Implementation/FramebufferState.h" namespace Magnum { +Renderbuffer::StorageImplementation Renderbuffer::storageImplementation = &Renderbuffer::storageImplementationDefault; + Renderbuffer::~Renderbuffer() { /* If bound, remove itself from state */ GLuint& binding = Context::current()->state()->framebuffer->renderbufferBinding; @@ -30,11 +33,6 @@ Renderbuffer::~Renderbuffer() { glDeleteRenderbuffers(1, &_id); } -void Renderbuffer::setStorage(Renderbuffer::InternalFormat internalFormat, const Vector2i& size) { - bind(); - glRenderbufferStorage(GL_RENDERBUFFER, GLenum(internalFormat), size.x(), size.y()); -} - void Renderbuffer::bind() { GLuint& binding = Context::current()->state()->framebuffer->renderbufferBinding; @@ -44,4 +42,27 @@ void Renderbuffer::bind() { glBindRenderbuffer(GL_RENDERBUFFER, _id); } +void Renderbuffer::initializeContextBasedFunctionality(Context* context) { + #ifndef MAGNUM_TARGET_GLES + if(context->isExtensionSupported()) { + Debug() << "Renderbuffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; + + storageImplementation = &Renderbuffer::storageImplementationDSA; + } + #else + static_cast(context); + #endif +} + +void Renderbuffer::storageImplementationDefault(Renderbuffer::InternalFormat internalFormat, const Vector2i& size) { + bind(); + glRenderbufferStorage(GL_RENDERBUFFER, GLenum(internalFormat), size.x(), size.y()); +} + +#ifndef MAGNUM_TARGET_GLES +void Renderbuffer::storageImplementationDSA(Renderbuffer::InternalFormat internalFormat, const Vector2i& size) { + glNamedRenderbufferStorageEXT(_id, GLenum(internalFormat), size.x(), size.y()); +} +#endif + } diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index d61c260a1..266bad113 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -19,7 +19,6 @@ * @brief Class Magnum::Renderbuffer */ -#include "Math/Vector2.h" #include "Magnum.h" #include "magnumVisibility.h" @@ -37,9 +36,15 @@ for more information. The engine tracks currently bound renderbuffer to avoid unnecessary calls to @fn_gl{BindRenderbuffer} in setStorage(). +If extension @extension{EXT,direct_state_access} is available, function +setStorage() uses DSA to avoid unnecessary calls to @fn_gl{BindFramebuffer}. +See its documentation for more information. + @requires_gl30 %Extension @extension{EXT,framebuffer_object} */ class MAGNUM_EXPORT Renderbuffer { + friend class Context; + Renderbuffer(const Renderbuffer& other) = delete; Renderbuffer(Renderbuffer&& other) = delete; Renderbuffer& operator=(const Renderbuffer& other) = delete; @@ -538,11 +543,26 @@ class MAGNUM_EXPORT Renderbuffer { * @param internalFormat Internal format * @param size Renderbuffer size * - * @see @fn_gl{BindRenderbuffer}, @fn_gl{RenderbufferStorage} + * If @extension{EXT,direct_state_access} is not available and the + * framebufferbuffer is not currently bound, it is bound before the + * operation. + * @see @fn_gl{BindRenderbuffer}, @fn_gl{RenderbufferStorage} or + * @fn_gl_extension{NamedRenderbufferStorage,EXT,direct_state_access} */ - void setStorage(InternalFormat internalFormat, const Vector2i& size); + inline void setStorage(InternalFormat internalFormat, const Vector2i& size) { + (this->*storageImplementation)(internalFormat, size); + } private: + static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); + + typedef void(Renderbuffer::*StorageImplementation)(InternalFormat, const Vector2i&); + void MAGNUM_LOCAL storageImplementationDefault(InternalFormat internalFormat, const Vector2i& size); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL storageImplementationDSA(InternalFormat internalFormat, const Vector2i& size); + #endif + static StorageImplementation storageImplementation; + void MAGNUM_LOCAL bind(); GLuint _id; From 5ef4dbbe3c3abee8a6ec3643d16e35ff673abff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 18:38:55 +0100 Subject: [PATCH 055/567] Reuse any binding (not just draw) when adding framebuffer attachments. --- src/AbstractFramebuffer.cpp | 19 +++++++++++++++++++ src/AbstractFramebuffer.h | 1 + src/Framebuffer.cpp | 12 ++++-------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 9e7147c8e..979576fe9 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -57,6 +57,25 @@ void AbstractFramebuffer::bindInternal(Target target) { glBindFramebuffer(static_cast(target), _id); } + +AbstractFramebuffer::Target AbstractFramebuffer::bindInternal() { + Implementation::FramebufferState* state = Context::current()->state()->framebuffer; + + /* Return target to which the framebuffer is already bound */ + if(state->readBinding == _id && state->drawBinding == _id) + return Target::ReadDraw; + if(state->readBinding == _id) + return Target::Read; + if(state->drawBinding == _id) + return Target::Draw; + + /* Or bind it, if not already */ + state->readBinding = _id; + if(readTarget == Target::ReadDraw) state->drawBinding = _id; + + glBindFramebuffer(GLenum(readTarget), _id); + return readTarget; +} #endif void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) { diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 777ed7dc6..c6f34a106 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -253,6 +253,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { #ifndef DOXYGEN_GENERATING_OUTPUT protected: void MAGNUM_LOCAL bindInternal(Target target); + Target MAGNUM_LOCAL bindInternal(); void MAGNUM_LOCAL setViewportInternal(); static MAGNUM_LOCAL Target readTarget; diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index def6ea157..afe16cd3d 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -92,8 +92,7 @@ void Framebuffer::initializeContextBasedFunctionality(Context* context) { } void Framebuffer::renderbufferImplementationDefault(GLenum attachment, Renderbuffer* renderbuffer) { - bindInternal(drawTarget); - glFramebufferRenderbuffer(static_cast(drawTarget), attachment, GL_RENDERBUFFER, renderbuffer->id()); + glFramebufferRenderbuffer(GLenum(bindInternal()), attachment, GL_RENDERBUFFER, renderbuffer->id()); } #ifndef MAGNUM_TARGET_GLES @@ -102,8 +101,7 @@ void Framebuffer::renderbufferImplementationDSA(GLenum attachment, Renderbuffer* } void Framebuffer::texture1DImplementationDefault(GLenum attachment, Texture1D* texture, GLint mipLevel) { - bindInternal(drawTarget); - glFramebufferTexture1D(static_cast(drawTarget), attachment, static_cast(texture->target()), texture->id(), mipLevel); + glFramebufferTexture1D(GLenum(bindInternal()), attachment, static_cast(texture->target()), texture->id(), mipLevel); } void Framebuffer::texture1DImplementationDSA(GLenum attachment, Texture1D* texture, GLint mipLevel) { @@ -112,8 +110,7 @@ void Framebuffer::texture1DImplementationDSA(GLenum attachment, Texture1D* textu #endif void Framebuffer::texture2DImplementationDefault(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { - bindInternal(drawTarget); - glFramebufferTexture2D(static_cast(drawTarget), attachment, textureTarget, textureId, mipLevel); + glFramebufferTexture2D(GLenum(bindInternal()), attachment, textureTarget, textureId, mipLevel); } #ifndef MAGNUM_TARGET_GLES @@ -124,10 +121,9 @@ void Framebuffer::texture2DImplementationDSA(GLenum attachment, GLenum textureTa void Framebuffer::texture3DImplementationDefault(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer) { /** @todo Check for texture target compatibility */ - bindInternal(drawTarget); /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ #ifndef MAGNUM_TARGET_GLES - glFramebufferTexture3D(static_cast(drawTarget), attachment, static_cast(texture->target()), texture->id(), mipLevel, layer); + glFramebufferTexture3D(GLenum(bindInternal()), attachment, static_cast(texture->target()), texture->id(), mipLevel, layer); #else static_cast(attachment); static_cast(texture); From c0827baafdd4f85215e04ec546583559aa69692d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 18:53:11 +0100 Subject: [PATCH 056/567] Allow building _only_ NaClApplication if on NaCl. --- CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 991605382..e64fa92e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,13 +17,14 @@ cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYT cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) -option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF) -cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library" OFF "NOT WITH_MAGNUMINFO" ON) -cmake_dependent_option(WITH_XEGLAPPLICATION "Build XEglApplication library" OFF "TARGET_GLES" OFF) -cmake_dependent_option(WITH_GLUTAPPLICATION "Build GlutApplication library" OFF "NOT TARGET_GLES" OFF) -option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF) if(${CMAKE_SYSTEM_NAME} STREQUAL NaCl) option(WITH_NACLAPPLICATION "Build NaClApplication library" OFF) +else() + option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF) + cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library" OFF "NOT WITH_MAGNUMINFO" ON) + cmake_dependent_option(WITH_XEGLAPPLICATION "Build XEglApplication library" OFF "TARGET_GLES" OFF) + cmake_dependent_option(WITH_GLUTAPPLICATION "Build GlutApplication library" OFF "NOT TARGET_GLES" OFF) + option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF) endif() option(BUILD_TESTS "Build unit tests." OFF) From e10b5a44737abb7af0859a5a8a8d2bca7c235d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 19:10:39 +0100 Subject: [PATCH 057/567] Updated Physics library dependencies. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e64fa92e9..9d2fe3463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,9 @@ cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF # Parts of the library option(WITH_EVERYTHING "Build everything (doesn't include contexts)" ON) -cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) -cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) From c96d0a882dcdf89e445fe216a9396d1bbd867302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 20:51:34 +0100 Subject: [PATCH 058/567] Doxygen fixes. --- src/AbstractFramebuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 979576fe9..999f64c6e 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -25,11 +25,11 @@ namespace Magnum { +#ifndef DOXYGEN_GENERATING_OUTPUT AbstractFramebuffer::DrawBuffersImplementation AbstractFramebuffer::drawBuffersImplementation = &AbstractFramebuffer::drawBuffersImplementationDefault; AbstractFramebuffer::DrawBufferImplementation AbstractFramebuffer::drawBufferImplementation = &AbstractFramebuffer::drawBufferImplementationDefault; AbstractFramebuffer::ReadBufferImplementation AbstractFramebuffer::readBufferImplementation = &AbstractFramebuffer::readBufferImplementationDefault; -#ifndef DOXYGEN_GENERATING_OUTPUT AbstractFramebuffer::Target AbstractFramebuffer::readTarget = AbstractFramebuffer::Target::ReadDraw; AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffer::Target::ReadDraw; #endif From 6ae94bffd7670785be49f6ea6c3ce706e806befb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 21:07:05 +0100 Subject: [PATCH 059/567] Ability to construct Matrix from rotation/scaling and translation parts. --- src/Math/Matrix3.h | 20 +++++++++++++++++++- src/Math/Matrix4.h | 23 ++++++++++++++++++++--- src/Math/Test/Matrix3Test.cpp | 24 ++++++++++++++++++++++++ src/Math/Test/Matrix3Test.h | 1 + src/Math/Test/Matrix4Test.cpp | 27 +++++++++++++++++++++++++++ src/Math/Test/Matrix4Test.h | 1 + 6 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 20910638d..ddf8431ae 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -83,6 +83,23 @@ template class Matrix3: public Matrix<3, T> { ); } + /** + * @brief Create matrix from rotation/scaling part and translation part + * @param rotationScaling Rotation/scaling part (upper-left 2x2 + * matrix) + * @param translation Translation part (first two elements of + * third column) + * + * @see rotationScaling() const, translation() const + */ + static Matrix3 from(const Matrix<2, T>& rotationScaling, const Vector2& translation = Vector2()) { + return from( + Vector3(rotationScaling[0], T(0)), + Vector3(rotationScaling[1], T(0)), + Vector3(translation, T(1)) + ); + } + /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {} @@ -107,7 +124,8 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D rotation and scaling part of the matrix * * Upper-left 2x2 part of the matrix. - * @see rotation() const, rotation(T), Matrix4::rotationScaling() const + * @see from(const Matrix<2, T>&, const Vector2&), rotation() const, + * rotation(T), Matrix4::rotationScaling() const */ inline Matrix<2, T> rotationScaling() const { return Matrix<2, T>::from( diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 899374fa7..2d669a7fc 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -173,6 +173,24 @@ template class Matrix4: public Matrix<4, T> { ); } + /** + * @brief Create matrix from rotation/scaling part and translation part + * @param rotationScaling Rotation/scaling part (upper-left 3x3 + * matrix) + * @param translation Translation part (first three elements of + * fourth column) + * + * @see rotationScaling() const, translation() const + */ + static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation = Vector3()) { + return from( + Vector4(rotationScaling[0], T(0)), + Vector4(rotationScaling[1], T(0)), + Vector4(rotationScaling[2], T(0)), + Vector4(translation, T(1)) + ); + } + /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} @@ -198,8 +216,8 @@ template class Matrix4: public Matrix<4, T> { * @brief 3D rotation and scaling part of the matrix * * Upper-left 3x3 part of the matrix. - * @see rotation() const, rotation(T, const Vector3&), - * Matrix3::rotationScaling() const + * @see from(const Matrix<3, T>&, const Vector3&), rotation() const, + * rotation(T, const Vector3&), Matrix3::rotationScaling() const */ inline Matrix<3, T> rotationScaling() const { /* Not Matrix3, because it is for affine 2D transformations */ @@ -224,7 +242,6 @@ template class Matrix4: public Matrix<4, T> { (*this)[2].xyz().normalized()); } - /** * @brief Right-pointing 3D vector * diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 0e7adb44b..a7e51a5e2 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -36,6 +36,7 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::translation, &Matrix3Test::scaling, &Matrix3Test::rotation, + &Matrix3Test::fromParts, &Matrix3Test::rotationScalingPart, &Matrix3Test::rotationPart, &Matrix3Test::vectorParts, @@ -95,6 +96,29 @@ void Matrix3Test::rotation() { CORRADE_COMPARE(Matrix3::rotation(deg(15.0f)), matrix); } +void Matrix3Test::fromParts() { + Matrix2 rotationScaling( + 3.0f, 5.0f, + 4.0f, 4.0f + ); + + Vector2 translation(7.0f, -1.0f); + + Matrix3 expected( + 3.0f, 5.0f, 0.0f, + 4.0f, 4.0f, 0.0f, + 7.0f, -1.0f, 1.0f + ); + CORRADE_COMPARE(Matrix3::from(rotationScaling, translation), expected); + + Matrix3 expectedNoRotation( + 3.0f, 5.0f, 0.0f, + 4.0f, 4.0f, 0.0f, + 0.0f, 0.0f, 1.0f + ); + CORRADE_COMPARE(Matrix3::from(rotationScaling), expectedNoRotation); +} + void Matrix3Test::rotationScalingPart() { Matrix3 m( 3.0f, 5.0f, 8.0f, diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h index 0b189e726..9a34ff78e 100644 --- a/src/Math/Test/Matrix3Test.h +++ b/src/Math/Test/Matrix3Test.h @@ -28,6 +28,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void translation(); void scaling(); void rotation(); + void fromParts(); void rotationScalingPart(); void rotationPart(); void vectorParts(); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 7761bd8b7..9e79985cd 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -39,6 +39,7 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotationX, &Matrix4Test::rotationY, &Matrix4Test::rotationZ, + &Matrix4Test::fromParts, &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, &Matrix4Test::vectorParts, @@ -135,6 +136,32 @@ void Matrix4Test::rotationZ() { CORRADE_COMPARE(Matrix4::rotationZ(rad(Math::Constants::pi()/7)), matrix); } +void Matrix4Test::fromParts() { + Matrix3 rotationScaling( + 3.0f, 5.0f, 8.0f, + 4.0f, 4.0f, 7.0f, + 7.0f, -1.0f, 8.0f + ); + + Vector3 translation(9.0f, 4.0f, 5.0f); + + Matrix4 expected( + 3.0f, 5.0f, 8.0f, 0.0f, + 4.0f, 4.0f, 7.0f, 0.0f, + 7.0f, -1.0f, 8.0f, 0.0f, + 9.0f, 4.0f, 5.0f, 1.0f + ); + CORRADE_COMPARE(Matrix4::from(rotationScaling, translation), expected); + + Matrix4 expectedNoTranslation( + 3.0f, 5.0f, 8.0f, 0.0f, + 4.0f, 4.0f, 7.0f, 0.0f, + 7.0f, -1.0f, 8.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + CORRADE_COMPARE(Matrix4::from(rotationScaling), expectedNoTranslation); +} + void Matrix4Test::rotationScalingPart() { Matrix4 m( 3.0f, 5.0f, 8.0f, 4.0f, diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index f00ac7393..238fa1cc2 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -31,6 +31,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotationX(); void rotationY(); void rotationZ(); + void fromParts(); void rotationScalingPart(); void rotationPart(); void vectorParts(); From e9e0de70d753b7f99cbc57621ae77a7993c46134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 21:36:59 +0100 Subject: [PATCH 060/567] Implemented reflection matrices. Long-standing TODO, can be used for in-game mirrors etc. I give up with shearing, as I think that it makes sense only in 2D and I can't find any reasonable use case for that yet. --- src/Math/Matrix3.h | 18 ++++++++++++++++-- src/Math/Matrix4.h | 20 ++++++++++++++++---- src/Math/Test/CMakeLists.txt | 2 +- src/Math/Test/Matrix3Test.cpp | 30 +++++++++++++++++++++++------- src/Math/Test/Matrix3Test.h | 1 + src/Math/Test/Matrix4Test.cpp | 32 ++++++++++++++++++++++++-------- src/Math/Test/Matrix4Test.h | 1 + 7 files changed, 82 insertions(+), 22 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index ddf8431ae..1a925a12b 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -83,6 +83,19 @@ template class Matrix3: public Matrix<3, T> { ); } + /** + * @brief 2D reflection matrix + * @param normal Normal of the line through which to reflect + * (normalized) + * + * @see Matrix4::reflection() + */ + static Matrix3 reflection(const Vector2& normal) { + CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), + "Math::Matrix3::reflection(): normal must be normalized", {}); + return from(Matrix<2, T>() - T(2)*normal*normal.transposed(), {}); + } + /** * @brief Create matrix from rotation/scaling part and translation part * @param rotationScaling Rotation/scaling part (upper-left 2x2 @@ -92,7 +105,7 @@ template class Matrix3: public Matrix<3, T> { * * @see rotationScaling() const, translation() const */ - static Matrix3 from(const Matrix<2, T>& rotationScaling, const Vector2& translation = Vector2()) { + static Matrix3 from(const Matrix<2, T>& rotationScaling, const Vector2& translation) { return from( Vector3(rotationScaling[0], T(0)), Vector3(rotationScaling[1], T(0)), @@ -167,7 +180,8 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D translation part of the matrix * * First two elements of third column. - * @see translation(const Vector2&), Matrix4::translation() + * @see from(const Matrix<2, T>&, const Vector2&), + * translation(const Vector2&), Matrix4::translation() */ inline Vector2& translation() { return (*this)[2].xy(); } inline constexpr Vector2 translation() const { return (*this)[2].xy(); } /**< @overload */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 2d669a7fc..f41458b03 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -32,8 +32,6 @@ Provides functions for transformations in 3D. See Matrix3 for 2D transformations. See also @ref matrix-vector for brief introduction. @see Magnum::Matrix4, SceneGraph::MatrixTransformation3D @configurationvalueref{Magnum::Math::Matrix4} -@todo Shearing -@todo Reflection */ template class Matrix4: public Matrix<4, T> { public: @@ -173,6 +171,19 @@ template class Matrix4: public Matrix<4, T> { ); } + /** + * @brief 3D reflection matrix + * @param normal Normal of the plane through which to reflect + * (normalized) + * + * @see Matrix3::reflection() + */ + static Matrix4 reflection(const Vector3& normal) { + CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), + "Math::Matrix4::reflection(): normal must be normalized", {}); + return from(Matrix<3, T>() - T(2)*normal*normal.transposed(), {}); + } + /** * @brief Create matrix from rotation/scaling part and translation part * @param rotationScaling Rotation/scaling part (upper-left 3x3 @@ -182,7 +193,7 @@ template class Matrix4: public Matrix<4, T> { * * @see rotationScaling() const, translation() const */ - static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation = Vector3()) { + static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation) { return from( Vector4(rotationScaling[0], T(0)), Vector4(rotationScaling[1], T(0)), @@ -273,7 +284,8 @@ template class Matrix4: public Matrix<4, T> { * @brief 3D translation part of the matrix * * First three elements of fourth column. - * @see translation(const Vector3&), Matrix3::translation() + * @see from(const Matrix<3, T>&, const Vector3&), + * translation(const Vector3&), Matrix3::translation() */ inline Vector3& translation() { return (*this)[3].xyz(); } inline constexpr Vector3 translation() const { return (*this)[3].xyz(); } /**< @overload */ diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 2d0739185..e613855b9 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -18,4 +18,4 @@ corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) -set_target_properties(MathVectorTest MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) +set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index a7e51a5e2..38dac55d3 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -36,6 +36,7 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::translation, &Matrix3Test::scaling, &Matrix3Test::rotation, + &Matrix3Test::reflection, &Matrix3Test::fromParts, &Matrix3Test::rotationScalingPart, &Matrix3Test::rotationPart, @@ -96,6 +97,27 @@ void Matrix3Test::rotation() { CORRADE_COMPARE(Matrix3::rotation(deg(15.0f)), matrix); } +void Matrix3Test::reflection() { + std::ostringstream o; + Error::setOutput(&o); + + Vector2 normal(-1.0f, 2.0f); + + CORRADE_COMPARE(Matrix3::reflection(normal), Matrix3()); + CORRADE_COMPARE(o.str(), "Math::Matrix3::reflection(): normal must be normalized\n"); + + Matrix3 actual = Matrix3::reflection(normal.normalized()); + Matrix3 expected( + 0.6f, 0.8f, 0.0f, + 0.8f, -0.6f, 0.0f, + 0.0f, 0.0f, 1.0f + ); + + CORRADE_COMPARE(actual*actual, Matrix3()); + CORRADE_COMPARE(actual*normal, -normal); + CORRADE_COMPARE(actual, expected); +} + void Matrix3Test::fromParts() { Matrix2 rotationScaling( 3.0f, 5.0f, @@ -109,14 +131,8 @@ void Matrix3Test::fromParts() { 4.0f, 4.0f, 0.0f, 7.0f, -1.0f, 1.0f ); - CORRADE_COMPARE(Matrix3::from(rotationScaling, translation), expected); - Matrix3 expectedNoRotation( - 3.0f, 5.0f, 0.0f, - 4.0f, 4.0f, 0.0f, - 0.0f, 0.0f, 1.0f - ); - CORRADE_COMPARE(Matrix3::from(rotationScaling), expectedNoRotation); + CORRADE_COMPARE(Matrix3::from(rotationScaling, translation), expected); } void Matrix3Test::rotationScalingPart() { diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h index 9a34ff78e..fa658f74a 100644 --- a/src/Math/Test/Matrix3Test.h +++ b/src/Math/Test/Matrix3Test.h @@ -28,6 +28,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void translation(); void scaling(); void rotation(); + void reflection(); void fromParts(); void rotationScalingPart(); void rotationPart(); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 9e79985cd..eac9539c8 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -39,6 +39,7 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotationX, &Matrix4Test::rotationY, &Matrix4Test::rotationZ, + &Matrix4Test::reflection, &Matrix4Test::fromParts, &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, @@ -136,6 +137,28 @@ void Matrix4Test::rotationZ() { CORRADE_COMPARE(Matrix4::rotationZ(rad(Math::Constants::pi()/7)), matrix); } +void Matrix4Test::reflection() { + std::ostringstream o; + Error::setOutput(&o); + + Vector3 normal(-1.0f, 2.0f, 2.0f); + + CORRADE_COMPARE(Matrix4::reflection(normal), Matrix4()); + CORRADE_COMPARE(o.str(), "Math::Matrix4::reflection(): normal must be normalized\n"); + + Matrix4 actual = Matrix4::reflection(normal.normalized()); + Matrix4 expected( + 0.777778f, 0.444444f, 0.444444f, 0.0f, + 0.444444f, 0.111111f, -0.888889f, 0.0f, + 0.444444f, -0.888889f, 0.111111f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); + + CORRADE_COMPARE(actual*actual, Matrix4()); + CORRADE_COMPARE(actual*normal, -normal); + CORRADE_COMPARE(actual, expected); +} + void Matrix4Test::fromParts() { Matrix3 rotationScaling( 3.0f, 5.0f, 8.0f, @@ -151,15 +174,8 @@ void Matrix4Test::fromParts() { 7.0f, -1.0f, 8.0f, 0.0f, 9.0f, 4.0f, 5.0f, 1.0f ); - CORRADE_COMPARE(Matrix4::from(rotationScaling, translation), expected); - Matrix4 expectedNoTranslation( - 3.0f, 5.0f, 8.0f, 0.0f, - 4.0f, 4.0f, 7.0f, 0.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); - CORRADE_COMPARE(Matrix4::from(rotationScaling), expectedNoTranslation); + CORRADE_COMPARE(Matrix4::from(rotationScaling, translation), expected); } void Matrix4Test::rotationScalingPart() { diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 238fa1cc2..3ea386b21 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -31,6 +31,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotationX(); void rotationY(); void rotationZ(); + void reflection(); void fromParts(); void rotationScalingPart(); void rotationPart(); From 45f50aff631fb4d79ceb507367dd1d9f8e411e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 21:49:04 +0100 Subject: [PATCH 061/567] SceneGraph: convenience function for reflecting objects. --- src/SceneGraph/MatrixTransformation2D.h | 14 ++++++++++++++ src/SceneGraph/MatrixTransformation3D.h | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index e797fba84..9ecb37a70 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -118,6 +118,20 @@ class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { return this; } + /** + * @brief Reflect object + * @param normal Normal of the line through which to reflect + * (normalized) + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Same as calling transform() with Matrix3::reflection(). + */ + inline MatrixTransformation2D* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { + transform(Math::Matrix3::reflection(normal), type); + return this; + } + /** * @brief Move object in stacking order * @param under Sibling object under which to move or `nullptr`, diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 4afc360c0..c133aca7b 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -160,6 +160,20 @@ class MatrixTransformation3D: public AbstractTranslationRotationScaling3D { return this; } + /** + * @brief Reflect object + * @param normal Normal of the plane through which to reflect + * (normalized) + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Same as calling transform() with Matrix4::reflection(). + */ + inline MatrixTransformation3D* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { + transform(Math::Matrix4::reflection(normal), type); + return this; + } + protected: /* Allow construction only from Object */ inline explicit MatrixTransformation3D() = default; From d981090e863bdf248a72f56992b2bb6663f8b525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Dec 2012 22:39:59 +0100 Subject: [PATCH 062/567] Functions for inverting Euclidean transformation matrices. --- src/Math/Matrix.h | 2 ++ src/Math/Matrix3.h | 18 ++++++++++++++++++ src/Math/Matrix4.h | 18 ++++++++++++++++++ src/Math/Test/Matrix3Test.cpp | 28 ++++++++++++++++++++++++++++ src/Math/Test/Matrix3Test.h | 1 + src/Math/Test/Matrix4Test.cpp | 29 +++++++++++++++++++++++++++++ src/Math/Test/Matrix4Test.h | 1 + 7 files changed, 97 insertions(+) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 66235ef99..8de204b05 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -137,6 +137,8 @@ template class Matrix: public RectangularMatrix inverted() const { Matrix out(Zero); diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 1a925a12b..a71854a7c 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -186,6 +186,24 @@ template class Matrix3: public Matrix<3, T> { inline Vector2& translation() { return (*this)[2].xy(); } inline constexpr Vector2 translation() const { return (*this)[2].xy(); } /**< @overload */ + /** + * @brief Inverted Euclidean transformation matrix + * + * Assumes that the matrix represents Euclidean transformation (i.e. + * only rotation and translation, no scaling) and creates inverted + * matrix from transposed rotation part and negated translation part. + * Significantly faster than the general algorithm in inverted(). + * @see rotationScaling() const, translation() const + */ + inline Matrix3 invertedEuclidean() const { + CORRADE_ASSERT((*this)(0, 2) == T(0) && (*this)(1, 2) == T(0) && (*this)(2, 2) == T(1), + "Math::Matrix3::invertedEuclidean(): unexpected values on last row", {}); + Matrix<2, T> inverseRotation = rotationScaling().transposed(); + CORRADE_ASSERT((inverseRotation*rotationScaling() == Matrix<2, T>()), + "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation", {}); + return from(inverseRotation, inverseRotation*-translation()); + } + #ifndef DOXYGEN_GENERATING_OUTPUT inline Point2D operator*(const Point2D& other) const { return Matrix<3, T>::operator*(other); diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index f41458b03..d7f28f1a4 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -290,6 +290,24 @@ template class Matrix4: public Matrix<4, T> { inline Vector3& translation() { return (*this)[3].xyz(); } inline constexpr Vector3 translation() const { return (*this)[3].xyz(); } /**< @overload */ + /** + * @brief Inverted Euclidean transformation matrix + * + * Assumes that the matrix represents Euclidean transformation (i.e. + * only rotation and translation, no scaling) and creates inverted + * matrix from transposed rotation part and negated translation part. + * Significantly faster than the general algorithm in inverted(). + * @see rotationScaling() const, translation() const + */ + inline Matrix4 invertedEuclidean() const { + CORRADE_ASSERT((*this)(0, 3) == T(0) && (*this)(1, 3) == T(0) && (*this)(2, 3) == T(0) && (*this)(3, 3) == T(1), + "Math::Matrix4::invertedEuclidean(): unexpected values on last row", {}); + Matrix<3, T> inverseRotation = rotationScaling().transposed(); + CORRADE_ASSERT((inverseRotation*rotationScaling() == Matrix<3, T>()), + "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation", {}); + return from(inverseRotation, inverseRotation*-translation()); + } + #ifndef DOXYGEN_GENERATING_OUTPUT inline Point3D operator*(const Point3D& other) const { return Matrix<4, T>::operator*(other); diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 38dac55d3..b9219b57a 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -41,6 +41,7 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::rotationScalingPart, &Matrix3Test::rotationPart, &Matrix3Test::vectorParts, + &Matrix3Test::invertedEuclidean, &Matrix3Test::debug, &Matrix3Test::configuration); } @@ -173,6 +174,33 @@ void Matrix3Test::vectorParts() { CORRADE_COMPARE(m.translation(), Vector2(-5.0f, 12.0f)); } +void Matrix3Test::invertedEuclidean() { + std::ostringstream o; + Error::setOutput(&o); + + Matrix3 m( + 3.0f, 5.0f, 8.0f, + 4.0f, 4.0f, 7.0f, + 7.0f, -1.0f, 8.0f + ); + CORRADE_COMPARE(m.invertedEuclidean(), Matrix3()); + CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): unexpected values on last row\n"); + + o.str(""); + CORRADE_COMPARE(Matrix3::scaling(Vector2(2.0f)).invertedEuclidean(), Matrix3()); + CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); + + Matrix3 actual = Matrix3::rotation(deg(-74.0f))* + Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* + Matrix3::translation({2.0f, -3.0f}); + Matrix3 expected = Matrix3::translation({-2.0f, 3.0f})* + Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* + Matrix3::rotation(deg(74.0f)); + + CORRADE_COMPARE(actual.invertedEuclidean(), expected); + CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); +} + void Matrix3Test::debug() { Matrix3 m( 3.0f, 5.0f, 8.0f, diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h index fa658f74a..bea82a6f8 100644 --- a/src/Math/Test/Matrix3Test.h +++ b/src/Math/Test/Matrix3Test.h @@ -33,6 +33,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void rotationScalingPart(); void rotationPart(); void vectorParts(); + void invertedEuclidean(); void debug(); void configuration(); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index eac9539c8..0f3ee5be6 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -44,6 +44,7 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, &Matrix4Test::vectorParts, + &Matrix4Test::invertedEuclidean, &Matrix4Test::debug, &Matrix4Test::configuration); } @@ -225,6 +226,34 @@ void Matrix4Test::vectorParts() { CORRADE_COMPARE(m.translation(), Vector3(-5.0f, 12.0f, 0.5f)); } +void Matrix4Test::invertedEuclidean() { + std::ostringstream o; + Error::setOutput(&o); + + Matrix4 m( + 3.0f, 5.0f, 8.0f, 4.0f, + 4.0f, 4.0f, 7.0f, 3.0f, + 7.0f, -1.0f, 8.0f, 0.0f, + 9.0f, 4.0f, 5.0f, 9.0f + ); + CORRADE_COMPARE(m.invertedEuclidean(), Matrix4()); + CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): unexpected values on last row\n"); + + o.str(""); + CORRADE_COMPARE(Matrix4::scaling(Vector3(2.0f)).invertedEuclidean(), Matrix4()); + CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); + + Matrix4 actual = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized())* + Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* + Matrix4::translation({1.0f, 2.0f, -3.0f}); + Matrix4 expected = Matrix4::translation({-1.0f, -2.0f, 3.0f})* + Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* + Matrix4::rotation(deg(74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized()); + + CORRADE_COMPARE(actual.invertedEuclidean(), expected); + CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); +} + void Matrix4Test::debug() { Matrix4 m( 3.0f, 5.0f, 8.0f, 4.0f, diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h index 3ea386b21..737778533 100644 --- a/src/Math/Test/Matrix4Test.h +++ b/src/Math/Test/Matrix4Test.h @@ -36,6 +36,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotationScalingPart(); void rotationPart(); void vectorParts(); + void invertedEuclidean(); void debug(); void configuration(); From 2734fde59393725f6ed1832fb65e5232f56ec854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Dec 2012 13:49:42 +0100 Subject: [PATCH 063/567] SceneGraph: euclidean transformation using matrices. Allows for faster computation of inverted transformations. --- src/SceneGraph/CMakeLists.txt | 6 +- .../EuclideanMatrixTransformation2D.cpp | 26 +++ .../EuclideanMatrixTransformation2D.h | 138 ++++++++++++++ .../EuclideanMatrixTransformation3D.cpp | 26 +++ .../EuclideanMatrixTransformation3D.h | 168 ++++++++++++++++++ src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/MatrixTransformation3D.h | 2 +- src/SceneGraph/Object.h | 2 + src/SceneGraph/SceneGraph.h | 3 + 9 files changed, 370 insertions(+), 3 deletions(-) create mode 100644 src/SceneGraph/EuclideanMatrixTransformation2D.cpp create mode 100644 src/SceneGraph/EuclideanMatrixTransformation2D.h create mode 100644 src/SceneGraph/EuclideanMatrixTransformation3D.cpp create mode 100644 src/SceneGraph/EuclideanMatrixTransformation3D.h diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 5348905bf..d8f3b047a 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -1,6 +1,8 @@ set(MagnumSceneGraph_SRCS Animable.cpp - Camera.cpp) + Camera.cpp + EuclideanMatrixTransformation2D.cpp + EuclideanMatrixTransformation3D.cpp) set(MagnumSceneGraph_HEADERS AbstractCamera.h AbstractCamera.hpp @@ -20,6 +22,8 @@ set(MagnumSceneGraph_HEADERS Camera3D.h Camera3D.hpp Drawable.h + EuclideanMatrixTransformation2D.h + EuclideanMatrixTransformation3D.h FeatureGroup.h MatrixTransformation2D.h MatrixTransformation3D.h diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.cpp b/src/SceneGraph/EuclideanMatrixTransformation2D.cpp new file mode 100644 index 000000000..589b0f569 --- /dev/null +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "EuclideanMatrixTransformation2D.h" + +#include "Object.hpp" + +namespace Magnum { namespace SceneGraph { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template class MAGNUM_SCENEGRAPH_EXPORT Object>; +#endif + +}} diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h new file mode 100644 index 000000000..1eb73381b --- /dev/null +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -0,0 +1,138 @@ +#ifndef Magnum_SceneGraph_EuclideanMatrixTransformation2D_h +#define Magnum_SceneGraph_EuclideanMatrixTransformation2D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::EuclideanMatrixTransformation2D + */ + +#include "Math/Matrix3.h" +#include "AbstractTranslationRotation2D.h" +#include "Object.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Two-dimensional euclidean transformation implemented using matrices + +Unlike MatrixTransformation2D this class allows only rotation, reflection and +translation (no scaling or setting arbitrary transformations). This allows to +use Matrix3::invertedEuclidean() for faster computation of inverse +transformations. +@see @ref scenegraph, EuclideanMatrixTransformation3D +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { + public: + /** @brief Transformation matrix type */ + typedef typename DimensionTraits<2, T>::MatrixType DataType; + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline constexpr static Math::Matrix3 fromMatrix(const Math::Matrix3& matrix) { + return matrix; + } + + inline constexpr static Math::Matrix3 toMatrix(const Math::Matrix3& transformation) { + return transformation; + } + + inline static Math::Matrix3 compose(const Math::Matrix3& parent, const Math::Matrix3& child) { + return parent*child; + } + + inline static Math::Matrix3 inverted(const Math::Matrix3& transformation) { + return transformation.invertedEuclidean(); + } + + inline Math::Matrix3 transformation() const { + return _transformation; + } + #endif + + /** + * @brief Reset transformation to default + * @return Pointer to self (for method chaining) + */ + inline EuclideanMatrixTransformation2D* resetTransformation() { + setTransformation({}); + return this; + } + + /** @copydoc AbstractTranslationRotation2D::translate() */ + inline EuclideanMatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix3::translation(vector), type); + return this; + } + + /** @copydoc AbstractTranslationRotation2D::rotate() */ + inline EuclideanMatrixTransformation2D* rotate(T angle, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix3::rotation(angle), type); + return this; + } + + /** + * @brief Reflect object + * @param normal Normal of the line through which to reflect + * (normalized) + * @param type Transformation type + * @return Pointer to self (for method chaining) + */ + inline EuclideanMatrixTransformation2D* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { + transform(Math::Matrix3::reflection(normal), type); + return this; + } + + /** + * @brief Move object in stacking order + * @param under Sibling object under which to move or `nullptr`, + * if you want to move it above all. + * @return Pointer to self (for method chaining) + */ + inline EuclideanMatrixTransformation2D* move(Object>* under) { + static_cast*>(this)->Corrade::Containers::LinkedList>>::move(this, under); + return this; + } + + protected: + /* Allow construction only from Object */ + inline explicit EuclideanMatrixTransformation2D() = default; + + private: + inline void setTransformation(const Math::Matrix3& transformation) { + /* Setting transformation is forbidden for the scene */ + /** @todo Assert for this? */ + /** @todo Do this in some common code so we don't need to include Object? */ + if(!static_cast>*>(this)->isScene()) { + _transformation = transformation; + static_cast>*>(this)->setDirty(); + } + } + + inline void transform(const Math::Matrix3& transformation, TransformationType type) { + setTransformation(type == TransformationType::Global ? + transformation*_transformation : _transformation*transformation); + } + + Math::Matrix3 _transformation; +}; + +}} + +#endif diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.cpp b/src/SceneGraph/EuclideanMatrixTransformation3D.cpp new file mode 100644 index 000000000..f670329ce --- /dev/null +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "EuclideanMatrixTransformation3D.h" + +#include "Object.hpp" + +namespace Magnum { namespace SceneGraph { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template class MAGNUM_SCENEGRAPH_EXPORT Object>; +#endif + +}} diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h new file mode 100644 index 000000000..45e2ba8b0 --- /dev/null +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -0,0 +1,168 @@ +#ifndef Magnum_SceneGraph_EuclideanMatrixTransformation3D_h +#define Magnum_SceneGraph_EuclideanMatrixTransformation3D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::EuclideanMatrixTransformation3D + */ + +#include "Math/Matrix4.h" +#include "AbstractTranslationRotation3D.h" +#include "Object.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Three-dimensional euclidean transformation implemented using matrices + +Unlike MatrixTransformation3D this class allows only rotation, reflection and +translation (no scaling or setting arbitrary transformations). This allows to +use Matrix4::invertedEuclidean() for faster computation of inverse +transformations. +@see @ref scenegraph, EuclideanMatrixTransformation2D +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { + public: + /** @brief Transformation matrix type */ + typedef typename DimensionTraits<3, T>::MatrixType DataType; + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline constexpr static Math::Matrix4 fromMatrix(const Math::Matrix4& matrix) { + return matrix; + } + + inline constexpr static Math::Matrix4 toMatrix(const Math::Matrix4& transformation) { + return transformation; + } + + inline static Math::Matrix4 compose(const Math::Matrix4& parent, const Math::Matrix4& child) { + return parent*child; + } + + inline static Math::Matrix4 inverted(const Math::Matrix4& transformation) { + return transformation.invertedEuclidean(); + } + + inline Math::Matrix4 transformation() const { + return _transformation; + } + #endif + + /** + * @brief Reset transformation to default + * @return Pointer to self (for method chaining) + */ + inline EuclideanMatrixTransformation3D* resetTransformation() { + setTransformation({}); + return this; + } + + /** @copydoc AbstractTranslationRotation3D::translate() */ + inline EuclideanMatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix4::translation(vector), type); + return this; + } + + /** @copydoc AbstractTranslationRotation3D::rotate() */ + inline EuclideanMatrixTransformation3D* rotate(T angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix4::rotation(angle, normalizedAxis), type); + return this; + } + + /** + * @brief Rotate object around X axis + * @param angle Angle in radians, counterclockwise + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * @see deg(), rad() + */ + inline EuclideanMatrixTransformation3D* rotateX(T angle, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix4::rotationX(angle), type); + return this; + } + + /** + * @brief Rotate object around Y axis + * @param angle Angle in radians, counterclockwise + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * @see deg(), rad() + */ + inline EuclideanMatrixTransformation3D* rotateY(T angle, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix4::rotationY(angle), type); + return this; + } + + /** + * @brief Rotate object around Z axis + * @param angle Angle in radians, counterclockwise + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * @see deg(), rad() + */ + inline EuclideanMatrixTransformation3D* rotateZ(T angle, TransformationType type = TransformationType::Global) override { + transform(Math::Matrix4::rotationZ(angle), type); + return this; + } + + /** + * @brief Reflect object + * @param normal Normal of the plane through which to reflect + * (normalized) + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Same as calling transform() with Matrix4::reflection(). + */ + inline EuclideanMatrixTransformation3D* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { + transform(Math::Matrix4::reflection(normal), type); + return this; + } + + protected: + /* Allow construction only from Object */ + inline explicit EuclideanMatrixTransformation3D() = default; + + private: + inline void setTransformation(const Math::Matrix4& transformation) { + /* Setting transformation is forbidden for the scene */ + /** @todo Assert for this? */ + /** @todo Do this in some common code so we don't need to include Object? */ + if(!static_cast>*>(this)->isScene()) { + _transformation = transformation; + static_cast>*>(this)->setDirty(); + } + } + + inline void transform(const Math::Matrix4& transformation, TransformationType type) { + setTransformation(type == TransformationType::Global ? + transformation*_transformation : _transformation*transformation); + } + + Math::Matrix4 _transformation; +}; + +}} + +#endif diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index 9ecb37a70..fa469bc42 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -29,7 +29,7 @@ namespace Magnum { namespace SceneGraph { @brief Two-dimensional transformation implemented using matrices Uses Math::Matrix3 as underlying type. -@see @ref scenegraph, MatrixTransformation3D +@see @ref scenegraph, EuclideanMatrixTransformation2D, MatrixTransformation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index c133aca7b..c5018a684 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -29,7 +29,7 @@ namespace Magnum { namespace SceneGraph { @brief Three-dimensional transformation implemented using matrices Uses Math::Matrix4 as underlying type. -@see @ref scenegraph, MatrixTransformation2D +@see @ref scenegraph, EuclideanMatrixTransformation3D, MatrixTransformation2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index b6f06696d..9b5efdc6f 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -73,6 +73,8 @@ avoid linker errors. See @ref compilation-speedup-hpp for more information. - @ref MatrixTransformation2D "Object>" - @ref MatrixTransformation3D "Object>" + - @ref EuclideanMatrixTransformation2D "Object>" + - @ref EuclideanMatrixTransformation3D "Object>" @see Scene, AbstractFeature, AbstractTransformation */ diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index 14fba11ca..c958654f1 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -89,6 +89,9 @@ template using Drawable2D = Drawable<2, T>; template using Drawable3D = Drawable<3, T>; #endif +template class EuclideanMatrixTransformation2D; +template class EuclideanMatrixTransformation3D; + template class FeatureGroup; #ifndef CORRADE_GCC46_COMPATIBILITY template using FeatureGroup2D = FeatureGroup<2, Feature, T>; From 5de5b34c485c305696012a07b827e7a154b68e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Dec 2012 20:32:37 +0100 Subject: [PATCH 064/567] Math: function for projecting vector onto another. --- src/Math/Test/VectorTest.cpp | 9 +++++++++ src/Math/Test/VectorTest.h | 1 + src/Math/Vector.h | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 74f2960bd..f7b1c6e72 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -38,6 +38,7 @@ VectorTest::VectorTest() { &VectorTest::dotSelf, &VectorTest::length, &VectorTest::normalized, + &VectorTest::projected, &VectorTest::sum, &VectorTest::product, &VectorTest::min, @@ -93,6 +94,14 @@ void VectorTest::normalized() { CORRADE_COMPARE(Vector4(1.0f, 1.0f, 1.0f, 1.0f).normalized(), Vector4(0.5f, 0.5f, 0.5f, 0.5f)); } +void VectorTest::projected() { + Vector3 line(1.0f, -1.0f, 0.5f); + Vector3 projected = Vector3(1.0f, 2.0f, 3.0f).projected(line); + + CORRADE_COMPARE(projected, Vector3(0.222222f, -0.222222f, 0.111111f)); + CORRADE_COMPARE(projected.normalized(), line.normalized()); +} + void VectorTest::sum() { CORRADE_COMPARE(Vector3(1.0f, 2.0f, 4.0f).sum(), 7.0f); } diff --git a/src/Math/Test/VectorTest.h b/src/Math/Test/VectorTest.h index 6c70e6e02..94590d604 100644 --- a/src/Math/Test/VectorTest.h +++ b/src/Math/Test/VectorTest.h @@ -30,6 +30,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void dotSelf(); void length(); void normalized(); + void projected(); void sum(); void product(); void min(); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 99b0bc32b..39589af74 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -224,6 +224,15 @@ template class Vector: public RectangularMatrix<1, si return *this/length(); } + /** + * @brief Vector projected onto another + * + * Returns vector projected onto line defined by @p other. + */ + inline Vector projected(const Vector& other) const { + return other*dot(*this, other)/other.dot(); + } + /** @brief Sum of values in the vector */ T sum() const { T out(0); From 4a6e0b6dfa7ca1f64257f7a99161e136113f44ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Dec 2012 22:34:58 +0100 Subject: [PATCH 065/567] Math: Gram-Schmidt orthonormalization. --- src/Math/Algorithms/CMakeLists.txt | 3 +- src/Math/Algorithms/GramSchmidt.h | 51 +++++++++++++++++ src/Math/Algorithms/Test/CMakeLists.txt | 1 + src/Math/Algorithms/Test/GramSchmidtTest.cpp | 60 ++++++++++++++++++++ src/Math/Algorithms/Test/GramSchmidtTest.h | 31 ++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/Math/Algorithms/GramSchmidt.h create mode 100644 src/Math/Algorithms/Test/GramSchmidtTest.cpp create mode 100644 src/Math/Algorithms/Test/GramSchmidtTest.h diff --git a/src/Math/Algorithms/CMakeLists.txt b/src/Math/Algorithms/CMakeLists.txt index cb5121b20..0a54d2d3c 100644 --- a/src/Math/Algorithms/CMakeLists.txt +++ b/src/Math/Algorithms/CMakeLists.txt @@ -1,5 +1,6 @@ set(MagnumMathAlgorithms_HEADERS - GaussJordan.h) + GaussJordan.h + GramSchmidt.h) install(FILES ${MagnumMathAlgorithms_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Algorithms) if(BUILD_TESTS) diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h new file mode 100644 index 000000000..cbaa3d04c --- /dev/null +++ b/src/Math/Algorithms/GramSchmidt.h @@ -0,0 +1,51 @@ +#ifndef Magnum_Math_Algorithms_GramSchmidt_h +#define Magnum_Math_Algorithms_GramSchmidt_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::Math::Algorithms::gramSchmidtInPlace(), Magnum::Math::Algorithms::gramSchmidt() + */ + +#include "Math/Matrix.h" + +namespace Magnum { namespace Math { namespace Algorithms { + +/** +@brief Gram-schmidt matrix orthonormalization +@param[in,out] matrix Matrix to perform orthonormalization on +*/ +template void gramSchmidtInPlace(Matrix& matrix) { + for(std::size_t i = 0; i != size; ++i) { + matrix[i] = matrix[i].normalized(); + for(std::size_t j = i+1; j != size; ++j) + matrix[j] -= matrix[j].projected(matrix[i]); + } +} + +/** +@brief Gram-schmidt matrix orthonormalization + +Unlike gramSchmidtInPlace() returns the modified matrix instead of performing +the orthonormalization in-place. +*/ +template Matrix gramSchmidt(Matrix matrix) { + gramSchmidtInPlace(matrix); + return matrix; +} + +}}} + +#endif diff --git a/src/Math/Algorithms/Test/CMakeLists.txt b/src/Math/Algorithms/Test/CMakeLists.txt index 88eb779c5..e7e6975e0 100644 --- a/src/Math/Algorithms/Test/CMakeLists.txt +++ b/src/Math/Algorithms/Test/CMakeLists.txt @@ -1 +1,2 @@ corrade_add_test(MathAlgorithmsGaussJordanTest GaussJordanTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathAlgorithmsGramSchmidtTest GramSchmidtTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp new file mode 100644 index 000000000..b7671eae9 --- /dev/null +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -0,0 +1,60 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "GramSchmidtTest.h" + +#include "Math/Algorithms/GramSchmidt.h" + +CORRADE_TEST_MAIN(Magnum::Math::Algorithms::Test::GramSchmidtTest) + +namespace Magnum { namespace Math { namespace Algorithms { namespace Test { + +typedef Matrix<3, float> Matrix3; +typedef Vector<3, float> Vector3; + +GramSchmidtTest::GramSchmidtTest() { + addTests(&GramSchmidtTest::test); +} + +void GramSchmidtTest::test() { + Matrix3 m( + 3.0f, 5.0f, 8.0f, + 4.0f, 4.0f, 7.0f, + 7.0f, -1.0f, 8.0f + ); + + Matrix3 normalized = Algorithms::gramSchmidt(m); + + /* Verify the first vector is in direction of first original */ + CORRADE_COMPARE(normalized[0], m[0].normalized()); + + /* Verify the vectors have unit length */ + CORRADE_COMPARE(normalized[0].length(), 1.0f); + CORRADE_COMPARE(normalized[1].length(), 1.0f); + CORRADE_COMPARE(normalized[2].length(), 1.0f); + + /* Verify the vectors are orthogonal */ + CORRADE_COMPARE(Vector3::dot(normalized[0], normalized[1]), 0.0f); + CORRADE_COMPARE(Vector3::dot(normalized[0], normalized[2]), 0.0f); + CORRADE_COMPARE(Vector3::dot(normalized[1], normalized[2]), 0.0f); + + /* Just to be sure */ + Matrix3 expected( 0.303046f, 0.505076f, 0.808122f, + 0.928316f, -0.348119f, -0.130544f, + -0.215388f, -0.789754f, 0.574367f); + CORRADE_COMPARE(normalized, expected); +} + +}}}} diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.h b/src/Math/Algorithms/Test/GramSchmidtTest.h new file mode 100644 index 000000000..c09df77d8 --- /dev/null +++ b/src/Math/Algorithms/Test/GramSchmidtTest.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Math_Algorithms_Test_GramSchmidtTest_h +#define Magnum_Math_Algorithms_Test_GramSchmidtTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Algorithms { namespace Test { + +class GramSchmidtTest: public Corrade::TestSuite::Tester { + public: + GramSchmidtTest(); + + void test(); +}; + +}}}} + +#endif From 041e541d39bf648c1b37e4e9c7d467a3d8ed6c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Dec 2012 22:54:54 +0100 Subject: [PATCH 066/567] SceneGraph: ability to normalize rotation in Euclidean transformation. --- .../EuclideanMatrixTransformation2D.h | 24 +++++++++++++- .../EuclideanMatrixTransformation3D.h | 32 ++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index 1eb73381b..cb4a59081 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -20,6 +20,7 @@ */ #include "Math/Matrix3.h" +#include "Math/Algorithms/GramSchmidt.h" #include "AbstractTranslationRotation2D.h" #include "Object.h" @@ -75,13 +76,34 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { return this; } + /** + * @brief Normalize rotation part + * @return Pointer to self (for method chaining) + * + * Normalizes the rotation part using Math::Algorithms::gramSchmidt() + * to prevent rounding errors when rotating the object subsequently. + */ + EuclideanMatrixTransformation2D* normalizeRotation() { + setTransformation(Math::Matrix3::from( + Math::Algorithms::gramSchmidt(_transformation.rotationScaling()), + _transformation.translation())); + return this; + } + /** @copydoc AbstractTranslationRotation2D::translate() */ inline EuclideanMatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::translation(vector), type); return this; } - /** @copydoc AbstractTranslationRotation2D::rotate() */ + /** + * @brief Rotate object + * @param angle Angle in radians, counterclockwise + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * @see deg(), rad(), normalizeRotation() + */ inline EuclideanMatrixTransformation2D* rotate(T angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::rotation(angle), type); return this; diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index 45e2ba8b0..d39dac91a 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -20,6 +20,7 @@ */ #include "Math/Matrix4.h" +#include "Math/Algorithms/GramSchmidt.h" #include "AbstractTranslationRotation3D.h" #include "Object.h" @@ -75,13 +76,36 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { return this; } + /** + * @brief Normalize rotation part + * @return Pointer to self (for method chaining) + * + * Normalizes the rotation part using Math::Algorithms::gramSchmidt() + * to prevent rounding errors when rotating the object subsequently. + */ + EuclideanMatrixTransformation3D* normalizeRotation() { + setTransformation(Math::Matrix4::from( + Math::Algorithms::gramSchmidt(_transformation.rotationScaling()), + _transformation.translation())); + return this; + } + /** @copydoc AbstractTranslationRotation3D::translate() */ inline EuclideanMatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::translation(vector), type); return this; } - /** @copydoc AbstractTranslationRotation3D::rotate() */ + /** + * @brief Rotate object + * @param angle Angle in radians, counterclockwise + * @param normalizedAxis Normalized rotation axis + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * @see deg(), rad(), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis(), normalizeRotation() + */ inline EuclideanMatrixTransformation3D* rotate(T angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotation(angle, normalizedAxis), type); return this; @@ -93,7 +117,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad() + * @see deg(), rad(), normalizeRotation() */ inline EuclideanMatrixTransformation3D* rotateX(T angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationX(angle), type); @@ -106,7 +130,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad() + * @see deg(), rad(), normalizeRotation() */ inline EuclideanMatrixTransformation3D* rotateY(T angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationY(angle), type); @@ -119,7 +143,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad() + * @see deg(), rad(), normalizeRotation() */ inline EuclideanMatrixTransformation3D* rotateZ(T angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationZ(angle), type); From e5db59aad5b7adeccd62667117477e2ee5ac6965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 19 Dec 2012 22:58:51 +0100 Subject: [PATCH 067/567] Removed "wontfix" TODOs. * Calling *Mesh::draw() with parameter to start on arbitrary vertex index might give users more freedom than they want to have (e.g. lines rendered where gaps should be, broken triangle strips...). * Single-precision floats have meaningful precision of ~6 decimal places, everything after that would be random garbage anyway, so we don't need anything "more precise" for icosphere. * Texture1D can have only one target and it can be used as framebuffer target. --- src/Framebuffer.h | 2 -- src/IndexedMesh.cpp | 1 - src/Mesh.cpp | 1 - src/Primitives/Icosphere.h | 2 -- src/SceneGraph/FeatureGroup.h | 3 --- 5 files changed, 9 deletions(-) diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 6bc7104a0..ec638d3b6 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -228,7 +228,6 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ (this->*texture1DImplementation)(GLenum(depthStencilAttachment), texture, mipLevel); } @@ -246,7 +245,6 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ inline void attachTexture1D(std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ (this->*texture1DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, texture, mipLevel); } #endif diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index b64885fae..2a09a70b6 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -37,7 +37,6 @@ void IndexedMesh::draw() { bind(); - /** @todo Start at given index */ glDrawElements(static_cast(primitive()), _indexCount, static_cast(_indexType), nullptr); unbind(); diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 67260b7cf..32dde612a 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -92,7 +92,6 @@ void Mesh::draw() { bind(); - /** @todo Start at given index */ glDrawArrays(static_cast(_primitive), 0, _vertexCount); unbind(); diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 9e1b275ba..93eb72aeb 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -32,8 +32,6 @@ template class Icosphere; @brief 3D icosphere primitive with zero subdivisions Indexed triangle mesh with normals. -@todo Use own computed (and more precise) icosahedron data, not these stolen -from Blender. */ template<> class Icosphere<0>: public Trade::MeshData3D { public: diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 3aecc66d1..f91a2b6a4 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -80,9 +80,6 @@ class FeatureGroup { * @see remove(), AbstractGroupedFeature::AbstractGroupedFeature() */ FeatureGroup* add(Feature* feature) { - /** @todo Assert the same scene for all items? -- can't easily - watch when feature object is removed from hierarchy */ - /* Remove from previous group */ if(feature->_group) feature->_group->remove(feature); From d552a658c0d88955e7a3a1815e9550cfbea3d4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 15:38:11 +0100 Subject: [PATCH 068/567] Platform: reworked GlutApplication events to mimic SDL and NaClApplication. --- src/Platform/AbstractXApplication.h | 5 +- src/Platform/GlutApplication.cpp | 20 ++- src/Platform/GlutApplication.h | 235 +++++++++++++++++++--------- src/Platform/NaClApplication.h | 3 +- src/Platform/Sdl2Application.h | 35 ++--- 5 files changed, 196 insertions(+), 102 deletions(-) diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 4b6d4d836..38121ce75 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -300,8 +300,9 @@ class AbstractXApplication { @brief Entry point for X11-based applications @param className Class name -Can be used as equivalent to the following code to achieve better portability, -see @ref portability-applications for more information. +Can be used with AbstractXApplication subclasses as equivalent to the +following code to achieve better portability, see @ref portability-applications +for more information. @code int main(int argc, char** argv) { className app(argc, argv); diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 85eab4416..6a8b6dabc 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -35,7 +35,7 @@ GlutApplication::GlutApplication(int& argc, char** argv, const std::string& titl glutReshapeFunc(staticViewportEvent); glutSpecialFunc(staticKeyEvent); glutMouseFunc(staticMouseEvent); - glutMotionFunc(staticMouseMotionEvent); + glutMotionFunc(staticMouseMoveEvent); glutDisplayFunc(staticDrawEvent); ExtensionWrangler::initialize(); @@ -47,4 +47,22 @@ GlutApplication::~GlutApplication() { delete c; } +void GlutApplication::staticKeyEvent(int key, int x, int y){ + KeyEvent e(static_cast(key), {x, y}); + instance->keyPressEvent(e); +} + +void GlutApplication::staticMouseEvent(int button, int state, int x, int y) { + MouseEvent e(static_cast(button), {x, y}); + if(state == GLUT_DOWN) + instance->mousePressEvent(e); + else + instance->mouseReleaseEvent(e); +} + +void GlutApplication::staticMouseMoveEvent(int x, int y) { + MouseMoveEvent e({x, y}); + instance->mouseMoveEvent(e); +} + }} diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 6b7fafee0..8345a4f13 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -53,6 +53,11 @@ MAGNUM_GLUTAPPLICATION_MAIN(MyApplication) */ class GlutApplication { public: + class InputEvent; + class KeyEvent; + class MouseEvent; + class MouseMoveEvent; + /** * @brief Constructor * @param argc Count of arguments of `main()` function @@ -79,9 +84,9 @@ class GlutApplication { /** * @brief Viewport event * - * Called when viewport size changes. You should pass the new size to - * Framebuffer::setViewport() (and SceneGraph::AbstractCamera::setViewport(), - * if using scene graph). + * Called when window size changes. You should pass the new size to + * DefaultFramebuffer::setViewport() and possibly elsewhere (cameras, + * other framebuffers...). */ virtual void viewportEvent(const Vector2i& size) = 0; @@ -119,63 +124,18 @@ class GlutApplication { /** @{ @name Keyboard handling */ - public: - /** - * @brief Key - * - * @see keyPressEvent() - */ - enum class Key: int { - Up = GLUT_KEY_UP, /**< Up arrow */ - Down = GLUT_KEY_DOWN, /**< Down arrow */ - Left = GLUT_KEY_LEFT, /**< Left arrow */ - Right = GLUT_KEY_RIGHT, /**< Right arrow */ - F1 = GLUT_KEY_F1, /**< F1 */ - F2 = GLUT_KEY_F2, /**< F2 */ - F3 = GLUT_KEY_F3, /**< F3 */ - F4 = GLUT_KEY_F4, /**< F4 */ - F5 = GLUT_KEY_F5, /**< F5 */ - F6 = GLUT_KEY_F6, /**< F6 */ - F7 = GLUT_KEY_F7, /**< F7 */ - F8 = GLUT_KEY_F8, /**< F8 */ - F9 = GLUT_KEY_F9, /**< F9 */ - F10 = GLUT_KEY_F10, /**< F10 */ - F11 = GLUT_KEY_F11, /**< F11 */ - F12 = GLUT_KEY_F12, /**< F12 */ - Home = GLUT_KEY_HOME, /**< Home */ - End = GLUT_KEY_END, /**< End */ - PageUp = GLUT_KEY_PAGE_UP, /**< Page up */ - PageDown = GLUT_KEY_PAGE_DOWN /**< Page down */ - }; - - protected: /** * @brief Key press event - * @param key Key pressed - * @param position Cursor position * * Called when an key is pressed. Default implementation does nothing. */ - virtual void keyPressEvent(Key key, const Vector2i& position); + virtual void keyPressEvent(KeyEvent& event); /*@}*/ /** @{ @name Mouse handling */ public: - /** - * @brief Mouse button - * - * @see mousePressEvent(), mouseReleaseEvent() - */ - enum class MouseButton: int { - Left = GLUT_LEFT_BUTTON, /**< Left button */ - Middle = GLUT_MIDDLE_BUTTON, /**< Middle button */ - Right = GLUT_RIGHT_BUTTON, /**< Right button */ - WheelUp = 3, /**< Wheel up */ - WheelDown = 4 /**< Wheel down */ - }; - /** * @brief Mouse cursor * @@ -193,7 +153,7 @@ class GlutApplication { * when no button is pressed. Mouse tracking is disabled by default. */ inline void setMouseTracking(bool enabled) { - glutPassiveMotionFunc(enabled ? staticMouseMotionEvent : nullptr); + glutPassiveMotionFunc(enabled ? staticMouseMoveEvent : nullptr); } /** @brief Set mouse cursor */ @@ -213,7 +173,7 @@ class GlutApplication { * Called when mouse button is pressed. Default implementation does * nothing. */ - virtual void mousePressEvent(MouseButton button, const Vector2i& position); + virtual void mousePressEvent(MouseEvent& event); /** * @brief Mouse release event @@ -221,16 +181,16 @@ class GlutApplication { * Called when mouse button is released. Default implementation does * nothing. */ - virtual void mouseReleaseEvent(MouseButton button, const Vector2i& position); + virtual void mouseReleaseEvent(MouseEvent& event); /** - * @brief Mouse motion event + * @brief Mouse move event * * Called when any mouse button is pressed and mouse is moved. Default * implementation does nothing. * @see setMouseTracking() */ - virtual void mouseMotionEvent(const Vector2i& position); + virtual void mouseMoveEvent(MouseMoveEvent& event); /*@}*/ @@ -239,20 +199,11 @@ class GlutApplication { instance->viewportEvent({x, y}); } - inline static void staticKeyEvent(int key, int x, int y) { - instance->keyPressEvent(static_cast(key), {x, y}); - } + static void staticKeyEvent(int key, int x, int y); - inline static void staticMouseEvent(int button, int state, int x, int y) { - if(state == GLUT_DOWN) - instance->mousePressEvent(static_cast(button), {x, y}); - else - instance->mouseReleaseEvent(static_cast(button), {x, y}); - } + static void staticMouseEvent(int button, int state, int x, int y); - inline static void staticMouseMotionEvent(int x, int y) { - instance->mouseMotionEvent({x, y}); - } + static void staticMouseMoveEvent(int x, int y); inline static void staticDrawEvent() { instance->drawEvent(); @@ -263,11 +214,151 @@ class GlutApplication { Context* c; }; +/** +@brief Base for input events + +@see KeyEvent, MouseEvent, MouseMoveEvent, keyPressEvent(), mousePressEvent(), + mouseReleaseEvent(), mouseMoveEvent() +*/ +class GlutApplication::InputEvent { + InputEvent(const InputEvent& other) = delete; + InputEvent(InputEvent&& other) = delete; + InputEvent& operator=(const InputEvent& other) = delete; + InputEvent& operator=(InputEvent&& other) = delete; + + public: + inline virtual ~InputEvent() {} + + /** + * @brief Set event as accepted + * + * If the event is ignored (i.e., not set as accepted), it might be + * propagated elsewhere. By default is each event ignored. + */ + inline void setAccepted(bool accepted = true) { _accepted = accepted; } + + /** @brief Whether the event is accepted */ + inline bool isAccepted() { return _accepted; } + + #ifndef DOXYGEN_GENERATING_OUTPUT + protected: + inline InputEvent(): _accepted(false) {} + #endif + + private: + bool _accepted; +}; + +/** +@brief Key event + +@see keyPressEvent() +*/ +class GlutApplication::KeyEvent: public GlutApplication::InputEvent { + friend class GlutApplication; + + public: + /** + * @brief Key + * + * @see key() + */ + enum class Key: int { + Up = GLUT_KEY_UP, /**< Up arrow */ + Down = GLUT_KEY_DOWN, /**< Down arrow */ + Left = GLUT_KEY_LEFT, /**< Left arrow */ + Right = GLUT_KEY_RIGHT, /**< Right arrow */ + F1 = GLUT_KEY_F1, /**< F1 */ + F2 = GLUT_KEY_F2, /**< F2 */ + F3 = GLUT_KEY_F3, /**< F3 */ + F4 = GLUT_KEY_F4, /**< F4 */ + F5 = GLUT_KEY_F5, /**< F5 */ + F6 = GLUT_KEY_F6, /**< F6 */ + F7 = GLUT_KEY_F7, /**< F7 */ + F8 = GLUT_KEY_F8, /**< F8 */ + F9 = GLUT_KEY_F9, /**< F9 */ + F10 = GLUT_KEY_F10, /**< F10 */ + F11 = GLUT_KEY_F11, /**< F11 */ + F12 = GLUT_KEY_F12, /**< F12 */ + Home = GLUT_KEY_HOME, /**< Home */ + End = GLUT_KEY_END, /**< End */ + PageUp = GLUT_KEY_PAGE_UP, /**< Page up */ + PageDown = GLUT_KEY_PAGE_DOWN /**< Page down */ + }; + + /** @brief Key */ + inline Key key() const { return _key; } + + /** @brief Position */ + inline Vector2i position() const { return _position; } + + private: + inline KeyEvent(Key key, const Vector2i& position): _key(key), _position(position) {} + + const Key _key; + const Vector2i _position; +}; + +/** +@brief Mouse event + +@see MouseMoveEvent, mousePressEvent(), mouseReleaseEvent() +*/ +class GlutApplication::MouseEvent: public GlutApplication::InputEvent { + friend class GlutApplication; + + public: + /** + * @brief Mouse button + * + * @see button() + */ + enum class Button: int { + Left = GLUT_LEFT_BUTTON, /**< Left button */ + Middle = GLUT_MIDDLE_BUTTON, /**< Middle button */ + Right = GLUT_RIGHT_BUTTON, /**< Right button */ + WheelUp = 3, /**< Wheel up */ + WheelDown = 4 /**< Wheel down */ + }; + + /** @brief Button */ + inline Button button() const { return _button; } + + /** @brief Position */ + inline Vector2i position() const { return _position; } + + private: + inline MouseEvent(Button button, const Vector2i& position): _button(button), _position(position) {} + + const Button _button; + const Vector2i _position; +}; + +/** +@brief Mouse move event + +@see MouseEvent, mouseMoveEvent() +*/ +class GlutApplication::MouseMoveEvent: public GlutApplication::InputEvent { + friend class GlutApplication; + + public: + /** @brief Position */ + inline Vector2i position() const { return _position; } + + private: + inline MouseMoveEvent(const Vector2i& position): _position(position) {} + + const Vector2i _position; +}; + /** @hideinitializer +@brief Entry point for GLUT-based applications @param className Class name -Can be used as equivalent to the following code to achieve better portability, -see @ref portability-applications for more information. +Can be with GlutApplication subclasses used as equivalent to the following +code to achieve better portability, see @ref portability-applications for more +information. @code int main(int argc, char** argv) { className app(argc, argv); @@ -292,10 +383,10 @@ When no other application header is included this macro is also aliased to #endif /* Implementations for inline functions with unused parameters */ -inline void GlutApplication::keyPressEvent(Key, const Vector2i&) {} -inline void GlutApplication::mousePressEvent(MouseButton, const Vector2i&) {} -inline void GlutApplication::mouseReleaseEvent(MouseButton, const Vector2i&) {} -inline void GlutApplication::mouseMotionEvent(const Vector2i&) {} +inline void GlutApplication::keyPressEvent(KeyEvent&) {} +inline void GlutApplication::mousePressEvent(MouseEvent&) {} +inline void GlutApplication::mouseReleaseEvent(MouseEvent&) {} +inline void GlutApplication::mouseMoveEvent(MouseMoveEvent&) {} }} diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 13ed6e09b..874499f56 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -261,7 +261,8 @@ class NaClApplication::InputEvent { * @brief Set event as accepted * * If the event is ignored (i.e., not set as accepted), it is - * propagated to the browser. By default is each event ignored. + * propagated elsewhere (e.g. to the browser). By default is each + * event ignored. */ inline void setAccepted(bool accepted = true) { _accepted = accepted; } diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 82f2b377e..14c375628 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -100,11 +100,7 @@ class Sdl2Application { /** @{ @name Keyboard handling */ - /** - * @brief Key press event - * - * Called when an key is pressed. Default implementation does nothing. - */ + /** @copydoc GlutApplication::keyPressEvent() */ virtual void keyPressEvent(KeyEvent& event); /** @@ -134,20 +130,10 @@ class Sdl2Application { void setMouseLocked(bool enabled); protected: - /** - * @brief Mouse press event - * - * Called when mouse button is pressed. Default implementation does - * nothing. - */ + /** @copydoc GlutApplication::mousePressEvent() */ virtual void mousePressEvent(MouseEvent& event); - /** - * @brief Mouse release event - * - * Called when mouse button is released. Default implementation does - * nothing. - */ + /** @copydoc GlutApplication::mouseReleaseEvent() */ virtual void mouseReleaseEvent(MouseEvent& event); /** @@ -205,15 +191,10 @@ class Sdl2Application::InputEvent { inline virtual ~InputEvent() {} - /** - * @brief Set event as accepted - * - * If the event is ignored (i.e., not set as accepted), it might be - * propagated elsewhere. By default is each event ignored. - */ + /** @copydoc GlutApplication::InputEvent::setAccepted() */ inline void setAccepted(bool accepted = true) { _accepted = accepted; } - /** @brief Whether the event is accepted */ + /** @copydoc GlutApplication::InputEvent::isAccepted() */ inline bool isAccepted() { return _accepted; } #ifndef DOXYGEN_GENERATING_OUTPUT @@ -404,10 +385,12 @@ class Sdl2Application::MouseMoveEvent: public Sdl2Application::InputEvent { }; /** @hideinitializer +@brief Entry point for SDL2-based applications @param className Class name -Can be used as equivalent to the following code to achieve better portability, -see @ref portability-applications for more information. +Can be used with Sdl2Application subclasses as equivalent to the following +code to achieve better portability, see @ref portability-applications for more +information. @code int main(int argc, char** argv) { className app(argc, argv); From 6b4a833d6e2df0736528958d060a616c1c294c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 15:57:27 +0100 Subject: [PATCH 069/567] Minor code cleanup. --- src/Platform/Sdl2Application.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index f8a0a0a8f..b423b5519 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -103,15 +103,13 @@ int Sdl2Application::exec() { case SDL_KEYUP: { KeyEvent e(static_cast(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod)); event.type == SDL_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e); - break; - } + } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { MouseEvent e(static_cast(event.button.button), {event.button.x, event.button.y}); event.type == SDL_MOUSEBUTTONDOWN ? mousePressEvent(e) : mouseReleaseEvent(e); - break; - } + } break; case SDL_MOUSEWHEEL: if(event.wheel.y != 0) { From 10de569755222035cc87f26aad5a7b96f1848e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 15:57:47 +0100 Subject: [PATCH 070/567] Doc++ --- doc/portability.dox | 5 +++-- src/Platform/Sdl2Application.h | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/portability.dox b/doc/portability.dox index fb0d32d8d..77d359ebb 100644 --- a/doc/portability.dox +++ b/doc/portability.dox @@ -136,7 +136,8 @@ macro is also aliased to MAGNUM_APPLICATION_MAIN() to save you typing. Example application, which targets both embedded Linux (using plain X and EGL) and desktop (using SDL2 toolkit). Thanks to static polymorphism most of the -functions will work on both without changes: +functions will work on both without changes, the main difference will be in +particular *Event class implementations: @code #ifndef MAGNUM_TARGET_GLES #include @@ -165,7 +166,7 @@ class MyApplication: public ApplicationBase { // ... } - void keyPressEvent(Key key, Modifiers modifiers, const Vector2i& position) { + void keyPressEvent(KeyEvent& event) override { // ... } }; diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 14c375628..00aad8e99 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -170,7 +170,8 @@ class Sdl2Application::InputEvent { /** * @brief %Modifier * - * @see Modifiers, KeyEvent::modifiers() + * @see Modifiers, KeyEvent::modifiers(), MouseEvent::modifiers(), + * MouseMoveEvent::modifiers() */ enum class Modifier: Uint16 { Shift = KMOD_SHIFT, /**< Shift */ @@ -185,7 +186,8 @@ class Sdl2Application::InputEvent { /** * @brief Set of modifiers * - * @see KeyEvent::modifiers() + * @see KeyEvent::modifiers(), MouseEvent::modifiers(), + * MouseMoveEvent::modifiers() */ typedef Corrade::Containers::EnumSet Modifiers; From d0def6a763ca42ef847be72221eb5aabbc6ceb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 15:58:09 +0100 Subject: [PATCH 071/567] Platform: reworked *XApplication events to mimic other implementations. --- src/Platform/AbstractXApplication.cpp | 25 ++- src/Platform/AbstractXApplication.h | 221 +++++++++++++++++--------- 2 files changed, 154 insertions(+), 92 deletions(-) diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index db8b58c7b..d96e9bd70 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -116,22 +116,21 @@ int AbstractXApplication::exec() { /* Key/mouse events */ case KeyPress: - keyPressEvent(static_cast(XLookupKeysym(&event.xkey, 0)), static_cast(event.xkey.state), {event.xkey.x, event.xkey.y}); - break; - case KeyRelease: - keyReleaseEvent(static_cast(XLookupKeysym(&event.xkey, 0)), static_cast(event.xkey.state), {event.xkey.x, event.xkey.y}); - break; + case KeyRelease: { + KeyEvent e(static_cast(XLookupKeysym(&event.xkey, 0)), static_cast(event.xkey.state), {event.xkey.x, event.xkey.y}); + event.type == KeyPress ? keyPressEvent(e) : keyReleaseEvent(e); + } break; case ButtonPress: - mousePressEvent(static_cast(event.xbutton.button), static_cast(event.xkey.state), {event.xbutton.x, event.xbutton.y}); - break; - case ButtonRelease: - mouseReleaseEvent(static_cast(event.xbutton.button), static_cast(event.xkey.state), {event.xbutton.x, event.xbutton.y}); - break; + case ButtonRelease: { + MouseEvent e(static_cast(event.xbutton.button), static_cast(event.xkey.state), {event.xbutton.x, event.xbutton.y}); + event.type == ButtonPress ? mousePressEvent(e) : mouseReleaseEvent(e); + } break; /* Mouse move events */ - case MotionNotify: - mouseMotionEvent(static_cast(event.xmotion.state), {event.xmotion.x, event.xmotion.y}); - break; + case MotionNotify: { + MouseMoveEvent e(static_cast(event.xmotion.state), {event.xmotion.x, event.xmotion.y}); + mouseMoveEvent(e); + } break; } } diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 38121ce75..b8f999ff1 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -47,6 +47,11 @@ Supports keyboard and mouse handling. */ class AbstractXApplication { public: + class InputEvent; + class KeyEvent; + class MouseEvent; + class MouseMoveEvent; + /** * @brief Constructor * @param contextHandler OpenGL context handler @@ -94,12 +99,70 @@ class AbstractXApplication { /** @{ @name Keyboard handling */ + protected: + /** @copydoc Sdl2Application::keyPressEvent() */ + virtual void keyPressEvent(KeyEvent& event); + + /** @copydoc Sdl2Application::keyReleaseEvent() */ + virtual void keyReleaseEvent(KeyEvent& event); + + /*@}*/ + + /** @{ @name Mouse handling */ + + protected: + /** @copydoc Sdl2Application::mousePressEvent() */ + virtual void mousePressEvent(MouseEvent& event); + + /** @copydoc Sdl2Application::mouseReleaseEvent() */ + virtual void mouseReleaseEvent(MouseEvent& event); + + /** @copydoc Sdl2Application::mouseMoveEvent() */ + virtual void mouseMoveEvent(MouseMoveEvent& event); + + /*@}*/ + + private: + enum class Flag: unsigned int { + Redraw = 1 << 0, + Exit = 1 << 1 + }; + + typedef Corrade::Containers::EnumSet Flags; + CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) + + Display* display; + Window window; + Atom deleteWindow; + + AbstractContextHandler* contextHandler; + + Context* c; + + /** @todo Get this from the created window */ + Vector2i viewportSize; + + Flags flags; +}; + +/** +@brief Base for input events + +@see KeyEvent, MouseEvent, MouseMoveEvent, keyPressEvent(), keyReleaseEvent(), + mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent() +*/ +class AbstractXApplication::InputEvent { + InputEvent(const InputEvent& other) = delete; + InputEvent(InputEvent&& other) = delete; + InputEvent& operator=(const InputEvent& other) = delete; + InputEvent& operator=(InputEvent&& other) = delete; + + public: public: /** * @brief %Modifier * - * @see Modifiers, keyPressEvent(), keyReleaseEvent(), - * mousePressEvent(), mouseReleaseEvent(), mouseMotionEvent() + * @see Modifiers, modifiers() */ enum class Modifier: unsigned int { Shift = ShiftMask, /**< Shift */ @@ -118,14 +181,44 @@ class AbstractXApplication { /** * @brief Set of modifiers * - * @see keyPressEvent(), keyReleaseEvent() + * @see modifiers() */ typedef Corrade::Containers::EnumSet Modifiers; + inline virtual ~InputEvent() {} + + /** @copydoc GlutApplication::InputEvent::setAccepted() */ + inline void setAccepted(bool accepted = true) { _accepted = accepted; } + + /** @copydoc GlutApplication::InputEvent::isAccepted() */ + inline bool isAccepted() { return _accepted; } + + /** @brief Modifiers */ + inline Modifiers modifiers() const { return _modifiers; } + + #ifndef DOXYGEN_GENERATING_OUTPUT + protected: + inline InputEvent(Modifiers modifiers): _modifiers(modifiers), _accepted(false) {} + #endif + + private: + Modifiers _modifiers; + bool _accepted; +}; + +/** +@brief Key event + +@see keyPressEvent(), keyReleaseEvent() +*/ +class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent { + friend class AbstractXApplication; + + public: /** * @brief Key * - * @see keyPressEvent(), keyReleaseEvent() + * @see key() */ enum class Key: KeySym { Enter = XK_Return, /**< Enter */ @@ -200,38 +293,34 @@ class AbstractXApplication { Z = XK_z /**< Small letter Z */ }; - protected: - /** - * @brief Key press event - * @param key Key pressed - * @param modifiers Active modifiers - * @param position Cursor position - * - * Called when an key is pressed. Default implementation does nothing. - */ - virtual void keyPressEvent(Key key, Modifiers modifiers, const Vector2i& position); + /** @brief Key */ + inline Key key() const { return _key; } - /** - * @brief Key press event - * @param key Key released - * @param modifiers Active modifiers - * @param position Cursor position - * - * Called when an key is released. Default implementation does nothing. - */ - virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Vector2i& position); + /** @brief Position */ + inline Vector2i position() const { return _position; } - /*@}*/ + private: + inline KeyEvent(Key key, Modifiers modifiers, const Vector2i& position): InputEvent(modifiers), _key(key), _position(position) {} - /** @{ @name Mouse handling */ + const Key _key; + const Vector2i _position; +}; + +/** +@brief Mouse event + +@see MouseMoveEvent, mousePressEvent(), mouseReleaseEvent() +*/ +class AbstractXApplication::MouseEvent: public AbstractXApplication::InputEvent { + friend class AbstractXApplication; public: /** * @brief Mouse button * - * @see mousePressEvent(), mouseReleaseEvent() + * @see button() */ - enum class MouseButton: unsigned int { + enum class Button: unsigned int { Left = Button1, /**< Left button */ Middle = Button2, /**< Middle button */ Right = Button3, /**< Right button */ @@ -239,61 +328,35 @@ class AbstractXApplication { WheelDown = Button5 /**< Wheel down */ }; - protected: - /** - * @brief Mouse press event - * @param button Button pressed - * @param modifiers Active modifiers - * @param position Cursor position - * - * Called when mouse button is pressed. Default implementation does - * nothing. - */ - virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Vector2i& position); + /** @brief Button */ + inline Button button() const { return _button; } - /** - * @brief Mouse release event - * @param button Button released - * @param modifiers Active modifiers - * @param position Cursor position - * - * Called when mouse button is released. Default implementation does - * nothing. - */ - virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Vector2i& position); - - /** - * @brief Mouse motion event - * @param modifiers Active modifiers - * @param position Cursor position - * - * Called when mouse is moved. - */ - virtual void mouseMotionEvent(Modifiers modifiers, const Vector2i& position); - - /*@}*/ + /** @brief Position */ + inline Vector2i position() const { return _position; } private: - enum class Flag: unsigned int { - Redraw = 1 << 0, - Exit = 1 << 1 - }; + inline MouseEvent(Button button, Modifiers modifiers, const Vector2i& position): InputEvent(modifiers), _button(button), _position(position) {} - typedef Corrade::Containers::EnumSet Flags; - CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) + const Button _button; + const Vector2i _position; +}; - Display* display; - Window window; - Atom deleteWindow; +/** +@brief Mouse move event - AbstractContextHandler* contextHandler; +@see MouseEvent, mouseMoveEvent() +*/ +class AbstractXApplication::MouseMoveEvent: public AbstractXApplication::InputEvent { + friend class AbstractXApplication; - Context* c; + public: + /** @brief Position */ + inline Vector2i position() const { return _position; } - /** @todo Get this from the created window */ - Vector2i viewportSize; + private: + inline MouseMoveEvent(Modifiers modifiers, const Vector2i& position): InputEvent(modifiers), _position(position) {} - Flags flags; + const Vector2i _position; }; /** @hideinitializer @@ -326,15 +389,15 @@ When no other application header is included this macro is also aliased to #endif #endif -CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Modifiers) +CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Modifiers) CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags) /* Implementations for inline functions with unused parameters */ -inline void AbstractXApplication::keyPressEvent(Key, Modifiers, const Vector2i&) {} -inline void AbstractXApplication::keyReleaseEvent(Key, Modifiers, const Vector2i&) {} -inline void AbstractXApplication::mousePressEvent(MouseButton, Modifiers, const Vector2i&) {} -inline void AbstractXApplication::mouseReleaseEvent(MouseButton, Modifiers, const Vector2i&) {} -inline void AbstractXApplication::mouseMotionEvent(Modifiers, const Vector2i&) {} +inline void AbstractXApplication::keyPressEvent(KeyEvent&) {} +inline void AbstractXApplication::keyReleaseEvent(KeyEvent&) {} +inline void AbstractXApplication::mousePressEvent(MouseEvent&) {} +inline void AbstractXApplication::mouseReleaseEvent(MouseEvent&) {} +inline void AbstractXApplication::mouseMoveEvent(MouseMoveEvent&) {} }} From e0728baf037e534576ff13573aaf1bf000959349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 19:12:30 +0100 Subject: [PATCH 072/567] Adapt to "recent" (sic) Platform changes, update docs. --- CMakeLists.txt | 2 +- doc/building.dox | 18 +++++++++++------- modules/FindMagnum.cmake | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d2fe3463..b03431419 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ option(TARGET_GLES "Build for OpenGL ES instead of desktop OpenGL" OFF) cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF) # Parts of the library -option(WITH_EVERYTHING "Build everything (doesn't include contexts)" ON) +option(WITH_EVERYTHING "Build everything (doesn't include *Application libraries)" ON) cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) diff --git a/doc/building.dox b/doc/building.dox index 9bf5dd1b1..4014adb3d 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -63,25 +63,29 @@ By default the engine is built with everything except @ref Platform "application libraries". Using `WITH_*` CMake parameters you can specify which parts will be built and which not: - - `WITH_EVERYTHING` - Defaults to `ON`, builds everything except window - contexts. If set to `OFF`, only the main library is built and you can - select additional libraries with the following: + - `WITH_EVERYTHING` - Defaults to `ON`, builds everything except application + libraries. If set to `OFF`, only the main library is built and you can + select additional components with the following: - `WITH_MESHTOOLS` - MeshTools library. - `WITH_PHYSICS` - Physics library. - `WITH_PRIMITIVES` - Primitives library. - `WITH_SCENEGRAPH` - SceneGraph library. - `WITH_SHADERS` - Shaders library. + - `WITH_MAGNUMINFO` - `magnum-info` executable, provides information about + Magnum engine and OpenGL capabilities. None of the application libraries is built by default, regardless to `WITH_EVERYTHING` is enabled or not: - - `WITH_XEGLAPPLICATION` - X/EGL application, available only if targeting + - `WITH_XEGLAPPLICATION` - XEglApplication, available only if targeting OpenGL ES (see above). Requires **X11** and **EGL** libraries. - - `WITH_GLXAPPLICATION` - GLX application. Requires **X11** and **GLX** + - `WITH_GLXAPPLICATION` - GlxApplication. Requires **X11** and **GLX** libraries. - - `WITH_GLUTAPPLICATION` - GLUT application, available only if targeting + - `WITH_WINDOWLESSGLXAPPLICATION` - Windowless GLX application. Requires + **X11** and **GLX** libraries. + - `WITH_GLUTAPPLICATION` - GlutApplication, available only if targeting desktop OpenGL. Requires **GLUT** library. - - `WITH_SDL2APPLICATION` - SDL2 application. Requires **SDL2** library. + - `WITH_SDL2APPLICATION` - Sdl2Application. Requires **SDL2** library. @subsection building-tests Building and running unit tests diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 1d031e8e2..6a69a0d03 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -155,7 +155,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() - # GLX application dependencies + # Windowless GLX application dependencies if(${component} STREQUAL WindowlessGlxApplication) find_package(X11) if(X11_FOUND) From de72421a7c914e3cbf0b542a24728696e442d4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 20:33:51 +0100 Subject: [PATCH 073/567] Physics: fixed debug output operator for AbstractShape::Type. It could be found by ADL only from Physics namespace itself, which is not too useful. --- src/Physics/AbstractShape.cpp | 8 ++++++-- src/Physics/AbstractShape.h | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index 5ce4474bd..c6d2511d9 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -31,7 +31,9 @@ template class AbstractShape<2>; template class AbstractShape<3>; #ifndef DOXYGEN_GENERATING_OUTPUT -Debug operator<<(Debug debug, AbstractShape2D::Type value) { +namespace Implementation { + +Debug operator<<(Debug debug, ShapeDimensionTraits<2>::Type value) { switch(value) { #define _val(value) case AbstractShape2D::Type::value: return debug << "AbstractShape2D::Type::" #value; _val(Point) @@ -48,7 +50,7 @@ Debug operator<<(Debug debug, AbstractShape2D::Type value) { return debug << "AbstractShape2D::Type::(unknown)"; } -Debug operator<<(Debug debug, AbstractShape3D::Type value) { +Debug operator<<(Debug debug, ShapeDimensionTraits<3>::Type value) { switch(value) { #define _val(value) case AbstractShape3D::Type::value: return debug << "AbstractShape3D::Type::" #value; _val(Point) @@ -65,6 +67,8 @@ Debug operator<<(Debug debug, AbstractShape3D::Type value) { return debug << "AbstractShape2D::Type::(unknown)"; } + +} #endif }} diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 84fc07a25..85aee4ad3 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -56,6 +56,9 @@ namespace Implementation { Plane }; }; + + Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, ShapeDimensionTraits<2>::Type value); + Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, ShapeDimensionTraits<3>::Type value); } #endif @@ -118,17 +121,15 @@ template class MAGNUM_PHYSICS_EXPORT AbstractShape { virtual bool collides(const AbstractShape* other) const; }; + /** @brief Abstract two-dimensional shape */ typedef AbstractShape<2> AbstractShape2D; /** @brief Abstract three-dimensional shape */ typedef AbstractShape<3> AbstractShape3D; +#ifdef DOXYGEN_GENERATING_OUTPUT /** @debugoperator{Magnum::Physics::AbstractShape} */ -#ifndef DOXYGEN_GENERATING_OUTPUT -Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, AbstractShape2D::Type value); -Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, AbstractShape3D::Type value); -#else template Debug operator<<(Debug debug, typename AbstractShape::Type value); #endif From c0a3ce84a45867d8bb70c722331168c96441abfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Dec 2012 21:07:00 +0100 Subject: [PATCH 074/567] Moved Profiler and debug draw from Physics to new DebugTools library. Also cleaned up the code and split renderer creation from resource manager. --- CMakeLists.txt | 11 +- doc/building.dox | 2 + doc/mainpage.dox | 2 +- doc/namespaces.dox | 9 ++ modules/FindMagnum.cmake | 10 +- src/CMakeLists.txt | 6 +- src/DebugTools/CMakeLists.txt | 24 ++++ src/DebugTools/DebugTools.h | 33 +++++ .../Implementation/AbstractBoxRenderer.cpp | 10 +- .../Implementation/AbstractBoxRenderer.h | 10 +- .../Implementation/AbstractShapeRenderer.cpp | 6 +- .../Implementation/AbstractShapeRenderer.h | 21 +--- .../Implementation/AxisAlignedBoxRenderer.cpp | 7 +- .../Implementation/AxisAlignedBoxRenderer.h | 12 +- .../Implementation/BoxRenderer.cpp | 7 +- .../Implementation/BoxRenderer.h | 12 +- src/{ => DebugTools}/Profiler.cpp | 4 +- src/{ => DebugTools}/Profiler.h | 20 +-- src/DebugTools/ResourceManager.cpp | 38 ++++++ src/DebugTools/ResourceManager.h | 54 ++++++++ src/DebugTools/ShapeRenderer.cpp | 75 +++++++++++ src/DebugTools/ShapeRenderer.h | 119 ++++++++++++++++++ src/DebugTools/magnumDebugToolsVisibility.h | 28 +++++ src/Magnum.h | 1 - src/Physics/CMakeLists.txt | 9 +- src/Physics/DebugDrawResourceManager.cpp | 76 ----------- src/Physics/DebugDrawResourceManager.h | 117 ----------------- .../Implementation/AbstractDebugRenderer.cpp | 32 ----- .../Implementation/AbstractDebugRenderer.h | 42 ------- src/Physics/Implementation/DebugRenderer.h | 58 --------- src/Physics/Physics.h | 6 +- src/ResourceManager.h | 2 +- 32 files changed, 456 insertions(+), 407 deletions(-) create mode 100644 src/DebugTools/CMakeLists.txt create mode 100644 src/DebugTools/DebugTools.h rename src/{Physics => DebugTools}/Implementation/AbstractBoxRenderer.cpp (77%) rename src/{Physics => DebugTools}/Implementation/AbstractBoxRenderer.h (75%) rename src/{Physics => DebugTools}/Implementation/AbstractShapeRenderer.cpp (77%) rename src/{Physics => DebugTools}/Implementation/AbstractShapeRenderer.h (66%) rename src/{Physics => DebugTools}/Implementation/AxisAlignedBoxRenderer.cpp (80%) rename src/{Physics => DebugTools}/Implementation/AxisAlignedBoxRenderer.h (58%) rename src/{Physics => DebugTools}/Implementation/BoxRenderer.cpp (76%) rename src/{Physics => DebugTools}/Implementation/BoxRenderer.h (62%) rename src/{ => DebugTools}/Profiler.cpp (98%) rename src/{ => DebugTools}/Profiler.h (93%) create mode 100644 src/DebugTools/ResourceManager.cpp create mode 100644 src/DebugTools/ResourceManager.h create mode 100644 src/DebugTools/ShapeRenderer.cpp create mode 100644 src/DebugTools/ShapeRenderer.h create mode 100644 src/DebugTools/magnumDebugToolsVisibility.h delete mode 100644 src/Physics/DebugDrawResourceManager.cpp delete mode 100644 src/Physics/DebugDrawResourceManager.h delete mode 100644 src/Physics/Implementation/AbstractDebugRenderer.cpp delete mode 100644 src/Physics/Implementation/AbstractDebugRenderer.h delete mode 100644 src/Physics/Implementation/DebugRenderer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b03431419..a0de8a35f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,12 @@ cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF # Parts of the library option(WITH_EVERYTHING "Build everything (doesn't include *Application libraries)" ON) -cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) -cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING" ON) -cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) -cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) -cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_PHYSICS" ON) +cmake_dependent_option(WITH_DEBUGTOOLS "Build DebugTools library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) diff --git a/doc/building.dox b/doc/building.dox index 4014adb3d..9d2d6ecda 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -66,6 +66,8 @@ specify which parts will be built and which not: - `WITH_EVERYTHING` - Defaults to `ON`, builds everything except application libraries. If set to `OFF`, only the main library is built and you can select additional components with the following: + - `WITH_DEBUGTOOLS` - DebugTools library. Enables also building of MeshTools, + Physics, Primitives, SceneGraph and Shaders libraries. - `WITH_MESHTOOLS` - MeshTools library. - `WITH_PHYSICS` - Physics library. - `WITH_PRIMITIVES` - Primitives library. diff --git a/doc/mainpage.dox b/doc/mainpage.dox index b262155a7..27a0ec6db 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -13,7 +13,7 @@ Features: @ref Framebuffer "framebuffer" and @ref AbstractQuery "occlusion queries". - @ref MeshTools "Mesh tools" for cleaning, optimizing and generating meshes, utility classes for @ref Color.h "color conversion", @ref Timeline "timeline" - and @ref Profiler "profiling". + and @ref DebugTools::Profiler "profiling". - Hierarchical @ref SceneGraph "scene graph" which supports transformation caching for better performance, @ref Physics "physics library" for collision detection and rigid body dynamics. diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 7e0f7c08e..915f3c0b2 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -47,6 +47,15 @@ Various matrix and vector algorithms. Functions for computing intersections, distances, areas and volumes. */ +/** @dir DebugTools + * @brief Namespace Magnum::DebugTools + */ +/** @namespace Magnum::DebugTools +@brief %Debug tools + +Debugging helpers, renderers and profilers. +*/ + /** @dir MeshTools * @brief Namespace Magnum::MeshTools */ diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 6a69a0d03..be3423bc4 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -15,9 +15,10 @@ # components. The base library depends on Corrade, OpenGL and GLEW # libraries. Additional dependencies are specified by the components. The # optional components are: +# DebugTools - DebugTools library (depends on MeshTools, Physics, +# Primitives, SceneGraph and Shaders components) # MeshTools - MeshTools library -# Physics - Physics library (depends on Primitives, SceneGraph and -# Shaders components) +# Physics - Physics library # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders @@ -166,6 +167,11 @@ foreach(component ${Magnum_FIND_COMPONENTS}) endif() endif() + # DebugTools library + if(${component} STREQUAL DebugTools) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Profiler.h) + endif() + # Mesh tools library if(${component} STREQUAL MeshTools) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb5732e97..ed702f4f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,7 +23,6 @@ set(Magnum_SRCS Image.cpp IndexedMesh.cpp Mesh.cpp - Profiler.cpp Query.cpp Renderbuffer.cpp Resource.cpp @@ -72,7 +71,6 @@ set(Magnum_HEADERS IndexedMesh.h Magnum.h Mesh.h - Profiler.h Query.h Renderbuffer.h Renderer.h @@ -140,6 +138,10 @@ add_subdirectory(Platform) add_subdirectory(Math) add_subdirectory(Trade) +if(WITH_DEBUGTOOLS) + add_subdirectory(DebugTools) +endif() + if(WITH_MESHTOOLS) add_subdirectory(MeshTools) endif() diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt new file mode 100644 index 000000000..3b6f17daf --- /dev/null +++ b/src/DebugTools/CMakeLists.txt @@ -0,0 +1,24 @@ +set(MagnumDebugTools_SRCS + Profiler.cpp + ResourceManager.cpp + ShapeRenderer.cpp + + Implementation/AbstractBoxRenderer.cpp + Implementation/AbstractShapeRenderer.cpp + Implementation/AxisAlignedBoxRenderer.cpp + Implementation/BoxRenderer.cpp) + +set(MagnumDebugTools_HEADERS + DebugTools.h + Profiler.h + ResourceManager.h + ShapeRenderer.h + + magnumDebugToolsVisibility.h) + +add_library(MagnumDebugTools SHARED ${MagnumDebugTools_SRCS}) + +target_link_libraries(MagnumDebugTools Magnum MagnumPhysics MagnumPrimitives MagnumSceneGraph MagnumShaders) + +install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h new file mode 100644 index 000000000..82ab4d2b3 --- /dev/null +++ b/src/DebugTools/DebugTools.h @@ -0,0 +1,33 @@ +#ifndef Magnum_DebugTools_DebugTools_h +#define Magnum_DebugTools_DebugTools_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Forward declarations for Magnum::DebugTools namespace + */ + +#include + +namespace Magnum { namespace DebugTools { + +class Profiler; +class ResourceManager; +template class ShapeRenderer; +struct ShapeRendererOptions; + +}} + +#endif diff --git a/src/Physics/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp similarity index 77% rename from src/Physics/Implementation/AbstractBoxRenderer.cpp rename to src/DebugTools/Implementation/AbstractBoxRenderer.cpp index 95e7cdaeb..d22610977 100644 --- a/src/Physics/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -16,12 +16,12 @@ #include "AbstractBoxRenderer.h" #include "Buffer.h" -#include "Physics/DebugDrawResourceManager.h" +#include "DebugTools/ResourceManager.h" #include "Primitives/Cube.h" #include "Primitives/Square.h" #include "Shaders/FlatShader.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { namespace { template struct BoxMesh {}; @@ -55,10 +55,10 @@ namespace { }; } -template AbstractBoxRenderer::AbstractBoxRenderer(): AbstractDebugRenderer(BoxMesh::shader(), BoxMesh::key()), buffer(DebugDrawResourceManager::instance()->get(BoxMesh::key())) { +template AbstractBoxRenderer::AbstractBoxRenderer(): AbstractShapeRenderer(BoxMesh::shader(), BoxMesh::key()), buffer(ResourceManager::instance()->get(BoxMesh::key())) { if(!this->mesh) { - DebugDrawResourceManager::instance()->set(this->buffer.key(), new Buffer, ResourceDataState::Final, ResourcePolicy::Manual); - DebugDrawResourceManager::instance()->set(this->mesh.key(), BoxMesh::mesh(buffer), ResourceDataState::Final, ResourcePolicy::Manual); + ResourceManager::instance()->set(this->buffer.key(), new Buffer, ResourceDataState::Final, ResourcePolicy::Manual); + ResourceManager::instance()->set(this->mesh.key(), BoxMesh::mesh(buffer), ResourceDataState::Final, ResourcePolicy::Manual); } } diff --git a/src/Physics/Implementation/AbstractBoxRenderer.h b/src/DebugTools/Implementation/AbstractBoxRenderer.h similarity index 75% rename from src/Physics/Implementation/AbstractBoxRenderer.h rename to src/DebugTools/Implementation/AbstractBoxRenderer.h index 2c7bcea28..ef3023527 100644 --- a/src/Physics/Implementation/AbstractBoxRenderer.h +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Physics_Implementation_AbstractBoxRenderer_h -#define Magnum_Physics_Implementation_AbstractBoxRenderer_h +#ifndef Magnum_DebugTools_Implementation_AbstractBoxRenderer_h +#define Magnum_DebugTools_Implementation_AbstractBoxRenderer_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -15,13 +15,13 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractDebugRenderer.h" +#include "AbstractShapeRenderer.h" #include "corradeCompatibility.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { -template class AbstractBoxRenderer: public AbstractDebugRenderer { +template class AbstractBoxRenderer: public AbstractShapeRenderer { public: AbstractBoxRenderer(); diff --git a/src/Physics/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp similarity index 77% rename from src/Physics/Implementation/AbstractShapeRenderer.cpp rename to src/DebugTools/Implementation/AbstractShapeRenderer.cpp index ee4d3596e..0ddb6964c 100644 --- a/src/Physics/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -17,12 +17,12 @@ #include "AbstractShaderProgram.h" #include "Mesh.h" -#include "Physics/DebugDrawResourceManager.h" +#include "DebugTools/ResourceManager.h" #include "Shaders/FlatShader.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { -template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey shader, ResourceKey mesh): shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)) {} +template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey shader, ResourceKey mesh): shader(ResourceManager::instance()->get>(shader)), mesh(ResourceManager::instance()->get(mesh)) {} template AbstractShapeRenderer::~AbstractShapeRenderer() {} diff --git a/src/Physics/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h similarity index 66% rename from src/Physics/Implementation/AbstractShapeRenderer.h rename to src/DebugTools/Implementation/AbstractShapeRenderer.h index 737e29895..adec6e7fe 100644 --- a/src/Physics/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Physics_Implementation_AbstractShapeRenderer_h -#define Magnum_Physics_Implementation_AbstractShapeRenderer_h +#ifndef Magnum_DebugTools_Implementation_AbstractShapeRenderer_h +#define Magnum_DebugTools_Implementation_AbstractShapeRenderer_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -18,19 +18,10 @@ #include "DimensionTraits.h" #include "ResourceManager.h" #include "SceneGraph/SceneGraph.h" +#include "Shaders/Shaders.h" +#include "DebugTools/DebugTools.h" -namespace Magnum { - -class AbstractShaderProgram; -class Mesh; - -namespace Shaders { - template class FlatShader; -} - -namespace Physics { namespace Implementation { - -struct Options; +namespace Magnum { namespace DebugTools { namespace Implementation { template class AbstractShapeRenderer { public: @@ -38,7 +29,7 @@ template class AbstractShapeRenderer { virtual ~AbstractShapeRenderer(); - virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; + virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; protected: Resource> shader; diff --git a/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp similarity index 80% rename from src/Physics/Implementation/AxisAlignedBoxRenderer.cpp rename to src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 97102bf35..507682d9a 100644 --- a/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -16,13 +16,14 @@ #include "AxisAlignedBoxRenderer.h" #include "Mesh.h" -#include "Physics/DebugDrawResourceManager.h" +#include "DebugTools/ResourceManager.h" +#include "DebugTools/ShapeRenderer.h" #include "SceneGraph/AbstractCamera.h" #include "Shaders/FlatShader.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { -template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { +template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { typename DimensionTraits::MatrixType transformation = DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()); diff --git a/src/Physics/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h similarity index 58% rename from src/Physics/Implementation/AxisAlignedBoxRenderer.h rename to src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index 7eae09acf..cf1120433 100644 --- a/src/Physics/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Physics_Implementation_AxisAlignedBoxRenderer_h -#define Magnum_Physics_Implementation_AxisAlignedBoxRenderer_h +#ifndef Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h +#define Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -21,16 +21,16 @@ #include "corradeCompatibility.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { template class AxisAlignedBoxRenderer: public AbstractBoxRenderer { public: - inline AxisAlignedBoxRenderer(AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} + inline AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} - void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; private: - AxisAlignedBox& axisAlignedBox; + Physics::AxisAlignedBox& axisAlignedBox; }; }}} diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp similarity index 76% rename from src/Physics/Implementation/BoxRenderer.cpp rename to src/DebugTools/Implementation/BoxRenderer.cpp index 840c6b306..a11ade2e7 100644 --- a/src/Physics/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -16,13 +16,14 @@ #include "BoxRenderer.h" #include "Mesh.h" -#include "Physics/DebugDrawResourceManager.h" +#include "DebugTools/ResourceManager.h" +#include "DebugTools/ShapeRenderer.h" #include "SceneGraph/AbstractCamera.h" #include "Shaders/FlatShader.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { -template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { +template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) ->setColor(options->color) ->use(); diff --git a/src/Physics/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h similarity index 62% rename from src/Physics/Implementation/BoxRenderer.h rename to src/DebugTools/Implementation/BoxRenderer.h index ef67869fd..acaf154f6 100644 --- a/src/Physics/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Physics_Implementation_BoxRenderer_h -#define Magnum_Physics_Implementation_BoxRenderer_h +#ifndef Magnum_DebugTools_Implementation_BoxRenderer_h +#define Magnum_DebugTools_Implementation_BoxRenderer_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -21,16 +21,16 @@ #include "corradeCompatibility.h" -namespace Magnum { namespace Physics { namespace Implementation { +namespace Magnum { namespace DebugTools { namespace Implementation { template class BoxRenderer: public AbstractBoxRenderer { public: - inline BoxRenderer(Box& box): box(box) {} + inline BoxRenderer(Physics::Box& box): box(box) {} - void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; private: - Box& box; + Physics::Box& box; }; }}} diff --git a/src/Profiler.cpp b/src/DebugTools/Profiler.cpp similarity index 98% rename from src/Profiler.cpp rename to src/DebugTools/Profiler.cpp index 5682c3072..288ba1392 100644 --- a/src/Profiler.cpp +++ b/src/DebugTools/Profiler.cpp @@ -21,7 +21,7 @@ #include "Magnum.h" -namespace Magnum { +namespace Magnum { namespace DebugTools { Profiler::Section Profiler::addSection(const std::string& name) { CORRADE_ASSERT(!enabled, "Profiler: cannot add section when profiling is enabled", 0); @@ -108,4 +108,4 @@ void Profiler::printStatistics() { Debug() << ' ' << sections[totalSorted[i]] << std::chrono::microseconds(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; } -} +}} diff --git a/src/Profiler.h b/src/DebugTools/Profiler.h similarity index 93% rename from src/Profiler.h rename to src/DebugTools/Profiler.h index 173b00b17..29f541f0a 100644 --- a/src/Profiler.h +++ b/src/DebugTools/Profiler.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Profiler_h -#define Magnum_Profiler_h +#ifndef Magnum_DebugTools_Profiler_h +#define Magnum_DebugTools_Profiler_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Profiler + * @brief Class Magnum::DebugTools::Profiler */ #include @@ -24,22 +24,22 @@ #include #include -#include "magnumVisibility.h" +#include "magnumDebugToolsVisibility.h" -namespace Magnum { +namespace Magnum { namespace DebugTools { /** -@brief Measuring elapsed time in each frame +@brief %Profiler Measures time passed during specified sections of each frame. It's meant to be used in rendering and event loops (e.g. Platform::GlutApplication::drawEvent()), but it's possible to use it standalone elsewhere. Example usage: @code -Profiler p; +DebugTools::Profiler p; // Register named sections struct { - Profiler::Section ai, physics, draw, bufferSwap; + DebugTools::Profiler::Section ai, physics, draw, bufferSwap; } sections; sections.ai = p.addSection("AI"); sections.physics = p.addSection("Physics"); @@ -88,7 +88,7 @@ stop it again using stop(), if you are not interested in profiling the rest. @todo Some unit testing @todo More time intervals */ -class MAGNUM_EXPORT Profiler { +class MAGNUM_DEBUGTOOLS_EXPORT Profiler { public: /** * @brief Section ID @@ -201,6 +201,6 @@ class MAGNUM_EXPORT Profiler { Section currentSection; }; -} +}} #endif diff --git a/src/DebugTools/ResourceManager.cpp b/src/DebugTools/ResourceManager.cpp new file mode 100644 index 000000000..5e85d0f48 --- /dev/null +++ b/src/DebugTools/ResourceManager.cpp @@ -0,0 +1,38 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE + +#include "ResourceManager.h" + +#include "Buffer.h" +#include "Mesh.h" +#include "Shaders/FlatShader.h" +#include "ShapeRenderer.h" + +namespace Magnum { + +template class ResourceManager; + +namespace DebugTools { + +ResourceManager::ResourceManager() { + setFallback(new ShapeRendererOptions); + set("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); +} + +ResourceManager::~ResourceManager() {} + +}} diff --git a/src/DebugTools/ResourceManager.h b/src/DebugTools/ResourceManager.h new file mode 100644 index 000000000..98ca34956 --- /dev/null +++ b/src/DebugTools/ResourceManager.h @@ -0,0 +1,54 @@ +#ifndef Magnum_DebugTools_ResourceManager_h +#define Magnum_DebugTools_ResourceManager_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::DebugTools::ResourceManager + */ + +#include "Magnum.h" + +#ifndef MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE +#define MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE +#endif +#include "../ResourceManager.h" + +#include "SceneGraph/SceneGraph.h" +#include "Physics/Physics.h" +#include "DebugTools.h" + +#include "magnumDebugToolsVisibility.h" + +namespace Magnum { + +extern template ResourceManager MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager::internalInstance(); + +namespace DebugTools { + +/** +@brief %Resource manager for debug tools + +Stores various data used by debug renderers. +*/ +class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager { + public: + explicit ResourceManager(); + ~ResourceManager(); +}; + +}} + +#endif diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp new file mode 100644 index 000000000..bb5f6fe6a --- /dev/null +++ b/src/DebugTools/ShapeRenderer.cpp @@ -0,0 +1,75 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ShapeRenderer.h" + +#include "ResourceManager.h" +#include "Physics/AbstractShape.h" +#include "Physics/AxisAlignedBox.h" +#include "Physics/Box.h" +#include "Physics/ObjectShape.h" +#include "Physics/ShapeGroup.h" + +#include "Implementation/AxisAlignedBoxRenderer.h" +#include "Implementation/BoxRenderer.h" + +namespace Magnum { namespace DebugTools { + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractShape<2>* shape) { + switch(shape->type()) { + case Physics::AbstractShape2D::Type::AxisAlignedBox: + renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast(shape))); + case Physics::AbstractShape2D::Type::Box: + renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast(shape))); + break; + case Physics::AbstractShape2D::Type::ShapeGroup: { + Physics::ShapeGroup2D* group = static_cast(shape); + if(group->first()) createDebugMesh(renderer, group->first()); + if(group->second()) createDebugMesh(renderer, group->second()); + } break; + default: + Warning() << "DebugTools::ShapeRenderer2D::createShapeRenderer(): type" << shape->type() << "not implemented"; + } +} + +template<> void createDebugMesh(ShapeRenderer<3>*, Physics::AbstractShape<3>* shape) { + switch(shape->type()) { + default: + Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; + } +} + +} +#endif + +template ShapeRenderer::ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { + Implementation::createDebugMesh(this, shape->shape()); +} + +template ShapeRenderer::~ShapeRenderer() { + for(auto i: renderers) delete i; +} + +template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { + for(auto i: renderers) i->draw(options, transformationMatrix, camera); +} + +template class ShapeRenderer<2>; +template class ShapeRenderer<3>; + +}} diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h new file mode 100644 index 000000000..0a600dff4 --- /dev/null +++ b/src/DebugTools/ShapeRenderer.h @@ -0,0 +1,119 @@ +#ifndef Magnum_DebugTools_ShapeRenderer_h +#define Magnum_DebugTools_ShapeRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Color.h" +#include "Resource.h" +#include "SceneGraph/Drawable.h" +#include "Physics/Physics.h" + +#include "magnumDebugToolsVisibility.h" + +namespace Magnum { namespace DebugTools { + +template class ShapeRenderer; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template class AbstractShapeRenderer; + + template void createDebugMesh(ShapeRenderer* renderer, Physics::AbstractShape* shape); +} +#endif + +/** +@brief Shape renderer options + +See ShapeRenderer documentation for more information. +*/ +struct ShapeRendererOptions { + Color3<> color; /**< @brief Color */ +}; + +/** +@brief Shape renderer + +Creates renderers for object collision shape. + +@section ShapeRenderer-usage Basic usage + +ResourceManager must be instanced for the whole lifetime of debug +renderers. You can specify options via Options struct - add it to the manager +and then create debug renderer with the same options key. This way you can +easily share the same options with more renderers. If no options for given key +exist, default is used. + +Example code: +@code +// Instance the manager at first +DebugTools::ResourceManager manager; + +// Group of drawables, preferrably dedicated for debug renderers, so you can +// easily enable or disable debug draw +SceneGraph::DrawableGroup2D debugDrawables; + +// Create some options +auto o = new DebugTools::ShapeRendererOptions { + {1.0f, 0.0f, 0.0f} // Red color +}; +manager->set("red", o, ResourceDataState::Final, ResourcePolicy::Persistent); + +// Create debug renderer for given shape, use "red" options for it +Physics::ObjectShape2D* shape; +debugDrawables.add(new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables)); +@endcode + +@see ShapeRenderer2D, ShapeRenderer3D +*/ +template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable { + #ifndef DOXYGEN_GENERATING_OUTPUT + friend void Implementation::createDebugMesh<>(ShapeRenderer*, Physics::AbstractShape*); + #endif + + public: + /** + * @brief Constructor + * @param shape Shape for which to create debug renderer + * @param options Options resource key. See + * @ref ShapeRenderer-usage "class documentation" for more + * information. + * @param drawables Drawable group + * + * @attention @p shape must be available for the whole lifetime of + * this class + */ + explicit ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); + + ~ShapeRenderer(); + + protected: + /** @todoc Remove GLfloat when Doxygen properly treats this as override */ + void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; + + private: + Resource options; + std::vector*> renderers; +}; + +/** @brief Two-dimensional shape renderer */ +typedef ShapeRenderer<2> ShapeRenderer2D; + +/** @brief Three-dimensional shape renderer */ +typedef ShapeRenderer<3> ShapeRenderer3D; + +}} + +#endif diff --git a/src/DebugTools/magnumDebugToolsVisibility.h b/src/DebugTools/magnumDebugToolsVisibility.h new file mode 100644 index 000000000..6032af2d1 --- /dev/null +++ b/src/DebugTools/magnumDebugToolsVisibility.h @@ -0,0 +1,28 @@ +#ifndef Magnum_DebugTools_magnumDebugToolsVisibility_h +#define Magnum_DebugTools_magnumDebugToolsVisibility_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#ifdef _WIN32 + #ifdef MagnumDebugTools_EXPORTS + #define MAGNUM_DEBUGTOOLS_EXPORT __declspec(dllexport) + #else + #define MAGNUM_DEBUGTOOLS_EXPORT __declspec(dllimport) + #endif +#else + #define MAGNUM_DEBUGTOOLS_EXPORT __attribute__ ((visibility ("default"))) +#endif + +#endif diff --git a/src/Magnum.h b/src/Magnum.h index 6e4cf7ee2..b4af2f8a3 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -175,7 +175,6 @@ typedef ImageWrapper<3> ImageWrapper3D; class IndexedMesh; class Mesh; -class Profiler; class Query; class Renderbuffer; diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index c2b35ce8a..a83dc21e3 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -3,26 +3,19 @@ set(MagnumPhysics_SRCS AxisAlignedBox.cpp Box.cpp Capsule.cpp - DebugDrawResourceManager.cpp Line.cpp Plane.cpp Point.cpp ObjectShape.cpp ObjectShapeGroup.cpp ShapeGroup.cpp - Sphere.cpp - - Implementation/AbstractBoxRenderer.cpp - Implementation/AbstractDebugRenderer.cpp - Implementation/AxisAlignedBoxRenderer.cpp - Implementation/BoxRenderer.cpp) + Sphere.cpp) set(MagnumPhysics_HEADERS AbstractShape.h AxisAlignedBox.h Box.h Capsule.h - DebugDrawResourceManager.h Line.h LineSegment.h ObjectShape.h diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp deleted file mode 100644 index ba2560e02..000000000 --- a/src/Physics/DebugDrawResourceManager.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE - -#include "DebugDrawResourceManager.h" - -#include "AbstractShaderProgram.h" -#include "Buffer.h" -#include "Mesh.h" -#include "ResourceManager.h" -#include "Shaders/FlatShader.h" -#include "AbstractShape.h" -#include "AxisAlignedBox.h" -#include "Box.h" -#include "ObjectShape.h" -#include "ShapeGroup.h" -#include "Implementation/AxisAlignedBoxRenderer.h" -#include "Implementation/BoxRenderer.h" -#include "Implementation/DebugRenderer.h" - -namespace Magnum { - -template class ResourceManager; - -namespace Physics { - -template SceneGraph::Drawable* DebugDrawResourceManager::createDebugRenderer(ObjectShape* shape, ResourceKey options) { - Implementation::DebugRenderer* renderer = new Implementation::DebugRenderer(shape->object(), instance()->get(options)); - createDebugMesh(renderer, shape->shape()); - return renderer; -} - -template SceneGraph::Drawable<2> MAGNUM_PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<2>* shape, ResourceKey options); -template SceneGraph::Drawable<3> MAGNUM_PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<3>* shape, ResourceKey options); - -void DebugDrawResourceManager::createDebugMesh(Implementation::DebugRenderer<2>* renderer, AbstractShape2D* shape) { - switch(shape->type()) { - case AbstractShape2D::Type::AxisAlignedBox: - renderer->addRenderer(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast(shape))); - case AbstractShape2D::Type::Box: - renderer->addRenderer(new Implementation::BoxRenderer<2>(*static_cast(shape))); - break; - case AbstractShape2D::Type::ShapeGroup: { - ShapeGroup2D* group = static_cast(shape); - if(group->first()) createDebugMesh(renderer, group->first()); - if(group->second()) createDebugMesh(renderer, group->second()); - break; - } - default: - Warning() << "Physics::DebugDrawResourceManager::createDebugRenderer(): type" << shape->type() << "not implemented"; - } -} - -void DebugDrawResourceManager::createDebugMesh(Implementation::DebugRenderer<3>*, AbstractShape3D*) {} - -DebugDrawResourceManager::DebugDrawResourceManager() { - setFallback(new Options); - set("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); -} - -DebugDrawResourceManager::~DebugDrawResourceManager() {} - -}} diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h deleted file mode 100644 index 9381ac3f7..000000000 --- a/src/Physics/DebugDrawResourceManager.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef Magnum_Physics_DebugDrawResourceManager_h -#define Magnum_Physics_DebugDrawResourceManager_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::Physics::DebugDrawResourceManager - */ - -#include "Magnum.h" -#include "Color.h" - -#ifndef MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE -#define MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE -#endif -#include "ResourceManager.h" - -#include "SceneGraph/SceneGraph.h" -#include "Physics.h" - -#include "magnumPhysicsVisibility.h" - -namespace Magnum { - -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Physics { namespace Implementation { - struct Options { - Color3<> color; - }; - template class DebugRenderer; -}} -#endif - -extern template ResourceManager MAGNUM_PHYSICS_EXPORT *& ResourceManager::internalInstance(); - -namespace Physics { - -/** -@brief %Resource manager for physics debug draw - -Can create objects which draw object collision shape for debugging purposes. - -@section DebugDrawResourceManager-usage Basic usage -The manager must be instanced for the whole lifetime of debug draw objects. -To create debug renderers, call createDebugRenderer() and add the resulting -drawable to some group. You can specify options via Options struct - add it to -the manager and then create debug renderer with the same options key. This way -you can easily share the same options with more renderers. If no options for -given key exist, default is used. - -Example code: -@code -// Group of drawables,preferrably dedicated for debug renderers, so you can -// easily enable or disable debug draw -DrawableGroup2D group; - -// Instance the manager at first -DebugDrawResourceManager manager; - -// Create some options -auto o = new DebugDrawResourceManager::Options { - {1.0f, 0.0f, 0.0f} // Red color -}; -manager->set("red", o, ResourceDataState::Final, ResourcePolicy::Persistent); - -// Create debug renderer for given shape, use "red" options for it. Don't -// forget to add it to some drawable group. -ObjectShape2D* shape; -group.add(DebugDrawResourceManager::createDebugRenderer(shape, "red")); -@endcode -*/ -class MAGNUM_PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager { - public: - #ifdef DOXYGEN_GENERATING_OUTPUT - /** @brief %Options */ - struct Options { - Color3<> color; /**< @brief Color */ - }; - #else - typedef Implementation::Options Options; - #endif - - /** - * @brief Create debug renderer for given shape - * @param shape Shape for which to create debug renderer - * @param options Options resource key. See - * @ref DebugDrawResourceManager-usage "class documentation" for - * more information. - * - * Returned drawable is not part of any group, you have to add it to - * one yourself. - */ - template static SceneGraph::Drawable* createDebugRenderer(ObjectShape* shape, ResourceKey options = ResourceKey()); - - explicit DebugDrawResourceManager(); - ~DebugDrawResourceManager(); - - private: - static void createDebugMesh(Implementation::DebugRenderer<2>* renderer, AbstractShape2D* shape); - static void createDebugMesh(Implementation::DebugRenderer<3>* renderer, AbstractShape3D* shape); -}; - -}} - -#endif diff --git a/src/Physics/Implementation/AbstractDebugRenderer.cpp b/src/Physics/Implementation/AbstractDebugRenderer.cpp deleted file mode 100644 index dbd41dcd7..000000000 --- a/src/Physics/Implementation/AbstractDebugRenderer.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "AbstractDebugRenderer.h" - -#include "AbstractShaderProgram.h" -#include "Mesh.h" -#include "Physics/DebugDrawResourceManager.h" -#include "Shaders/FlatShader.h" - -namespace Magnum { namespace Physics { namespace Implementation { - -template AbstractDebugRenderer::AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh): shader(DebugDrawResourceManager::instance()->get>(shader)), mesh(DebugDrawResourceManager::instance()->get(mesh)) {} - -template AbstractDebugRenderer::~AbstractDebugRenderer() {} - -template class AbstractDebugRenderer<2>; -template class AbstractDebugRenderer<3>; - -}}} diff --git a/src/Physics/Implementation/AbstractDebugRenderer.h b/src/Physics/Implementation/AbstractDebugRenderer.h deleted file mode 100644 index 04e7a8a6b..000000000 --- a/src/Physics/Implementation/AbstractDebugRenderer.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef Magnum_Physics_Implementation_AbstractDebugRenderer_h -#define Magnum_Physics_Implementation_AbstractDebugRenderer_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "DimensionTraits.h" -#include "ResourceManager.h" -#include "SceneGraph/SceneGraph.h" -#include "Shaders/Shaders.h" - -namespace Magnum { namespace Physics { namespace Implementation { - -struct Options; - -template class AbstractDebugRenderer { - public: - AbstractDebugRenderer(ResourceKey shader, ResourceKey mesh); - - virtual ~AbstractDebugRenderer(); - - virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; - - protected: - Resource> shader; - Resource mesh; -}; - -}}} - -#endif diff --git a/src/Physics/Implementation/DebugRenderer.h b/src/Physics/Implementation/DebugRenderer.h deleted file mode 100644 index 87e806392..000000000 --- a/src/Physics/Implementation/DebugRenderer.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef Magnum_Physics_Implementation_DebugRenderer_h -#define Magnum_Physics_Implementation_DebugRenderer_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "ResourceManager.h" -#include "SceneGraph/Drawable.h" -#include "AbstractDebugRenderer.h" - -namespace Magnum { - -class AbstractShaderProgram; -class Mesh; - -namespace Shaders { - template class FlatShader; -} - -namespace Physics { namespace Implementation { - -struct Options; - -template class DebugRenderer: public SceneGraph::Drawable { - public: - DebugRenderer(SceneGraph::AbstractObject* object, Resource&& options): SceneGraph::Drawable(object), options(options) {} - - inline ~DebugRenderer() { - for(auto i: renderers) delete i; - } - - inline void addRenderer(AbstractDebugRenderer* renderer) { - renderers.push_back(renderer); - } - - inline void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override { - for(auto i: renderers) i->draw(options, transformationMatrix, camera); - } - - private: - Resource options; - std::vector*> renderers; -}; - -}}} - -#endif diff --git a/src/Physics/Physics.h b/src/Physics/Physics.h index aca5325fe..066c0a029 100644 --- a/src/Physics/Physics.h +++ b/src/Physics/Physics.h @@ -15,12 +15,12 @@ GNU Lesser General Public License version 3 for more details. */ -#include - /** @file * @brief Forward declarations for Magnum::Physics namespace */ +#include + namespace Magnum { namespace Physics { template class AbstractShape; @@ -39,8 +39,6 @@ template class Capsule; typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; -class DebugDrawResourceManager; - template class Line; typedef Line<2> Line2D; typedef Line<3> Line3D; diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 19bb8f1aa..1e6e68516 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -15,7 +15,7 @@ GNU Lesser General Public License version 3 for more details. */ -/** @file +/** @file /ResourceManager.h * @brief Class Magnum::ResourceManager, enum Magnum::ResourceDataState, Magnum::ResourcePolicy */ From e16b5cc263a508a74e08977ed16e864e01a21aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Dec 2012 01:28:47 +0100 Subject: [PATCH 075/567] Doc: worked around Doxygen warnings. It seems that Doxygen parser breaks itself each third Saturday after full moon. --- src/SceneGraph/Drawable.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 36ee9fa75..bb20a3960 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -114,8 +114,15 @@ template #endif class Drawable: public AbstractGroupedFeature, T> { public: - /** @copydoc AbstractGroupedFeature::AbstractGroupedFeature() */ - inline explicit Drawable(AbstractObject* object, DrawableGroup* group = nullptr): AbstractGroupedFeature, T>(object, group) {} + /** + * @brief Constructor + * @param object %Object this drawable belongs to + * @param drawables Group this drawable belongs to + * + * Adds the feature to the object and also to the group, if specified. + * Otherwise you can use DrawableGroup::add(). + */ + inline explicit Drawable(AbstractObject* object, DrawableGroup* drawables = nullptr): AbstractGroupedFeature, T>(object, drawables) {} /** * @brief Draw the object using given camera From 5cd4aa8dcd8707d263b981c1cf3c6708b532f82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 18:24:27 +0100 Subject: [PATCH 076/567] Doc++ --- doc/compilation-speedup.dox | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/compilation-speedup.dox b/doc/compilation-speedup.dox index d67a69c6b..ca42d8774 100644 --- a/doc/compilation-speedup.dox +++ b/doc/compilation-speedup.dox @@ -20,6 +20,7 @@ typedefs etc. In this case a header with forward declarations is usually available, each namespace has its own: - Magnum.h + - DebugTools/DebugTools.h - Physics/Physics.h - SceneGraph/SceneGraph.h - Shaders/Shaders.h From c4b6e5ea33979a41530aae5218bc0b85de762d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Dec 2012 02:41:30 +0100 Subject: [PATCH 077/567] Math: helper Rectangle class. --- src/Math/Geometry/CMakeLists.txt | 3 +- src/Math/Geometry/Rectangle.h | 110 +++++++++++++++++++++++ src/Math/Geometry/Test/CMakeLists.txt | 1 + src/Math/Geometry/Test/RectangleTest.cpp | 71 +++++++++++++++ src/Math/Geometry/Test/RectangleTest.h | 34 +++++++ 5 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 src/Math/Geometry/Rectangle.h create mode 100644 src/Math/Geometry/Test/RectangleTest.cpp create mode 100644 src/Math/Geometry/Test/RectangleTest.h diff --git a/src/Math/Geometry/CMakeLists.txt b/src/Math/Geometry/CMakeLists.txt index 35e4ba1e0..fb55add04 100644 --- a/src/Math/Geometry/CMakeLists.txt +++ b/src/Math/Geometry/CMakeLists.txt @@ -2,7 +2,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(MagnumMathGeometry_HEADERS Distance.h - Intersection.h) + Intersection.h + Rectangle.h) install(FILES ${MagnumMathGeometry_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Geometry) if(BUILD_TESTS) diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h new file mode 100644 index 000000000..fea8225cd --- /dev/null +++ b/src/Math/Geometry/Rectangle.h @@ -0,0 +1,110 @@ +#ifndef Magnum_Math_Geometry_Rectangle_h +#define Magnum_Math_Geometry_Rectangle_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Geometry::Rectangle + */ + +#include "Math/Vector2.h" + +namespace Magnum { namespace Math { namespace Geometry { + +/** +@brief %Rectangle + +Helper class for storing axis-aligned rectangles consisting of bottom left and +top right corner positions. Bottom left position is inclusive, while top right +position is exclusive. +*/ +template class Rectangle { + public: + /** + * Create rectangle from position and size + * @param bottomLeft Bottom left rectangle corner + * @param size %Rectangle size + */ + inline static Rectangle fromSize(const Vector2& bottomLeft, const Vector2& size) { + return {bottomLeft, bottomLeft+size}; + } + + /** + * @brief Default constructor + * + * Construct zero-area rectangle positioned at origin. + */ + inline constexpr Rectangle() = default; + + /** + * @brief Constructor + * @param bottomLeft Bottom left rectangle corner + * @param topRight Top right rectangle corner + */ + inline constexpr Rectangle(const Vector2& bottomLeft, const Vector2& topRight): _bottomLeft(bottomLeft), _topRight(topRight) {} + + /** @brief Equality operator */ + inline constexpr bool operator==(const Rectangle& other) const { + return _bottomLeft == other._bottomLeft && _topRight == other._topRight; + } + + /** @brief Non-equality operator */ + inline constexpr bool operator!=(const Rectangle& other) const { + return !operator==(other); + } + + /** @brief Bottom left corner */ + inline Vector2& bottomLeft() { return _bottomLeft; } + inline constexpr Vector2 bottomLeft() const { return _bottomLeft; } /**< @overload */ + + /** @brief Top right corner */ + inline Vector2& topRight() { return _topRight; } + inline constexpr Vector2 topRight() const { return _topRight; } /**< @overload */ + + /** @brief Bottom edge */ + inline T& bottom() { return _bottomLeft.y(); } + inline constexpr T bottom() const { return _bottomLeft.y(); } /**< @overload */ + + /** @brief Top edge */ + inline T& top() { return _topRight.y(); } + inline constexpr T top() const { return _topRight.y(); } /**< @overload */ + + /** @brief Left edge */ + inline T& left() { return _bottomLeft.x(); } + inline constexpr T left() const { return _bottomLeft.x(); } /**< @overload */ + + /** @brief Right edge */ + inline T& right() { return _topRight.x(); } + inline constexpr T right() const { return _topRight.x(); } /**< @overload */ + + /** @brief %Rectangle size */ + inline constexpr Vector2 size() const { + return _topRight-_bottomLeft; + } + + /** @brief %Rectangle width */ + inline constexpr T width() const { return _topRight.x() - _bottomLeft.x(); } + + /** @brief %Rectangle height */ + inline constexpr T height() const { return _topRight.y() - _bottomLeft.y(); } + + private: + Vector2 _bottomLeft; + Vector2 _topRight; +}; + +}}} + +#endif diff --git a/src/Math/Geometry/Test/CMakeLists.txt b/src/Math/Geometry/Test/CMakeLists.txt index 7d6dcfa93..46ad2a19e 100644 --- a/src/Math/Geometry/Test/CMakeLists.txt +++ b/src/Math/Geometry/Test/CMakeLists.txt @@ -1,2 +1,3 @@ corrade_add_test(MathGeometryDistanceTest DistanceTest.cpp) corrade_add_test(MathGeometryIntersectionTest IntersectionTest.cpp) +corrade_add_test(MathGeometryRectangleTest RectangleTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp new file mode 100644 index 000000000..315acfed4 --- /dev/null +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -0,0 +1,71 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "RectangleTest.h" + +#include "Rectangle.h" + +CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) + +namespace Magnum { namespace Math { namespace Geometry { namespace Test { + +typedef Rectangle Rectanglei; +typedef Vector2 Vector2i; + +RectangleTest::RectangleTest() { + addTests(&RectangleTest::access, + &RectangleTest::compare, + &RectangleTest::construct, + &RectangleTest::size); +} + +void RectangleTest::access() { + Rectanglei rect({34, 23}, {47, 30}); + const Rectanglei crect({34, 23}, {47, 30}); + + CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23)); + CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30)); + CORRADE_COMPARE(rect.bottom(), 23); + CORRADE_COMPARE(rect.top(), 30); + CORRADE_COMPARE(rect.left(), 34); + CORRADE_COMPARE(rect.right(), 47); + CORRADE_COMPARE(crect.bottomLeft(), Vector2i(34, 23)); + CORRADE_COMPARE(crect.topRight(), Vector2i(47, 30)); + CORRADE_COMPARE(crect.bottom(), 23); + CORRADE_COMPARE(crect.top(), 30); + CORRADE_COMPARE(crect.left(), 34); + CORRADE_COMPARE(crect.right(), 47); +} + +void RectangleTest::compare() { + CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) == Rectanglei({34, 23}, {47, 30})); + CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) != Rectanglei({34, 23}, {48, 30})); + CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) != Rectanglei({35, 23}, {47, 30})); +} + +void RectangleTest::construct() { + CORRADE_VERIFY(Rectanglei() == Rectanglei({0, 0}, {0, 0})); + CORRADE_VERIFY(Rectanglei::fromSize({3, 5}, {23, 78}) == Rectanglei({3, 5}, {26, 83})); +} + +void RectangleTest::size() { + Rectanglei rect({34, 23}, {47, 30}); + + CORRADE_COMPARE(rect.size(), Vector2i(13, 7)); + CORRADE_COMPARE(rect.width(), 13); + CORRADE_COMPARE(rect.height(), 7); +} + +}}}} diff --git a/src/Math/Geometry/Test/RectangleTest.h b/src/Math/Geometry/Test/RectangleTest.h new file mode 100644 index 000000000..2fbfd4e3b --- /dev/null +++ b/src/Math/Geometry/Test/RectangleTest.h @@ -0,0 +1,34 @@ +#ifndef Magnum_Math_Geometry_Test_RectangleTest_h +#define Magnum_Math_Geometry_Test_RectangleTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Math { namespace Geometry { namespace Test { + +class RectangleTest: public Corrade::TestSuite::Tester { + public: + RectangleTest(); + + void access(); + void compare(); + void construct(); + void size(); +}; + +}}}} + +#endif From bc2f98266e73adcf101e98a2202413f80a0d4369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 13:39:38 +0100 Subject: [PATCH 078/567] Math: debug output operator for Rectangle. --- src/Math/Geometry/Rectangle.h | 9 +++++++++ src/Math/Geometry/Test/RectangleTest.cpp | 16 +++++++++++++--- src/Math/Geometry/Test/RectangleTest.h | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index fea8225cd..f8eac6511 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -105,6 +105,15 @@ template class Rectangle { Vector2 _topRight; }; +/** @debugoperator{Magnum::Math::Geometry::Rectangle} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Rectangle& value) { + debug << "Rectangle({"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << value.left() << ", " << value.bottom() << "}, {" << value.right() << ", " << value.top() <<"})"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + }}} #endif diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 315acfed4..a09ca0cc7 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -15,6 +15,8 @@ #include "RectangleTest.h" +#include + #include "Rectangle.h" CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) @@ -28,7 +30,8 @@ RectangleTest::RectangleTest() { addTests(&RectangleTest::access, &RectangleTest::compare, &RectangleTest::construct, - &RectangleTest::size); + &RectangleTest::size, + &RectangleTest::debug); } void RectangleTest::access() { @@ -56,8 +59,8 @@ void RectangleTest::compare() { } void RectangleTest::construct() { - CORRADE_VERIFY(Rectanglei() == Rectanglei({0, 0}, {0, 0})); - CORRADE_VERIFY(Rectanglei::fromSize({3, 5}, {23, 78}) == Rectanglei({3, 5}, {26, 83})); + CORRADE_COMPARE(Rectanglei(), Rectanglei({0, 0}, {0, 0})); + CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83})); } void RectangleTest::size() { @@ -68,4 +71,11 @@ void RectangleTest::size() { CORRADE_COMPARE(rect.height(), 7); } +void RectangleTest::debug() { + std::ostringstream o; + Corrade::Utility::Debug(&o) << Rectanglei({34, 23}, {47, 30}); + + CORRADE_COMPARE(o.str(), "Rectangle({34, 23}, {47, 30})\n"); +} + }}}} diff --git a/src/Math/Geometry/Test/RectangleTest.h b/src/Math/Geometry/Test/RectangleTest.h index 2fbfd4e3b..87f552c03 100644 --- a/src/Math/Geometry/Test/RectangleTest.h +++ b/src/Math/Geometry/Test/RectangleTest.h @@ -27,6 +27,8 @@ class RectangleTest: public Corrade::TestSuite::Tester { void compare(); void construct(); void size(); + + void debug(); }; }}}} From 423beaebebebf405cdd4372e4e00c40817d86c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Dec 2012 02:45:46 +0100 Subject: [PATCH 079/567] Bring Math::Geometry::Rectangle to Magnum namespace. --- src/Magnum.h | 12 +++++++++++- src/Math/Geometry/Rectangle.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Magnum.h b/src/Magnum.h index b4af2f8a3..7123b40f7 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -66,7 +66,11 @@ namespace Math { template constexpr T deg(T value); template constexpr T rad(T value); - template struct Constants; + template class Constants; + + namespace Geometry { + template class Rectangle; + } } /* Bring debugging facility from Corrade::Utility namespace */ @@ -117,6 +121,12 @@ typedef Math::Matrix4 Matrix4; /* Using float instead of GLfloat to not break KDevelop autocompletion */ typedef Math::Constants Constants; +/** @brief Floating-point rectangle */ +typedef Math::Geometry::Rectangle Rectangle; + +/** @brief Integer rectangle */ +typedef Math::Geometry::Rectangle Rectanglei; + /* Copying angle converters from Math namespace */ using Math::deg; using Math::rad; diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index f8eac6511..a8bda2d1c 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -29,6 +29,7 @@ namespace Magnum { namespace Math { namespace Geometry { Helper class for storing axis-aligned rectangles consisting of bottom left and top right corner positions. Bottom left position is inclusive, while top right position is exclusive. +@see Magnum::Rectanglei */ template class Rectangle { public: From a45b4fba8bd4231d89c2aadf1d6118d6c9e06333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 12:41:44 +0100 Subject: [PATCH 080/567] Using Rectangle in framebuffer. --- src/AbstractFramebuffer.cpp | 22 +++++++-------- src/AbstractFramebuffer.h | 39 +++++++++++---------------- src/DefaultFramebuffer.cpp | 3 +-- src/Framebuffer.cpp | 5 ++-- src/Framebuffer.h | 4 +-- src/Implementation/FramebufferState.h | 4 +-- 6 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 999f64c6e..06b86d8e8 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -78,25 +78,22 @@ AbstractFramebuffer::Target AbstractFramebuffer::bindInternal() { } #endif -void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) { +void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& sourceRectangle, const Rectanglei& destinationRectangle, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) { source.bindInternal(AbstractFramebuffer::Target::Read); destination.bindInternal(AbstractFramebuffer::Target::Draw); /** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glBlitFramebuffer(sourceBottomLeft.x(), sourceBottomLeft.y(), sourceTopRight.x(), sourceTopRight.y(), destinationBottomLeft.x(), destinationBottomLeft.y(), destinationTopRight.x(), destinationTopRight.y(), static_cast(mask), static_cast(filter)); + glBlitFramebuffer(sourceRectangle.left(), sourceRectangle.bottom(), sourceRectangle.right(), sourceRectangle.top(), destinationRectangle.left(), destinationRectangle.bottom(), destinationRectangle.right(), destinationRectangle.top(), static_cast(mask), static_cast(filter)); #else - static_cast(sourceBottomLeft); - static_cast(sourceTopRight); - static_cast(destinationBottomLeft); - static_cast(destinationTopRight); + static_cast(sourceRectangle); + static_cast(destinationRectangle); static_cast(mask); static_cast(filter); #endif } -void AbstractFramebuffer::setViewport(const Vector2i& position, const Vector2i& size) { - _viewportPosition = position; - _viewportSize = size; +void AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { + _viewport = rectangle; /* Update the viewport if the framebuffer is currently bound */ if(Context::current()->state()->framebuffer->drawBinding == _id) @@ -110,13 +107,12 @@ void AbstractFramebuffer::setViewportInternal() { CORRADE_INTERNAL_ASSERT(state->drawBinding == _id); /* Already up-to-date, nothing to do */ - if(state->viewportPosition == _viewportPosition && state->viewportSize == _viewportSize) + if(state->viewport == _viewport) return; /* Update the state and viewport */ - state->viewportPosition = _viewportPosition; - state->viewportSize = _viewportSize; - glViewport(_viewportPosition.x(), _viewportPosition.y(), _viewportSize.x(), _viewportSize.y()); + state->viewport = _viewport; + glViewport(_viewport.left(), _viewport.bottom(), _viewport.width(), _viewport.height()); } #endif diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index c6f34a106..f2efec6b1 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -21,7 +21,7 @@ #include -#include "Math/Vector2.h" +#include "Math/Geometry/Rectangle.h" #include "AbstractImage.h" #include "Buffer.h" @@ -139,11 +139,8 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @brief Copy block of pixels * @param source Source framebuffer * @param destination Destination framebuffer - * @param sourceBottomLeft Bottom left coordinates of source rectangle - * @param sourceTopRight Top right coordinates of source rectangle - * @param destinationBottomLeft Bottom left coordinates of destination rectangle - * @param destinationTopRight Top right coordinates of destination - * rectangle + * @param sourceRectangle Source rectangle + * @param destinationRectangle Destination rectangle * @param mask Which buffers to perform blit operation on * @param filter Interpolation filter * @@ -157,16 +154,13 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ - static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& sourceBottomLeft, const Vector2i& sourceTopRight, const Vector2i& destinationBottomLeft, const Vector2i& destinationTopRight, BlitMask mask, BlitFilter filter); + static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& sourceRectangle, const Rectanglei& destinationRectangle, BlitMask mask, BlitFilter filter); /** * @brief Copy block of pixels * @param source Source framebuffer * @param destination Destination framebuffer - * @param bottomLeft Bottom left coordinates of source and - * destination rectangle - * @param topRight Top right coordinates of source and - * destination rectangle + * @param rectangle Source and destination rectangle * @param mask Which buffers to perform blit operation on * * Convenience alternative to above function when source rectangle is @@ -178,8 +172,8 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ - inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Vector2i& bottomLeft, const Vector2i& topRight, BlitMask mask) { - blit(source, destination, bottomLeft, topRight, bottomLeft, topRight, mask, BlitFilter::NearestNeighbor); + inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& rectangle, BlitMask mask) { + blit(source, destination, rectangle, rectangle, mask, BlitFilter::NearestNeighbor); } explicit AbstractFramebuffer() = default; @@ -196,21 +190,18 @@ class MAGNUM_EXPORT AbstractFramebuffer { */ void bind(Target target); - /** @brief Viewport position */ - inline Vector2i viewportPosition() const { return _viewportPosition; } - - /** @brief Viewport size */ - inline Vector2i viewportSize() const { return _viewportSize; } + /** @brief Viewport rectangle */ + inline Rectanglei viewport() const { return _viewport; } /** - * @brief Set viewport size + * @brief Set viewport * - * Saves the viewport size to be used at later time in bind(). If the + * Saves the viewport to be used at later time in bind(). If the * framebuffer is currently bound, updates the viewport to given - * dimensions. + * rectangle. * @see @fn_gl{Viewport} */ - void setViewport(const Vector2i& position, const Vector2i& size); + void setViewport(const Rectanglei& rectangle); /** * @brief Clear specified buffers in framebuffer @@ -231,6 +222,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @param image %Image where to put the data * * @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} + * @todo Read size, format & type from image? */ void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); @@ -246,6 +238,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { * * @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} * @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. + * @todo Read size, format & type from image? */ void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); #endif @@ -269,7 +262,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { static ReadBufferImplementation readBufferImplementation; GLuint _id; - Vector2i _viewportPosition, _viewportSize; + Rectanglei _viewport; #endif private: diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 38081e96b..a8b0649c4 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -50,8 +50,7 @@ void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) { /* Initial framebuffer size */ GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); - defaultFramebuffer._viewportPosition = state->viewportPosition = {viewport[0], viewport[1]}; - defaultFramebuffer._viewportSize = state->viewportSize = {viewport[2], viewport[3]}; + defaultFramebuffer._viewport = state->viewport = Rectanglei::fromSize({viewport[0], viewport[1]}, {viewport[2], viewport[3]}); } } diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index afe16cd3d..8d68e73dc 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -34,9 +34,8 @@ Framebuffer::Texture1DImplementation Framebuffer::texture1DImplementation = &Fra Framebuffer::Texture2DImplementation Framebuffer::texture2DImplementation = &Framebuffer::texture2DImplementationDefault; Framebuffer::Texture3DImplementation Framebuffer::texture3DImplementation = &Framebuffer::texture3DImplementationDefault; -Framebuffer::Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize) { - _viewportPosition = viewportPosition; - _viewportSize = viewportSize; +Framebuffer::Framebuffer(const Rectanglei& viewport) { + _viewport = viewport; glGenFramebuffers(1, &_id); } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index ec638d3b6..0fd057e81 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -95,9 +95,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @brief Constructor * * Generates new OpenGL framebuffer. - * @see @fn_gl{GenFramebuffers} + * @see setViewport(), @fn_gl{GenFramebuffers} */ - explicit Framebuffer(const Vector2i& viewportPosition, const Vector2i& viewportSize); + explicit Framebuffer(const Rectanglei& viewport); /** * @brief Destructor diff --git a/src/Implementation/FramebufferState.h b/src/Implementation/FramebufferState.h index 93b83f1ad..b5d7cf891 100644 --- a/src/Implementation/FramebufferState.h +++ b/src/Implementation/FramebufferState.h @@ -15,7 +15,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Math/Vector2.h" +#include "Math/Geometry/Rectangle.h" #include "Magnum.h" namespace Magnum { namespace Implementation { @@ -24,7 +24,7 @@ struct FramebufferState { inline FramebufferState(): readBinding(0), drawBinding(0), renderbufferBinding(0) {} GLuint readBinding, drawBinding, renderbufferBinding; - Vector2i viewportPosition, viewportSize; + Rectanglei viewport; }; }} From 96e936039c02e75eeb774a1003ae0b9a491ad531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 18:24:00 +0100 Subject: [PATCH 081/567] New TextureTools library with joke implementation of atlas packer. --- CMakeLists.txt | 1 + doc/namespaces.dox | 9 +++ modules/FindMagnum.cmake | 6 ++ src/CMakeLists.txt | 4 ++ src/TextureTools/Atlas.cpp | 53 +++++++++++++++ src/TextureTools/Atlas.h | 42 ++++++++++++ src/TextureTools/CMakeLists.txt | 19 ++++++ src/TextureTools/Test/AtlasTest.cpp | 65 +++++++++++++++++++ src/TextureTools/Test/AtlasTest.h | 33 ++++++++++ src/TextureTools/Test/CMakeLists.txt | 1 + .../magnumTextureToolsVisibility.h | 28 ++++++++ 11 files changed, 261 insertions(+) create mode 100644 src/TextureTools/Atlas.cpp create mode 100644 src/TextureTools/Atlas.h create mode 100644 src/TextureTools/CMakeLists.txt create mode 100644 src/TextureTools/Test/AtlasTest.cpp create mode 100644 src/TextureTools/Test/AtlasTest.h create mode 100644 src/TextureTools/Test/CMakeLists.txt create mode 100644 src/TextureTools/magnumTextureToolsVisibility.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a0de8a35f..d0398a9fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYT cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 915f3c0b2..90d800d8b 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -104,6 +104,15 @@ Collision detection system and rigid body objects. See @ref collision-detection for introduction. */ +/** @dir TextureTools + * @brief Namespace Magnum::TextureTools + */ +/** @namespace Magnum::TextureTools +@brief %Texture tools + +Tools for generating, compressing and optimizing textures. +*/ + /** @dir Trade * @brief Namespace Magnum::Trade */ diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index be3423bc4..ee5437f6e 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -22,6 +22,7 @@ # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders +# TextureTools - TextureTools library # GlxApplication - GLX application (depends on X11 libraries) # XEglApplication - X/EGL application (depends on EGL and X11 libraries) # WindowlessGlxApplication - Windowless GLX application (depends on X11 @@ -197,6 +198,11 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES PhongShader.h) endif() + # TextureTools library + if(${component} STREQUAL TextureTools) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h) + endif() + # Try to find the includes if(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES) find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed702f4f8..18619eac3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -162,6 +162,10 @@ if(WITH_SHADERS) add_subdirectory(Shaders) endif() +if(WITH_TEXTURETOOLS) + add_subdirectory(TextureTools) +endif() + if(BUILD_TESTS) enable_testing() diff --git a/src/TextureTools/Atlas.cpp b/src/TextureTools/Atlas.cpp new file mode 100644 index 000000000..336777880 --- /dev/null +++ b/src/TextureTools/Atlas.cpp @@ -0,0 +1,53 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Atlas.h" + +#include "Math/Geometry/Rectangle.h" + +namespace Magnum { namespace TextureTools { + +std::vector atlas(const Vector2i& atlasSize, const std::vector& sizes) { + if(sizes.empty()) return {}; + + /* Size of largest texture */ + Vector2i maxSize; + for(const Vector2i& size: sizes) { + /** @todo max() for vector types */ + if(size.x() > maxSize.x()) maxSize.x() = size.x(); + if(size.y() > maxSize.y()) maxSize.y() = size.y(); + } + + std::vector atlas; + + /* Columns and rows */ + Vector2i gridSize = atlasSize/maxSize; + if(std::size_t(gridSize.product()) < sizes.size()) { + Error() << "TextureTools::Atlas::create(): requested atlas size" + << atlasSize << "is too small to fit" << sizes.size() + << maxSize << "textures. Generated atlas will be empty."; + return atlas; + } + + /** @todo actual magic implementation, not this joke */ + + atlas.reserve(sizes.size()); + for(std::size_t i = 0; i != sizes.size(); ++i) + atlas.push_back(Rectanglei::fromSize(Vector2i(i%gridSize.x(), i/gridSize.x())*maxSize, sizes[i])); + + return atlas; +} + +}} diff --git a/src/TextureTools/Atlas.h b/src/TextureTools/Atlas.h new file mode 100644 index 000000000..d91b5f1e3 --- /dev/null +++ b/src/TextureTools/Atlas.h @@ -0,0 +1,42 @@ +#ifndef Magnum_TextureTools_Atlas_h +#define Magnum_TextureTools_Atlas_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::TextureTools::atlas() + */ + +#include + +#include "Magnum.h" + +#include "magnumTextureToolsVisibility.h" + +namespace Magnum { namespace TextureTools { + +/** +@brief Pack textures into texture atlas +@param atlasSize Size of resulting atlas +@param sizes Sizes of all textures in the atlas + +Packs many small textures into one larger. If the textures cannot be packed +into required size, empty vector is returned. +*/ +std::vector MAGNUM_TEXTURETOOLS_EXPORT atlas(const Vector2i& atlasSize, const std::vector& sizes); + +}} + +#endif diff --git a/src/TextureTools/CMakeLists.txt b/src/TextureTools/CMakeLists.txt new file mode 100644 index 000000000..e7bbd4fa6 --- /dev/null +++ b/src/TextureTools/CMakeLists.txt @@ -0,0 +1,19 @@ +set(MagnumTextureTools_SRCS + Atlas.cpp) + +set(MagnumTextureTools_HEADERS + Atlas.h + + magnumTextureToolsVisibility.h) + +add_library(MagnumTextureTools SHARED ${MagnumTextureTools_SRCS}) + +target_link_libraries(MagnumTextureTools Magnum) + +install(TARGETS MagnumTextureTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +install(FILES ${MagnumTextureTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/TextureTools) + +if(BUILD_TESTS) + enable_testing() + add_subdirectory(Test) +endif() diff --git a/src/TextureTools/Test/AtlasTest.cpp b/src/TextureTools/Test/AtlasTest.cpp new file mode 100644 index 000000000..01a7e53ce --- /dev/null +++ b/src/TextureTools/Test/AtlasTest.cpp @@ -0,0 +1,65 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AtlasTest.h" + +#include + +#include "Math/Geometry/Rectangle.h" +#include "TextureTools/Atlas.h" + +CORRADE_TEST_MAIN(Magnum::TextureTools::Test::AtlasTest) + +namespace Magnum { namespace TextureTools { namespace Test { + +AtlasTest::AtlasTest() { + addTests(&AtlasTest::create, + &AtlasTest::createEmpty, + &AtlasTest::createTooSmall); +} + +void AtlasTest::create() { + std::vector atlas = TextureTools::atlas({64, 64}, { + {12, 18}, + {32, 15}, + {23, 25} + }); + + CORRADE_COMPARE(atlas.size(), 3); + CORRADE_COMPARE(atlas, (std::vector{ + Rectanglei::fromSize({0, 0}, {12, 18}), + Rectanglei::fromSize({32, 0}, {32, 15}), + Rectanglei::fromSize({0, 25}, {23, 25})})); +} + +void AtlasTest::createEmpty() { + std::vector atlas = TextureTools::atlas({}, {}); + CORRADE_VERIFY(atlas.empty()); +} + +void AtlasTest::createTooSmall() { + std::ostringstream o; + Error::setOutput(&o); + + std::vector atlas = TextureTools::atlas({64, 32}, { + {12, 18}, + {25, 15}, + {23, 31} + }); + CORRADE_VERIFY(atlas.empty()); + CORRADE_COMPARE(o.str(), "TextureTools::Atlas::create(): requested atlas size Vector(64, 32) is too small to fit 3 Vector(25, 31) textures. Generated atlas will be empty.\n"); +} + +}}} diff --git a/src/TextureTools/Test/AtlasTest.h b/src/TextureTools/Test/AtlasTest.h new file mode 100644 index 000000000..13c92aa27 --- /dev/null +++ b/src/TextureTools/Test/AtlasTest.h @@ -0,0 +1,33 @@ +#ifndef Magnum_TextureTools_Test_AtlasTest_h +#define Magnum_TextureTools_Test_AtlasTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace TextureTools { namespace Test { + +class AtlasTest: public Corrade::TestSuite::Tester { + public: + explicit AtlasTest(); + + void create(); + void createEmpty(); + void createTooSmall(); +}; + +}}} + +#endif diff --git a/src/TextureTools/Test/CMakeLists.txt b/src/TextureTools/Test/CMakeLists.txt new file mode 100644 index 000000000..4c4610b50 --- /dev/null +++ b/src/TextureTools/Test/CMakeLists.txt @@ -0,0 +1 @@ +corrade_add_test(TextureToolsAtlasTest AtlasTest.cpp LIBRARIES MagnumTextureTools) diff --git a/src/TextureTools/magnumTextureToolsVisibility.h b/src/TextureTools/magnumTextureToolsVisibility.h new file mode 100644 index 000000000..725041d71 --- /dev/null +++ b/src/TextureTools/magnumTextureToolsVisibility.h @@ -0,0 +1,28 @@ +#ifndef Magnum_TextureTools_magnumTextureToolsVisibility_h +#define Magnum_TextureTools_magnumTextureToolsVisibility_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#ifdef _WIN32 + #ifdef MagnumTextureTools_EXPORTS + #define MAGNUM_TEXTURETOOLS_EXPORT __declspec(dllexport) + #else + #define MAGNUM_TEXTURETOOLS_EXPORT __declspec(dllimport) + #endif +#else + #define MAGNUM_TEXTURETOOLS_EXPORT __attribute__ ((visibility ("default"))) +#endif + +#endif From cce32d7bc8b95c9f182eaa08693785e978ccc6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 15:27:23 +0100 Subject: [PATCH 082/567] Physics: don't link to irrelevant libraries. Leftover after moving debug draw to DebugTools library. --- src/Physics/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index a83dc21e3..6d91069b2 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -30,7 +30,7 @@ set(MagnumPhysics_HEADERS add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS}) -target_link_libraries(MagnumPhysics Magnum MagnumPrimitives MagnumSceneGraph MagnumShaders) +target_link_libraries(MagnumPhysics Magnum MagnumSceneGraph) install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) From c3bcaee6a7a565add9eaa7e98e4d0810b758d6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 11:19:20 +0100 Subject: [PATCH 083/567] Shaders compatibility: check for explicit texture layer support. --- src/Shaders/compatibility.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Shaders/compatibility.glsl b/src/Shaders/compatibility.glsl index 8c67705d5..c6ebfa748 100644 --- a/src/Shaders/compatibility.glsl +++ b/src/Shaders/compatibility.glsl @@ -10,6 +10,10 @@ #extension GL_ARB_explicit_attrib_location: enable #define EXPLICIT_ATTRIB_LOCATION #endif +#if defined(GL_ARB_shading_language_420pack) + #extension GL_ARB_shading_language_420pack: enable + #define EXPLICIT_TEXTURE_LAYER +#endif #ifdef GL_ARB_explicit_uniform_location #extension GL_ARB_explicit_uniform_location: enable #define EXPLICIT_UNIFORM_LOCATION @@ -19,7 +23,7 @@ #if defined(GL_ES) && __VERSION__ >= 300 #define EXPLICIT_ATTRIB_LOCATION -/* EXPLICIT_UNIFORM_LOCATION is not available in OpenGL ES */ +/* EXPLICIT_TEXTURE_LAYER & EXPLICIT_UNIFORM_LOCATION is not available in OpenGL ES */ #endif /* Precision qualifiers are not supported in GLSL 1.20 */ From ebf0107ab9e52f9f5e0940ffd0778f392b3ddaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 15:34:31 +0100 Subject: [PATCH 084/567] Move constructor and move assignment for textures. --- src/AbstractTexture.cpp | 25 ++++++++++++++++++++++++- src/AbstractTexture.h | 15 ++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 1e14bf5d6..cd8cd661c 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -83,7 +83,10 @@ GLfloat AbstractTexture::maxSupportedAnisotropy() { return value; } -AbstractTexture::~AbstractTexture() { +void AbstractTexture::destroy() { + /* Moved out */ + if(!_id) return; + /* Remove all bindings */ for(GLuint& binding: Context::current()->state()->texture->bindings) if(binding == _id) binding = 0; @@ -91,6 +94,26 @@ AbstractTexture::~AbstractTexture() { glDeleteTextures(1, &_id); } +void AbstractTexture::move() { + _id = 0; +} + +AbstractTexture::~AbstractTexture() { destroy(); } + +AbstractTexture::AbstractTexture(AbstractTexture&& other): _target(other._target), _id(other._id) { + other.move(); +} + +AbstractTexture& AbstractTexture::operator=(AbstractTexture&& other) { + destroy(); + + _target = other._target; + _id = other._id; + + other.move(); + return *this; +} + void AbstractTexture::bind(GLint layer) { Implementation::TextureState* const textureState = Context::current()->state()->texture; diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 31d8f916c..5dd689f48 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -55,14 +55,14 @@ can optimize the data to match your settings. @todo Add glPixelStore encapsulation @todo Texture copying +@todo Move constructor/assignment - how to avoid creation of empty texture and + then deleting it immediately? */ class MAGNUM_EXPORT AbstractTexture { friend class Context; AbstractTexture(const AbstractTexture& other) = delete; - AbstractTexture(AbstractTexture&& other) = delete; AbstractTexture& operator=(const AbstractTexture& other) = delete; - AbstractTexture& operator=(AbstractTexture&& other) = delete; public: /** @@ -986,6 +986,12 @@ class MAGNUM_EXPORT AbstractTexture { */ virtual ~AbstractTexture() = 0; + /** @brief Move constructor */ + AbstractTexture(AbstractTexture&& other); + + /** @brief Move assignment */ + AbstractTexture& operator=(AbstractTexture&& other); + /** @brief OpenGL texture ID */ inline GLuint id() const { return _id; } @@ -1109,7 +1115,7 @@ class MAGNUM_EXPORT AbstractTexture { /* Unlike bind() this also sets the binding layer as active */ void MAGNUM_LOCAL bindInternal(); - const GLenum _target; + GLenum _target; #endif private: @@ -1184,6 +1190,9 @@ class MAGNUM_EXPORT AbstractTexture { void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage3DImplementation subImage3DImplementation; + void MAGNUM_LOCAL destroy(); + void MAGNUM_LOCAL move(); + GLuint _id; }; From 7905a5e96c213ee716bc3bd53549fab12627a887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 18:46:36 +0100 Subject: [PATCH 085/567] Math: return proper type from Vector::projected() in subclasses. --- src/Math/Vector.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 39589af74..a2b2ee7d1 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -365,7 +365,10 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit return *this; \ } \ \ - inline Type normalized() const { return Math::Vector::normalized(); } + inline Type normalized() const { return Math::Vector::normalized(); } \ + inline Type projected(const Math::Vector& other) const { \ + return Math::Vector::projected(other); \ + } #define MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \ template inline typename std::enable_if::value, Type>::type operator*(U number, const Type& vector) { \ From f9f848d94c6dd2ec536d082c9d774e0ec225b890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 18:50:21 +0100 Subject: [PATCH 086/567] Math: ability to multiply and divide Vector with other of arbitrary type. --- src/Math/Vector.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index a2b2ee7d1..c8ad4ec9d 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -155,19 +155,19 @@ template class Vector: public RectangularMatrix<1, si /** * @brief Multiply vector component-wise * - * @see operator*=(const Vector&) + * @see operator*=(const Vector&) */ - inline Vector operator*(const Vector& other) const { + template inline Vector operator*(const Vector& other) const { return Vector(*this)*=other; } /** * @brief Multiply vector component-wise and assign * - * More efficient than operator*(const Vector&) const, + * More efficient than operator*(const Vector&) const, * because it does the computation in-place. */ - Vector& operator*=(const Vector& other) { + template Vector& operator*=(const Vector& other) { for(std::size_t i = 0; i != size; ++i) (*this)[i] *= other[i]; @@ -177,19 +177,19 @@ template class Vector: public RectangularMatrix<1, si /** * @brief Divide vector component-wise * - * @see operator/=(const Vector&) + * @see operator/=(const Vector&) */ - inline Vector operator/(const Vector& other) const { + template inline Vector operator/(const Vector& other) const { return Vector(*this)/=other; } /** * @brief Divide vector component-wise and assign * - * More efficient than operator/(const Vector&) const, + * More efficient than operator/(const Vector&) const, * because it does the computation in-place. */ - Vector& operator/=(const Vector& other) { + template Vector& operator/=(const Vector& other) { for(std::size_t i = 0; i != size; ++i) (*this)[i] /= other[i]; @@ -350,17 +350,17 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit template inline Math::RectangularMatrix operator*(const Math::RectangularMatrix& other) const { \ return Math::Vector::operator*(other); \ } \ - inline Type operator*(const Math::Vector& other) const { \ + template inline Type operator*(const Math::Vector& other) const { \ return Math::Vector::operator*(other); \ } \ - inline Type& operator*=(const Math::Vector& other) { \ + template inline Type& operator*=(const Math::Vector& other) { \ Math::Vector::operator*=(other); \ return *this; \ } \ - inline Type operator/(const Math::Vector& other) const { \ + template inline Type operator/(const Math::Vector& other) const { \ return Math::Vector::operator/(other); \ } \ - inline Type& operator/=(const Math::Vector& other) { \ + template inline Type& operator/=(const Math::Vector& other) { \ Math::Vector::operator/=(other); \ return *this; \ } \ From a7a4c28c033741061e6fac7b340173729cacc0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 18:52:14 +0100 Subject: [PATCH 087/567] Math: ability to create Rectangle from other of arbitrary type. --- src/Math/Geometry/Rectangle.h | 15 +++++++++++++++ src/Math/Geometry/Test/RectangleTest.cpp | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index a8bda2d1c..3a0d848a2 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -42,6 +42,21 @@ template class Rectangle { return {bottomLeft, bottomLeft+size}; } + /** + * @brief %Rectangle from another of different type + * + * Performs only default casting on the values, no rounding or + * anything else. Example usage: + * @code + * Rectangle floatingPoint({1.3f, 2.7f}, {-15.0f, 7.0f}); + * auto integral = Rectangle::from(floatingPoint); + * // integral == {{1, 2}, {-15, 7}} + * @endcode + */ + template inline constexpr static Rectangle from(const Rectangle& other) { + return {Vector2::from(other.bottomLeft()), Vector2::from(other.topRight())}; + } + /** * @brief Default constructor * diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index a09ca0cc7..362bed166 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -23,7 +23,8 @@ CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) namespace Magnum { namespace Math { namespace Geometry { namespace Test { -typedef Rectangle Rectanglei; +typedef Geometry::Rectangle Rectangle; +typedef Geometry::Rectangle Rectanglei; typedef Vector2 Vector2i; RectangleTest::RectangleTest() { @@ -61,6 +62,8 @@ void RectangleTest::compare() { void RectangleTest::construct() { CORRADE_COMPARE(Rectanglei(), Rectanglei({0, 0}, {0, 0})); CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83})); + CORRADE_COMPARE(Rectanglei::from(Rectangle({1.3f, 2.7f}, {-15.0f, 7.0f})), + Rectanglei({1, 2}, {-15, 7})); } void RectangleTest::size() { From e506951829eb3befa46b888dffefd980e448e87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 18:52:53 +0100 Subject: [PATCH 088/567] Math: functions for bottom right and top left Rectangle corners. --- src/Math/Geometry/Rectangle.h | 6 ++++++ src/Math/Geometry/Test/RectangleTest.cpp | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 3a0d848a2..18fed134a 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -85,6 +85,12 @@ template class Rectangle { inline Vector2& bottomLeft() { return _bottomLeft; } inline constexpr Vector2 bottomLeft() const { return _bottomLeft; } /**< @overload */ + /** @brief Bottom right corner */ + inline constexpr Vector2 bottomRight() const { return {_topRight.x(), _bottomLeft.y()}; } /**< @overload */ + + /** @brief Top left corner */ + inline constexpr Vector2 topLeft() const { return {_bottomLeft.x(), _topRight.y()}; } /**< @overload */ + /** @brief Top right corner */ inline Vector2& topRight() { return _topRight; } inline constexpr Vector2 topRight() const { return _topRight; } /**< @overload */ diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 362bed166..c5ab1f6e6 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -51,6 +51,9 @@ void RectangleTest::access() { CORRADE_COMPARE(crect.top(), 30); CORRADE_COMPARE(crect.left(), 34); CORRADE_COMPARE(crect.right(), 47); + + CORRADE_COMPARE(rect.topLeft(), Vector2i(34, 30)); + CORRADE_COMPARE(rect.bottomRight(), Vector2i(47, 23)); } void RectangleTest::compare() { From 06d60323003c110e070bc8bf28d0bf47659ba276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 20:36:45 +0100 Subject: [PATCH 089/567] Shaders: base for text shaders. --- src/Shaders/AbstractTextShader.h | 58 ++++++++++++++++++++++++++++++++ src/Shaders/CMakeLists.txt | 1 + src/Shaders/Shaders.h | 4 +++ 3 files changed, 63 insertions(+) create mode 100644 src/Shaders/AbstractTextShader.h diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h new file mode 100644 index 000000000..3310bbc58 --- /dev/null +++ b/src/Shaders/AbstractTextShader.h @@ -0,0 +1,58 @@ +#ifndef Magnum_Shaders_AbstractTextShader_h +#define Magnum_Shaders_AbstractTextShader_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Shaders::AbstractTextShader + */ + +#include "AbstractShaderProgram.h" +#include "Color.h" +#include "DimensionTraits.h" + +namespace Magnum { namespace Shaders { + +/** +@brief Base for text shaders + +@see AbstractTextShader2D, AbstractTextShader3D +*/ +template class AbstractTextShader: public AbstractShaderProgram { + public: + /** @brief Vertex position */ + typedef Attribute<0, typename DimensionTraits::PointType> Position; + + /** @brief Texture coordinates */ + typedef Attribute<1, Vector2> TextureCoordinates; + + enum: GLint { + FontTextureLayer = 16, /**< @brief Layer for font texture */ + }; + + ~AbstractTextShader() = 0; +}; + +template inline AbstractTextShader::~AbstractTextShader() {} + +/** @brief Base for two-dimensional text shaders */ +typedef AbstractTextShader<2> AbstractTextShader2D; + +/** @brief Base for three-dimensional text shader */ +typedef AbstractTextShader<3> AbstractTextShader3D; + +}} + +#endif diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 5ef7001c6..96f1708c7 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -9,6 +9,7 @@ set(MagnumShaders_SRCS VertexColorShader.cpp ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS + AbstractTextShader.h FlatShader.h PhongShader.h Shaders.h diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index 5a36b34f8..846a0c3f1 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -23,6 +23,10 @@ namespace Magnum { namespace Shaders { +template class AbstractTextShader; +typedef AbstractTextShader<2> AbstractTextShader2D; +typedef AbstractTextShader<3> AbstractTextShader3D; + template class FlatShader; typedef FlatShader<2> FlatShader2D; typedef FlatShader<3> FlatShader3D; From df1d8a95b4f098950c7ccc147d3bc3c2ad48a05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 20:37:22 +0100 Subject: [PATCH 090/567] Shaders: basic text shader. --- src/Shaders/CMakeLists.txt | 3 ++ src/Shaders/Shaders.h | 4 ++ src/Shaders/TextShader.cpp | 88 +++++++++++++++++++++++++++++++++++ src/Shaders/TextShader.h | 64 +++++++++++++++++++++++++ src/Shaders/TextShader2D.frag | 27 +++++++++++ src/Shaders/TextShader2D.vert | 25 ++++++++++ 6 files changed, 211 insertions(+) create mode 100644 src/Shaders/TextShader.cpp create mode 100644 src/Shaders/TextShader.h create mode 100644 src/Shaders/TextShader2D.frag create mode 100644 src/Shaders/TextShader2D.vert diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 96f1708c7..aa1b50560 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,11 +1,13 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders FlatShader2D.vert FlatShader2D.frag PhongShader.vert PhongShader.frag + TextShader2D.vert TextShader2D.frag VertexColorShader2D.vert VertexColorShader2D.frag compatibility.glsl) set(MagnumShaders_SRCS FlatShader.cpp PhongShader.cpp + TextShader.cpp VertexColorShader.cpp ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS @@ -13,6 +15,7 @@ set(MagnumShaders_HEADERS FlatShader.h PhongShader.h Shaders.h + TextShader.h VertexColorShader.h magnumShadersVisibility.h) diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index 846a0c3f1..80052a755 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -33,6 +33,10 @@ typedef FlatShader<3> FlatShader3D; class PhongShader; +template class TextShader; +typedef TextShader<2> TextShader2D; +typedef TextShader<3> TextShader3D; + template class VertexColorShader; typedef VertexColorShader<2> VertexColorShader2D; typedef VertexColorShader<3> VertexColorShader3D; diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/TextShader.cpp new file mode 100644 index 000000000..69a61d762 --- /dev/null +++ b/src/Shaders/TextShader.cpp @@ -0,0 +1,88 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "TextShader.h" + +#include + +#include "Context.h" +#include "Extensions.h" +#include "Shader.h" + +namespace Magnum { namespace Shaders { + +namespace { + template struct ShaderName {}; + + template<> struct ShaderName<2> { + constexpr static const char* vertex() { return "TextShader2D.vert"; } + constexpr static const char* fragment() { return "TextShader2D.frag"; } + }; + + template<> struct ShaderName<3> { + constexpr static const char* vertex() { return "TextShader3D.vert"; } + constexpr static const char* fragment() { return "TextShader3D.frag"; } + }; +} + +template TextShader::TextShader() { + Corrade::Utility::Resource rs("MagnumShaders"); + + #ifndef MAGNUM_TARGET_GLES + Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + #else + Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + #endif + + Shader vertexShader(v, Shader::Type::Vertex); + vertexShader.addSource(rs.get("compatibility.glsl")); + vertexShader.addSource(rs.get(ShaderName::vertex())); + AbstractTextShader::attachShader(vertexShader); + + Shader fragmentShader(v, Shader::Type::Fragment); + fragmentShader.addSource(rs.get("compatibility.glsl")); + fragmentShader.addSource(rs.get(ShaderName::fragment())); + AbstractTextShader::attachShader(fragmentShader); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + if(!Context::current()->isVersionSupported(Version::GLES300)) { + #endif + AbstractTextShader::bindAttributeLocation(AbstractTextShader::Position::Location, "position"); + AbstractTextShader::bindAttributeLocation(AbstractTextShader::TextureCoordinates::Location, "textureCoordinates"); + } + + AbstractTextShader::link(); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + { + #endif + transformationProjectionMatrixUniform = AbstractTextShader::uniformLocation("transformationProjectionMatrix"); + colorUniform = AbstractTextShader::uniformLocation("color"); + } + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) + AbstractTextShader::setUniform(AbstractTextShader::uniformLocation("fontTexture"), AbstractTextShader::FontTextureLayer); + #endif +} + +template class TextShader<2>; +template class TextShader<3>; + +}} diff --git a/src/Shaders/TextShader.h b/src/Shaders/TextShader.h new file mode 100644 index 000000000..de2d06523 --- /dev/null +++ b/src/Shaders/TextShader.h @@ -0,0 +1,64 @@ +#ifndef Magnum_Shaders_TextShader_h +#define Magnum_Shaders_TextShader_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Shaders::TextShader + */ + +#include "Math/Matrix3.h" +#include "Math/Matrix4.h" +#include "AbstractTextShader.h" + +#include "magnumShadersVisibility.h" + +namespace Magnum { namespace Shaders { + +/** +@brief %Text shader + +@see TextShader2D, TextShader3D +*/ +template class MAGNUM_SHADERS_EXPORT TextShader: public AbstractTextShader { + public: + TextShader(); + + /** @brief Set transformation and projection matrix */ + inline TextShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + AbstractTextShader::setUniform(transformationProjectionMatrixUniform, matrix); + return this; + } + + /** @brief Set text color */ + inline TextShader* setColor(const Color3<>& color) { + AbstractTextShader::setUniform(colorUniform, color); + return this; + } + + private: + GLint transformationProjectionMatrixUniform = 0, + colorUniform = 1; +}; + +/** @brief Two-dimensional text shader */ +typedef TextShader<2> TextShader2D; + +/** @brief Three-dimensional text shader */ +typedef TextShader<3> TextShader3D; + +}} + +#endif diff --git a/src/Shaders/TextShader2D.frag b/src/Shaders/TextShader2D.frag new file mode 100644 index 000000000..fdc02e682 --- /dev/null +++ b/src/Shaders/TextShader2D.frag @@ -0,0 +1,27 @@ +#ifndef NEW_GLSL +#define in varying +#define fragmentColor gl_FragColor +#endif + +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 1) uniform vec3 color; +#else +uniform lowp vec3 color; +#endif + +#ifdef EXPLICIT_TEXTURE_LAYER +layout(binding = 16) uniform sampler2D fontTexture; +#else +uniform lowp sampler2D fontTexture; +#endif + +in vec2 fragmentTextureCoordinates; + +#ifdef NEW_GLSL +out vec4 fragmentColor; +#endif + +void main() { + lowp float intensity = texture(fontTexture, fragmentTextureCoordinates).r; + fragmentColor = vec4(intensity*color, intensity); +} diff --git a/src/Shaders/TextShader2D.vert b/src/Shaders/TextShader2D.vert new file mode 100644 index 000000000..9d030d59d --- /dev/null +++ b/src/Shaders/TextShader2D.vert @@ -0,0 +1,25 @@ +#ifndef NEW_GLSL +#define in attribute +#define out varying +#endif + +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat3 transformationProjectionMatrix; +#else +uniform highp mat3 transformationProjectionMatrix; +#endif + +#ifdef EXPLICIT_ATTRIB_LOCATION +layout(location = 0) in highp vec3 position; +layout(location = 1) in mediump vec2 textureCoordinates; +#else +in highp vec3 position; +in mediump vec2 textureCoordinates; +#endif + +out vec2 fragmentTextureCoordinates; + +void main() { + gl_Position = vec4(transformationProjectionMatrix*position, 0.0).xywz; + fragmentTextureCoordinates = textureCoordinates; +} From a208a289bac171feb7ca12be6b0f1dc8cc7e6a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 11:18:11 +0100 Subject: [PATCH 091/567] Initial support for Text library. --- CMakeLists.txt | 1 + doc/namespaces.dox | 9 +++++++++ modules/FindMagnum.cmake | 6 ++++++ src/CMakeLists.txt | 4 ++++ src/Text/CMakeLists.txt | 0 5 files changed, 20 insertions(+) create mode 100644 src/Text/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d0398a9fa..f6753b6ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYT cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_TEXT "Build Text library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" OFF "NOT WITH_EVERYTHING" ON) cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 90d800d8b..654ff8540 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -104,6 +104,15 @@ Collision detection system and rigid body objects. See @ref collision-detection for introduction. */ +/** @dir Text + * @brief Namespace Magnum::Text + */ +/** @namespace Magnum::Text +@brief %Text rendering + +Font texture creation and text layouting. +*/ + /** @dir TextureTools * @brief Namespace Magnum::TextureTools */ diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index ee5437f6e..9f2e0e138 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -22,6 +22,7 @@ # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders +# Text - Text rendering library # TextureTools - TextureTools library # GlxApplication - GLX application (depends on X11 libraries) # XEglApplication - X/EGL application (depends on EGL and X11 libraries) @@ -198,6 +199,11 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES PhongShader.h) endif() + # Text library + if(${component} STREQUAL Text) + set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Font.h) + endif() + # TextureTools library if(${component} STREQUAL TextureTools) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18619eac3..8ae6ea8fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -162,6 +162,10 @@ if(WITH_SHADERS) add_subdirectory(Shaders) endif() +if(WITH_TEXT) + add_subdirectory(Text) +endif() + if(WITH_TEXTURETOOLS) add_subdirectory(TextureTools) endif() diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt new file mode 100644 index 000000000..e69de29bb From 3b92d711c742ea14c74213f0a67758c5a7ea50d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 31 Dec 2012 18:56:29 +0100 Subject: [PATCH 092/567] CMake module for finding HarfBuzz library. --- modules/FindHarfBuzz.cmake | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 modules/FindHarfBuzz.cmake diff --git a/modules/FindHarfBuzz.cmake b/modules/FindHarfBuzz.cmake new file mode 100644 index 000000000..bf2c71e7e --- /dev/null +++ b/modules/FindHarfBuzz.cmake @@ -0,0 +1,33 @@ +# - Find HarfBuzz +# +# This module tries to find HarfBuzz library and then defines: +# HARFBUZZ_FOUND - True if HarfBuzz library is found +# HARFBUZZ_INCLUDE_DIRS - Include dirs +# HARFBUZZ_LIBRARIES - HarfBuzz libraries +# +# Additionally these variables are defined for internal usage: +# HARFBUZZ_INCLUDE_DIR - Include dir (w/o dependencies) +# HARFBUZZ_LIBRARY - HarfBuzz library (w/o dependencies) +# + +# Library +find_library(HARFBUZZ_LIBRARY NAMES harfbuzz) + +# Include dir +find_path(HARFBUZZ_INCLUDE_DIR + NAMES hb.h + PATH_SUFFIXES harfbuzz +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args("HarfBuzz" DEFAULT_MSG + HARFBUZZ_LIBRARY + HARFBUZZ_INCLUDE_DIR +) + +set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR}) +set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY}) + +mark_as_advanced(FORCE + HARFBUZZ_LIBRARY + HARFBUZZ_INCLUDE_DIR) From 9d260b72d8de4af483aed503aed23dacd560b0ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Dec 2012 20:40:11 +0100 Subject: [PATCH 093/567] Text: initial implementation of font and text rendering. The library uses FreeType for glyph pre-rendering and basic glyph geometry and HarfBuzz for text layouting (i.e. ligatures, kerning, ...). Currently all used glyphs must be prerendered into texture atlas, other glyphs are simply not rendered (although the layouting code handles them like if they are there). Text rendering supports UTF-8, although glyph pre-rendering is currently ASCII only, as I couldn't find any working implementation of Unicode STL function in recent GCC versions. Will be fixed later. --- doc/compilation-speedup.dox | 1 + src/Text/CMakeLists.txt | 23 +++++ src/Text/Font.cpp | 145 ++++++++++++++++++++++++++++ src/Text/Font.h | 111 ++++++++++++++++++++++ src/Text/FontRenderer.cpp | 32 +++++++ src/Text/FontRenderer.h | 51 ++++++++++ src/Text/Text.h | 32 +++++++ src/Text/TextRenderer.cpp | 161 ++++++++++++++++++++++++++++++++ src/Text/TextRenderer.h | 84 +++++++++++++++++ src/Text/magnumTextVisibility.h | 30 ++++++ 10 files changed, 670 insertions(+) create mode 100644 src/Text/Font.cpp create mode 100644 src/Text/Font.h create mode 100644 src/Text/FontRenderer.cpp create mode 100644 src/Text/FontRenderer.h create mode 100644 src/Text/Text.h create mode 100644 src/Text/TextRenderer.cpp create mode 100644 src/Text/TextRenderer.h create mode 100644 src/Text/magnumTextVisibility.h diff --git a/doc/compilation-speedup.dox b/doc/compilation-speedup.dox index ca42d8774..bfd68db8a 100644 --- a/doc/compilation-speedup.dox +++ b/doc/compilation-speedup.dox @@ -24,6 +24,7 @@ available, each namespace has its own: - Physics/Physics.h - SceneGraph/SceneGraph.h - Shaders/Shaders.h + - Text/Text.h @section compilation-speedup-templates Templates diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index e69de29bb..2bdebfb92 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -0,0 +1,23 @@ +find_package(Freetype REQUIRED) +find_package(HarfBuzz REQUIRED) + +include_directories(${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS}) + +set(MagnumText_SRCS + Font.cpp + FontRenderer.cpp + TextRenderer.cpp) +set(MagnumText_HEADERS + Font.h + FontRenderer.h + Text.h + TextRenderer.h + + magnumTextVisibility.h) + +add_library(MagnumText SHARED ${MagnumText_SRCS}) + +target_link_libraries(MagnumText Magnum MagnumMeshTools MagnumTextureTools ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES}) + +install(TARGETS MagnumText DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) +install(FILES ${MagnumText_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Text) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp new file mode 100644 index 000000000..2161f4be7 --- /dev/null +++ b/src/Text/Font.cpp @@ -0,0 +1,145 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Font.h" + +#include +#include FT_FREETYPE_H +#include + +#include "Image.h" +#include "TextureTools/Atlas.h" + +namespace Magnum { namespace Text { + +Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size): _size(size) { + /** @todo Use delegating constructor when GCC 4.6 support is dropped */ + create(renderer, fontFile); +} + +Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, const std::string& characters, const Vector2i& atlasSize): _size(size) { + /** @todo Use delegating constructor when GCC 4.6 support is dropped */ + create(renderer, fontFile); + + /** @bug Crash when atlas is too small */ + /** @todo Get rid of duplicate characters */ + + /* Get character codes from string */ + /** @todo proper UTF-8 decoding */ + std::vector charCodes(characters.begin(), characters.end()); + + /* Get character indices */ + std::vector charIndices; + charIndices.push_back(0); + for(std::uint32_t charCode: charCodes) + charIndices.push_back(FT_Get_Char_Index(_ftFont, charCode)); + + /* Sizes of all characters */ + std::vector charSizes; + charSizes.reserve(charIndices.size()); + for(FT_UInt c: charIndices) { + CORRADE_INTERNAL_ASSERT(FT_Load_Glyph(_ftFont, c, FT_LOAD_DEFAULT) == 0); + charSizes.push_back((Vector2i(_ftFont->glyph->metrics.width, _ftFont->glyph->metrics.height))/64); + } + + /* Create texture atlas */ + std::vector charPositions = TextureTools::atlas(atlasSize, charSizes); + + /* Render all characters to the atlas and create character map */ + glyphs.reserve(charPositions.size()); + unsigned char* pixmap = new unsigned char[atlasSize.product()](); + Image2D image(atlasSize, Image2D::Format::Red, Image2D::Type::UnsignedByte, pixmap); + for(std::size_t i = 0; i != charPositions.size(); ++i) { + /* Load and render glyph */ + /** @todo B&W only */ + FT_GlyphSlot glyph = _ftFont->glyph; + CORRADE_INTERNAL_ASSERT(FT_Load_Glyph(_ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0); + CORRADE_INTERNAL_ASSERT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0); + + /* Copy rendered bitmap to texture image */ + const FT_Bitmap& bitmap = glyph->bitmap; + CORRADE_INTERNAL_ASSERT(std::abs(bitmap.width-charPositions[i].width()) <= 2); + CORRADE_INTERNAL_ASSERT(std::abs(bitmap.rows-charPositions[i].height()) <= 2); + for(std::int32_t yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout) + for(std::int32_t xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout) + pixmap[yout*atlasSize.x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin]; + + /* Save character texture position and texture coordinates for given character index */ + glyphs.insert({charIndices[i], std::make_tuple( + Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/size, + Vector2::from(charPositions[i].size())/size), + Rectangle(Vector2::from(charPositions[i].bottomLeft())/atlasSize, + Vector2::from(charPositions[i].topRight())/atlasSize) + )}); + } + + /* Set texture data */ + _texture.setData(0, Texture2D::InternalFormat::R8, &image); +} + +void Font::create(FontRenderer& renderer, const std::string& fontFile) { + /* Create FreeType font */ + CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); + CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); + + /* Create Harfbuzz font */ + _hbFont = hb_ft_font_create(_ftFont, nullptr); + + /* Set up the texture */ + _texture.setWrapping(Texture2D::Wrapping::ClampToEdge) + ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) + ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); +} + +void Font::destroy() { + if(!_ftFont) return; + + hb_font_destroy(_hbFont); + FT_Done_Face(_ftFont); +} + +void Font::move() { + _hbFont = nullptr; + _ftFont = nullptr; +} + +Font::~Font() { destroy(); } + +Font::Font(Font&& other): glyphs(std::move(other.glyphs)), _texture(std::move(other._texture)), _ftFont(other._ftFont), _hbFont(other._hbFont), _size(other._size) { + other.move(); +} + +Font& Font::operator=(Font&& other) { + destroy(); + + glyphs = std::move(other.glyphs); + _texture = std::move(other._texture); + _ftFont = other._ftFont; + _hbFont = other._hbFont; + _size = other._size; + + other.move(); + return *this; +} + +const std::tuple& Font::operator[](std::uint32_t character) const { + auto it = glyphs.find(character); + + if(it == glyphs.end()) + return glyphs.at(0); + return it->second; +} + +}} diff --git a/src/Text/Font.h b/src/Text/Font.h new file mode 100644 index 000000000..326a58ca6 --- /dev/null +++ b/src/Text/Font.h @@ -0,0 +1,111 @@ +#ifndef Magnum_Text_Font_h +#define Magnum_Text_Font_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Text::Font + */ + +#include + +#include "Math/Geometry/Rectangle.h" +#include "Texture.h" +#include "Text/FontRenderer.h" + +#include "magnumTextVisibility.h" + +#ifndef DOXYGEN_GENERATING_OUTPUT +struct FT_FaceRec_; +typedef FT_FaceRec_* FT_Face; +struct hb_font_t; +#endif + +namespace Magnum { namespace Text { + +/** +@brief %Font + +Contains font with characters prerendered into texture atlas. +*/ +class MAGNUM_TEXT_EXPORT Font { + Font(const Font&) = delete; + Font& operator=(const Font&) = delete; + + public: + /** + * @brief Empty font constructor + * @param renderer %Font renderer + * @param fontFile %Font file + * @param size %Font size + * + * Creates font with no prerendered characters. + */ + Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); + + /** + * @brief Create font for given character set + * @param renderer %Font renderer + * @param fontFile %Font file + * @param size %Font size + * @param characters Characters to render + * @param atlasSize Size of resulting atlas + */ + Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, const std::string& characters, const Vector2i& atlasSize); + + ~Font(); + + /** @brief Move constructor */ + Font(Font&& other); + + /** @brief Move assignment */ + Font& operator=(Font&& other); + + /** @brief %Font size */ + inline GLfloat size() const { return _size; } + + /** @brief Count of prerendered glyphs in the font */ + inline std::size_t glyphCount() const { return glyphs.size(); } + + /** + * @brief Position of given character in the texture + * @param character Unicode character code (UTF-32) + * + * First returned rectangle is texture position relative to point on + * baseline, second is position of the texture in texture atlas. + */ + const std::tuple& operator[](std::uint32_t character) const; + + /** @brief %Font texture atlas */ + inline Texture2D& texture() { return _texture; } + + /** @brief HarfBuzz font handle */ + inline hb_font_t* font() { return _hbFont; } + + private: + void MAGNUM_TEXT_LOCAL create(FontRenderer& renderer, const std::string& fontFile); + void MAGNUM_TEXT_LOCAL destroy(); + void MAGNUM_TEXT_LOCAL move(); + + std::unordered_map> glyphs; + Texture2D _texture; + FT_Face _ftFont; + hb_font_t* _hbFont; + GLfloat _size; +}; + +}} + +#endif diff --git a/src/Text/FontRenderer.cpp b/src/Text/FontRenderer.cpp new file mode 100644 index 000000000..94c5fde25 --- /dev/null +++ b/src/Text/FontRenderer.cpp @@ -0,0 +1,32 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "FontRenderer.h" + +#include +#include FT_FREETYPE_H +#include + +namespace Magnum { namespace Text { + +FontRenderer::FontRenderer() { + CORRADE_INTERNAL_ASSERT(FT_Init_FreeType(&_library) == 0); +} + +FontRenderer::~FontRenderer() { + FT_Done_FreeType(_library); +} + +}} diff --git a/src/Text/FontRenderer.h b/src/Text/FontRenderer.h new file mode 100644 index 000000000..0164edf32 --- /dev/null +++ b/src/Text/FontRenderer.h @@ -0,0 +1,51 @@ +#ifndef Magnum_Text_FontRenderer_h +#define Magnum_Text_FontRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Text::FontRenderer + */ + +#include "magnumTextVisibility.h" + +#ifndef DOXYGEN_GENERATING_OUTPUT +struct FT_LibraryRec_; +typedef FT_LibraryRec_* FT_Library; +#endif + +namespace Magnum { namespace Text { + +/** +@brief Font renderer + +Contains global instance of font renderer used by Font class. +*/ +class MAGNUM_TEXT_EXPORT FontRenderer { + public: + explicit FontRenderer(); + + ~FontRenderer(); + + /** @brief FreeType library handle */ + inline FT_Library library() { return _library; } + + private: + FT_Library _library; +}; + +}} + +#endif diff --git a/src/Text/Text.h b/src/Text/Text.h new file mode 100644 index 000000000..982b73d75 --- /dev/null +++ b/src/Text/Text.h @@ -0,0 +1,32 @@ +#ifndef Magnum_Text_Text_h +#define Magnum_Text_Text_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Forward declarations for Magnum::Text namespace + */ + +#include + +namespace Magnum { namespace Text { + +class Font; +class FontRenderer; +/* TextRenderer used only statically */ + +}} + +#endif diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp new file mode 100644 index 000000000..053cb5845 --- /dev/null +++ b/src/Text/TextRenderer.cpp @@ -0,0 +1,161 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "TextRenderer.h" + +#include +#include + +#include "Math/Point2D.h" +#include "Math/Point3D.h" +#include "IndexedMesh.h" +#include "Swizzle.h" +#include "MeshTools/CompressIndices.h" +#include "MeshTools/Interleave.h" +#include "Shaders/AbstractTextShader.h" +#include "Text/Font.h" + +namespace Magnum { namespace Text { + +namespace { + +std::tuple, std::vector, std::vector> renderInternal(Font& font, GLfloat size, const std::string& text) { + /* Prepare HarfBuzz buffer */ + hb_buffer_t *buffer = hb_buffer_create(); + hb_buffer_set_unicode_funcs(buffer, hb_icu_get_unicode_funcs()); + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); + hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); + + /* Layout the text */ + hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); + hb_shape(font.font(), buffer, nullptr, 0); + + std::uint32_t glyphCount; + hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos(buffer, &glyphCount); + hb_glyph_position_t* glyphPositions = hb_buffer_get_glyph_positions(buffer, &glyphCount); + + /* Output data */ + std::vector positions, texcoords; + std::vector indices; + positions.reserve(glyphCount*4); + texcoords.reserve(glyphCount*4); + indices.reserve(glyphCount*6); + + /* Starting cursor position */ + Vector2 cursorPosition; + + /* Create quads for all glyphs */ + for(std::uint32_t i = 0; i != glyphCount; ++i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle texturePosition, textureCoordinates; + std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; + + /* Glyph offset and advance to next glyph in normalized coordinates */ + Vector2 offset = Vector2(glyphPositions[i].x_offset, + glyphPositions[i].y_offset)/(64*font.size()); + Vector2 advance = Vector2(glyphPositions[i].x_advance, + glyphPositions[i].y_advance)/(64*font.size()); + + /* Absolute quad position, composed from cursor position, glyph offset + and texture position, denormalized to requested text size */ + Rectangle quadPosition = Rectangle::fromSize( + (cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, + texturePosition.size()*size); + + /* 0---2 2 + | / /| + | / / | + |/ / | + 1 1---3 */ + + /* Quad with texture coordinates */ + indices.insert(indices.end(), { + std::uint32_t(positions.size()), + std::uint32_t(positions.size()+1), + std::uint32_t(positions.size()+2), + std::uint32_t(positions.size()+1), + std::uint32_t(positions.size()+3), + std::uint32_t(positions.size()+2) + }); + positions.insert(positions.end(), { + quadPosition.topLeft(), + quadPosition.bottomLeft(), + quadPosition.topRight(), + quadPosition.bottomRight(), + }); + texcoords.insert(texcoords.end(), { + textureCoordinates.topLeft(), + textureCoordinates.bottomLeft(), + textureCoordinates.topRight(), + textureCoordinates.bottomRight() + }); + + /* Advance cursor position to next character */ + cursorPosition += advance; + } + + /* Destroy HarfBuzz buffer */ + hb_buffer_destroy(buffer); + + return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices)); +} + +template typename DimensionTraits::PointType point(const Vector2& vec); + +template<> inline Point2D point<2>(const Vector2& vec) { + return swizzle<'x', 'y', '1'>(vec); +} + +template<> inline Point3D point<3>(const Vector2& vec) { + return swizzle<'x', 'y', '0', '1'>(vec); +} + +} + +template std::tuple::PointType>, std::vector, std::vector> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { + std::vector positions, textureCoordinates; + std::vector indices; + std::tie(positions, textureCoordinates, indices) = renderInternal(font, size, text); + + /* Create PointXD from Vector2 */ + std::vector::PointType> positionsXD; + positionsXD.reserve(positions.size()); + for(const Vector2& position: positions) + positionsXD.push_back(point(position)); + + return std::make_tuple(std::move(positionsXD), std::move(textureCoordinates), std::move(indices)); +} + +template IndexedMesh TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { + IndexedMesh mesh; + + std::vector::PointType> positions; + std::vector textureCoordinates; + std::vector indices; + std::tie(positions, textureCoordinates, indices) = render(font, size, text); + + MeshTools::interleave(&mesh, vertexBuffer, usage, positions, textureCoordinates); + MeshTools::compressIndices(&mesh, indexBuffer, usage, indices); + mesh.setPrimitive(Mesh::Primitive::Triangles) + ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::AbstractTextShader::Position(), typename Shaders::AbstractTextShader::TextureCoordinates()); + + return mesh; +} + +template class TextRenderer<2>; +template class TextRenderer<3>; + +}} diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h new file mode 100644 index 000000000..81016d362 --- /dev/null +++ b/src/Text/TextRenderer.h @@ -0,0 +1,84 @@ +#ifndef Magnum_Text_TextRenderer_h +#define Magnum_Text_TextRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Text::TextRenderer + */ + +#include "Math/Vector2.h" +#include "Buffer.h" +#include "DimensionTraits.h" +#include "Text/Text.h" + +#include "magnumTextVisibility.h" + +#include +#include +#include + +namespace Magnum { namespace Text { + +/** +@brief %Text renderer + +Lays out the text into mesh using [HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz) +library. Use of ligatures, kerning etc. depends on features supported by the +particular font. +@see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractTextShader +*/ +template class MAGNUM_TEXT_EXPORT TextRenderer { + public: + /** + * @brief Render text + * @param font %Font to use + * @param size %Font size + * @param text %Text to render + * @return Tuple with vertex positions, texture coordinates and indices + */ + static std::tuple::PointType>, std::vector, std::vector> render(Font& font, GLfloat size, const std::string& text); + + /** + * @brief Render text + * @param font %Font to use + * @param size %Font size + * @param text %Text to render + * @param vertexBuffer %Buffer where to store vertices + * @param indexBuffer %Buffer where to store indices + * @param usage Usage of vertex and index buffer + * @return Indexed mesh prepared for use with Shaders::AbstractTextShader + * subclasses + */ + static IndexedMesh render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + + private: + #ifndef DOXYGEN_GENERATING_OUTPUT + struct Vertex { + typename DimensionTraits::PointType position; + Vector2 textureCoordinates; + }; + #endif +}; + +/** @brief Two-dimensional text renderer */ +typedef TextRenderer<2> TextRenderer2D; + +/** @brief Three-dimensional text renderer */ +typedef TextRenderer<3> TextRenderer3D; + +}} + +#endif diff --git a/src/Text/magnumTextVisibility.h b/src/Text/magnumTextVisibility.h new file mode 100644 index 000000000..4d70506c9 --- /dev/null +++ b/src/Text/magnumTextVisibility.h @@ -0,0 +1,30 @@ +#ifndef Magnum_Text_magnumTextVisibility_h +#define Magnum_Text_magnumTextVisibility_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#ifdef _WIN32 + #ifdef MagnumText_EXPORTS + #define MAGNUM_TEXT_EXPORT __declspec(dllexport) + #else + #define MAGNUM_TEXT_EXPORT __declspec(dllimport) + #endif + #define MAGNUM_TEXT_LOCAL +#else + #define MAGNUM_TEXT_EXPORT __attribute__ ((visibility ("default"))) + #define MAGNUM_TEXT_LOCAL __attribute__ ((visibility ("hidden"))) +#endif + +#endif From 21337dafc04c4ce84e3f1cad43be1a348bb55e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 1 Jan 2013 19:45:31 +0100 Subject: [PATCH 094/567] Doc++ --- src/Math/Geometry/Rectangle.h | 6 +++--- src/Math/Vector2.h | 2 +- src/Math/Vector3.h | 2 +- src/Math/Vector4.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 18fed134a..5917c1f5b 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -27,9 +27,9 @@ namespace Magnum { namespace Math { namespace Geometry { @brief %Rectangle Helper class for storing axis-aligned rectangles consisting of bottom left and -top right corner positions. Bottom left position is inclusive, while top right -position is exclusive. -@see Magnum::Rectanglei +top right corner positions with origin in bottom left. Bottom/left positions +are inclusive, while top/right positions are exclusive. +@see Magnum::Rectangle, Magnum::Rectanglei */ template class Rectangle { public: diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 24297213a..f27be7c48 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Math { @tparam T Data type See @ref matrix-vector for brief introduction. -@see Magnum::Vector2 +@see Magnum::Vector2, Magnum::Vector2i, Magnum::Vector2ui @configurationvalueref{Magnum::Math::Vector2} */ template class Vector2: public Vector<2, T> { diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 52250101b..1e81d7f8e 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Math { See @ref matrix-vector for brief introduction. See also Point2D for homogeneous two-dimensional coordinates. -@see Magnum::Vector3 +@see Magnum::Vector3, Magnum::Vector3i, Magnum::Vector3ui @configurationvalueref{Magnum::Math::Vector3} */ template class Vector3: public Vector<3, T> { diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 206b5a8aa..9bc2265b2 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Math { See @ref matrix-vector for brief introduction. See also Point3D for homogeneous three-dimensional coordinates. -@see Magnum::Vector4 +@see Magnum::Vector4, Magnum::Vector4i, Magnum::Vector4ui @configurationvalueref{Magnum::Math::Vector4} */ template class Vector4: public Vector<4, T> { From 29a07c7d62219736091c7640ee1add5b70e8faf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 3 Jan 2013 00:12:50 +0100 Subject: [PATCH 095/567] GCC 4.6 compilation fixes. --- src/Platform/magnum-info.cpp | 1 + src/Renderbuffer.h | 4 ++-- src/Shaders/AbstractTextShader.h | 2 +- src/Shaders/FlatShader.cpp | 2 +- src/Shaders/FlatShader.h | 4 ++-- src/Shaders/PhongShader.cpp | 2 +- src/Shaders/PhongShader.h | 18 +++++++++--------- src/Shaders/TextShader.cpp | 2 +- src/Shaders/TextShader.h | 4 ++-- src/Shaders/VertexColorShader.cpp | 2 +- src/Shaders/VertexColorShader.h | 2 +- 11 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 01912273b..0cd691d6c 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "Context.h" #include "Platform/WindowlessGlxApplication.h" diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 266bad113..10cc29f95 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -503,7 +503,7 @@ class MAGNUM_EXPORT Renderbuffer { * @requires_gles30 %Extension @es_extension{OES,packed_depth_stencil} */ #ifdef MAGNUM_TARGET_GLES2 - Depth24Stencil8 = GL_DEPTH24_STENCIL8_OES, + Depth24Stencil8 = GL_DEPTH24_STENCIL8_OES #else Depth24Stencil8 = GL_DEPTH24_STENCIL8, @@ -513,7 +513,7 @@ class MAGNUM_EXPORT Renderbuffer { * @requires_gles30 Only integral depth textures are available in * OpenGL ES 2.0. */ - Depth32FStencil8 = GL_DEPTH32F_STENCIL8, + Depth32FStencil8 = GL_DEPTH32F_STENCIL8 #endif }; diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h index 3310bbc58..e8604b21b 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractTextShader.h @@ -39,7 +39,7 @@ template class AbstractTextShader: public AbstractShade typedef Attribute<1, Vector2> TextureCoordinates; enum: GLint { - FontTextureLayer = 16, /**< @brief Layer for font texture */ + FontTextureLayer = 16 /**< @brief Layer for font texture */ }; ~AbstractTextShader() = 0; diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index aba54c0f3..0999fdd1d 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -36,7 +36,7 @@ namespace { }; } -template FlatShader::FlatShader() { +template FlatShader::FlatShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index 33ee62607..93a020a4a 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -61,8 +61,8 @@ template class MAGNUM_SHADERS_EXPORT FlatShader: public } private: - GLint transformationProjectionMatrixUniform = 0, - colorUniform = 1; + GLint transformationProjectionMatrixUniform, + colorUniform; }; /** @brief 2D flat shader */ diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index 638831d8e..b069eedf8 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace Shaders { -PhongShader::PhongShader() { +PhongShader::PhongShader(): transformationMatrixUniform(0), projectionMatrixUniform(1), normalMatrixUniform(2), lightUniform(3), diffuseColorUniform(4), ambientColorUniform(5), specularColorUniform(6), lightColorUniform(7), shininessUniform(8) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index ff0d483cf..b37d93361 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -123,15 +123,15 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } private: - GLint transformationMatrixUniform = 0, - projectionMatrixUniform = 1, - normalMatrixUniform = 2, - lightUniform = 3, - diffuseColorUniform = 4, - ambientColorUniform = 5, - specularColorUniform = 6, - lightColorUniform = 7, - shininessUniform = 8; + GLint transformationMatrixUniform, + projectionMatrixUniform, + normalMatrixUniform, + lightUniform, + diffuseColorUniform, + ambientColorUniform, + specularColorUniform, + lightColorUniform, + shininessUniform; }; }} diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/TextShader.cpp index 69a61d762..4f38ba324 100644 --- a/src/Shaders/TextShader.cpp +++ b/src/Shaders/TextShader.cpp @@ -37,7 +37,7 @@ namespace { }; } -template TextShader::TextShader() { +template TextShader::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/TextShader.h b/src/Shaders/TextShader.h index de2d06523..4b1819dbb 100644 --- a/src/Shaders/TextShader.h +++ b/src/Shaders/TextShader.h @@ -49,8 +49,8 @@ template class MAGNUM_SHADERS_EXPORT TextShader: public } private: - GLint transformationProjectionMatrixUniform = 0, - colorUniform = 1; + GLint transformationProjectionMatrixUniform, + colorUniform; }; /** @brief Two-dimensional text shader */ diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index b2a93b8e5..5a687c657 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -36,7 +36,7 @@ namespace { }; } -template VertexColorShader::VertexColorShader() { +template VertexColorShader::VertexColorShader(): transformationProjectionMatrixUniform(0) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 061022a91..3ac86aaec 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -55,7 +55,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: } private: - GLint transformationProjectionMatrixUniform = 0; + GLint transformationProjectionMatrixUniform; }; /** @brief 2D vertex color shader */ From 7151486e024ddff7a5008e5944ef96df9dc170ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 3 Jan 2013 00:30:30 +0100 Subject: [PATCH 096/567] Another Doxygen parsing workaround. --- src/Shaders/AbstractTextShader.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h index e8604b21b..6ecc5617d 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractTextShader.h @@ -38,9 +38,18 @@ template class AbstractTextShader: public AbstractShade /** @brief Texture coordinates */ typedef Attribute<1, Vector2> TextureCoordinates; + /** @todoc Remove when Doxygen is sane */ + #ifndef DOXYGEN_GENERATING_OUTPUT enum: GLint { + #else + static const GLint + #endif FontTextureLayer = 16 /**< @brief Layer for font texture */ + #ifndef DOXYGEN_GENERATING_OUTPUT }; + #else + ; + #endif ~AbstractTextShader() = 0; }; From 5367bef3ef81eb0c6f345ff3813985e62773e374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 3 Jan 2013 00:35:03 +0100 Subject: [PATCH 097/567] Ability to specify buffer range in BufferTexture. Extension ARB_texture_buffer_range in OpenGL 4.3. --- src/BufferTexture.cpp | 16 ++++++++++++++-- src/BufferTexture.h | 25 ++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/BufferTexture.cpp b/src/BufferTexture.cpp index 7fd4f6d50..621d4feee 100644 --- a/src/BufferTexture.cpp +++ b/src/BufferTexture.cpp @@ -23,23 +23,35 @@ namespace Magnum { BufferTexture::SetBufferImplementation BufferTexture::setBufferImplementation = &BufferTexture::setBufferImplementationDefault; +BufferTexture::SetBufferRangeImplementation BufferTexture::setBufferRangeImplementation = &BufferTexture::setBufferRangeImplementationDefault; void BufferTexture::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { Debug() << "BufferTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; setBufferImplementation = &BufferTexture::setBufferImplementationDSA; + setBufferRangeImplementation = &BufferTexture::setBufferRangeImplementationDSA; } } -void BufferTexture::setBufferImplementationDefault(BufferTexture::InternalFormat internalFormat, Buffer* buffer) { +void BufferTexture::setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer) { bindInternal(); glTexBuffer(GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); } -void BufferTexture::setBufferImplementationDSA(BufferTexture::InternalFormat internalFormat, Buffer* buffer) { +void BufferTexture::setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer) { glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); } +void BufferTexture::setBufferRangeImplementationDefault(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size) { + bindInternal(); + glTexBufferRange(GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id(), offset, size); +} + +void BufferTexture::setBufferRangeImplementationDSA(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size) { + glTextureBufferRangeEXT(id(), GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id(), offset, size); +} + + } #endif diff --git a/src/BufferTexture.h b/src/BufferTexture.h index 37cc3c9a1..4a6130fb1 100644 --- a/src/BufferTexture.h +++ b/src/BufferTexture.h @@ -62,7 +62,7 @@ AbstractShaderProgram documentation for more information. @section BufferTexture-performance-optimization Performance optimizations If extension @extension{EXT,direct_state_access} is available, setBuffer() -uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and +functions use DSA to avoid unnecessary calls to @fn_gl{ActiveTexture} and @fn_gl{BindTexture}. See @ref AbstractTexture-performance-optimization "relevant section in AbstractTexture documentation" and respective function documentation for more information. @@ -214,6 +214,24 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { (this->*setBufferImplementation)(internalFormat, buffer); } + /** + * @brief Set texture buffer + * @param internalFormat Internal format + * @param buffer %Buffer + * @param offset Offset + * @param size Data size + * + * Binds range of given buffer to this texture. The buffer itself can + * be then filled with data of proper format at any time using Buffer + * own data setting functions. + * @requires_gl43 %Extension @extension{ARB,texture_buffer_range} + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBuffer} + * or @fn_gl_extension{TextureBufferRange,EXT,direct_state_access} + */ + inline void setBuffer(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size) { + (this->*setBufferRangeImplementation)(internalFormat, buffer, offset, size); + } + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); @@ -221,6 +239,11 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { void MAGNUM_LOCAL setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer); void MAGNUM_LOCAL setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer); static SetBufferImplementation setBufferImplementation; + + typedef void(BufferTexture::*SetBufferRangeImplementation)(InternalFormat, Buffer*, GLintptr, GLsizeiptr); + void MAGNUM_LOCAL setBufferRangeImplementationDefault(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size); + void MAGNUM_LOCAL setBufferRangeImplementationDSA(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size); + static SetBufferRangeImplementation setBufferRangeImplementation; }; } From ef81b1035c932bf3c3bdde4c86833c410026594c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 19:46:36 +0100 Subject: [PATCH 098/567] Doc++ --- src/Mesh.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mesh.h b/src/Mesh.h index a7df32fe1..1b918a814 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -416,6 +416,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Add buffer with non-interleaved vertex attributes for use with given shader + * @return Pointer to self (for method chaining) * * Attribute list is combination of * @ref AbstractShaderProgram::Attribute "attribute definitions" @@ -469,6 +470,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Add buffer with interleaved vertex attributes for use with given shader + * @return Pointer to self (for method chaining) * * Parameter @p offset is offset of the interleaved array from the * beginning, attribute list is combination of @@ -530,6 +532,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Add buffer with interleaved vertex attributes for use with given shader + * @return Pointer to self (for method chaining) * * See addInterleavedVertexBuffer() for more information. */ From f9f95946b1a4c7bf3992830d892253657e837f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 19:47:47 +0100 Subject: [PATCH 099/567] Shaders: 3D version of VertexColorShader. Fragment shader can be shared for 2D and 3D version, modified the sources accordingly. --- src/Shaders/CMakeLists.txt | 2 +- src/Shaders/VertexColorShader.cpp | 18 ++++--------- ...orShader2D.frag => VertexColorShader.frag} | 0 src/Shaders/VertexColorShader3D.vert | 25 +++++++++++++++++++ 4 files changed, 31 insertions(+), 14 deletions(-) rename src/Shaders/{VertexColorShader2D.frag => VertexColorShader.frag} (100%) create mode 100644 src/Shaders/VertexColorShader3D.vert diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index aa1b50560..5ea5c8577 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -2,7 +2,7 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders FlatShader2D.vert FlatShader2D.frag PhongShader.vert PhongShader.frag TextShader2D.vert TextShader2D.frag - VertexColorShader2D.vert VertexColorShader2D.frag + VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) set(MagnumShaders_SRCS FlatShader.cpp diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 5a687c657..67fcfde3b 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -23,17 +23,9 @@ namespace Magnum { namespace Shaders { namespace { - template struct ShaderName {}; - - template<> struct ShaderName<2> { - constexpr static const char* vertex() { return "VertexColorShader2D.vert"; } - constexpr static const char* fragment() { return "VertexColorShader2D.frag"; } - }; - - template<> struct ShaderName<3> { - constexpr static const char* vertex() { return "VertexColorShader3D.vert"; } - constexpr static const char* fragment() { return "VertexColorShader3D.frag"; } - }; + template constexpr const char* vertexShaderName(); + template<> constexpr const char* vertexShaderName<2>() { return "VertexColorShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "VertexColorShader3D.vert"; } } template VertexColorShader::VertexColorShader(): transformationProjectionMatrixUniform(0) { @@ -47,12 +39,12 @@ template VertexColorShader::VertexColorShad Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); - vertexShader.addSource(rs.get(ShaderName::vertex())); + vertexShader.addSource(rs.get(vertexShaderName())); attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); - fragmentShader.addSource(rs.get(ShaderName::fragment())); + fragmentShader.addSource(rs.get("VertexColorShader.frag")); attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/VertexColorShader2D.frag b/src/Shaders/VertexColorShader.frag similarity index 100% rename from src/Shaders/VertexColorShader2D.frag rename to src/Shaders/VertexColorShader.frag diff --git a/src/Shaders/VertexColorShader3D.vert b/src/Shaders/VertexColorShader3D.vert new file mode 100644 index 000000000..8a871000f --- /dev/null +++ b/src/Shaders/VertexColorShader3D.vert @@ -0,0 +1,25 @@ +#ifndef NEW_GLSL +#define in attribute +#define out varying +#endif + +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat4 transformationProjectionMatrix; +#else +uniform highp mat4 transformationProjectionMatrix; +#endif + +#ifdef EXPLICIT_ATTRIB_LOCATION +layout(location = 0) in highp vec4 position; +layout(location = 1) in lowp vec3 color; +#else +in highp vec4 position; +in lowp vec3 color; +#endif + +out lowp vec3 interpolatedColor; + +void main() { + gl_Position = transformationProjectionMatrix*position; + interpolatedColor = color; +} From 22d405809f33011b846b8b8dd8713806f4588cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 19:52:53 +0100 Subject: [PATCH 100/567] DebugTools: ShapeRenderer cleanup. * Added missing forward declarations. * Added getters and setters to ShapeRendererOptions class. * Cube primitive is indexed, modified the mesh creation accordingly. It now uses MeshTools, link the library to DebugTools. * Simplified resource handling so it's now handled in one place. It still needs to be thought out better. --- src/DebugTools/CMakeLists.txt | 2 +- src/DebugTools/DebugTools.h | 5 +- .../Implementation/AbstractBoxRenderer.cpp | 94 +++++++++++-------- .../Implementation/AbstractBoxRenderer.h | 21 ++++- .../Implementation/AbstractShapeRenderer.cpp | 2 - .../Implementation/AbstractShapeRenderer.h | 8 -- .../Implementation/AxisAlignedBoxRenderer.cpp | 2 +- src/DebugTools/Implementation/BoxRenderer.cpp | 2 +- src/DebugTools/ResourceManager.cpp | 4 +- src/DebugTools/ShapeRenderer.h | 43 ++++++--- 10 files changed, 112 insertions(+), 71 deletions(-) diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 3b6f17daf..25bd0dfeb 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -18,7 +18,7 @@ set(MagnumDebugTools_HEADERS add_library(MagnumDebugTools SHARED ${MagnumDebugTools_SRCS}) -target_link_libraries(MagnumDebugTools Magnum MagnumPhysics MagnumPrimitives MagnumSceneGraph MagnumShaders) +target_link_libraries(MagnumDebugTools Magnum MagnumMeshTools MagnumPhysics MagnumPrimitives MagnumSceneGraph MagnumShaders) install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h index 82ab4d2b3..529a3194a 100644 --- a/src/DebugTools/DebugTools.h +++ b/src/DebugTools/DebugTools.h @@ -25,8 +25,11 @@ namespace Magnum { namespace DebugTools { class Profiler; class ResourceManager; + template class ShapeRenderer; -struct ShapeRendererOptions; +typedef ShapeRenderer<2> ShapeRenderer2D; +typedef ShapeRenderer<3> ShapeRenderer3D; +class ShapeRendererOptions; }} diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index d22610977..e3283626b 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -16,55 +16,71 @@ #include "AbstractBoxRenderer.h" #include "Buffer.h" +#include "IndexedMesh.h" #include "DebugTools/ResourceManager.h" +#include "MeshTools/CompressIndices.h" #include "Primitives/Cube.h" #include "Primitives/Square.h" #include "Shaders/FlatShader.h" namespace Magnum { namespace DebugTools { namespace Implementation { -namespace { - template struct BoxMesh {}; - - template<> struct BoxMesh<2> { - static ResourceKey shader() { return {"shader2d"}; } - static ResourceKey key() { return {"box2d"}; } - - static Mesh* mesh(Buffer* buffer) { - Primitives::Square square; - Mesh* mesh = new Mesh; - buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); - return mesh->setPrimitive(square.primitive()) - ->setVertexCount(square.positions(0)->size()) - ->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position()); - } - }; - - template<> struct BoxMesh<3> { - static ResourceKey shader() { return {"shader3d"}; } - static ResourceKey key() { return {"box3d"}; } - - static Mesh* mesh(Buffer* buffer) { - Primitives::Cube cube; - Mesh* mesh = new Mesh; - buffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); - return mesh->setPrimitive(cube.primitive()) - ->setVertexCount(cube.positions(0)->size()) - ->addVertexBuffer(buffer, Shaders::FlatShader<2>::Position()); - } - }; -} +AbstractBoxRenderer<2>::AbstractBoxRenderer() { + /* Shader */ + shader = ResourceManager::instance()->get("FlatShader2D"); + if(!shader) ResourceManager::instance()->set(shader.key(), + new Shaders::FlatShader2D, ResourceDataState::Final, ResourcePolicy::Resident); + + /* Mesh and vertex buffer */ + mesh = ResourceManager::instance()->get("box2d"); + buffer = ResourceManager::instance()->get("box2d"); + if(mesh) return; + + /* Create the mesh */ + Primitives::Square square; + Buffer* buffer = new Buffer(Buffer::Target::Array); + Mesh* mesh = new Mesh; -template AbstractBoxRenderer::AbstractBoxRenderer(): AbstractShapeRenderer(BoxMesh::shader(), BoxMesh::key()), buffer(ResourceManager::instance()->get(BoxMesh::key())) { - if(!this->mesh) { - ResourceManager::instance()->set(this->buffer.key(), new Buffer, ResourceDataState::Final, ResourcePolicy::Manual); - ResourceManager::instance()->set(this->mesh.key(), BoxMesh::mesh(buffer), ResourceDataState::Final, ResourcePolicy::Manual); - } + buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(this->buffer.key(), buffer, ResourceDataState::Final, ResourcePolicy::Manual); + + mesh->setPrimitive(square.primitive()) + ->setVertexCount(square.positions(0)->size()) + ->addVertexBuffer(buffer, Shaders::FlatShader2D::Position()); + ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } -template AbstractBoxRenderer::~AbstractBoxRenderer() {} +AbstractBoxRenderer<3>::AbstractBoxRenderer() { + /* Shader */ + shader = ResourceManager::instance()->get("FlatShader3D"); + if(!shader) ResourceManager::instance()->set(shader.key(), + new Shaders::FlatShader3D, ResourceDataState::Final, ResourcePolicy::Resident); + + /* Mesh and vertex buffer */ + mesh = ResourceManager::instance()->get("box3d"); + vertexBuffer = ResourceManager::instance()->get("box3d-vertices"); + indexBuffer = ResourceManager::instance()->get("box3d-indices"); + if(mesh) return; + + /* Create the mesh */ + Primitives::Cube cube; + Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); + Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); + IndexedMesh* mesh = new IndexedMesh; + + vertexBuffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cube.indices()); + ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + mesh->setPrimitive(cube.primitive()) + ->setVertexCount(cube.positions(0)->size()) + ->addVertexBuffer(vertexBuffer, Shaders::FlatShader3D::Position()); + ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); +} -template class AbstractBoxRenderer<2>; -template class AbstractBoxRenderer<3>; +AbstractBoxRenderer<2>::~AbstractBoxRenderer() {} +AbstractBoxRenderer<3>::~AbstractBoxRenderer() {} }}} diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.h b/src/DebugTools/Implementation/AbstractBoxRenderer.h index ef3023527..5f2ecfe8c 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.h +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.h @@ -17,20 +17,39 @@ #include "AbstractShapeRenderer.h" +#include "Resource.h" +#include "Shaders/Shaders.h" + #include "corradeCompatibility.h" namespace Magnum { namespace DebugTools { namespace Implementation { -template class AbstractBoxRenderer: public AbstractShapeRenderer { +template class AbstractBoxRenderer {}; + +template<> class AbstractBoxRenderer<2>: public AbstractShapeRenderer<2> { public: AbstractBoxRenderer(); ~AbstractBoxRenderer(); protected: + Resource mesh; + Resource shader; Resource buffer; }; +template<> class AbstractBoxRenderer<3>: public AbstractShapeRenderer<3> { + public: + AbstractBoxRenderer(); + + ~AbstractBoxRenderer(); + + protected: + Resource mesh; + Resource shader; + Resource vertexBuffer, indexBuffer; +}; + }}} #endif diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index 0ddb6964c..a1cf63dbb 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -22,8 +22,6 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey shader, ResourceKey mesh): shader(ResourceManager::instance()->get>(shader)), mesh(ResourceManager::instance()->get(mesh)) {} - template AbstractShapeRenderer::~AbstractShapeRenderer() {} template class AbstractShapeRenderer<2>; diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index adec6e7fe..ee2c15a23 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -16,24 +16,16 @@ */ #include "DimensionTraits.h" -#include "ResourceManager.h" #include "SceneGraph/SceneGraph.h" -#include "Shaders/Shaders.h" #include "DebugTools/DebugTools.h" namespace Magnum { namespace DebugTools { namespace Implementation { template class AbstractShapeRenderer { public: - AbstractShapeRenderer(ResourceKey shader, ResourceKey mesh); - virtual ~AbstractShapeRenderer(); virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; - - protected: - Resource> shader; - Resource mesh; }; }}} diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 507682d9a..345f69642 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -28,7 +28,7 @@ template void AxisAlignedBoxRenderer::draw( DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()); this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*transformation) - ->setColor(options->color) + ->setColor(options->color()) ->use(); this->mesh->draw(); } diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index a11ade2e7..4a0b98675 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -25,7 +25,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) - ->setColor(options->color) + ->setColor(options->color()) ->use(); this->mesh->draw(); } diff --git a/src/DebugTools/ResourceManager.cpp b/src/DebugTools/ResourceManager.cpp index 5e85d0f48..3c75732e9 100644 --- a/src/DebugTools/ResourceManager.cpp +++ b/src/DebugTools/ResourceManager.cpp @@ -19,8 +19,7 @@ #include "Buffer.h" #include "Mesh.h" -#include "Shaders/FlatShader.h" -#include "ShapeRenderer.h" +#include "DebugTools/ShapeRenderer.h" namespace Magnum { @@ -30,7 +29,6 @@ namespace DebugTools { ResourceManager::ResourceManager() { setFallback(new ShapeRendererOptions); - set("shader2d", new Shaders::FlatShader<2>, ResourceDataState::Final, ResourcePolicy::Resident); } ResourceManager::~ResourceManager() {} diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 0a600dff4..21adf2c59 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -39,22 +39,38 @@ namespace Implementation { See ShapeRenderer documentation for more information. */ -struct ShapeRendererOptions { - Color3<> color; /**< @brief Color */ +class ShapeRendererOptions { + public: + /** @brief Color of rendered shape */ + inline constexpr Color3<> color() const { return _color; } + + /** + * @brief Set color of rendered shape + * @return Pointer to self (for method chaining) + * + * Default is black. + */ + inline ShapeRendererOptions* setColor(const Color3<>& color) { + _color = color; + return this; + } + + private: + Color3<> _color; }; /** @brief Shape renderer -Creates renderers for object collision shape. +Visualizes collision shape. @section ShapeRenderer-usage Basic usage ResourceManager must be instanced for the whole lifetime of debug -renderers. You can specify options via Options struct - add it to the manager -and then create debug renderer with the same options key. This way you can -easily share the same options with more renderers. If no options for given key -exist, default is used. +renderers. You can specify options via ShapeRendererOptions struct - add it to +the manager and then create debug renderer with the same options key. This way +you can easily share the same options with more renderers. If no options for +given key exist, default is used. Example code: @code @@ -66,14 +82,13 @@ DebugTools::ResourceManager manager; SceneGraph::DrawableGroup2D debugDrawables; // Create some options -auto o = new DebugTools::ShapeRendererOptions { - {1.0f, 0.0f, 0.0f} // Red color -}; -manager->set("red", o, ResourceDataState::Final, ResourcePolicy::Persistent); +DebugTools::ResourceManager::instance()->set("red", + (new DebugTools::ShapeRendererOptions())->setColor({1.0f, 0.0f, 0.0f}), + ResourceDataState::Final, ResourcePolicy::Persistent); // Create debug renderer for given shape, use "red" options for it Physics::ObjectShape2D* shape; -debugDrawables.add(new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables)); +new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); @endcode @see ShapeRenderer2D, ShapeRenderer3D @@ -92,8 +107,8 @@ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: * information. * @param drawables Drawable group * - * @attention @p shape must be available for the whole lifetime of - * this class + * The renderer is automatically added to shape's object features, + * @p shape must be available for the whole lifetime of the renderer. */ explicit ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); From b8ae50267fb4768ee4a1bf98a7fa33f08837ad96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 19:55:52 +0100 Subject: [PATCH 101/567] DebugTools: ObjectRenderer class. Visualizes object position, rotation and size. Common usage as with ShapeRenderer, common documentation extended and moved to new `debug-tools` page. --- doc/debug-tools.dox | 56 +++++++++ doc/features.dox | 1 + src/DebugTools/CMakeLists.txt | 2 + src/DebugTools/DebugTools.h | 5 + src/DebugTools/ObjectRenderer.cpp | 178 +++++++++++++++++++++++++++++ src/DebugTools/ObjectRenderer.h | 107 +++++++++++++++++ src/DebugTools/ResourceManager.cpp | 4 +- src/DebugTools/ResourceManager.h | 4 +- 8 files changed, 354 insertions(+), 3 deletions(-) create mode 100644 doc/debug-tools.dox create mode 100644 src/DebugTools/ObjectRenderer.cpp create mode 100644 src/DebugTools/ObjectRenderer.h diff --git a/doc/debug-tools.dox b/doc/debug-tools.dox new file mode 100644 index 000000000..97e439783 --- /dev/null +++ b/doc/debug-tools.dox @@ -0,0 +1,56 @@ +namespace Magnum { +/** @page debug-tools Debugging helpers + +@brief Convenience classes to help you during development. + +@tableofcontents + +DebugTools library provides various helper classes to help you with +prototyping and debugging applications without the need to write too much +common code. They probably have no usage in production code, but can be useful +in development. + +@section debug-tools-renderers Debug renderers + +%Debug renderers provide a way to visualize objects and object features in +@ref scenegraph "scene graph" without the need to mess around with meshes and +shaders. They are implemented as object features, so you can attach any number +of them to any object. + +Basic usage involves instancing DebugTools::ResourceManager and keeping it for +for the whole lifetime of debug renderers. Next you need some SceneGraph::DrawableGroup +instance. You can use the same group as for the rest of your scene, but +preferrably use dedicated one for debug renderers, so you can easily enable or +disable debug rendering. + +Next step is to create configuration for your debug renderers and create +particular debug renderer. The configuration is managed using the resource +manager - you create configuration instance, add it to the manager and then +reference it using particular resource key. This way you can easily share the +same options with more renderers. If no options are specified or resource with +given key doesn't exist, default fallback is used. + +Example usage: visualizing object position, rotation and scaling using +DebugTools::ObjectRenderer: +@code +// Global instance of debug resource manager, drawable group for the renderers +DebugTools::ResourceManager manager; +SceneGraph::DrawableGroup3D debugDrawables; + +// Create renderer options which will be referenced later by "my" resource key +DebugTools::ResourceManager::instance()->set("my", + (new DebugTools::ObjectRendererOptions())->setSize(0.3f), + ResourceDataState::Final, ResourcePolicy::Persistent); + +// Create debug renderer for given object, use "my" options for it. The +// renderer is automatically added to the object features and also to +// specified drawable group. +Object3D* object; +new DebugTools::ObjectRenderer2D(object, "my", debugDrawables); +@endcode + +See DebugTools::ObjectRenderer and DebugTools::ShapeRenderer for more +information. + +*/ +} diff --git a/doc/features.dox b/doc/features.dox index 339e66824..3a0084de2 100644 --- a/doc/features.dox +++ b/doc/features.dox @@ -5,5 +5,6 @@ namespace Magnum { - @subpage matrix-vector - @copybrief matrix-vector - @subpage scenegraph - @copybrief scenegraph - @subpage collision-detection - @copybrief collision-detection +- @subpage debug-tools - @copybrief debug-tools */ } diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 25bd0dfeb..3f828e7dd 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -1,4 +1,5 @@ set(MagnumDebugTools_SRCS + ObjectRenderer.cpp Profiler.cpp ResourceManager.cpp ShapeRenderer.cpp @@ -10,6 +11,7 @@ set(MagnumDebugTools_SRCS set(MagnumDebugTools_HEADERS DebugTools.h + ObjectRenderer.h Profiler.h ResourceManager.h ShapeRenderer.h diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h index 529a3194a..d1aeff182 100644 --- a/src/DebugTools/DebugTools.h +++ b/src/DebugTools/DebugTools.h @@ -23,6 +23,11 @@ namespace Magnum { namespace DebugTools { +template class ObjectRenderer; +typedef ObjectRenderer<2> ObjectRenderer2D; +typedef ObjectRenderer<3> ObjectRenderer3D; +class ObjectRendererOptions; + class Profiler; class ResourceManager; diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp new file mode 100644 index 000000000..3632f65a8 --- /dev/null +++ b/src/DebugTools/ObjectRenderer.cpp @@ -0,0 +1,178 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ObjectRenderer.h" + +#include "Buffer.h" +#include "IndexedMesh.h" +#include "DebugTools/ResourceManager.h" +#include "MeshTools/Interleave.h" +#include "SceneGraph/AbstractCamera.h" +#include "Shaders/VertexColorShader.h" + +namespace Magnum { namespace DebugTools { + +namespace { + +template struct Renderer; + +template<> struct Renderer<2> { + inline static ResourceKey shader() { return {"VertexColorShader2D"}; } + inline static ResourceKey vertexBuffer() { return {"object2d-vertices"}; } + inline static ResourceKey indexBuffer() { return {"object2d-indices"}; } + inline static ResourceKey mesh() { return {"object2d"}; } + + static const std::array positions; + static const std::array, 8> colors; + static const std::array indices; +}; + +const std::array Renderer<2>::positions{{ + { 0.0f, 0.0f}, + { 1.0f, 0.0f}, /* X axis */ + { 0.9f, 0.1f}, + { 0.9f, -0.1f}, + + { 0.0f, 0.0f}, + { 0.0f, 1.0f}, /* Y axis */ + { 0.1f, 0.9f}, + {-0.1f, 0.9f} +}}; + +const std::array, 8> Renderer<2>::colors{{ + {1.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, /* X axis */ + {1.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, /* Y axis */ + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, +}}; + +const std::array Renderer<2>::indices{{ + 0, 1, + 1, 2, /* X axis */ + 1, 3, + + 4, 5, + 5, 6, /* Y axis */ + 5, 7 +}}; + +template<> struct Renderer<3> { + inline static ResourceKey shader() { return {"VertexColorShader3D"}; } + inline static ResourceKey vertexBuffer() { return {"object3d-vertices"}; } + inline static ResourceKey indexBuffer() { return {"object3d-indices"}; } + inline static ResourceKey mesh() { return {"object3d"}; } + + static const std::array positions; + static const std::array, 12> colors; + static const std::array indices; +}; + +const std::array Renderer<3>::positions{{ + { 0.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, /* X axis */ + { 0.9f, 0.1f, 0.0f}, + { 0.9f, -0.1f, 0.0f}, + + { 0.0f, 0.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, /* Y axis */ + { 0.1f, 0.9f, 0.0f}, + {-0.1f, 0.9f, 0.0f}, + + { 0.0f, 0.0f, 0.0f}, + { 0.0f, 0.0f, 1.0f}, /* Z axis */ + { 0.1f, 0.0f, 0.9f}, + {-0.1f, 0.0f, 0.9f} +}}; + +const std::array, 12> Renderer<3>::colors{{ + {1.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, /* X axis */ + {1.0f, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f}, + + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, /* Y axis */ + {0.0f, 1.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, /* Z axis */ + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f} +}}; + +const std::array Renderer<3>::indices{{ + 0, 1, + 1, 2, /* X axis */ + 1, 3, + + 4, 5, + 5, 6, /* Y axis */ + 5, 7, + + 8, 9, + 9, 10, /* Z axis */ + 9, 11 +}}; + +} + +template ObjectRenderer::ObjectRenderer(SceneGraph::AbstractObject* object, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(object, drawables), options(ResourceManager::instance()->get(options)) { + /* Shader */ + shader = ResourceManager::instance()->get>(Renderer::shader()); + if(!shader) ResourceManager::instance()->set(shader.key(), + new Shaders::VertexColorShader, ResourceDataState::Final, ResourcePolicy::Resident); + + /* Mesh and vertex buffer */ + mesh = ResourceManager::instance()->get(Renderer::mesh()); + vertexBuffer = ResourceManager::instance()->get(Renderer::vertexBuffer()); + indexBuffer = ResourceManager::instance()->get(Renderer::indexBuffer()); + if(mesh) return; + + /* Create the mesh */ + Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); + Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); + IndexedMesh* mesh = new IndexedMesh; + + MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, Renderer::positions, Renderer::colors); + ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + indexBuffer->setData(Renderer::indices, Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + mesh->setPrimitive(Mesh::Primitive::Lines) + ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColorShader::Position(), typename Shaders::VertexColorShader::Color()) + ->setIndexCount(Renderer::indices.size()) + ->setIndexType(Type::UnsignedByte) + ->setIndexBuffer(indexBuffer); + ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); +} + +template void ObjectRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { + shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->size()))) + ->use(); + + mesh->draw(); +} + +template class ObjectRenderer<2>; +template class ObjectRenderer<3>; + +}} diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h new file mode 100644 index 000000000..b94f42025 --- /dev/null +++ b/src/DebugTools/ObjectRenderer.h @@ -0,0 +1,107 @@ +#ifndef Magnum_DebugTools_ObjectRenderer_h +#define Magnum_DebugTools_ObjectRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Resource.h" +#include "SceneGraph/Drawable.h" +#include "Shaders/Shaders.h" + +#include "magnumDebugToolsVisibility.h" + +namespace Magnum { namespace DebugTools { + +/** +@brief Object renderer options + +See ObjectRenderer documentation for more information. +*/ +class ObjectRendererOptions { + public: + inline constexpr ObjectRendererOptions(): _size(1.0f) {} + + /** @brief Size of the rendered axes */ + inline constexpr GLfloat size() const { return _size; } + + /** + * @brief Set size of the rendered axes + * @return Pointer to self (for method chaining) + * + * Default is `1.0f`. + */ + inline ObjectRendererOptions* setSize(GLfloat size) { + _size = size; + return this; + } + + private: + GLfloat _size; +}; + +/** +@brief Object renderer + +Visualizes object position, rotation and scale using colored axes. + +@section ObjectRenderer-usage Basic usage + +Example code: +@code +// Create some options +DebugTools::ResourceManager::instance()->set("my", + (new DebugTools::ObjectRendererOptions())->setSize(0.3f), + ResourceDataState::Final, ResourcePolicy::Persistent); + +// Create debug renderer for given object, use "my" options for it +Object3D* object; +new DebugTools::ObjectRenderer2D(object, "my", debugDrawables); +@endcode + +@see ObjectRenderer2D, ObjectRenderer3D +*/ +template class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: public SceneGraph::Drawable { + public: + /** + * @brief Constructor + * @param object Object for which to create debug renderer + * @param options Options resource key. See + * @ref ObjectRenderer-usage "class documentation" for more + * information. + * @param drawables Drawable group + * + * The renderer is automatically added to object's features. + */ + explicit ObjectRenderer(SceneGraph::AbstractObject* object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); + + protected: + /** @todoc Remove GLfloat when Doxygen properly treats this as override */ + void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; + + private: + Resource options; + Resource> shader; + Resource mesh; + Resource vertexBuffer, indexBuffer; +}; + +/** @brief Two-dimensional object renderer */ +typedef ObjectRenderer<2> ObjectRenderer2D; + +/** @brief Three-dimensional object renderer */ +typedef ObjectRenderer<3> ObjectRenderer3D; + +}} + +#endif diff --git a/src/DebugTools/ResourceManager.cpp b/src/DebugTools/ResourceManager.cpp index 3c75732e9..fccdd75b3 100644 --- a/src/DebugTools/ResourceManager.cpp +++ b/src/DebugTools/ResourceManager.cpp @@ -19,15 +19,17 @@ #include "Buffer.h" #include "Mesh.h" +#include "DebugTools/ObjectRenderer.h" #include "DebugTools/ShapeRenderer.h" namespace Magnum { -template class ResourceManager; +template class ResourceManager; namespace DebugTools { ResourceManager::ResourceManager() { + setFallback(new ObjectRendererOptions); setFallback(new ShapeRendererOptions); } diff --git a/src/DebugTools/ResourceManager.h b/src/DebugTools/ResourceManager.h index 98ca34956..3e90d8526 100644 --- a/src/DebugTools/ResourceManager.h +++ b/src/DebugTools/ResourceManager.h @@ -34,7 +34,7 @@ namespace Magnum { -extern template ResourceManager MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager::internalInstance(); +extern template ResourceManager MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager::internalInstance(); namespace DebugTools { @@ -43,7 +43,7 @@ namespace DebugTools { Stores various data used by debug renderers. */ -class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager { +class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager { public: explicit ResourceManager(); ~ResourceManager(); From 89f5200aae20c09a8545d66c144727ca72d73dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 21:46:54 +0100 Subject: [PATCH 102/567] Minor code cleanup. --- src/Math/Geometry/Rectangle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 5917c1f5b..66bf161f4 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -131,7 +131,7 @@ template class Rectangle { template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Rectangle& value) { debug << "Rectangle({"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); - debug << value.left() << ", " << value.bottom() << "}, {" << value.right() << ", " << value.top() <<"})"; + debug << value.left() << ", " << value.bottom() << "}, {" << value.right() << ", " << value.top() << "})"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); return debug; } From 89c2bf913cd97ba10654fccd9889086323ecd6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 21:47:41 +0100 Subject: [PATCH 103/567] Math: initial implementation of Quaternion class. Still practically unusable. --- src/CMakeLists.txt | 1 + src/Math/CMakeLists.txt | 1 + src/Math/Quaternion.cpp | 27 +++++ src/Math/Quaternion.h | 168 +++++++++++++++++++++++++++ src/Math/Test/CMakeLists.txt | 2 + src/Math/Test/MathQuaternionTest.cpp | 105 +++++++++++++++++ 6 files changed, 304 insertions(+) create mode 100644 src/Math/Quaternion.cpp create mode 100644 src/Math/Quaternion.h create mode 100644 src/Math/Test/MathQuaternionTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ae6ea8fa..48cbbc1b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,6 +103,7 @@ add_library(MagnumObjects OBJECT ${Magnum_SRCS}) # Files shared between main library and math unit test library set(MagnumMath_SRCS Math/Math.cpp + Math/Quaternion.cpp Math/RectangularMatrix.cpp Math/Vector.cpp) add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index ef962ab43..4e4505fee 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -9,6 +9,7 @@ set(MagnumMath_HEADERS Matrix4.h Point2D.h Point3D.h + Quaternion.h RectangularMatrix.h Swizzle.h Vector.h diff --git a/src/Math/Quaternion.cpp b/src/Math/Quaternion.cpp new file mode 100644 index 000000000..80d01c33b --- /dev/null +++ b/src/Math/Quaternion.cpp @@ -0,0 +1,27 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Quaternion.h" + +namespace Magnum { namespace Math { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Quaternion&); +#ifndef MAGNUM_TARGET_GLES +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Quaternion&); +#endif +#endif + +}} diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h new file mode 100644 index 000000000..dac5f1a39 --- /dev/null +++ b/src/Math/Quaternion.h @@ -0,0 +1,168 @@ +#ifndef Magnum_Math_Quaternion_h +#define Magnum_Math_Quaternion_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Quaternion + */ + +#include +#include + +#include "Vector3.h" +#include "MathTypeTraits.h" + +namespace Magnum { namespace Math { + +/** @brief %Quaternion */ +template class Quaternion { + public: + /** @brief Default constructor */ + inline constexpr Quaternion(): _scalar(T(1)) {} + + /** @brief Create quaternion from vector and scalar */ + inline constexpr Quaternion(const Vector3& vector, T scalar): _vector(vector), _scalar(scalar) {} + + /** @brief Equality comparison */ + inline bool operator==(const Quaternion& other) const { + return _vector == other._vector && MathTypeTraits::equals(_scalar, other._scalar); + } + + /** @brief Non-equality comparison */ + inline bool operator!=(const Quaternion& other) const { + return !operator==(other); + } + + /** @brief %Vector part */ + inline constexpr Vector3 vector() const { return _vector; } + + /** @brief %Scalar part */ + inline constexpr T scalar() const { return _scalar; } + + /** + * @brief Multiply with scalar and assign + * + * The computation is done in-place. + */ + inline Quaternion& operator*=(T number) { + _vector *= number; + _scalar *= number; + return *this; + } + + /** + * @brief Divide with scalar and assign + * + * The computation is done in-place. + */ + inline Quaternion& operator/=(T number) { + _vector /= number; + _scalar /= number; + return *this; + } + + /** + * @brief Multiply with scalar + * + * @see operator*=(T) + */ + inline constexpr Quaternion operator*(T scalar) const { + return Quaternion(*this)*=scalar; + } + + /** + * @brief Divide with scalar + * + * @see operator/=(T) + */ + inline constexpr Quaternion operator/(T scalar) const { + return Quaternion(*this)/=scalar; + } + + /** + * @brief Multiply with quaternion + * + * The computation is *not* done in-place. + */ + inline constexpr Quaternion operator*(const Quaternion& other) const { + return {_scalar*other._vector + other._scalar*_vector + Vector3::cross(_vector, other._vector), + _scalar*other._scalar - Vector3::dot(_vector, other._vector)}; + } + + /** + * @brief Multiply with quaternion and assign + * + * @see operator*(const Quaternion&) const + */ + inline Quaternion& operator*=(const Quaternion& other) { + return (*this = *this * other); + } + + /** @brief %Quaternion length squared */ + inline constexpr T lengthSquared() const { + return _vector.dot() + _scalar*_scalar; + } + + /** @brief %Quaternion length */ + inline constexpr T length() const { + return std::sqrt(lengthSquared()); + } + + /** @brief Normalized quaternion */ + inline constexpr Quaternion normalized() const { + return (*this)/length(); + } + + /** @brief Conjugated quaternion */ + inline constexpr Quaternion conjugated() const { + return {-_vector, _scalar}; + } + + /** + * @brief Inverted quaternion + * + * If the quaternion is already normalized, this function is + * equivalent to conjugated(). + */ + inline constexpr Quaternion inverted() const { + return conjugated()/lengthSquared(); + } + + private: + Vector3 _vector; + T _scalar; +}; + +/** @debugoperator{Magnum::Math::Geometry::Rectangle} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Quaternion& value) { + debug << "Quaternion({"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << value.vector().x() << ", " << value.vector().y() << ", " << value.vector().z() << "}, " << value.scalar() << ")"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/* Explicit instantiation for commonly used types */ +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Quaternion&); +#ifndef MAGNUM_TARGET_GLES +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Quaternion&); +#endif +#endif + +}} + +#endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index e613855b9..c193b8335 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -18,4 +18,6 @@ corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathQuaternionTest MathQuaternionTest.cpp LIBRARIES MagnumMathTestLib) + set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp new file mode 100644 index 000000000..362ee3825 --- /dev/null +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -0,0 +1,105 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/Quaternion.h" + +namespace Magnum { namespace Math { namespace Test { + +class QuaternionTest: public Corrade::TestSuite::Tester { + public: + explicit QuaternionTest(); + + void construct(); + void multiplyDivideScalar(); + void multiply(); + void length(); + void normalized(); + void conjugated(); + void inverted(); + + void debug(); +}; + +typedef Math::Quaternion Quaternion; +typedef Math::Vector3 Vector3; + +QuaternionTest::QuaternionTest() { + addTests(&QuaternionTest::construct, + &QuaternionTest::multiplyDivideScalar, + &QuaternionTest::multiply, + &QuaternionTest::length, + &QuaternionTest::normalized, + &QuaternionTest::conjugated, + &QuaternionTest::inverted, + &QuaternionTest::debug); +} + +void QuaternionTest::construct() { + Quaternion q({1.0f, 2.0f, 3.0f}, -4.0f); + CORRADE_COMPARE(q.vector(), Vector3(1.0f, 2.0f, 3.0f)); + CORRADE_COMPARE(q.scalar(), -4.0f); + + CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f})); +} + +void QuaternionTest::multiplyDivideScalar() { + Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f); + + CORRADE_COMPARE(a*-1.5f, b); + CORRADE_COMPARE(b/-1.5f, a); +} + +void QuaternionTest::multiply() { + CORRADE_COMPARE(Quaternion({-6.0f, -9.0f, 15.0f}, 0.5f)*Quaternion({2.0f, 3.0f, -5.0f}, 2.0f), + Quaternion({-11.0f, -16.5f, 27.5f}, 115.0f)); +} + +void QuaternionTest::length() { + CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).length(), std::sqrt(30.0f)); +} + +void QuaternionTest::normalized() { + CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).normalized(), + Quaternion({1.0f, 3.0f, -2.0f}, -4.0f)/std::sqrt(30.0f)); +} + +void QuaternionTest::conjugated() { + CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).conjugated(), + Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)); +} + +void QuaternionTest::inverted() { + Quaternion a = Quaternion({1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion inverted = a.inverted(); + + CORRADE_COMPARE(a*inverted, Quaternion()); + CORRADE_COMPARE(inverted*a, Quaternion()); + CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/30.0f); +} + +void QuaternionTest::debug() { + std::ostringstream o; + + Corrade::Utility::Debug(&o) << Quaternion({1.0f, 2.0f, 3.0f}, -4.0f); + CORRADE_COMPARE(o.str(), "Quaternion({1, 2, 3}, -4)\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::QuaternionTest) From fcb8a7b768ad884d3bf89248639a06e8e17e4b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 22:36:14 +0100 Subject: [PATCH 104/567] Got rid of header files in tests. They have no practical use and they only bloat codebase size and add maintenance burden. --- src/Math/Algorithms/Test/GaussJordanTest.cpp | 16 ++++-- src/Math/Algorithms/Test/GaussJordanTest.h | 32 ------------ src/Math/Algorithms/Test/GramSchmidtTest.cpp | 13 +++-- src/Math/Algorithms/Test/GramSchmidtTest.h | 31 ----------- src/Math/CMakeLists.txt | 2 - src/Math/Geometry/CMakeLists.txt | 2 - src/Math/Geometry/Test/DistanceTest.cpp | 21 +++++--- src/Math/Geometry/Test/DistanceTest.h | 34 ------------- src/Math/Geometry/Test/IntersectionTest.cpp | 16 ++++-- src/Math/Geometry/Test/IntersectionTest.h | 31 ----------- src/Math/Geometry/Test/RectangleTest.cpp | 21 ++++++-- src/Math/Geometry/Test/RectangleTest.h | 36 ------------- src/Math/Test/ConstantsTest.cpp | 18 +++++-- src/Math/Test/ConstantsTest.h | 32 ------------ src/Math/Test/MathTest.cpp | 19 +++++-- src/Math/Test/MathTest.h | 35 ------------- src/Math/Test/MathTypeTraitsTest.cpp | 21 ++++++-- src/Math/Test/MathTypeTraitsTest.h | 36 ------------- src/Math/Test/Matrix3Test.cpp | 31 ++++++++--- src/Math/Test/Matrix3Test.h | 44 ---------------- src/Math/Test/Matrix4Test.cpp | 34 ++++++++++--- src/Math/Test/Matrix4Test.h | 47 ----------------- src/Math/Test/MatrixTest.cpp | 25 +++++++-- src/Math/Test/MatrixTest.h | 40 --------------- src/Math/Test/Point2DTest.cpp | 18 +++++-- src/Math/Test/Point2DTest.h | 33 ------------ src/Math/Test/Point3DTest.cpp | 18 +++++-- src/Math/Test/Point3DTest.h | 33 ------------ src/Math/Test/RectangularMatrixTest.cpp | 30 +++++++++-- src/Math/Test/RectangularMatrixTest.h | 45 ---------------- src/Math/Test/SwizzleTest.cpp | 15 ++++-- src/Math/Test/SwizzleTest.h | 33 ------------ src/Math/Test/Vector2Test.cpp | 22 ++++++-- src/Math/Test/Vector2Test.h | 37 -------------- src/Math/Test/Vector3Test.cpp | 24 +++++++-- src/Math/Test/Vector3Test.h | 39 -------------- src/Math/Test/Vector4Test.cpp | 22 ++++++-- src/Math/Test/Vector4Test.h | 37 -------------- src/Math/Test/VectorTest.cpp | 33 +++++++++--- src/Math/Test/VectorTest.h | 46 ----------------- src/MeshTools/Test/CleanTest.cpp | 30 +++++++++-- src/MeshTools/Test/CleanTest.h | 48 ----------------- .../Test/CombineIndexedArraysTest.cpp | 15 ++++-- src/MeshTools/Test/CombineIndexedArraysTest.h | 32 ------------ src/MeshTools/Test/CompressIndicesTest.cpp | 16 ++++-- src/MeshTools/Test/CompressIndicesTest.h | 33 ------------ src/MeshTools/Test/FlipNormalsTest.cpp | 16 ++++-- src/MeshTools/Test/FlipNormalsTest.h | 33 ------------ .../Test/GenerateFlatNormalsTest.cpp | 15 ++++-- src/MeshTools/Test/GenerateFlatNormalsTest.h | 32 ------------ src/MeshTools/Test/InterleaveTest.cpp | 16 ++++-- src/MeshTools/Test/InterleaveTest.h | 33 ------------ src/MeshTools/Test/SubdivideTest.cpp | 34 +++++++++++-- src/MeshTools/Test/SubdivideTest.h | 51 ------------------- src/MeshTools/Test/TipsifyTest.cpp | 18 +++++-- src/MeshTools/Test/TipsifyTest.h | 36 ------------- src/Physics/Test/AbstractShapeTest.cpp | 15 ++++-- src/Physics/Test/AbstractShapeTest.h | 31 ----------- src/Physics/Test/AxisAlignedBoxTest.cpp | 13 +++-- src/Physics/Test/AxisAlignedBoxTest.h | 31 ----------- src/Physics/Test/BoxTest.cpp | 13 +++-- src/Physics/Test/BoxTest.h | 31 ----------- src/Physics/Test/CapsuleTest.cpp | 15 ++++-- src/Physics/Test/CapsuleTest.h | 33 ------------ src/Physics/Test/LineTest.cpp | 13 +++-- src/Physics/Test/LineTest.h | 31 ----------- src/Physics/Test/ObjectShapeTest.cpp | 13 +++-- src/Physics/Test/ObjectShapeTest.h | 31 ----------- src/Physics/Test/PlaneTest.cpp | 15 ++++-- src/Physics/Test/PlaneTest.h | 33 ------------ src/Physics/Test/PointTest.cpp | 13 +++-- src/Physics/Test/PointTest.h | 31 ----------- src/Physics/Test/ShapeGroupTest.cpp | 14 +++-- src/Physics/Test/ShapeGroupTest.h | 32 ------------ src/Physics/Test/SphereTest.cpp | 17 +++++-- src/Physics/Test/SphereTest.h | 35 ------------- src/Primitives/Test/CapsuleTest.cpp | 15 ++++-- src/Primitives/Test/CapsuleTest.h | 32 ------------ src/Primitives/Test/CylinderTest.cpp | 15 ++++-- src/Primitives/Test/CylinderTest.h | 32 ------------ src/Primitives/Test/UVSphereTest.cpp | 15 ++++-- src/Primitives/Test/UVSphereTest.h | 32 ------------ src/SceneGraph/Test/AnimableTest.cpp | 21 ++++++-- src/SceneGraph/Test/AnimableTest.h | 38 -------------- src/SceneGraph/Test/CameraTest.cpp | 20 ++++++-- src/SceneGraph/Test/CameraTest.h | 38 -------------- src/SceneGraph/Test/ObjectTest.cpp | 19 +++++-- src/SceneGraph/Test/ObjectTest.h | 36 ------------- src/SceneGraph/Test/SceneTest.cpp | 15 ++++-- src/SceneGraph/Test/SceneTest.h | 32 ------------ src/Test/ArrayTest.cpp | 16 ++++-- src/Test/ArrayTest.h | 34 ------------- src/Test/ColorTest.cpp | 32 ++++++++++-- src/Test/ColorTest.h | 49 ------------------ src/Test/MeshTest.cpp | 15 ++++-- src/Test/MeshTest.h | 32 ------------ src/Test/ResourceManagerTest.cpp | 21 ++++++-- src/Test/ResourceManagerTest.h | 38 -------------- src/Test/SwizzleTest.cpp | 15 ++++-- src/Test/SwizzleTest.h | 33 ------------ src/Test/TypeTraitsTest.cpp | 15 ++++-- src/Test/TypeTraitsTest.h | 32 ------------ src/TextureTools/Test/AtlasTest.cpp | 16 ++++-- src/TextureTools/Test/AtlasTest.h | 33 ------------ 104 files changed, 760 insertions(+), 2021 deletions(-) delete mode 100644 src/Math/Algorithms/Test/GaussJordanTest.h delete mode 100644 src/Math/Algorithms/Test/GramSchmidtTest.h delete mode 100644 src/Math/Geometry/Test/DistanceTest.h delete mode 100644 src/Math/Geometry/Test/IntersectionTest.h delete mode 100644 src/Math/Geometry/Test/RectangleTest.h delete mode 100644 src/Math/Test/ConstantsTest.h delete mode 100644 src/Math/Test/MathTest.h delete mode 100644 src/Math/Test/MathTypeTraitsTest.h delete mode 100644 src/Math/Test/Matrix3Test.h delete mode 100644 src/Math/Test/Matrix4Test.h delete mode 100644 src/Math/Test/MatrixTest.h delete mode 100644 src/Math/Test/Point2DTest.h delete mode 100644 src/Math/Test/Point3DTest.h delete mode 100644 src/Math/Test/RectangularMatrixTest.h delete mode 100644 src/Math/Test/SwizzleTest.h delete mode 100644 src/Math/Test/Vector2Test.h delete mode 100644 src/Math/Test/Vector3Test.h delete mode 100644 src/Math/Test/Vector4Test.h delete mode 100644 src/Math/Test/VectorTest.h delete mode 100644 src/MeshTools/Test/CleanTest.h delete mode 100644 src/MeshTools/Test/CombineIndexedArraysTest.h delete mode 100644 src/MeshTools/Test/CompressIndicesTest.h delete mode 100644 src/MeshTools/Test/FlipNormalsTest.h delete mode 100644 src/MeshTools/Test/GenerateFlatNormalsTest.h delete mode 100644 src/MeshTools/Test/InterleaveTest.h delete mode 100644 src/MeshTools/Test/SubdivideTest.h delete mode 100644 src/MeshTools/Test/TipsifyTest.h delete mode 100644 src/Physics/Test/AbstractShapeTest.h delete mode 100644 src/Physics/Test/AxisAlignedBoxTest.h delete mode 100644 src/Physics/Test/BoxTest.h delete mode 100644 src/Physics/Test/CapsuleTest.h delete mode 100644 src/Physics/Test/LineTest.h delete mode 100644 src/Physics/Test/ObjectShapeTest.h delete mode 100644 src/Physics/Test/PlaneTest.h delete mode 100644 src/Physics/Test/PointTest.h delete mode 100644 src/Physics/Test/ShapeGroupTest.h delete mode 100644 src/Physics/Test/SphereTest.h delete mode 100644 src/Primitives/Test/CapsuleTest.h delete mode 100644 src/Primitives/Test/CylinderTest.h delete mode 100644 src/Primitives/Test/UVSphereTest.h delete mode 100644 src/SceneGraph/Test/AnimableTest.h delete mode 100644 src/SceneGraph/Test/CameraTest.h delete mode 100644 src/SceneGraph/Test/ObjectTest.h delete mode 100644 src/SceneGraph/Test/SceneTest.h delete mode 100644 src/Test/ArrayTest.h delete mode 100644 src/Test/ColorTest.h delete mode 100644 src/Test/MeshTest.h delete mode 100644 src/Test/ResourceManagerTest.h delete mode 100644 src/Test/SwizzleTest.h delete mode 100644 src/Test/TypeTraitsTest.h delete mode 100644 src/TextureTools/Test/AtlasTest.h diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index 5a13365df..aad48debd 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -13,15 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GaussJordanTest.h" +#include -#include "Math/Algorithms/GaussJordan.h" #include "Math/Matrix.h" - -CORRADE_TEST_MAIN(Magnum::Math::Algorithms::Test::GaussJordanTest) +#include "Math/Algorithms/GaussJordan.h" namespace Magnum { namespace Math { namespace Algorithms { namespace Test { +class GaussJordanTest: public Corrade::TestSuite::Tester { + public: + explicit GaussJordanTest(); + + void singular(); + void invert(); +}; + typedef Matrix<4, float> Matrix4; GaussJordanTest::GaussJordanTest() { @@ -59,3 +65,5 @@ void GaussJordanTest::invert() { } }}}} + +CORRADE_TEST_MAIN(Magnum::Math::Algorithms::Test::GaussJordanTest) diff --git a/src/Math/Algorithms/Test/GaussJordanTest.h b/src/Math/Algorithms/Test/GaussJordanTest.h deleted file mode 100644 index fb5389cf9..000000000 --- a/src/Math/Algorithms/Test/GaussJordanTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Math_Algorithms_Test_GaussJordanTest_h -#define Magnum_Math_Algorithms_Test_GaussJordanTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Algorithms { namespace Test { - -class GaussJordanTest: public Corrade::TestSuite::Tester { - public: - GaussJordanTest(); - - void singular(); - void invert(); -}; - -}}}} - -#endif diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index b7671eae9..764616324 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -13,14 +13,19 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GramSchmidtTest.h" +#include #include "Math/Algorithms/GramSchmidt.h" -CORRADE_TEST_MAIN(Magnum::Math::Algorithms::Test::GramSchmidtTest) - namespace Magnum { namespace Math { namespace Algorithms { namespace Test { +class GramSchmidtTest: public Corrade::TestSuite::Tester { + public: + GramSchmidtTest(); + + void test(); +}; + typedef Matrix<3, float> Matrix3; typedef Vector<3, float> Vector3; @@ -58,3 +63,5 @@ void GramSchmidtTest::test() { } }}}} + +CORRADE_TEST_MAIN(Magnum::Math::Algorithms::Test::GramSchmidtTest) diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.h b/src/Math/Algorithms/Test/GramSchmidtTest.h deleted file mode 100644 index c09df77d8..000000000 --- a/src/Math/Algorithms/Test/GramSchmidtTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Math_Algorithms_Test_GramSchmidtTest_h -#define Magnum_Math_Algorithms_Test_GramSchmidtTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Algorithms { namespace Test { - -class GramSchmidtTest: public Corrade::TestSuite::Tester { - public: - GramSchmidtTest(); - - void test(); -}; - -}}}} - -#endif diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 4e4505fee..ed55629d2 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - set(MagnumMath_HEADERS Constants.h Math.h diff --git a/src/Math/Geometry/CMakeLists.txt b/src/Math/Geometry/CMakeLists.txt index fb55add04..73cd0f0f6 100644 --- a/src/Math/Geometry/CMakeLists.txt +++ b/src/Math/Geometry/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - set(MagnumMathGeometry_HEADERS Distance.h Intersection.h diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index 79de37345..069ad493d 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -13,17 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "DistanceTest.h" - #include +#include -#include "Constants.h" -#include "Distance.h" - -CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::DistanceTest) +#include "Math/Constants.h" +#include "Math/Geometry/Distance.h" namespace Magnum { namespace Math { namespace Geometry { namespace Test { +class DistanceTest: public Corrade::TestSuite::Tester { + public: + DistanceTest(); + + void linePoint2D(); + void linePoint3D(); + void lineSegmentPoint2D(); + void lineSegmentPoint3D(); +}; + typedef Magnum::Math::Vector2 Vector2; typedef Magnum::Math::Vector3 Vector3; @@ -122,3 +129,5 @@ void DistanceTest::lineSegmentPoint3D() { } }}}} + +CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::DistanceTest) diff --git a/src/Math/Geometry/Test/DistanceTest.h b/src/Math/Geometry/Test/DistanceTest.h deleted file mode 100644 index 485e1d576..000000000 --- a/src/Math/Geometry/Test/DistanceTest.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef Magnum_Math_Geometry_Test_DistanceTest_h -#define Magnum_Math_Geometry_Test_DistanceTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Geometry { namespace Test { - -class DistanceTest: public Corrade::TestSuite::Tester { - public: - DistanceTest(); - - void linePoint2D(); - void linePoint3D(); - void lineSegmentPoint2D(); - void lineSegmentPoint3D(); -}; - -}}}} - -#endif diff --git a/src/Math/Geometry/Test/IntersectionTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp index c19591be8..3e1f27d08 100644 --- a/src/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -13,16 +13,20 @@ GNU Lesser General Public License version 3 for more details. */ -#include "IntersectionTest.h" - +#include #include -#include "Intersection.h" - -CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::IntersectionTest) +#include "Math/Geometry/Intersection.h" namespace Magnum { namespace Math { namespace Geometry { namespace Test { +class IntersectionTest: public Corrade::TestSuite::Tester { + public: + IntersectionTest(); + + void planeLine(); +}; + typedef Magnum::Math::Vector3 Vector3; IntersectionTest::IntersectionTest() { @@ -51,3 +55,5 @@ void IntersectionTest::planeLine() { } }}}} + +CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::IntersectionTest) diff --git a/src/Math/Geometry/Test/IntersectionTest.h b/src/Math/Geometry/Test/IntersectionTest.h deleted file mode 100644 index 7375b2d51..000000000 --- a/src/Math/Geometry/Test/IntersectionTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Math_Geometry_Test_IntersectionTest_h -#define Magnum_Math_Geometry_Test_IntersectionTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Geometry { namespace Test { - -class IntersectionTest: public Corrade::TestSuite::Tester { - public: - IntersectionTest(); - - void planeLine(); -}; - -}}}} - -#endif diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index c5ab1f6e6..20562c860 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -13,16 +13,25 @@ GNU Lesser General Public License version 3 for more details. */ -#include "RectangleTest.h" - #include +#include -#include "Rectangle.h" - -CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) +#include "Math/Geometry/Rectangle.h" namespace Magnum { namespace Math { namespace Geometry { namespace Test { +class RectangleTest: public Corrade::TestSuite::Tester { + public: + RectangleTest(); + + void access(); + void compare(); + void construct(); + void size(); + + void debug(); +}; + typedef Geometry::Rectangle Rectangle; typedef Geometry::Rectangle Rectanglei; typedef Vector2 Vector2i; @@ -85,3 +94,5 @@ void RectangleTest::debug() { } }}}} + +CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) diff --git a/src/Math/Geometry/Test/RectangleTest.h b/src/Math/Geometry/Test/RectangleTest.h deleted file mode 100644 index 87f552c03..000000000 --- a/src/Math/Geometry/Test/RectangleTest.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef Magnum_Math_Geometry_Test_RectangleTest_h -#define Magnum_Math_Geometry_Test_RectangleTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Geometry { namespace Test { - -class RectangleTest: public Corrade::TestSuite::Tester { - public: - RectangleTest(); - - void access(); - void compare(); - void construct(); - void size(); - - void debug(); -}; - -}}}} - -#endif diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index 4a780de5c..0baa25d12 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -13,15 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ConstantsTest.h" +#include -#include "Constants.h" -#include "Math.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) +#include "Math/Constants.h" +#include "Math/Math.h" namespace Magnum { namespace Math { namespace Test { +class ConstantsTest: public Corrade::TestSuite::Tester { + public: + ConstantsTest(); + + void constants(); + void degrad(); +}; + ConstantsTest::ConstantsTest() { addTests(&ConstantsTest::constants, &ConstantsTest::degrad); @@ -42,3 +48,5 @@ void ConstantsTest::degrad() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) diff --git a/src/Math/Test/ConstantsTest.h b/src/Math/Test/ConstantsTest.h deleted file mode 100644 index 3a96e0c35..000000000 --- a/src/Math/Test/ConstantsTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Math_Test_ConstantsTest_h -#define Magnum_Math_Test_ConstantsTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class ConstantsTest: public Corrade::TestSuite::Tester { - public: - ConstantsTest(); - - void constants(); - void degrad(); -}; - -}}} - -#endif diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 424e470cc..e14aeaf18 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -13,14 +13,23 @@ GNU Lesser General Public License version 3 for more details. */ -#include "MathTest.h" +#include -#include "Math.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) +#include "Math/Math.h" namespace Magnum { namespace Math { namespace Test { +class MathTest: public Corrade::TestSuite::Tester { + public: + MathTest(); + + void normalize(); + void denormalize(); + void clamp(); + void pow(); + void log(); +}; + MathTest::MathTest() { addTests(&MathTest::normalize, &MathTest::denormalize, @@ -97,3 +106,5 @@ void MathTest::log() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) diff --git a/src/Math/Test/MathTest.h b/src/Math/Test/MathTest.h deleted file mode 100644 index 3f16d33d9..000000000 --- a/src/Math/Test/MathTest.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef Magnum_Math_Test_MathTest_h -#define Magnum_Math_Test_MathTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class MathTest: public Corrade::TestSuite::Tester { - public: - MathTest(); - - void normalize(); - void denormalize(); - void clamp(); - void pow(); - void log(); -}; - -}}} - -#endif diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index e2d08dd1c..74e50d286 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -13,16 +13,25 @@ GNU Lesser General Public License version 3 for more details. */ -#include "MathTypeTraitsTest.h" - #include +#include -#include "MathTypeTraits.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) +#include "Math/MathTypeTraits.h" namespace Magnum { namespace Math { namespace Test { +class MathTypeTraitsTest: public Corrade::TestSuite::Tester { + public: + MathTypeTraitsTest(); + + void equalsFloatingPoint(); + void equalsIntegral(); + + private: + template void _equalsFloatingPoint(); + template void _equalsIntegral(); +}; + MathTypeTraitsTest::MathTypeTraitsTest() { addTests(&MathTypeTraitsTest::equalsIntegral, &MathTypeTraitsTest::equalsFloatingPoint); @@ -63,3 +72,5 @@ template void MathTypeTraitsTest::_equalsFloatingPoint() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) diff --git a/src/Math/Test/MathTypeTraitsTest.h b/src/Math/Test/MathTypeTraitsTest.h deleted file mode 100644 index 5baa9da49..000000000 --- a/src/Math/Test/MathTypeTraitsTest.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef Magnum_Math_Test_MathTypeTraitsTest_h -#define Magnum_Math_Test_MathTypeTraitsTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class MathTypeTraitsTest: public Corrade::TestSuite::Tester { - public: - MathTypeTraitsTest(); - - void equalsFloatingPoint(); - void equalsIntegral(); - - private: - template void _equalsFloatingPoint(); - template void _equalsIntegral(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index b9219b57a..bc57f5e51 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -13,20 +13,37 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Matrix3Test.h" - #include +#include #include -#include "Constants.h" -#include "Matrix3.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Test) +#include "Math/Constants.h" +#include "Math/Matrix3.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Matrix3Test: public Corrade::TestSuite::Tester { + public: + Matrix3Test(); + + void constructIdentity(); + + void translation(); + void scaling(); + void rotation(); + void reflection(); + void fromParts(); + void rotationScalingPart(); + void rotationPart(); + void vectorParts(); + void invertedEuclidean(); + + void debug(); + void configuration(); +}; + typedef Math::Matrix3 Matrix3; typedef Math::Matrix<2, float> Matrix2; typedef Math::Vector2 Vector2; @@ -231,3 +248,5 @@ void Matrix3Test::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Test) diff --git a/src/Math/Test/Matrix3Test.h b/src/Math/Test/Matrix3Test.h deleted file mode 100644 index bea82a6f8..000000000 --- a/src/Math/Test/Matrix3Test.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef Magnum_Math_Test_Matrix3Test_h -#define Magnum_Math_Test_Matrix3Test_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Matrix3Test: public Corrade::TestSuite::Tester { - public: - Matrix3Test(); - - void constructIdentity(); - - void translation(); - void scaling(); - void rotation(); - void reflection(); - void fromParts(); - void rotationScalingPart(); - void rotationPart(); - void vectorParts(); - void invertedEuclidean(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 0f3ee5be6..7787eb49b 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -13,20 +13,40 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Matrix4Test.h" - #include +#include #include -#include "Constants.h" -#include "Matrix4.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix4Test) +#include "Math/Constants.h" +#include "Math/Matrix4.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Matrix4Test: public Corrade::TestSuite::Tester { + public: + Matrix4Test(); + + void constructIdentity(); + + void translation(); + void scaling(); + void rotation(); + void rotationX(); + void rotationY(); + void rotationZ(); + void reflection(); + void fromParts(); + void rotationScalingPart(); + void rotationPart(); + void vectorParts(); + void invertedEuclidean(); + + void debug(); + void configuration(); +}; + typedef Math::Matrix4 Matrix4; typedef Math::Matrix<3, float> Matrix3; typedef Math::Vector3 Vector3; @@ -287,3 +307,5 @@ void Matrix4Test::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix4Test) diff --git a/src/Math/Test/Matrix4Test.h b/src/Math/Test/Matrix4Test.h deleted file mode 100644 index 737778533..000000000 --- a/src/Math/Test/Matrix4Test.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef Magnum_Math_Test_Matrix4Test_h -#define Magnum_Math_Test_Matrix4Test_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Matrix4Test: public Corrade::TestSuite::Tester { - public: - Matrix4Test(); - - void constructIdentity(); - - void translation(); - void scaling(); - void rotation(); - void rotationX(); - void rotationY(); - void rotationZ(); - void reflection(); - void fromParts(); - void rotationScalingPart(); - void rotationPart(); - void vectorParts(); - void invertedEuclidean(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 28432709d..b004d6a3e 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -13,19 +13,32 @@ GNU Lesser General Public License version 3 for more details. */ -#include "MatrixTest.h" - #include +#include #include -#include "Matrix.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::MatrixTest) +#include "Math/Matrix.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class MatrixTest: public Corrade::TestSuite::Tester { + public: + MatrixTest(); + + void construct(); + void constructIdentity(); + void constructZero(); + void trace(); + void ij(); + void determinant(); + void inverted(); + + void debug(); + void configuration(); +}; + typedef Matrix<4, float> Matrix4; typedef Matrix<3, float> Matrix3; typedef Vector<4, float> Vector4; @@ -202,3 +215,5 @@ void MatrixTest::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::MatrixTest) diff --git a/src/Math/Test/MatrixTest.h b/src/Math/Test/MatrixTest.h deleted file mode 100644 index a3c6f53ea..000000000 --- a/src/Math/Test/MatrixTest.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef Magnum_Math_Test_MatrixTest_h -#define Magnum_Math_Test_MatrixTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class MatrixTest: public Corrade::TestSuite::Tester { - public: - MatrixTest(); - - void construct(); - void constructIdentity(); - void constructZero(); - void trace(); - void ij(); - void determinant(); - void inverted(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp index 70093d026..f69179c37 100644 --- a/src/Math/Test/Point2DTest.cpp +++ b/src/Math/Test/Point2DTest.cpp @@ -13,19 +13,25 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Point2DTest.h" - #include +#include #include -#include "Point2D.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest) +#include "Math/Point2D.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Point2DTest: public Corrade::TestSuite::Tester { + public: + Point2DTest(); + + void construct(); + void debug(); + void configuration(); +}; + typedef Math::Point2D Point2D; Point2DTest::Point2DTest() { @@ -58,3 +64,5 @@ void Point2DTest::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest) diff --git a/src/Math/Test/Point2DTest.h b/src/Math/Test/Point2DTest.h deleted file mode 100644 index 8baf04980..000000000 --- a/src/Math/Test/Point2DTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_Math_Test_Point2DTest_h -#define Magnum_Math_Test_Point2DTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Point2DTest: public Corrade::TestSuite::Tester { - public: - Point2DTest(); - - void construct(); - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp index dc77ab420..4617b6fbc 100644 --- a/src/Math/Test/Point3DTest.cpp +++ b/src/Math/Test/Point3DTest.cpp @@ -13,19 +13,25 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Point3DTest.h" - #include +#include #include -#include "Point3D.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest) +#include "Math/Point3D.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Point3DTest: public Corrade::TestSuite::Tester { + public: + Point3DTest(); + + void construct(); + void debug(); + void configuration(); +}; + typedef Math::Point3D Point3D; Point3DTest::Point3DTest() { @@ -58,3 +64,5 @@ void Point3DTest::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest) diff --git a/src/Math/Test/Point3DTest.h b/src/Math/Test/Point3DTest.h deleted file mode 100644 index 54518afa7..000000000 --- a/src/Math/Test/Point3DTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_Math_Test_Point3DTest_h -#define Magnum_Math_Test_Point3DTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Point3DTest: public Corrade::TestSuite::Tester { - public: - Point3DTest(); - - void construct(); - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index a2fbd0af8..24fc78fba 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -13,19 +13,37 @@ GNU Lesser General Public License version 3 for more details. */ -#include "RectangularMatrixTest.h" - #include +#include #include -#include "RectangularMatrix.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::RectangularMatrixTest) +#include "Math/RectangularMatrix.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class RectangularMatrixTest: public Corrade::TestSuite::Tester { + public: + RectangularMatrixTest(); + + void construct(); + void constructFromVectors(); + void constructFrom(); + void constructZero(); + void data(); + + void negative(); + void addSubtract(); + void multiplyDivide(); + void multiply(); + + void transposed(); + + void debug(); + void configuration(); +}; + typedef RectangularMatrix<4, 3, float> Matrix4x3; typedef RectangularMatrix<3, 4, float> Matrix3x4; typedef RectangularMatrix<2, 2, float> Matrix2; @@ -251,3 +269,5 @@ void RectangularMatrixTest::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::RectangularMatrixTest) diff --git a/src/Math/Test/RectangularMatrixTest.h b/src/Math/Test/RectangularMatrixTest.h deleted file mode 100644 index 34754f583..000000000 --- a/src/Math/Test/RectangularMatrixTest.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef Magnum_Math_Test_RectangularMatrixTest_h -#define Magnum_Math_Test_RectangularMatrixTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class RectangularMatrixTest: public Corrade::TestSuite::Tester { - public: - RectangularMatrixTest(); - - void construct(); - void constructFromVectors(); - void constructFrom(); - void constructZero(); - void data(); - - void negative(); - void addSubtract(); - void multiplyDivide(); - void multiply(); - - void transposed(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp index 78fc7a1dd..9df00e89f 100644 --- a/src/Math/Test/SwizzleTest.cpp +++ b/src/Math/Test/SwizzleTest.cpp @@ -13,14 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "SwizzleTest.h" +#include #include "Math/Swizzle.h" -CORRADE_TEST_MAIN(Magnum::Math::Test::SwizzleTest) - namespace Magnum { namespace Math { namespace Test { +class SwizzleTest: public Corrade::TestSuite::Tester { + public: + SwizzleTest(); + + void components(); + void constants(); + void sizes(); +}; + typedef Vector<4, std::int32_t> Vector4i; SwizzleTest::SwizzleTest() { @@ -47,3 +54,5 @@ void SwizzleTest::sizes() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::SwizzleTest) diff --git a/src/Math/Test/SwizzleTest.h b/src/Math/Test/SwizzleTest.h deleted file mode 100644 index a2d64fb2a..000000000 --- a/src/Math/Test/SwizzleTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_Math_Test_SwizzleTest_h -#define Magnum_Math_Test_SwizzleTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class SwizzleTest: public Corrade::TestSuite::Tester { - public: - SwizzleTest(); - - void components(); - void constants(); - void sizes(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 7b427650a..729281509 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -13,19 +13,29 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Vector2Test.h" - #include +#include #include -#include "Vector2.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Vector2Test) +#include "Math/Vector2.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Vector2Test: public Corrade::TestSuite::Tester { + public: + Vector2Test(); + + void construct(); + void access(); + void axes(); + void scales(); + + void debug(); + void configuration(); +}; + typedef Math::Vector2 Vector2; Vector2Test::Vector2Test() { @@ -79,3 +89,5 @@ void Vector2Test::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Vector2Test) diff --git a/src/Math/Test/Vector2Test.h b/src/Math/Test/Vector2Test.h deleted file mode 100644 index b9cc71797..000000000 --- a/src/Math/Test/Vector2Test.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef Magnum_Math_Test_Vector2Test_h -#define Magnum_Math_Test_Vector2Test_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Vector2Test: public Corrade::TestSuite::Tester { - public: - Vector2Test(); - - void construct(); - void access(); - void axes(); - void scales(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 6a97a5f87..c4a7a2c03 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -13,19 +13,31 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Vector3Test.h" - #include +#include #include -#include "Vector3.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Vector3Test) +#include "Math/Vector3.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Vector3Test: public Corrade::TestSuite::Tester { + public: + Vector3Test(); + + void construct(); + void access(); + void cross(); + void axes(); + void scales(); + void twoComponent(); + + void debug(); + void configuration(); +}; + typedef Math::Vector3 Vector3; typedef Math::Vector2 Vector2; @@ -99,3 +111,5 @@ void Vector3Test::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Vector3Test) diff --git a/src/Math/Test/Vector3Test.h b/src/Math/Test/Vector3Test.h deleted file mode 100644 index 23ecd5db5..000000000 --- a/src/Math/Test/Vector3Test.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef Magnum_Math_Test_Vector3Test_h -#define Magnum_Math_Test_Vector3Test_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Vector3Test: public Corrade::TestSuite::Tester { - public: - Vector3Test(); - - void construct(); - void access(); - void cross(); - void axes(); - void scales(); - void twoComponent(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index 9d4b1e959..b1606c230 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -13,19 +13,29 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Vector4Test.h" - #include +#include #include -#include "Vector4.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::Vector4Test) +#include "Math/Vector4.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class Vector4Test: public Corrade::TestSuite::Tester { + public: + Vector4Test(); + + void access(); + void construct(); + void threeComponent(); + void twoComponent(); + + void debug(); + void configuration(); +}; + typedef Math::Vector4 Vector4; typedef Math::Vector3 Vector3; typedef Math::Vector2 Vector2; @@ -85,3 +95,5 @@ void Vector4Test::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::Vector4Test) diff --git a/src/Math/Test/Vector4Test.h b/src/Math/Test/Vector4Test.h deleted file mode 100644 index 95b41c986..000000000 --- a/src/Math/Test/Vector4Test.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef Magnum_Math_Test_Vector4Test_h -#define Magnum_Math_Test_Vector4Test_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class Vector4Test: public Corrade::TestSuite::Tester { - public: - Vector4Test(); - - void access(); - void construct(); - void threeComponent(); - void twoComponent(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index f7b1c6e72..3b1dc417c 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -13,20 +13,39 @@ GNU Lesser General Public License version 3 for more details. */ -#include "VectorTest.h" - #include +#include #include -#include "Constants.h" -#include "Vector.h" - -CORRADE_TEST_MAIN(Magnum::Math::Test::VectorTest) +#include "Math/Constants.h" +#include "Math/Vector.h" using namespace Corrade::Utility; namespace Magnum { namespace Math { namespace Test { +class VectorTest: public Corrade::TestSuite::Tester { + public: + VectorTest(); + + void construct(); + void compareComponentWise(); + void dot(); + void multiplyDivideComponentWise(); + void dotSelf(); + void length(); + void normalized(); + void projected(); + void sum(); + void product(); + void min(); + void max(); + void angle(); + + void debug(); + void configuration(); +}; + typedef Vector<4, float> Vector4; typedef Vector<3, float> Vector3; @@ -151,3 +170,5 @@ void VectorTest::configuration() { } }}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::VectorTest) diff --git a/src/Math/Test/VectorTest.h b/src/Math/Test/VectorTest.h deleted file mode 100644 index 94590d604..000000000 --- a/src/Math/Test/VectorTest.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef Magnum_Math_Test_VectorTest_h -#define Magnum_Math_Test_VectorTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Math { namespace Test { - -class VectorTest: public Corrade::TestSuite::Tester { - public: - VectorTest(); - - void construct(); - void compareComponentWise(); - void dot(); - void multiplyDivideComponentWise(); - void dotSelf(); - void length(); - void normalized(); - void projected(); - void sum(); - void product(); - void min(); - void max(); - void angle(); - - void debug(); - void configuration(); -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index 23d80e10b..c26413082 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -13,14 +13,36 @@ GNU Lesser General Public License version 3 for more details. */ -#include "CleanTest.h" +#include #include "MeshTools/Clean.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CleanTest) - namespace Magnum { namespace MeshTools { namespace Test { +class CleanTest: public Corrade::TestSuite::Tester { + public: + CleanTest(); + + void cleanMesh(); + + private: + class Vector1 { + public: + static const std::size_t Size = 1; + typedef std::int32_t Type; + + Vector1(): data(0) {} + 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: + Type data; + }; +}; + CleanTest::CleanTest() { addTests(&CleanTest::cleanMesh); } @@ -36,3 +58,5 @@ void CleanTest::cleanMesh() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CleanTest) diff --git a/src/MeshTools/Test/CleanTest.h b/src/MeshTools/Test/CleanTest.h deleted file mode 100644 index 2b6b797ef..000000000 --- a/src/MeshTools/Test/CleanTest.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef Magnum_MeshTools_Test_CleanTest_h -#define Magnum_MeshTools_Test_CleanTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class CleanTest: public Corrade::TestSuite::Tester { - public: - CleanTest(); - - void cleanMesh(); - - private: - class Vector1 { - public: - static const std::size_t Size = 1; - typedef std::int32_t Type; - - Vector1(): data(0) {} - 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: - Type data; - }; -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index b97447e68..1758d5856 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -13,16 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "CombineIndexedArraysTest.h" - #include +#include #include "MeshTools/CombineIndexedArrays.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CombineIndexedArraysTest) - namespace Magnum { namespace MeshTools { namespace Test { +class CombineIndexedArraysTest: public Corrade::TestSuite::Tester { + public: + CombineIndexedArraysTest(); + + void wrongIndexCount(); + void combine(); +}; + CombineIndexedArraysTest::CombineIndexedArraysTest() { addTests(&CombineIndexedArraysTest::wrongIndexCount, &CombineIndexedArraysTest::combine); @@ -57,3 +62,5 @@ void CombineIndexedArraysTest::combine() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CombineIndexedArraysTest) diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.h b/src/MeshTools/Test/CombineIndexedArraysTest.h deleted file mode 100644 index 80b08c418..000000000 --- a/src/MeshTools/Test/CombineIndexedArraysTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_MeshTools_Test_CombineIndexedArraysTest_h -#define Magnum_MeshTools_Test_CombineIndexedArraysTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class CombineIndexedArraysTest: public Corrade::TestSuite::Tester { - public: - CombineIndexedArraysTest(); - - void wrongIndexCount(); - void combine(); -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index 7814e2872..696e949fb 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -13,18 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "CompressIndicesTest.h" - +#include #include #include "MeshTools/CompressIndices.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CompressIndicesTest) - using Corrade::Utility::Endianness; namespace Magnum { namespace MeshTools { namespace Test { +class CompressIndicesTest: public Corrade::TestSuite::Tester { + public: + CompressIndicesTest(); + + void compressChar(); + void compressShort(); + void compressInt(); +}; + CompressIndicesTest::CompressIndicesTest() { addTests(&CompressIndicesTest::compressChar, &CompressIndicesTest::compressShort, @@ -98,3 +104,5 @@ void CompressIndicesTest::compressInt() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CompressIndicesTest) diff --git a/src/MeshTools/Test/CompressIndicesTest.h b/src/MeshTools/Test/CompressIndicesTest.h deleted file mode 100644 index 187610326..000000000 --- a/src/MeshTools/Test/CompressIndicesTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_MeshTools_Test_CompressIndicesTest_h -#define Magnum_MeshTools_Test_CompressIndicesTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class CompressIndicesTest: public Corrade::TestSuite::Tester { - public: - CompressIndicesTest(); - - void compressChar(); - void compressShort(); - void compressInt(); -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index 0a693b6de..6fc61d1ca 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -13,17 +13,23 @@ GNU Lesser General Public License version 3 for more details. */ -#include "FlipNormalsTest.h" - #include +#include #include "Math/Vector3.h" #include "MeshTools/FlipNormals.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::FlipNormalsTest) - namespace Magnum { namespace MeshTools { namespace Test { +class FlipNormalsTest: public Corrade::TestSuite::Tester { + public: + FlipNormalsTest(); + + void wrongIndexCount(); + void flipFaceWinding(); + void flipNormals(); +}; + FlipNormalsTest::FlipNormalsTest() { addTests(&FlipNormalsTest::wrongIndexCount, &FlipNormalsTest::flipFaceWinding, @@ -61,3 +67,5 @@ void FlipNormalsTest::flipNormals() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::FlipNormalsTest) diff --git a/src/MeshTools/Test/FlipNormalsTest.h b/src/MeshTools/Test/FlipNormalsTest.h deleted file mode 100644 index 8a25d8bed..000000000 --- a/src/MeshTools/Test/FlipNormalsTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_MeshTools_Test_FlipNormalsTest_h -#define Magnum_MeshTools_Test_FlipNormalsTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class FlipNormalsTest: public Corrade::TestSuite::Tester { - public: - FlipNormalsTest(); - - void wrongIndexCount(); - void flipFaceWinding(); - void flipNormals(); -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 5f91f05d9..64107680e 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -13,17 +13,22 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GenerateFlatNormalsTest.h" - #include +#include #include "Math/Point3D.h" #include "MeshTools/GenerateFlatNormals.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) - namespace Magnum { namespace MeshTools { namespace Test { +class GenerateFlatNormalsTest: public Corrade::TestSuite::Tester { + public: + GenerateFlatNormalsTest(); + + void wrongIndexCount(); + void generate(); +}; + GenerateFlatNormalsTest::GenerateFlatNormalsTest() { addTests(&GenerateFlatNormalsTest::wrongIndexCount, &GenerateFlatNormalsTest::generate); @@ -68,3 +73,5 @@ void GenerateFlatNormalsTest::generate() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.h b/src/MeshTools/Test/GenerateFlatNormalsTest.h deleted file mode 100644 index b699e991e..000000000 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_MeshTools_Test_GenerateFlatNormalsTest_h -#define Magnum_MeshTools_Test_GenerateFlatNormalsTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class GenerateFlatNormalsTest: public Corrade::TestSuite::Tester { - public: - GenerateFlatNormalsTest(); - - void wrongIndexCount(); - void generate(); -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index e3416b166..09f1ba2d3 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -13,20 +13,26 @@ GNU Lesser General Public License version 3 for more details. */ -#include "InterleaveTest.h" - #include +#include #include "Utility/Endianness.h" #include "Utility/Debug.h" #include "MeshTools/Interleave.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::InterleaveTest) - using Corrade::Utility::Endianness; namespace Magnum { namespace MeshTools { namespace Test { +class InterleaveTest: public Corrade::TestSuite::Tester { + public: + InterleaveTest(); + + void attributeCount(); + void stride(); + void write(); +}; + InterleaveTest::InterleaveTest() { addTests(&InterleaveTest::attributeCount, &InterleaveTest::stride, @@ -80,3 +86,5 @@ void InterleaveTest::write() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::InterleaveTest) diff --git a/src/MeshTools/Test/InterleaveTest.h b/src/MeshTools/Test/InterleaveTest.h deleted file mode 100644 index 19aae30fb..000000000 --- a/src/MeshTools/Test/InterleaveTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_MeshTools_Test_InterleaveTest_h -#define Magnum_MeshTools_Test_InterleaveTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class InterleaveTest: public Corrade::TestSuite::Tester { - public: - InterleaveTest(); - - void attributeCount(); - void stride(); - void write(); -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 33401d54d..4bd09edd9 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -13,17 +13,41 @@ GNU Lesser General Public License version 3 for more details. */ -#include "SubdivideTest.h" - #include +#include #include "MeshTools/Clean.h" #include "MeshTools/Subdivide.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::SubdivideTest) - namespace Magnum { namespace MeshTools { namespace Test { +class SubdivideTest: public Corrade::TestSuite::Tester { + public: + SubdivideTest(); + + void wrongIndexCount(); + void subdivide(); + + private: + class Vector1 { + public: + static const std::size_t Size = 1; + typedef std::int32_t Type; + + Vector1(): data(0) {} + 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: + Type data; + }; + + inline static Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; } +}; + SubdivideTest::SubdivideTest() { addTests(&SubdivideTest::wrongIndexCount, &SubdivideTest::subdivide); @@ -56,3 +80,5 @@ void SubdivideTest::subdivide() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::SubdivideTest) diff --git a/src/MeshTools/Test/SubdivideTest.h b/src/MeshTools/Test/SubdivideTest.h deleted file mode 100644 index 9d1521a9c..000000000 --- a/src/MeshTools/Test/SubdivideTest.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef Magnum_MeshTools_Test_SubdivideTest_h -#define Magnum_MeshTools_Test_SubdivideTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class SubdivideTest: public Corrade::TestSuite::Tester { - public: - SubdivideTest(); - - void wrongIndexCount(); - void subdivide(); - - private: - class Vector1 { - public: - static const std::size_t Size = 1; - typedef std::int32_t Type; - - Vector1(): data(0) {} - 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: - Type data; - }; - - inline static Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; } -}; - -}}} - -#endif diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index 6138075b7..a62159947 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -13,14 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "TipsifyTest.h" +#include #include "MeshTools/Tipsify.h" -CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TipsifyTest) - namespace Magnum { namespace MeshTools { namespace Test { +class TipsifyTest: public Corrade::TestSuite::Tester { + public: + TipsifyTest(); + + void buildAdjacency(); + void tipsify(); + + private: + std::vector indices; + std::size_t vertexCount; +}; + /* 0 ----- 1 ----- 2 ----- 3 @@ -136,3 +146,5 @@ void TipsifyTest::tipsify() { } }}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TipsifyTest) diff --git a/src/MeshTools/Test/TipsifyTest.h b/src/MeshTools/Test/TipsifyTest.h deleted file mode 100644 index 5e4952430..000000000 --- a/src/MeshTools/Test/TipsifyTest.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef Magnum_MeshTools_Test_TipsifyTest_h -#define Magnum_MeshTools_Test_TipsifyTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace MeshTools { namespace Test { - -class TipsifyTest: public Corrade::TestSuite::Tester { - public: - TipsifyTest(); - - void buildAdjacency(); - void tipsify(); - - private: - std::vector indices; - std::size_t vertexCount; -}; - -}}} - -#endif diff --git a/src/Physics/Test/AbstractShapeTest.cpp b/src/Physics/Test/AbstractShapeTest.cpp index a7979c8ae..973041087 100644 --- a/src/Physics/Test/AbstractShapeTest.cpp +++ b/src/Physics/Test/AbstractShapeTest.cpp @@ -13,17 +13,20 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractShapeTest.h" - #include -#include +#include #include "Physics/AbstractShape.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::AbstractShapeTest) - namespace Magnum { namespace Physics { namespace Test { +class AbstractShapeTest: public Corrade::TestSuite::Tester { + public: + AbstractShapeTest(); + + void debug(); +}; + AbstractShapeTest::AbstractShapeTest() { addTests(&AbstractShapeTest::debug); } @@ -39,3 +42,5 @@ void AbstractShapeTest::debug() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::AbstractShapeTest) diff --git a/src/Physics/Test/AbstractShapeTest.h b/src/Physics/Test/AbstractShapeTest.h deleted file mode 100644 index 4272b72d5..000000000 --- a/src/Physics/Test/AbstractShapeTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Physics_Test_AbstractShapeTest_h -#define Magnum_Physics_Test_AbstractShapeTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class AbstractShapeTest: public Corrade::TestSuite::Tester { - public: - AbstractShapeTest(); - - void debug(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index a3b8595d8..a9554d30d 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -13,16 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AxisAlignedBoxTest.h" +#include #include "Math/Constants.h" #include "Math/Matrix4.h" #include "Physics/AxisAlignedBox.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest) - namespace Magnum { namespace Physics { namespace Test { +class AxisAlignedBoxTest: public Corrade::TestSuite::Tester { + public: + AxisAlignedBoxTest(); + + void applyTransformation(); +}; + AxisAlignedBoxTest::AxisAlignedBoxTest() { addTests(&AxisAlignedBoxTest::applyTransformation); } @@ -40,3 +45,5 @@ void AxisAlignedBoxTest::applyTransformation() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest) diff --git a/src/Physics/Test/AxisAlignedBoxTest.h b/src/Physics/Test/AxisAlignedBoxTest.h deleted file mode 100644 index 63451a508..000000000 --- a/src/Physics/Test/AxisAlignedBoxTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Physics_Test_AxisAlignedBoxTest_h -#define Magnum_Physics_Test_AxisAlignedBoxTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class AxisAlignedBoxTest: public Corrade::TestSuite::Tester { - public: - AxisAlignedBoxTest(); - - void applyTransformation(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp index 824ce34d9..7c162baee 100644 --- a/src/Physics/Test/BoxTest.cpp +++ b/src/Physics/Test/BoxTest.cpp @@ -13,15 +13,20 @@ GNU Lesser General Public License version 3 for more details. */ -#include "BoxTest.h" +#include #include "Math/Matrix4.h" #include "Physics/Box.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::BoxTest) - namespace Magnum { namespace Physics { namespace Test { +class BoxTest: public Corrade::TestSuite::Tester { + public: + BoxTest(); + + void applyTransformation(); +}; + BoxTest::BoxTest() { addTests(&BoxTest::applyTransformation); } @@ -34,3 +39,5 @@ void BoxTest::applyTransformation() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::BoxTest) diff --git a/src/Physics/Test/BoxTest.h b/src/Physics/Test/BoxTest.h deleted file mode 100644 index abf67ce52..000000000 --- a/src/Physics/Test/BoxTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Physics_Test_BoxTest_h -#define Magnum_Physics_Test_BoxTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class BoxTest: public Corrade::TestSuite::Tester { - public: - BoxTest(); - - void applyTransformation(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 04c85235b..60636bf5e 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -13,17 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "CapsuleTest.h" - #include "Math/Constants.h" #include "Physics/Capsule.h" #include "Physics/Point.h" #include "Physics/Sphere.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::CapsuleTest) +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { +class CapsuleTest: public Corrade::TestSuite::Tester, ShapeTestBase { + public: + CapsuleTest(); + + void applyTransformation(); + void collisionPoint(); + void collisionSphere(); +}; + CapsuleTest::CapsuleTest() { addTests(&CapsuleTest::applyTransformation, &CapsuleTest::collisionPoint); @@ -75,3 +82,5 @@ void CapsuleTest::collisionSphere() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::CapsuleTest) diff --git a/src/Physics/Test/CapsuleTest.h b/src/Physics/Test/CapsuleTest.h deleted file mode 100644 index 6c6c969a1..000000000 --- a/src/Physics/Test/CapsuleTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_Physics_Test_CapsuleTest_h -#define Magnum_Physics_Test_CapsuleTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "ShapeTestBase.h" - -namespace Magnum { namespace Physics { namespace Test { - -class CapsuleTest: public Corrade::TestSuite::Tester, ShapeTestBase { - public: - CapsuleTest(); - - void applyTransformation(); - void collisionPoint(); - void collisionSphere(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 2de48f44a..2b9c8be2c 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -13,16 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "LineTest.h" +#include #include "Math/Constants.h" #include "Math/Matrix4.h" #include "Physics/Line.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::LineTest) - namespace Magnum { namespace Physics { namespace Test { +class LineTest: public Corrade::TestSuite::Tester { + public: + LineTest(); + + void applyTransformation(); +}; + LineTest::LineTest() { addTests(&LineTest::applyTransformation); } @@ -35,3 +40,5 @@ void LineTest::applyTransformation() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::LineTest) diff --git a/src/Physics/Test/LineTest.h b/src/Physics/Test/LineTest.h deleted file mode 100644 index 8f33c3245..000000000 --- a/src/Physics/Test/LineTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Physics_Test_LineTest_h -#define Magnum_Physics_Test_LineTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class LineTest: public Corrade::TestSuite::Tester { - public: - LineTest(); - - void applyTransformation(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/ObjectShapeTest.cpp b/src/Physics/Test/ObjectShapeTest.cpp index dd5b438bd..256e453d0 100644 --- a/src/Physics/Test/ObjectShapeTest.cpp +++ b/src/Physics/Test/ObjectShapeTest.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ObjectShapeTest.h" +#include #include "Physics/ObjectShapeGroup.h" #include "Physics/ObjectShape.h" @@ -21,10 +21,15 @@ #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::ObjectShapeTest) - namespace Magnum { namespace Physics { namespace Test { +class ObjectShapeTest: public Corrade::TestSuite::Tester { + public: + ObjectShapeTest(); + + void clean(); +}; + typedef SceneGraph::Scene> Scene3D; typedef SceneGraph::Object> Object3D; @@ -74,3 +79,5 @@ void ObjectShapeTest::clean() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::ObjectShapeTest) diff --git a/src/Physics/Test/ObjectShapeTest.h b/src/Physics/Test/ObjectShapeTest.h deleted file mode 100644 index 6a3f0b398..000000000 --- a/src/Physics/Test/ObjectShapeTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Physics_Test_ObjectShapeTest_h -#define Magnum_Physics_Test_ObjectShapeTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class ObjectShapeTest: public Corrade::TestSuite::Tester { - public: - ObjectShapeTest(); - - void clean(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index 2ec0ab9d0..d3af840e0 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -13,17 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "PlaneTest.h" - #include "Math/Constants.h" #include "Physics/LineSegment.h" #include "Physics/Point.h" #include "Physics/Plane.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::PlaneTest) +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { +class PlaneTest: public Corrade::TestSuite::Tester, ShapeTestBase { + public: + PlaneTest(); + + void applyTransformation(); + void collisionLine(); + void collisionLineSegment(); +}; + PlaneTest::PlaneTest() { addTests(&PlaneTest::applyTransformation, &PlaneTest::collisionLine, @@ -76,3 +83,5 @@ void PlaneTest::collisionLineSegment() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::PlaneTest) diff --git a/src/Physics/Test/PlaneTest.h b/src/Physics/Test/PlaneTest.h deleted file mode 100644 index d685917e4..000000000 --- a/src/Physics/Test/PlaneTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_Physics_Test_PlaneTest_h -#define Magnum_Physics_Test_PlaneTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "ShapeTestBase.h" - -namespace Magnum { namespace Physics { namespace Test { - -class PlaneTest: public Corrade::TestSuite::Tester, ShapeTestBase { - public: - PlaneTest(); - - void applyTransformation(); - void collisionLine(); - void collisionLineSegment(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/PointTest.cpp b/src/Physics/Test/PointTest.cpp index 25c36bf53..5a2cbe83f 100644 --- a/src/Physics/Test/PointTest.cpp +++ b/src/Physics/Test/PointTest.cpp @@ -13,15 +13,20 @@ GNU Lesser General Public License version 3 for more details. */ -#include "PointTest.h" +#include #include "Math/Matrix4.h" #include "Physics/Point.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::PointTest) - namespace Magnum { namespace Physics { namespace Test { +class PointTest: public Corrade::TestSuite::Tester { + public: + PointTest(); + + void applyTransformation(); +}; + PointTest::PointTest() { addTests(&PointTest::applyTransformation); } @@ -33,3 +38,5 @@ void PointTest::applyTransformation() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::PointTest) diff --git a/src/Physics/Test/PointTest.h b/src/Physics/Test/PointTest.h deleted file mode 100644 index 529ffbd9e..000000000 --- a/src/Physics/Test/PointTest.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef Magnum_Physics_Test_PointTest_h -#define Magnum_Physics_Test_PointTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class PointTest: public Corrade::TestSuite::Tester { - public: - PointTest(); - - void applyTransformation(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index eb5d0f989..74189b5ca 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -13,17 +13,23 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ShapeGroupTest.h" +#include #include "Math/Matrix4.h" #include "Physics/Point.h" #include "Physics/LineSegment.h" #include "Physics/ShapeGroup.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapeGroupTest) - namespace Magnum { namespace Physics { namespace Test { +class ShapeGroupTest: public Corrade::TestSuite::Tester { + public: + ShapeGroupTest(); + + void copy(); + void reference(); +}; + ShapeGroupTest::ShapeGroupTest() { addTests(&ShapeGroupTest::copy, &ShapeGroupTest::reference); @@ -57,3 +63,5 @@ void ShapeGroupTest::reference() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapeGroupTest) diff --git a/src/Physics/Test/ShapeGroupTest.h b/src/Physics/Test/ShapeGroupTest.h deleted file mode 100644 index 49c93a949..000000000 --- a/src/Physics/Test/ShapeGroupTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Physics_Test_ShapeGroupTest_h -#define Magnum_Physics_Test_ShapeGroupTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Physics { namespace Test { - -class ShapeGroupTest: public Corrade::TestSuite::Tester { - public: - ShapeGroupTest(); - - void copy(); - void reference(); -}; - -}}} - -#endif diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index 3b8414e79..f53057f6d 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -13,17 +13,26 @@ GNU Lesser General Public License version 3 for more details. */ -#include "SphereTest.h" - #include "Math/Constants.h" #include "Physics/LineSegment.h" #include "Physics/Point.h" #include "Physics/Sphere.h" -CORRADE_TEST_MAIN(Magnum::Physics::Test::SphereTest) +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { +class SphereTest: public Corrade::TestSuite::Tester, ShapeTestBase { + public: + SphereTest(); + + void applyTransformation(); + void collisionPoint(); + void collisionLine(); + void collisionLineSegment(); + void collisionSphere(); +}; + SphereTest::SphereTest() { addTests(&SphereTest::applyTransformation, &SphereTest::collisionPoint, @@ -102,3 +111,5 @@ void SphereTest::collisionSphere() { } }}} + +CORRADE_TEST_MAIN(Magnum::Physics::Test::SphereTest) diff --git a/src/Physics/Test/SphereTest.h b/src/Physics/Test/SphereTest.h deleted file mode 100644 index a8fa7ef0b..000000000 --- a/src/Physics/Test/SphereTest.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef Magnum_Physics_Test_SphereTest_h -#define Magnum_Physics_Test_SphereTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "ShapeTestBase.h" - -namespace Magnum { namespace Physics { namespace Test { - -class SphereTest: public Corrade::TestSuite::Tester, ShapeTestBase { - public: - SphereTest(); - - void applyTransformation(); - void collisionPoint(); - void collisionLine(); - void collisionLineSegment(); - void collisionSphere(); -}; - -}}} - -#endif diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 51f2230ea..a39871d77 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -16,8 +16,7 @@ /* Less precision */ #define FLOAT_EQUALITY_PRECISION 1.0e-5 -#include "CapsuleTest.h" - +#include #include #include "Math/Point3D.h" @@ -25,10 +24,16 @@ using Corrade::TestSuite::Compare::Container; -CORRADE_TEST_MAIN(Magnum::Primitives::Test::CapsuleTest) - namespace Magnum { namespace Primitives { namespace Test { +class CapsuleTest: public Corrade::TestSuite::Tester { + public: + CapsuleTest(); + + void withoutTextureCoords(); + void withTextureCoords(); +}; + CapsuleTest::CapsuleTest() { addTests(&CapsuleTest::withoutTextureCoords, &CapsuleTest::withTextureCoords); @@ -175,3 +180,5 @@ void CapsuleTest::withTextureCoords() { } }}} + +CORRADE_TEST_MAIN(Magnum::Primitives::Test::CapsuleTest) diff --git a/src/Primitives/Test/CapsuleTest.h b/src/Primitives/Test/CapsuleTest.h deleted file mode 100644 index ab276ae4f..000000000 --- a/src/Primitives/Test/CapsuleTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Primitives_Test_CapsuleTest_h -#define Magnum_Primitives_Test_CapsuleTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Primitives { namespace Test { - -class CapsuleTest: public Corrade::TestSuite::Tester { - public: - CapsuleTest(); - - void withoutTextureCoords(); - void withTextureCoords(); -}; - -}}} - -#endif diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 4eda71de4..dd951d8e5 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -13,8 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "CylinderTest.h" - +#include #include #include "Math/Point3D.h" @@ -22,10 +21,16 @@ using Corrade::TestSuite::Compare::Container; -CORRADE_TEST_MAIN(Magnum::Primitives::Test::CylinderTest) - namespace Magnum { namespace Primitives { namespace Test { +class CylinderTest: public Corrade::TestSuite::Tester { + public: + CylinderTest(); + + void withoutAnything(); + void withTextureCoordsAndCaps(); +}; + CylinderTest::CylinderTest() { addTests(&CylinderTest::withoutAnything, &CylinderTest::withTextureCoordsAndCaps); @@ -173,3 +178,5 @@ void CylinderTest::withTextureCoordsAndCaps() { } }}} + +CORRADE_TEST_MAIN(Magnum::Primitives::Test::CylinderTest) diff --git a/src/Primitives/Test/CylinderTest.h b/src/Primitives/Test/CylinderTest.h deleted file mode 100644 index 48234fb99..000000000 --- a/src/Primitives/Test/CylinderTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Primitives_Test_CylinderTest_h -#define Magnum_Primitives_Test_CylinderTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Primitives { namespace Test { - -class CylinderTest: public Corrade::TestSuite::Tester { - public: - CylinderTest(); - - void withoutAnything(); - void withTextureCoordsAndCaps(); -}; - -}}} - -#endif diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 4a57c5c0b..20c88f625 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -13,8 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "UVSphereTest.h" - +#include #include #include "Math/Point3D.h" @@ -22,10 +21,16 @@ using Corrade::TestSuite::Compare::Container; -CORRADE_TEST_MAIN(Magnum::Primitives::Test::UVSphereTest) - namespace Magnum { namespace Primitives { namespace Test { +class UVSphereTest: public Corrade::TestSuite::Tester { + public: + UVSphereTest(); + + void withoutTextureCoords(); + void withTextureCoords(); +}; + UVSphereTest::UVSphereTest() { addTests(&UVSphereTest::withoutTextureCoords, &UVSphereTest::withTextureCoords); @@ -112,3 +117,5 @@ void UVSphereTest::withTextureCoords() { } }}} + +CORRADE_TEST_MAIN(Magnum::Primitives::Test::UVSphereTest) diff --git a/src/Primitives/Test/UVSphereTest.h b/src/Primitives/Test/UVSphereTest.h deleted file mode 100644 index 560cb9d4c..000000000 --- a/src/Primitives/Test/UVSphereTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Primitives_Test_UVSphereTest_h -#define Magnum_Primitives_Test_UVSphereTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Primitives { namespace Test { - -class UVSphereTest: public Corrade::TestSuite::Tester { - public: - UVSphereTest(); - - void withoutTextureCoords(); - void withTextureCoords(); -}; - -}}} - -#endif diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index 9b6505589..d824ff4ff 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -13,18 +13,29 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AnimableTest.h" - #include +#include #include "SceneGraph/Animable.h" #include "SceneGraph/AnimableGroup.h" #include "SceneGraph/MatrixTransformation3D.h" -CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::AnimableTest) - namespace Magnum { namespace SceneGraph { namespace Test { +class AnimableTest: public Corrade::TestSuite::Tester { + public: + AnimableTest(); + + void state(); + void step(); + void duration(); + void repeat(); + void stop(); + void pause(); + + void debug(); +}; + typedef SceneGraph::Object> Object3D; AnimableTest::AnimableTest() { @@ -304,3 +315,5 @@ void AnimableTest::debug() { } }}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::AnimableTest) diff --git a/src/SceneGraph/Test/AnimableTest.h b/src/SceneGraph/Test/AnimableTest.h deleted file mode 100644 index 1428db3ca..000000000 --- a/src/SceneGraph/Test/AnimableTest.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef Magnum_SceneGraph_Test_AnimableTest_h -#define Magnum_SceneGraph_Test_AnimableTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace SceneGraph { namespace Test { - -class AnimableTest: public Corrade::TestSuite::Tester { - public: - AnimableTest(); - - void state(); - void step(); - void duration(); - void repeat(); - void stop(); - void pause(); - - void debug(); -}; - -}}} - -#endif diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 4dd856798..e0a737e24 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "CameraTest.h" +#include #include "Math/Constants.h" #include "SceneGraph/AbstractCamera.hpp" /* only for aspectRatioFix(), so it doesn't have to be exported */ @@ -24,10 +24,22 @@ #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" -CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::CameraTest) - namespace Magnum { namespace SceneGraph { namespace Test { +class CameraTest: public Corrade::TestSuite::Tester { + public: + CameraTest(); + + void fixAspectRatio(); + void defaultProjection2D(); + void defaultProjection3D(); + void projection2D(); + void orthographic(); + void perspective(); + void projectionSizeViewport(); + void draw(); +}; + typedef SceneGraph::Object> Object2D; typedef SceneGraph::Object> Object3D; typedef SceneGraph::Scene> Scene3D; @@ -209,3 +221,5 @@ void CameraTest::draw() { } }}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::CameraTest) diff --git a/src/SceneGraph/Test/CameraTest.h b/src/SceneGraph/Test/CameraTest.h deleted file mode 100644 index b43ec879b..000000000 --- a/src/SceneGraph/Test/CameraTest.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef Magnum_SceneGraph_Test_CameraTest_h -#define Magnum_SceneGraph_Test_CameraTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace SceneGraph { namespace Test { - -class CameraTest: public Corrade::TestSuite::Tester { - public: - CameraTest(); - - void fixAspectRatio(); - void defaultProjection2D(); - void defaultProjection3D(); - void projection2D(); - void orthographic(); - void perspective(); - void projectionSizeViewport(); - void draw(); -}; - -}}} - -#endif diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 60bab57b6..bf586bb10 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -13,18 +13,27 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ObjectTest.h" - #include +#include #include "Math/Constants.h" #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" -CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::ObjectTest) - namespace Magnum { namespace SceneGraph { namespace Test { +class ObjectTest: public Corrade::TestSuite::Tester { + public: + ObjectTest(); + + void parenting(); + void scene(); + void absoluteTransformation(); + void transformations(); + void setClean(); + void bulkSetClean(); +}; + typedef SceneGraph::Object> Object3D; typedef SceneGraph::Scene> Scene3D; @@ -312,3 +321,5 @@ void ObjectTest::bulkSetClean() { } }}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::ObjectTest) diff --git a/src/SceneGraph/Test/ObjectTest.h b/src/SceneGraph/Test/ObjectTest.h deleted file mode 100644 index 0c2e594d9..000000000 --- a/src/SceneGraph/Test/ObjectTest.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef Magnum_SceneGraph_Test_ObjectTest_h -#define Magnum_SceneGraph_Test_ObjectTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace SceneGraph { namespace Test { - -class ObjectTest: public Corrade::TestSuite::Tester { - public: - ObjectTest(); - - void parenting(); - void scene(); - void absoluteTransformation(); - void transformations(); - void setClean(); - void bulkSetClean(); -}; - -}}} - -#endif diff --git a/src/SceneGraph/Test/SceneTest.cpp b/src/SceneGraph/Test/SceneTest.cpp index 301a82846..a8c7b177e 100644 --- a/src/SceneGraph/Test/SceneTest.cpp +++ b/src/SceneGraph/Test/SceneTest.cpp @@ -13,16 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "SceneTest.h" +#include -#include "Magnum.h" #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" -CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::SceneTest) - namespace Magnum { namespace SceneGraph { namespace Test { +class SceneTest: public Corrade::TestSuite::Tester { + public: + SceneTest(); + + void transformation(); + void parent(); +}; + typedef SceneGraph::Scene> Scene3D; typedef SceneGraph::Object> Object3D; @@ -52,3 +57,5 @@ void SceneTest::parent() { } }}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::SceneTest) diff --git a/src/SceneGraph/Test/SceneTest.h b/src/SceneGraph/Test/SceneTest.h deleted file mode 100644 index 93aef48a7..000000000 --- a/src/SceneGraph/Test/SceneTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_SceneGraph_Test_SceneTest_h -#define Magnum_SceneGraph_Test_SceneTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace SceneGraph { namespace Test { - -class SceneTest: public Corrade::TestSuite::Tester { - public: - SceneTest(); - - void transformation(); - void parent(); -}; - -}}} - -#endif diff --git a/src/Test/ArrayTest.cpp b/src/Test/ArrayTest.cpp index 928ecc274..eb3fe1da9 100644 --- a/src/Test/ArrayTest.cpp +++ b/src/Test/ArrayTest.cpp @@ -13,14 +13,22 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ArrayTest.h" +#include #include "Array.h" -CORRADE_TEST_MAIN(Magnum::Test::ArrayTest) - namespace Magnum { namespace Test { +class ArrayTest: public Corrade::TestSuite::Tester { + public: + ArrayTest(); + + void construct(); + void constexprConstruct(); + void equality(); + void access(); +}; + typedef Magnum::Array1D Array1D; typedef Magnum::Array2D Array2D; typedef Magnum::Array3D Array3D; @@ -90,3 +98,5 @@ void ArrayTest::access() { } }} + +CORRADE_TEST_MAIN(Magnum::Test::ArrayTest) diff --git a/src/Test/ArrayTest.h b/src/Test/ArrayTest.h deleted file mode 100644 index eab504e9b..000000000 --- a/src/Test/ArrayTest.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef Magnum_Test_ArrayTest_h -#define Magnum_Test_ArrayTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Test { - -class ArrayTest: public Corrade::TestSuite::Tester { - public: - ArrayTest(); - - void construct(); - void constexprConstruct(); - void equality(); - void access(); -}; - -}} - -#endif diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 6d77f5555..d7ae54931 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -13,19 +13,41 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ColorTest.h" - #include +#include #include #include "Color.h" -CORRADE_TEST_MAIN(Magnum::Test::ColorTest) - using namespace Corrade::Utility; namespace Magnum { namespace Test { +class ColorTest: public Corrade::TestSuite::Tester { + public: + ColorTest(); + + void access(); + + void fromDenormalized(); + void fromNormalized(); + + void fromHue(); + void fromSaturation(); + void fromValue(); + + void hue(); + void saturation(); + void value(); + + void hsv(); + void hsvOverflow(); + void hsvAlpha(); + + void debug(); + void configuration(); +}; + typedef Magnum::Color3 Color3; typedef Magnum::Color4 Color4; typedef Magnum::Color3 Color3f; @@ -180,3 +202,5 @@ void ColorTest::configuration() { } }} + +CORRADE_TEST_MAIN(Magnum::Test::ColorTest) diff --git a/src/Test/ColorTest.h b/src/Test/ColorTest.h deleted file mode 100644 index 27991ea3d..000000000 --- a/src/Test/ColorTest.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef Magnum_Test_ColorTest_h -#define Magnum_Test_ColorTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Test { - -class ColorTest: public Corrade::TestSuite::Tester { - public: - ColorTest(); - - void access(); - - void fromDenormalized(); - void fromNormalized(); - - void fromHue(); - void fromSaturation(); - void fromValue(); - - void hue(); - void saturation(); - void value(); - - void hsv(); - void hsvOverflow(); - void hsvAlpha(); - - void debug(); - void configuration(); -}; - -}} - -#endif diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index 36b3248d8..658febb17 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -13,19 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "MeshTest.h" - #include +#include #include #include "Mesh.h" -CORRADE_TEST_MAIN(Magnum::Test::MeshTest) - using namespace Corrade::Utility; namespace Magnum { namespace Test { +class MeshTest: public Corrade::TestSuite::Tester { + public: + MeshTest(); + + void debug(); + void configuration(); +}; + MeshTest::MeshTest() { addTests(&MeshTest::debug, &MeshTest::configuration); @@ -46,3 +51,5 @@ void MeshTest::configuration() { } }} + +CORRADE_TEST_MAIN(Magnum::Test::MeshTest) diff --git a/src/Test/MeshTest.h b/src/Test/MeshTest.h deleted file mode 100644 index 4b40a3f69..000000000 --- a/src/Test/MeshTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Test_MeshTest_h -#define Magnum_Test_MeshTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Test { - -class MeshTest: public Corrade::TestSuite::Tester { - public: - MeshTest(); - - void debug(); - void configuration(); -}; - -}} - -#endif diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 6efa8c520..79a2c308f 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -13,9 +13,8 @@ GNU Lesser General Public License version 3 for more details. */ -#include "ResourceManagerTest.h" - #include +#include #include "AbstractResourceLoader.h" #include "ResourceManager.h" @@ -24,10 +23,22 @@ using namespace Corrade::Utility; -CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerTest) - namespace Magnum { namespace Test { +class ResourceManagerTest: public Corrade::TestSuite::Tester { + public: + ResourceManagerTest(); + + void state(); + void stateFallback(); + void stateDisallowed(); + void basic(); + void residentPolicy(); + void referenceCountedPolicy(); + void manualPolicy(); + void loader(); +}; + class Data { public: static std::size_t count; @@ -239,3 +250,5 @@ void ResourceManagerTest::loader() { } }} + +CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerTest) diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h deleted file mode 100644 index 35aa5aa0a..000000000 --- a/src/Test/ResourceManagerTest.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef Magnum_Test_ResourceManagerTest_h -#define Magnum_Test_ResourceManagerTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Test { - -class ResourceManagerTest: public Corrade::TestSuite::Tester { - public: - ResourceManagerTest(); - - void state(); - void stateFallback(); - void stateDisallowed(); - void basic(); - void residentPolicy(); - void referenceCountedPolicy(); - void manualPolicy(); - void loader(); -}; - -}} - -#endif diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index b07c4da34..d3f500333 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -13,14 +13,21 @@ GNU Lesser General Public License version 3 for more details. */ -#include "SwizzleTest.h" +#include #include "Swizzle.h" -CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) - namespace Magnum { namespace Test { +class SwizzleTest: public Corrade::TestSuite::Tester { + public: + SwizzleTest(); + + void rgba(); + void type(); + void defaultType(); +}; + SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::rgba, &SwizzleTest::type, @@ -52,3 +59,5 @@ void SwizzleTest::defaultType() { } }} + +CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) diff --git a/src/Test/SwizzleTest.h b/src/Test/SwizzleTest.h deleted file mode 100644 index e432ed9ec..000000000 --- a/src/Test/SwizzleTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_Test_SwizzleTest_h -#define Magnum_Test_SwizzleTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Test { - -class SwizzleTest: public Corrade::TestSuite::Tester { - public: - SwizzleTest(); - - void rgba(); - void type(); - void defaultType(); -}; - -}} - -#endif diff --git a/src/Test/TypeTraitsTest.cpp b/src/Test/TypeTraitsTest.cpp index 6da0f265f..a6da165a7 100644 --- a/src/Test/TypeTraitsTest.cpp +++ b/src/Test/TypeTraitsTest.cpp @@ -13,19 +13,24 @@ GNU Lesser General Public License version 3 for more details. */ -#include "TypeTraitsTest.h" - #include +#include #include #include "TypeTraits.h" -CORRADE_TEST_MAIN(Magnum::Test::TypeTraitsTest) - using namespace Corrade::Utility; namespace Magnum { namespace Test { +class TypeTraitsTest: public Corrade::TestSuite::Tester { + public: + TypeTraitsTest(); + + void debug(); + void configuration(); +}; + TypeTraitsTest::TypeTraitsTest() { addTests(&TypeTraitsTest::debug, &TypeTraitsTest::configuration); @@ -46,3 +51,5 @@ void TypeTraitsTest::configuration() { } }} + +CORRADE_TEST_MAIN(Magnum::Test::TypeTraitsTest) diff --git a/src/Test/TypeTraitsTest.h b/src/Test/TypeTraitsTest.h deleted file mode 100644 index d39a42265..000000000 --- a/src/Test/TypeTraitsTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Magnum_Test_TypeTraitsTest_h -#define Magnum_Test_TypeTraitsTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Test { - -class TypeTraitsTest: public Corrade::TestSuite::Tester { - public: - TypeTraitsTest(); - - void debug(); - void configuration(); -}; - -}} - -#endif diff --git a/src/TextureTools/Test/AtlasTest.cpp b/src/TextureTools/Test/AtlasTest.cpp index 01a7e53ce..de508ce2d 100644 --- a/src/TextureTools/Test/AtlasTest.cpp +++ b/src/TextureTools/Test/AtlasTest.cpp @@ -13,17 +13,23 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AtlasTest.h" - #include +#include #include "Math/Geometry/Rectangle.h" #include "TextureTools/Atlas.h" -CORRADE_TEST_MAIN(Magnum::TextureTools::Test::AtlasTest) - namespace Magnum { namespace TextureTools { namespace Test { +class AtlasTest: public Corrade::TestSuite::Tester { + public: + explicit AtlasTest(); + + void create(); + void createEmpty(); + void createTooSmall(); +}; + AtlasTest::AtlasTest() { addTests(&AtlasTest::create, &AtlasTest::createEmpty, @@ -63,3 +69,5 @@ void AtlasTest::createTooSmall() { } }}} + +CORRADE_TEST_MAIN(Magnum::TextureTools::Test::AtlasTest) diff --git a/src/TextureTools/Test/AtlasTest.h b/src/TextureTools/Test/AtlasTest.h deleted file mode 100644 index 13c92aa27..000000000 --- a/src/TextureTools/Test/AtlasTest.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Magnum_TextureTools_Test_AtlasTest_h -#define Magnum_TextureTools_Test_AtlasTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace TextureTools { namespace Test { - -class AtlasTest: public Corrade::TestSuite::Tester { - public: - explicit AtlasTest(); - - void create(); - void createEmpty(); - void createTooSmall(); -}; - -}}} - -#endif From 7ae00deee72def232a5fa2825d47c164e2218f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 23:27:49 +0100 Subject: [PATCH 105/567] Math: removed constexpr from non-trivial Quaternion methods. They will probably involve SIMD operations, which cannot be implemented as constexpr. --- src/Math/Quaternion.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index dac5f1a39..4effe4f28 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -79,7 +79,7 @@ template class Quaternion { * * @see operator*=(T) */ - inline constexpr Quaternion operator*(T scalar) const { + inline Quaternion operator*(T scalar) const { return Quaternion(*this)*=scalar; } @@ -88,7 +88,7 @@ template class Quaternion { * * @see operator/=(T) */ - inline constexpr Quaternion operator/(T scalar) const { + inline Quaternion operator/(T scalar) const { return Quaternion(*this)/=scalar; } @@ -97,7 +97,7 @@ template class Quaternion { * * The computation is *not* done in-place. */ - inline constexpr Quaternion operator*(const Quaternion& other) const { + inline Quaternion operator*(const Quaternion& other) const { return {_scalar*other._vector + other._scalar*_vector + Vector3::cross(_vector, other._vector), _scalar*other._scalar - Vector3::dot(_vector, other._vector)}; } @@ -112,22 +112,22 @@ template class Quaternion { } /** @brief %Quaternion length squared */ - inline constexpr T lengthSquared() const { + inline T lengthSquared() const { return _vector.dot() + _scalar*_scalar; } /** @brief %Quaternion length */ - inline constexpr T length() const { + inline T length() const { return std::sqrt(lengthSquared()); } /** @brief Normalized quaternion */ - inline constexpr Quaternion normalized() const { + inline Quaternion normalized() const { return (*this)/length(); } /** @brief Conjugated quaternion */ - inline constexpr Quaternion conjugated() const { + inline Quaternion conjugated() const { return {-_vector, _scalar}; } @@ -137,7 +137,7 @@ template class Quaternion { * If the quaternion is already normalized, this function is * equivalent to conjugated(). */ - inline constexpr Quaternion inverted() const { + inline Quaternion inverted() const { return conjugated()/lengthSquared(); } From c841c63b344771a3c1d29e18a22218c8434ad546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 23:44:16 +0100 Subject: [PATCH 106/567] Doc++ --- src/Math/Matrix.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 8de204b05..c9194f8d2 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -138,7 +138,8 @@ template class Matrix: public RectangularMatrix inverted() const { Matrix out(Zero); From 3b57d530a43ed2828e4759f0f8119594211bab54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 23:44:30 +0100 Subject: [PATCH 107/567] Math: test also properties of normalized Quaternion. --- src/Math/Test/MathQuaternionTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 362ee3825..24fccec56 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -75,8 +75,9 @@ void QuaternionTest::length() { } void QuaternionTest::normalized() { - CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).normalized(), - Quaternion({1.0f, 3.0f, -2.0f}, -4.0f)/std::sqrt(30.0f)); + Quaternion normalized = Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).normalized(); + CORRADE_COMPARE(normalized.length(), 1.0f); + CORRADE_COMPARE(normalized, Quaternion({1.0f, 3.0f, -2.0f}, -4.0f)/std::sqrt(30.0f)); } void QuaternionTest::conjugated() { From 3126d0947dee4573a48bf8f7548c881cbbd5f515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 5 Jan 2013 23:44:54 +0100 Subject: [PATCH 108/567] Math: "checked" function for inverting normalized Quaternion. --- src/Math/Quaternion.h | 18 ++++++++++++++++-- src/Math/Test/CMakeLists.txt | 2 +- src/Math/Test/MathQuaternionTest.cpp | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 4effe4f28..adaf3c5fa 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -20,6 +20,7 @@ */ #include +#include #include #include "Vector3.h" @@ -134,13 +135,26 @@ template class Quaternion { /** * @brief Inverted quaternion * - * If the quaternion is already normalized, this function is - * equivalent to conjugated(). + * See invertedNormalized() which is faster for normalized + * quaternions. */ inline Quaternion inverted() const { return conjugated()/lengthSquared(); } + /** + * @brief Inverted normalized quaternion + * + * Equivalent to conjugated(). Assumes that the quaternion is + * normalized. + */ + inline Quaternion invertedNormalized() const { + CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + "Math::Quaternion::invertedNormalized(): quaternion must be normalized", + Quaternion({}, std::numeric_limits::quiet_NaN())); + return conjugated(); + } + private: Vector3 _vector; T _scalar; diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index c193b8335..13b60f6ab 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -20,4 +20,4 @@ corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathQuaternionTest MathQuaternionTest.cpp LIBRARIES MagnumMathTestLib) -set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) +set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test MathQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 24fccec56..0e3de5aa0 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -31,6 +31,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void normalized(); void conjugated(); void inverted(); + void invertedNormalized(); void debug(); }; @@ -46,6 +47,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::normalized, &QuaternionTest::conjugated, &QuaternionTest::inverted, + &QuaternionTest::invertedNormalized, &QuaternionTest::debug); } @@ -94,6 +96,23 @@ void QuaternionTest::inverted() { CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/30.0f); } +void QuaternionTest::invertedNormalized() { + Quaternion a = Quaternion({1.0f, 3.0f, -2.0f}, -4.0f); + + std::ostringstream o; + Corrade::Utility::Error::setOutput(&o); + Quaternion notInverted = a.invertedNormalized(); + CORRADE_COMPARE(notInverted.vector(), Vector3()); + CORRADE_COMPARE(notInverted.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::invertedNormalized(): quaternion must be normalized\n"); + + Quaternion aNormalized = a.normalized(); + Quaternion inverted = aNormalized.invertedNormalized(); + CORRADE_COMPARE(aNormalized*inverted, Quaternion()); + CORRADE_COMPARE(inverted*aNormalized.normalized(), Quaternion()); + CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/std::sqrt(30.0f)); +} + void QuaternionTest::debug() { std::ostringstream o; From 3076c4266337adb86442657162fd1b681bace253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 15:37:31 +0100 Subject: [PATCH 109/567] Math: using absolute #includes in Quaternion.h. --- src/Math/Quaternion.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index adaf3c5fa..f41c93c73 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -23,8 +23,8 @@ #include #include -#include "Vector3.h" -#include "MathTypeTraits.h" +#include "Math/MathTypeTraits.h" +#include "Math/Vector3.h" namespace Magnum { namespace Math { From 3b92d2b9f3889f834ab2df0d771335780b8782e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 15:40:08 +0100 Subject: [PATCH 110/567] Math: creating Quaternion from axis/angle. --- src/Math/Quaternion.h | 39 ++++++++++++++++++++++++++++ src/Math/Test/MathQuaternionTest.cpp | 19 ++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index f41c93c73..5cdcb9dbe 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -23,6 +23,7 @@ #include #include +#include "Math/Math.h" #include "Math/MathTypeTraits.h" #include "Math/Vector3.h" @@ -31,6 +32,20 @@ namespace Magnum { namespace Math { /** @brief %Quaternion */ template class Quaternion { public: + /** + * @brief Create quaternion from rotation + * @param angle Rotation angle (counterclockwise, in radians) + * @param normalizedAxis Normalized rotation axis + * + * Assumes that the rotation axis is normalized. + */ + inline static Quaternion fromRotation(T angle, const Vector3& normalizedAxis) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + "Math::Quaternion::fromRotation(): axis must be normalized", {}); + + return {normalizedAxis*std::sin(angle/2), std::cos(angle/2)}; + } + /** @brief Default constructor */ inline constexpr Quaternion(): _scalar(T(1)) {} @@ -53,6 +68,30 @@ template class Quaternion { /** @brief %Scalar part */ inline constexpr T scalar() const { return _scalar; } + /** + * @brief Rotation angle of unit quaternion + * + * Assumes that the quaternion is normalized. + */ + inline T rotationAngle() const { + CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + "Math::Quaternion::rotationAngle(): quaternion must be normalized", + std::numeric_limits::quiet_NaN()); + return T(2)*std::acos(_scalar); + } + + /** + * @brief Rotation axis of unit quaternion + * + * Assumes that the quaternion is normalized. + */ + inline Vector3 rotationAxis() const { + CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + "Math::Quaternion::rotationAxis(): quaternion must be normalized", + {}); + return _vector/std::sqrt(1-pow<2>(_scalar)); + } + /** * @brief Multiply with scalar and assign * diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 0e3de5aa0..1b8a351eb 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -16,6 +16,7 @@ #include #include +#include "Math/Constants.h" #include "Math/Quaternion.h" namespace Magnum { namespace Math { namespace Test { @@ -32,6 +33,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void conjugated(); void inverted(); void invertedNormalized(); + void rotation(); void debug(); }; @@ -48,6 +50,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::conjugated, &QuaternionTest::inverted, &QuaternionTest::invertedNormalized, + &QuaternionTest::rotation, &QuaternionTest::debug); } @@ -113,6 +116,22 @@ void QuaternionTest::invertedNormalized() { CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/std::sqrt(30.0f)); } +void QuaternionTest::rotation() { + float angle = deg(120.0f); + Vector3 axis(1.0f/Constants::sqrt3()); + Quaternion q = Quaternion::fromRotation(angle, axis); + CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f)); + CORRADE_COMPARE(q.rotationAngle(), angle); + CORRADE_COMPARE(q.rotationAxis(), axis); + CORRADE_COMPARE(q.rotationAxis().length(), 1.0f); + + /* Verify negative angle */ + Quaternion q2 = Quaternion::fromRotation(deg(-120.0f), axis); + CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f)); + CORRADE_COMPARE(q2.rotationAngle(), deg(120.0f)); + CORRADE_COMPARE(q2.rotationAxis(), -axis); +} + void QuaternionTest::debug() { std::ostringstream o; From 8e93520bd64e9daefea6e42a13d4b76fba6bf000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 15:40:28 +0100 Subject: [PATCH 111/567] Math: converting Quaternion to rotation matrix. --- src/Math/Quaternion.h | 20 ++++++++++++++++++++ src/Math/Test/MathQuaternionTest.cpp | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 5cdcb9dbe..81f0a7a88 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -25,6 +25,7 @@ #include "Math/Math.h" #include "Math/MathTypeTraits.h" +#include "Math/Matrix.h" #include "Math/Vector3.h" namespace Magnum { namespace Math { @@ -92,6 +93,25 @@ template class Quaternion { return _vector/std::sqrt(1-pow<2>(_scalar)); } + /** + * @brief Convert quaternion to rotation matrix + * + * @see Matrix4::from(const Matrix<3, T>&, const Vector3&) + */ + Matrix<3, T> matrix() const { + return { /* Column-major! */ + T(1) - 2*pow<2>(_vector.y()) - 2*pow<2>(_vector.z()), + 2*_vector.x()*_vector.y() + 2*_vector.z()*_scalar, + 2*_vector.x()*_vector.z() - 2*_vector.y()*_scalar, + 2*_vector.x()*_vector.y() - 2*_vector.z()*_scalar, + T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.z()), + 2*_vector.y()*_vector.z() + 2*_vector.x()*_scalar, + 2*_vector.x()*_vector.z() + 2*_vector.y()*_scalar, + 2*_vector.y()*_vector.z() - 2*_vector.x()*_scalar, + T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.y()) + }; + } + /** * @brief Multiply with scalar and assign * diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 1b8a351eb..fe2360964 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -17,6 +17,7 @@ #include #include "Math/Constants.h" +#include "Math/Matrix4.h" #include "Math/Quaternion.h" namespace Magnum { namespace Math { namespace Test { @@ -34,6 +35,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void inverted(); void invertedNormalized(); void rotation(); + void matrix(); void debug(); }; @@ -51,6 +53,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::inverted, &QuaternionTest::invertedNormalized, &QuaternionTest::rotation, + &QuaternionTest::matrix, &QuaternionTest::debug); } @@ -132,6 +135,14 @@ void QuaternionTest::rotation() { CORRADE_COMPARE(q2.rotationAxis(), -axis); } +void QuaternionTest::matrix() { + float angle = deg(37.0f); + Vector3 axis(1.0f/Constants::sqrt3()); + Quaternion q = Quaternion::fromRotation(angle, axis); + Matrix<3, float> expected = Matrix4::rotation(angle, axis).rotationScaling(); + CORRADE_COMPARE(q.matrix(), expected); +} + void QuaternionTest::debug() { std::ostringstream o; From b55f3a2071591dbe30b632fd2e6da4d5f5a4a772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 16:46:32 +0100 Subject: [PATCH 112/567] Math: function for negating Quaternion, improved tests. --- src/Math/Quaternion.h | 11 +++++++++++ src/Math/RectangularMatrix.h | 2 +- src/Math/Test/MathQuaternionTest.cpp | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 81f0a7a88..da9ccf642 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -112,6 +112,17 @@ template class Quaternion { }; } + /** + * @brief Negated quaternion + * + * @f[ + * -q = [-\boldsymbol q_V, -q_S] + * @f] + */ + inline Quaternion operator-() const { + return {-_vector, -_scalar}; + } + /** * @brief Multiply with scalar and assign * diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 7ff919cb2..e87e8c4bb 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -221,7 +221,7 @@ template class RectangularMatrix { return *this; } - /** @brief Negative matrix */ + /** @brief Negated matrix */ RectangularMatrix operator-() const { RectangularMatrix out; diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index fe2360964..15326582f 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -27,6 +27,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { explicit QuaternionTest(); void construct(); + void negated(); void multiplyDivideScalar(); void multiply(); void length(); @@ -45,6 +46,7 @@ typedef Math::Vector3 Vector3; QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, + &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, &QuaternionTest::multiply, &QuaternionTest::length, @@ -65,6 +67,10 @@ void QuaternionTest::construct() { CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f})); } +void QuaternionTest::negated() { + CORRADE_COMPARE(-Quaternion({1.0f, 2.0f, -3.0f}, -4.0f), Quaternion({-1.0f, -2.0f, 3.0f}, 4.0f)); +} + void QuaternionTest::multiplyDivideScalar() { Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f); @@ -141,6 +147,9 @@ void QuaternionTest::matrix() { Quaternion q = Quaternion::fromRotation(angle, axis); Matrix<3, float> expected = Matrix4::rotation(angle, axis).rotationScaling(); CORRADE_COMPARE(q.matrix(), expected); + + /* Verify that negated quaternion gives the same rotation */ + CORRADE_COMPARE((-q).matrix(), expected); } void QuaternionTest::debug() { From d9c900f076f2f87c7b7ba3f37a3179c0c0e4a02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 16:40:25 +0100 Subject: [PATCH 113/567] Doc++ * Added math equations to Quaternion, Vector and Matrix method documentation. * Removed confusing Quat*=Quat operator overload, as it isn't exactly clear from which side the non-commutative multiplication is done: Quaternion a; a *= b; // eh? a = a*b; // okay! For similar reason this operator wasn't present in RectangularMatrix either. * Unified documentation of expected vector/quaternion normalization state. Now it is not "assumed" but "expected", because failing to do so results in assertion failure. --- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 10 ++--- src/Math/Quaternion.h | 83 ++++++++++++++++++++++++------------ src/Math/RectangularMatrix.h | 78 +++++++++++++++++++++------------ src/Math/Vector.h | 18 ++++---- src/Math/Vector3.h | 1 + 6 files changed, 120 insertions(+), 72 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index a71854a7c..0e55d5169 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -86,8 +86,8 @@ template class Matrix3: public Matrix<3, T> { /** * @brief 2D reflection matrix * @param normal Normal of the line through which to reflect - * (normalized) * + * Expects that the normal is normalized. * @see Matrix4::reflection() */ static Matrix3 reflection(const Vector2& normal) { diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index d7f28f1a4..ce34891e0 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -72,12 +72,10 @@ template class Matrix4: public Matrix<4, T> { * @param angle Rotation angle (counterclockwise, in radians) * @param normalizedAxis Normalized rotation axis * - * If possible, use faster alternatives like rotationX(), rotationY() - * and rotationZ(). + * Expects that the rotation axis is normalized. If possible, use + * faster alternatives like rotationX(), rotationY() and rotationZ(). * @see rotation() const, Matrix3::rotation(T), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() - * @attention Assertion fails on non-normalized rotation vector and - * identity matrix is returned. */ static Matrix4 rotation(T angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), @@ -174,8 +172,8 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D reflection matrix * @param normal Normal of the plane through which to reflect - * (normalized) * + * Expects that the normal is normalized. * @see Matrix3::reflection() */ static Matrix4 reflection(const Vector3& normal) { @@ -293,7 +291,7 @@ template class Matrix4: public Matrix<4, T> { /** * @brief Inverted Euclidean transformation matrix * - * Assumes that the matrix represents Euclidean transformation (i.e. + * Expects that the matrix represents Euclidean transformation (i.e. * only rotation and translation, no scaling) and creates inverted * matrix from transposed rotation part and negated translation part. * Significantly faster than the general algorithm in inverted(). diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index da9ccf642..79e95d496 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -38,7 +38,9 @@ template class Quaternion { * @param angle Rotation angle (counterclockwise, in radians) * @param normalizedAxis Normalized rotation axis * - * Assumes that the rotation axis is normalized. + * Expects that the rotation axis is normalized. @f[ + * q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] + * @f] */ inline static Quaternion fromRotation(T angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), @@ -72,7 +74,10 @@ template class Quaternion { /** * @brief Rotation angle of unit quaternion * - * Assumes that the quaternion is normalized. + * Expects that the quaternion is normalized. @f[ + * \theta = 2 \cdot acos q_S + * @f] + * @see rotationAxis(), fromRotation() */ inline T rotationAngle() const { CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), @@ -84,7 +89,10 @@ template class Quaternion { /** * @brief Rotation axis of unit quaternion * - * Assumes that the quaternion is normalized. + * Expects that the quaternion is normalized. @f[ + * \boldsymbol a = \frac{\boldsymbol q_V}{\sqrt{1 - q_S^2}} + * @f] + * @see rotationAngle(), fromRotation() */ inline Vector3 rotationAxis() const { CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), @@ -126,7 +134,9 @@ template class Quaternion { /** * @brief Multiply with scalar and assign * - * The computation is done in-place. + * The computation is done in-place. @f[ + * q \cdot a = [\boldsymbol q_V \cdot a, q_S \cdot a] + * @f] */ inline Quaternion& operator*=(T number) { _vector *= number; @@ -135,23 +145,25 @@ template class Quaternion { } /** - * @brief Divide with scalar and assign + * @brief Multiply with scalar * - * The computation is done in-place. + * @see operator*=(T) */ - inline Quaternion& operator/=(T number) { - _vector /= number; - _scalar /= number; - return *this; + inline Quaternion operator*(T scalar) const { + return Quaternion(*this)*=scalar; } /** - * @brief Multiply with scalar + * @brief Divide with scalar and assign * - * @see operator*=(T) + * The computation is done in-place. @f[ + * \frac q a = [\frac {\boldsymbol q_V} a, \frac {q_S} a] + * @f] */ - inline Quaternion operator*(T scalar) const { - return Quaternion(*this)*=scalar; + inline Quaternion& operator/=(T number) { + _vector /= number; + _scalar /= number; + return *this; } /** @@ -166,7 +178,10 @@ template class Quaternion { /** * @brief Multiply with quaternion * - * The computation is *not* done in-place. + * @f[ + * p q = [p_S \boldsymbol q_V + q_S \boldsymbol p_V + \boldsymbol p_V \times \boldsymbol q_V, + * p_S q_S - \boldsymbol p_V \cdot \boldsymbol q_V] + * @f] */ inline Quaternion operator*(const Quaternion& other) const { return {_scalar*other._vector + other._scalar*_vector + Vector3::cross(_vector, other._vector), @@ -174,30 +189,38 @@ template class Quaternion { } /** - * @brief Multiply with quaternion and assign + * @brief %Quaternion length squared * - * @see operator*(const Quaternion&) const + * Should be used instead of length() for comparing quaternion length + * with other values, because it doesn't compute the square root. @f[ + * |q|^2 = \boldsymbol q_V \cdot \boldsymbol q_V + q_S q_S + * @f] */ - inline Quaternion& operator*=(const Quaternion& other) { - return (*this = *this * other); - } - - /** @brief %Quaternion length squared */ inline T lengthSquared() const { return _vector.dot() + _scalar*_scalar; } - /** @brief %Quaternion length */ + /** + * @brief %Quaternion length + * + * @see lengthSquared() + */ inline T length() const { return std::sqrt(lengthSquared()); } - /** @brief Normalized quaternion */ + /** @brief Normalized quaternion (of length 1) */ inline Quaternion normalized() const { return (*this)/length(); } - /** @brief Conjugated quaternion */ + /** + * @brief Conjugated quaternion + * + * @f[ + * q^* = [-\boldsymbol q_V, q_S] + * @f] + */ inline Quaternion conjugated() const { return {-_vector, _scalar}; } @@ -206,7 +229,9 @@ template class Quaternion { * @brief Inverted quaternion * * See invertedNormalized() which is faster for normalized - * quaternions. + * quaternions. @f[ + * q^{-1} = \frac{q^*}{|q|^2} = \frac{[-\boldsymbol q_V, q_S]}{|q|^2} + * @f] */ inline Quaternion inverted() const { return conjugated()/lengthSquared(); @@ -215,8 +240,10 @@ template class Quaternion { /** * @brief Inverted normalized quaternion * - * Equivalent to conjugated(). Assumes that the quaternion is - * normalized. + * Equivalent to conjugated(). Expects that the quaternion is + * normalized. @f[ + * q^{-1} = q^* = [-\boldsymbol q_V, q_S] ~~~~~ |q| = 1 + * @f] */ inline Quaternion invertedNormalized() const { CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index e87e8c4bb..691174766 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -63,6 +63,10 @@ template class Vector; See @ref matrix-vector for brief introduction. See also Matrix (square) and Vector. + +The data are stored in column-major order, to reflect that, all indices in +math formulas are in reverse order (i.e. @f$ \boldsymbol A_{ji} @f$ instead +of @f$ \boldsymbol A_{ij} @f$). */ template class RectangularMatrix { static_assert(cols != 0 && rows != 0, "Matrix cannot have zero elements"); @@ -199,6 +203,20 @@ template class RectangularMatrix { return !operator==(other); } + /** + * @brief Add and assign matrix + * + * The computation is done in-place. @f[ + * \boldsymbol A_{ji} = \boldsymbol A_{ji} + \boldsymbol B_{ji} + * @f] + */ + RectangularMatrix& operator+=(const RectangularMatrix& other) { + for(std::size_t i = 0; i != cols*rows; ++i) + _data[i] += other._data[i]; + + return *this; + } + /** * @brief Add matrix * @@ -209,19 +227,12 @@ template class RectangularMatrix { } /** - * @brief Add and assign matrix + * @brief Negated matrix * - * More efficient than operator+(), because it does the computation - * in-place. + * The computation is done in-place. @f[ + * \boldsymbol A_{ji} = -\boldsymbol A_{ji} + * @f] */ - RectangularMatrix& operator+=(const RectangularMatrix& other) { - for(std::size_t i = 0; i != cols*rows; ++i) - _data[i] += other._data[i]; - - return *this; - } - - /** @brief Negated matrix */ RectangularMatrix operator-() const { RectangularMatrix out; @@ -231,20 +242,12 @@ template class RectangularMatrix { return out; } - /** - * @brief Subtract matrix - * - * @see operator-=() - */ - inline RectangularMatrix operator-(const RectangularMatrix& other) const { - return RectangularMatrix(*this)-=other; - } - /** * @brief Subtract and assign matrix * - * More efficient than operator-(), because it does the computation - * in-place. + * The computation is done in-place. @f[ + * \boldsymbol A_{ji} = \boldsymbol A_{ji} - \boldsymbol B_{ji} + * @f] */ RectangularMatrix& operator-=(const RectangularMatrix& other) { for(std::size_t i = 0; i != cols*rows; ++i) @@ -253,6 +256,15 @@ template class RectangularMatrix { return *this; } + /** + * @brief Subtract matrix + * + * @see operator-=() + */ + inline RectangularMatrix operator-(const RectangularMatrix& other) const { + return RectangularMatrix(*this)-=other; + } + /** * @brief Multiply matrix with number * @@ -269,8 +281,9 @@ template class RectangularMatrix { /** * @brief Multiply matrix with number and assign * - * More efficient than operator*(U), because it does the computation - * in-place. + * The computation is done in-place. @f[ + * \boldsymbol A_{ji} = a \boldsymbol A_{ji} + * @f] */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline typename std::enable_if::value, RectangularMatrix&>::type operator*=(U number) { @@ -299,8 +312,9 @@ template class RectangularMatrix { /** * @brief Divide matrix with number and assign * - * More efficient than operator/(), because it does the computation - * in-place. + * The computation is done in-place. @f[ + * \boldsymbol A_{ji} = \frac{\boldsymbol A_{ji}} a + * @f] */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline typename std::enable_if::value, RectangularMatrix&>::type operator/=(U number) { @@ -313,7 +327,13 @@ template class RectangularMatrix { return *this; } - /** @brief Multiply matrix */ + /** + * @brief Multiply matrix + * + * @f[ + * (\boldsymbol {AB})_{ji} = \sum_{k=0}^{m-1} \boldsymbol A_{ki} \boldsymbol B_{jk} + * @f] + */ template RectangularMatrix operator*(const RectangularMatrix& other) const { RectangularMatrix out; @@ -329,7 +349,9 @@ template class RectangularMatrix { * @brief Multiply vector * * Internally the same as multiplying with one-column matrix, but - * returns vector. + * returns vector. @f[ + * (\boldsymbol {Aa})_i = \sum_{k=0}^{m-1} \boldsymbol A_{ki} \boldsymbol a_k + * @f] */ Vector operator*(const Vector& other) const { return operator*(static_cast>(other)); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index c8ad4ec9d..838b75c25 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -57,10 +57,9 @@ template class Vector: public RectangularMatrix<1, si /** * @brief Angle between normalized vectors (in radians) * - * @f[ - * \phi = acos \left(\frac{a \cdot b}{|a| \cdot |b|} \right) + * Expects that both vectors are normalized. @f[ + * \theta = acos \left(\frac{a \cdot b}{|a| \cdot |b|} \right) * @f] - * @attention Both vectors must be normalized. */ inline static T angle(const Vector& normalizedA, const Vector& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), @@ -200,10 +199,9 @@ template class Vector: public RectangularMatrix<1, si * @brief Dot product of the vector * * Should be used instead of length() for comparing vector length with - * other values, because it doesn't compute the square root, just the - * dot product: @f$ a \cdot a < length \cdot length @f$ is faster - * than @f$ \sqrt{a \cdot a} < length @f$. - * + * other values, because it doesn't compute the square root. @f[ + * |a|^2 = a \cdot a + * @f] * @see dot(const Vector&, const Vector&) */ inline T dot() const { @@ -225,9 +223,11 @@ template class Vector: public RectangularMatrix<1, si } /** - * @brief Vector projected onto another + * @brief %Vector projected onto another * - * Returns vector projected onto line defined by @p other. + * Returns vector projected onto line defined by @p other. @f[ + * \boldsymbol a_1 = \frac{\boldsymbol a \cdot \boldsymbol b}{\boldsymbol b \cdot \boldsymbol b} \boldsymbol b + * @f] */ inline Vector projected(const Vector& other) const { return other*dot(*this, other)/other.dot(); diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 1e81d7f8e..ddec15a4a 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -94,6 +94,7 @@ template class Vector3: public Vector<3, T> { * @brief Cross product * * @f[ + * \boldsymbol a \times \boldsymbol b = * \begin{pmatrix} c_0 \\ c_1 \\ c_2 \end{pmatrix} = * \begin{pmatrix}a_1b_2 - a_2b_1 \\ a_2b_0 - a_0b_2 \\ a_0b_1 - a_1b_0 \end{pmatrix} * @f] From eeed955154836f34abfd9237f0c328aab5856666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 18:26:48 +0100 Subject: [PATCH 114/567] Minor code cleanup. --- src/Math/Quaternion.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 79e95d496..248d5fc01 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -138,9 +138,9 @@ template class Quaternion { * q \cdot a = [\boldsymbol q_V \cdot a, q_S \cdot a] * @f] */ - inline Quaternion& operator*=(T number) { - _vector *= number; - _scalar *= number; + inline Quaternion& operator*=(T scalar) { + _vector *= scalar; + _scalar *= scalar; return *this; } @@ -160,9 +160,9 @@ template class Quaternion { * \frac q a = [\frac {\boldsymbol q_V} a, \frac {q_S} a] * @f] */ - inline Quaternion& operator/=(T number) { - _vector /= number; - _scalar /= number; + inline Quaternion& operator/=(T scalar) { + _vector /= scalar; + _scalar /= scalar; return *this; } @@ -248,7 +248,7 @@ template class Quaternion { inline Quaternion invertedNormalized() const { CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), "Math::Quaternion::invertedNormalized(): quaternion must be normalized", - Quaternion({}, std::numeric_limits::quiet_NaN())); + Quaternion({}, std::numeric_limits::quiet_NaN())); return conjugated(); } From 705bf3f597e72cb0068114a65bcd6115dca65bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 18:33:41 +0100 Subject: [PATCH 115/567] Math: reverse scalar/quaternion multiplication and division operators. Also updated related documentation in RectangularMatrix. --- src/Math/Quaternion.h | 21 +++++++++++++++++++++ src/Math/RectangularMatrix.h | 10 ++++------ src/Math/Test/MathQuaternionTest.cpp | 3 +++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 248d5fc01..7c9da9874 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -257,6 +257,27 @@ template class Quaternion { T _scalar; }; +/** @relates Quaternion +@brief Multiply scalar with quaternion + +Same as Quaternion::operator*(T) const. +*/ +template inline Quaternion operator*(T scalar, const Quaternion& quaternion) { + return quaternion*scalar; +} + +/** @relates Quaternion +@brief Divide quaternion with number and invert + +@f[ + \frac a q = [\frac a {\boldsymbol q_V}, \frac a {q_S}] +@f] +@see Quaternion::operator/() +*/ +template inline Quaternion operator/(T scalar, const Quaternion& quaternion) { + return {scalar/quaternion.vector(), scalar/quaternion.scalar()}; +} + /** @debugoperator{Magnum::Math::Geometry::Rectangle} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Quaternion& value) { debug << "Quaternion({"; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 691174766..592e062c5 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -385,7 +385,7 @@ template class RectangularMatrix { /** @relates RectangularMatrix @brief Multiply number with matrix -@see RectangularMatrix::operator*(U) const +Same as RectangularMatrix::operator*(U) const. */ #ifndef DOXYGEN_GENERATING_OUTPUT template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number, const RectangularMatrix& matrix) { @@ -398,11 +398,9 @@ template inline Rectangula /** @relates RectangularMatrix @brief Divide matrix with number and invert -Example: -@code -RectangularMatrix<2, 3, float> mat(1.0f, 2.0f, -4.0f, 8.0f, -1.0f, 0.5f); -RectangularMatrix<2, 3, float> another = 1.0f/mat; // {1.0f, 0.5f, -0.25f, 0.128f, -1.0f, 2.0f} -@endcode +@f[ + \boldsymbol B_{ji} = \frac a {\boldsymbol A_{ji}} +@f] @see RectangularMatrix::operator/() */ #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 15326582f..33c37b490 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -76,7 +76,10 @@ void QuaternionTest::multiplyDivideScalar() { Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f); CORRADE_COMPARE(a*-1.5f, b); + CORRADE_COMPARE(-1.5f*a, b); CORRADE_COMPARE(b/-1.5f, a); + + CORRADE_COMPARE(2.0f/a, Quaternion({2.0f, 0.666666f, -1.0f}, -0.5f)); } void QuaternionTest::multiply() { From eaa819755fdaaf3d734071b0f2ba8f16a3b0299d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 18:34:45 +0100 Subject: [PATCH 116/567] Math: added Quaternion addition and subtraction. --- src/Math/Quaternion.h | 44 ++++++++++++++++++++++++++++ src/Math/Test/MathQuaternionTest.cpp | 11 +++++++ 2 files changed, 55 insertions(+) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 7c9da9874..83f62f6f4 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -120,6 +120,28 @@ template class Quaternion { }; } + /** + * @brief Add and assign quaternion + * + * The computation is done in-place. @f[ + * p + q = [\boldsymbol p_V + \boldsymbol q_V, p_S + q_S] + * @f] + */ + inline Quaternion& operator+=(const Quaternion& other) { + _vector += other._vector; + _scalar += other._scalar; + return *this; + } + + /** + * @brief Add quaternion + * + * @see operator+=() + */ + inline Quaternion operator+(const Quaternion& other) const { + return Quaternion(*this)+=other; + } + /** * @brief Negated quaternion * @@ -131,6 +153,28 @@ template class Quaternion { return {-_vector, -_scalar}; } + /** + * @brief Subtract and assign quaternion + * + * The computation is done in-place. @f[ + * p - q = [\boldsymbol p_V - \boldsymbol q_V, p_S - q_S] + * @f] + */ + inline Quaternion& operator-=(const Quaternion& other) { + _vector -= other._vector; + _scalar -= other._scalar; + return *this; + } + + /** + * @brief Subtract quaternion + * + * @see operator-=() + */ + inline Quaternion operator-(const Quaternion& other) const { + return Quaternion(*this)-=other; + } + /** * @brief Multiply with scalar and assign * diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 33c37b490..99512883e 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -27,6 +27,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { explicit QuaternionTest(); void construct(); + void addSubtract(); void negated(); void multiplyDivideScalar(); void multiply(); @@ -46,6 +47,7 @@ typedef Math::Vector3 Vector3; QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, + &QuaternionTest::addSubtract, &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, &QuaternionTest::multiply, @@ -67,6 +69,15 @@ void QuaternionTest::construct() { CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f})); } +void QuaternionTest::addSubtract() { + Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); + Quaternion c({0.5f, 4.4f, 1.0f}, 8.0f); + + CORRADE_COMPARE(a+b, c); + CORRADE_COMPARE(c-b, a); +} + void QuaternionTest::negated() { CORRADE_COMPARE(-Quaternion({1.0f, 2.0f, -3.0f}, -4.0f), Quaternion({-1.0f, -2.0f, 3.0f}, 4.0f)); } From ed147ebe4088654f0aafd4a53432daa2fad5f2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 18:35:16 +0100 Subject: [PATCH 117/567] Math: linear Quaternion interpolation. --- src/Math/Quaternion.h | 16 ++++++++++++++++ src/Math/Test/MathQuaternionTest.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 83f62f6f4..5498ca159 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -33,6 +33,22 @@ namespace Magnum { namespace Math { /** @brief %Quaternion */ template class Quaternion { public: + /** + * @brief Linear interpolation of two quaternions + * @param normalizedA First quaternion + * @param normalizedB Second quaternion + * @param t Interpolation phase (from range @f$ [0; 1] @f$) + * + * Expects that both quaternions are normalized. @f[ + * q_{LERP} = \frac{(1 - t) q_A + t q_B}{|(1 - t) q_A + t q_B|} + * @f] + */ + inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.lengthSquared(), T(1)) && MathTypeTraits::equals(normalizedB.lengthSquared(), T(1)), + "Math::Quaternion::lerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); + return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); + } + /** * @brief Create quaternion from rotation * @param angle Rotation angle (counterclockwise, in radians) diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 99512883e..20414b0d6 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -38,6 +38,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void invertedNormalized(); void rotation(); void matrix(); + void lerp(); void debug(); }; @@ -58,6 +59,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::invertedNormalized, &QuaternionTest::rotation, &QuaternionTest::matrix, + &QuaternionTest::lerp, &QuaternionTest::debug); } @@ -166,6 +168,28 @@ void QuaternionTest::matrix() { CORRADE_COMPARE((-q).matrix(), expected); } +void QuaternionTest::lerp() { + Quaternion a = Quaternion::fromRotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + + std::ostringstream o; + Corrade::Utility::Error::setOutput(&o); + + Quaternion notLerpA = Quaternion::lerp(a*3.0f, b, 0.35f); + CORRADE_COMPARE(notLerpA.vector(), Vector3()); + CORRADE_COMPARE(notLerpA.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::lerp(): quaternions must be normalized\n"); + + o.str(""); + Quaternion notLerpB = Quaternion::lerp(a, b*-3.0f, 0.35f); + CORRADE_COMPARE(notLerpB.vector(), Vector3()); + CORRADE_COMPARE(notLerpB.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::lerp(): quaternions must be normalized\n"); + + Quaternion lerp = Quaternion::lerp(a, b, 0.35f); + CORRADE_COMPARE(lerp, Quaternion({0.119127f, 0.049134f, 0.049134f}, 0.990445f)); +} + void QuaternionTest::debug() { std::ostringstream o; From 23a94b27097af8e9b8a9c84ceaa2857de9bbde41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 18:53:14 +0100 Subject: [PATCH 118/567] Math: Quaternion has dot product too! Original lengthSquared() renamed to parameterless dot(), it is now consistent with what Vector has. Also updated related Vector documentation. --- src/Math/Quaternion.h | 41 ++++++++++++++++++++-------- src/Math/Test/MathQuaternionTest.cpp | 9 ++++++ src/Math/Vector.h | 5 +++- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 5498ca159..d4775c629 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -33,6 +33,19 @@ namespace Magnum { namespace Math { /** @brief %Quaternion */ template class Quaternion { public: + /** + * @brief Dot product + * + * @f[ + * p \cdot q = \boldsymbol p_V \cdot \boldsymbol q_V + p_S q_S + * @f] + * @see dot() const + */ + inline static T dot(const Quaternion& a, const Quaternion& b) { + /** @todo Use four-component SIMD implementation when available */ + return Vector3::dot(a.vector(), b.vector()) + a.scalar()*b.scalar(); + } + /** * @brief Linear interpolation of two quaternions * @param normalizedA First quaternion @@ -44,7 +57,7 @@ template class Quaternion { * @f] */ inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.lengthSquared(), T(1)) && MathTypeTraits::equals(normalizedB.lengthSquared(), T(1)), + CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::lerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); } @@ -96,7 +109,7 @@ template class Quaternion { * @see rotationAxis(), fromRotation() */ inline T rotationAngle() const { - CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAngle(): quaternion must be normalized", std::numeric_limits::quiet_NaN()); return T(2)*std::acos(_scalar); @@ -111,7 +124,7 @@ template class Quaternion { * @see rotationAngle(), fromRotation() */ inline Vector3 rotationAxis() const { - CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAxis(): quaternion must be normalized", {}); return _vector/std::sqrt(1-pow<2>(_scalar)); @@ -249,24 +262,28 @@ template class Quaternion { } /** - * @brief %Quaternion length squared + * @brief Dot product of the quaternion * * Should be used instead of length() for comparing quaternion length * with other values, because it doesn't compute the square root. @f[ - * |q|^2 = \boldsymbol q_V \cdot \boldsymbol q_V + q_S q_S + * q \cdot q = \boldsymbol q_V \cdot \boldsymbol q_V + q_S^2 * @f] + * @see dot(const Quaternion&, const Quaternion&) */ - inline T lengthSquared() const { - return _vector.dot() + _scalar*_scalar; + inline T dot() const { + return dot(*this, *this); } /** * @brief %Quaternion length * - * @see lengthSquared() + * @f[ + * |q| = \sqrt{q \cdot q} + * @f] + * @see dot() const */ inline T length() const { - return std::sqrt(lengthSquared()); + return std::sqrt(dot()); } /** @brief Normalized quaternion (of length 1) */ @@ -290,11 +307,11 @@ template class Quaternion { * * See invertedNormalized() which is faster for normalized * quaternions. @f[ - * q^{-1} = \frac{q^*}{|q|^2} = \frac{[-\boldsymbol q_V, q_S]}{|q|^2} + * q^{-1} = \frac{q^*}{|q|^2} = \frac{[-\boldsymbol q_V, q_S]}{q \cdot q} * @f] */ inline Quaternion inverted() const { - return conjugated()/lengthSquared(); + return conjugated()/dot(); } /** @@ -306,7 +323,7 @@ template class Quaternion { * @f] */ inline Quaternion invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), "Math::Quaternion::invertedNormalized(): quaternion must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return conjugated(); diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index 20414b0d6..d4d52cf96 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -31,6 +31,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void negated(); void multiplyDivideScalar(); void multiply(); + void dot(); void length(); void normalized(); void conjugated(); @@ -52,6 +53,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, &QuaternionTest::multiply, + &QuaternionTest::dot, &QuaternionTest::length, &QuaternionTest::normalized, &QuaternionTest::conjugated, @@ -100,6 +102,13 @@ void QuaternionTest::multiply() { Quaternion({-11.0f, -16.5f, 27.5f}, 115.0f)); } +void QuaternionTest::dot() { + Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion b({-0.5f, 1.5f, 3.0f}, 12.0f); + + CORRADE_COMPARE(Quaternion::dot(a, b), -50.0f); +} + void QuaternionTest::length() { CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).length(), std::sqrt(30.0f)); } diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 838b75c25..421dcdf41 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -200,7 +200,7 @@ template class Vector: public RectangularMatrix<1, si * * Should be used instead of length() for comparing vector length with * other values, because it doesn't compute the square root. @f[ - * |a|^2 = a \cdot a + * a \cdot a = \sum_{i=0}^{n-1} a_i^2 * @f] * @see dot(const Vector&, const Vector&) */ @@ -211,6 +211,9 @@ template class Vector: public RectangularMatrix<1, si /** * @brief %Vector length * + * @f[ + * |a| = \sqrt{a \cdot a} + * @f] * @see dot() const */ inline T length() const { From 53a95b62963386484b5ba284564aac3105fac0e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 19:05:40 +0100 Subject: [PATCH 119/567] Math: test also parameterless Quaternion::dot(). Just to be sure (and to be consistent with Vector test). --- src/Math/Test/MathQuaternionTest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index d4d52cf96..e134a2769 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -32,6 +32,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void multiplyDivideScalar(); void multiply(); void dot(); + void dotSelf(); void length(); void normalized(); void conjugated(); @@ -54,6 +55,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::multiplyDivideScalar, &QuaternionTest::multiply, &QuaternionTest::dot, + &QuaternionTest::dotSelf, &QuaternionTest::length, &QuaternionTest::normalized, &QuaternionTest::conjugated, @@ -109,6 +111,10 @@ void QuaternionTest::dot() { CORRADE_COMPARE(Quaternion::dot(a, b), -50.0f); } +void QuaternionTest::dotSelf() { + CORRADE_COMPARE(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).dot(), 30.0f); +} + void QuaternionTest::length() { CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).length(), std::sqrt(30.0f)); } From 669a08daa538de9fab2e13f3ec44ffe68237460f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 19:06:25 +0100 Subject: [PATCH 120/567] Math: angle between two quaternions. Also updated related Vector test. --- src/Math/Quaternion.h | 13 +++++++++++++ src/Math/Test/MathQuaternionTest.cpp | 18 ++++++++++++++++++ src/Math/Test/VectorTest.cpp | 13 +++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index d4775c629..43c3b959c 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -46,6 +46,19 @@ template class Quaternion { return Vector3::dot(a.vector(), b.vector()) + a.scalar()*b.scalar(); } + /** + * @brief Angle between normalized quaternions (in radians) + * + * Expects that both quaternions are normalized. @f[ + * \theta = acos \left(\frac{p \cdot q}{|p| \cdot |q|} \right) + * @f] + */ + inline static T angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + "Math::Quaternion::angle(): quaternions must be normalized", std::numeric_limits::quiet_NaN()); + return std::acos(dot(normalizedA, normalizedB)); + } + /** * @brief Linear interpolation of two quaternions * @param normalizedA First quaternion diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/MathQuaternionTest.cpp index e134a2769..4f1422084 100644 --- a/src/Math/Test/MathQuaternionTest.cpp +++ b/src/Math/Test/MathQuaternionTest.cpp @@ -39,6 +39,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void inverted(); void invertedNormalized(); void rotation(); + void angle(); void matrix(); void lerp(); @@ -62,6 +63,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::inverted, &QuaternionTest::invertedNormalized, &QuaternionTest::rotation, + &QuaternionTest::angle, &QuaternionTest::matrix, &QuaternionTest::lerp, &QuaternionTest::debug); @@ -172,6 +174,22 @@ void QuaternionTest::rotation() { CORRADE_COMPARE(q2.rotationAxis(), -axis); } +void QuaternionTest::angle() { + std::ostringstream o; + Corrade::Utility::Error::setOutput(&o); + CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), {{4.0f, -3.0f, 2.0f}, -1.0f}), + std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); + + o.str(""); + CORRADE_COMPARE(Quaternion::angle({{1.0f, 2.0f, -3.0f}, -4.0f}, Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), + std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); + + CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), + rad(1.704528f)); +} + void QuaternionTest::matrix() { float angle = deg(37.0f); Vector3 axis(1.0f/Constants::sqrt3()); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 3b1dc417c..d8d9f303f 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -140,12 +140,17 @@ void VectorTest::max() { void VectorTest::angle() { std::ostringstream o; Error::setOutput(&o); - /* Both vectors must be normalized, otherwise NaN is returned */ - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), + std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); - CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), std::numeric_limits::quiet_NaN()); - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), Vector3(1.0f, -2.0f, 3.0f).normalized()), rad(1.162514f)); + o.str(""); + CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), + std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); + + CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), Vector3(1.0f, -2.0f, 3.0f).normalized()), + rad(1.162514f)); } void VectorTest::debug() { From b9f21d14301f48df30c4b35dedf15a1b3bace70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 19:07:45 +0100 Subject: [PATCH 121/567] Removed unnecessary prefix from test filename. My brain is lagging behind my keyboard. --- src/Math/Test/CMakeLists.txt | 2 +- src/Math/Test/{MathQuaternionTest.cpp => QuaternionTest.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/Math/Test/{MathQuaternionTest.cpp => QuaternionTest.cpp} (100%) diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 13b60f6ab..760d8bcdf 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -18,6 +18,6 @@ corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(MathQuaternionTest MathQuaternionTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test MathQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/MathQuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp similarity index 100% rename from src/Math/Test/MathQuaternionTest.cpp rename to src/Math/Test/QuaternionTest.cpp From 538601fc06425860ee0bf87e9f9d172f4d2911ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 19:34:56 +0100 Subject: [PATCH 122/567] Minor code cleanup. --- src/Math/Quaternion.h | 5 +++-- src/Math/Vector.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 43c3b959c..794677ed3 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -50,7 +50,7 @@ template class Quaternion { * @brief Angle between normalized quaternions (in radians) * * Expects that both quaternions are normalized. @f[ - * \theta = acos \left(\frac{p \cdot q}{|p| \cdot |q|} \right) + * \theta = acos \left( \frac{p \cdot q}{|p| \cdot |q|} \right) * @f] */ inline static T angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { @@ -71,7 +71,8 @@ template class Quaternion { */ inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), - "Math::Quaternion::lerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); + "Math::Quaternion::lerp(): quaternions must be normalized", + Quaternion({}, std::numeric_limits::quiet_NaN())); return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); } diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 421dcdf41..34fe81911 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -41,7 +41,7 @@ template class Vector: public RectangularMatrix<1, si * @brief Dot product * * @f[ - * a \cdot b = \sum_{i=0}^{n-1} a_ib_i + * a \cdot b = \sum_{i=0}^{n-1} a_ib_i * @f] * @see dot() const */ @@ -58,7 +58,7 @@ template class Vector: public RectangularMatrix<1, si * @brief Angle between normalized vectors (in radians) * * Expects that both vectors are normalized. @f[ - * \theta = acos \left(\frac{a \cdot b}{|a| \cdot |b|} \right) + * \theta = acos \left( \frac{a \cdot b}{|a| \cdot |b|} \right) * @f] */ inline static T angle(const Vector& normalizedA, const Vector& normalizedB) { From f06b53724c449a46afb7d5b57cd425e413971a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Jan 2013 19:35:38 +0100 Subject: [PATCH 123/567] Math: spherical linear Quaternion interpolation. --- src/Math/Quaternion.h | 27 ++++++++++++++++++++++++++- src/Math/Test/QuaternionTest.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 794677ed3..737f3978c 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -56,7 +56,7 @@ template class Quaternion { inline static T angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::angle(): quaternions must be normalized", std::numeric_limits::quiet_NaN()); - return std::acos(dot(normalizedA, normalizedB)); + return angleInternal(normalizedA, normalizedB); } /** @@ -76,6 +76,26 @@ template class Quaternion { return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); } + /** + * @brief Spherical linear interpolation of two quaternions + * @param normalizedA First quaternion + * @param normalizedB Second quaternion + * @param t Interpolation phase (from range @f$ [0; 1] @f$) + * + * Expects that both quaternions are normalized. @f[ + * q_{SLERP} = \frac{sin((1 - t) \theta) q_A + sin(t \theta) q_B}{sin \theta} + * ~~~~~~~~~~ + * \theta = acos \left( \frac{q_A \cdot q_B}{|q_A| \cdot |q_B|} \right) + * @f] + */ + inline static Quaternion slerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + "Math::Quaternion::slerp(): quaternions must be normalized", + Quaternion({}, std::numeric_limits::quiet_NaN())); + T a = angleInternal(normalizedA, normalizedB); + return (std::sin((T(1) - t)*a)*normalizedA + std::sin(t*a)*normalizedB)/std::sin(a); + } + /** * @brief Create quaternion from rotation * @param angle Rotation angle (counterclockwise, in radians) @@ -344,6 +364,11 @@ template class Quaternion { } private: + /* Used in angle() and slerp() (no assertions) */ + inline static T angleInternal(const Quaternion& normalizedA, const Quaternion& normalizedB) { + return std::acos(dot(normalizedA, normalizedB)); + } + Vector3 _vector; T _scalar; }; diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 4f1422084..40176ec9f 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -42,6 +42,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void angle(); void matrix(); void lerp(); + void slerp(); void debug(); }; @@ -66,6 +67,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::angle, &QuaternionTest::matrix, &QuaternionTest::lerp, + &QuaternionTest::slerp, &QuaternionTest::debug); } @@ -223,6 +225,28 @@ void QuaternionTest::lerp() { CORRADE_COMPARE(lerp, Quaternion({0.119127f, 0.049134f, 0.049134f}, 0.990445f)); } +void QuaternionTest::slerp() { + Quaternion a = Quaternion::fromRotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + + std::ostringstream o; + Corrade::Utility::Error::setOutput(&o); + + Quaternion notSlerpA = Quaternion::slerp(a*3.0f, b, 0.35f); + CORRADE_COMPARE(notSlerpA.vector(), Vector3()); + CORRADE_COMPARE(notSlerpA.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::slerp(): quaternions must be normalized\n"); + + o.str(""); + Quaternion notSlerpB = Quaternion::slerp(a, b*-3.0f, 0.35f); + CORRADE_COMPARE(notSlerpB.vector(), Vector3()); + CORRADE_COMPARE(notSlerpB.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::slerp(): quaternions must be normalized\n"); + + Quaternion slerp = Quaternion::slerp(a, b, 0.35f); + CORRADE_COMPARE(slerp, Quaternion({0.119165f, 0.0491109f, 0.0491109f}, 0.990442f)); +} + void QuaternionTest::debug() { std::ostringstream o; From c7d7fdad289973d9bb263fe5757d91dbe054f6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Jan 2013 01:20:57 +0100 Subject: [PATCH 124/567] Math: removed done TODO. --- src/Math/Math.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Math/Math.h b/src/Math/Math.h index 5d68b2e2d..91052e156 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -28,13 +28,6 @@ namespace Magnum { namespace Math { -/** -@todo Quaternions: - - interpolation between rotations (=> animation, continuous collision detection) - - better rotation representation (4 floats instead of 9/16 floats when using - matrices) -*/ - #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Pow { From a4514e7acbe61dcffc32609243f67c36e5aebee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Jan 2013 01:21:12 +0100 Subject: [PATCH 125/567] Brought Math::Quaternion into Magnum namespace as Quaternion. --- src/Magnum.h | 5 +++++ src/Math/Quaternion.h | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Magnum.h b/src/Magnum.h index 7123b40f7..1f8c7d14f 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -64,6 +64,8 @@ namespace Math { template class Matrix3; template class Matrix4; + template class Quaternion; + template constexpr T deg(T value); template constexpr T rad(T value); template class Constants; @@ -117,6 +119,9 @@ typedef Math::Matrix3 Matrix3; /** @brief 4x4 floating-point matrix */ typedef Math::Matrix4 Matrix4; +/** @brief Quaternion */ +typedef Math::Quaternion Quaternion; + /** @brief Floating-point constants */ /* Using float instead of GLfloat to not break KDevelop autocompletion */ typedef Math::Constants Constants; diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 737f3978c..abac00de5 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -30,7 +30,11 @@ namespace Magnum { namespace Math { -/** @brief %Quaternion */ +/** +@brief %Quaternion + +@see Magnum::Quaternion +*/ template class Quaternion { public: /** From 1eef70b184f3aed3dfe5080e21d7a80e964ec87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Jan 2013 01:22:35 +0100 Subject: [PATCH 126/567] Doc++ --- src/Math/Quaternion.h | 4 ++-- src/Math/Vector.h | 36 +++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index abac00de5..808413a15 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -117,10 +117,10 @@ template class Quaternion { } /** @brief Default constructor */ - inline constexpr Quaternion(): _scalar(T(1)) {} + inline constexpr /*implicit*/ Quaternion(): _scalar(T(1)) {} /** @brief Create quaternion from vector and scalar */ - inline constexpr Quaternion(const Vector3& vector, T scalar): _vector(vector), _scalar(scalar) {} + inline constexpr /*implicit*/ Quaternion(const Vector3& vector, T scalar): _vector(vector), _scalar(scalar) {} /** @brief Equality comparison */ inline bool operator==(const Quaternion& other) const { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 34fe81911..5cb7d25c2 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -151,20 +151,12 @@ template class Vector: public RectangularMatrix<1, si return true; } - /** - * @brief Multiply vector component-wise - * - * @see operator*=(const Vector&) - */ - template inline Vector operator*(const Vector& other) const { - return Vector(*this)*=other; - } - /** * @brief Multiply vector component-wise and assign * - * More efficient than operator*(const Vector&) const, - * because it does the computation in-place. + * The computation is done in-place. @f[ + * \boldsymbol a_i = \boldsymbol a_i \boldsymbol b_i + * @f] */ template Vector& operator*=(const Vector& other) { for(std::size_t i = 0; i != size; ++i) @@ -174,19 +166,20 @@ template class Vector: public RectangularMatrix<1, si } /** - * @brief Divide vector component-wise + * @brief Multiply vector component-wise * - * @see operator/=(const Vector&) + * @see operator*=(const Vector&) */ - template inline Vector operator/(const Vector& other) const { - return Vector(*this)/=other; + template inline Vector operator*(const Vector& other) const { + return Vector(*this)*=other; } /** * @brief Divide vector component-wise and assign * - * More efficient than operator/(const Vector&) const, - * because it does the computation in-place. + * The computation is done in-place. @f[ + * \boldsymbol a_i = \frac{\boldsymbol a_i}{\boldsymbol b_i} + * @f] */ template Vector& operator/=(const Vector& other) { for(std::size_t i = 0; i != size; ++i) @@ -195,6 +188,15 @@ template class Vector: public RectangularMatrix<1, si return *this; } + /** + * @brief Divide vector component-wise + * + * @see operator/=(const Vector&) + */ + template inline Vector operator/(const Vector& other) const { + return Vector(*this)/=other; + } + /** * @brief Dot product of the vector * From 5f19343bee432bc81ccf49bffaebc697389fd626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Jan 2013 01:22:51 +0100 Subject: [PATCH 127/567] Math: linear interpolation of two Vectors. --- src/Math/Test/VectorTest.cpp | 9 +++++++++ src/Math/Vector.h | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index d8d9f303f..b1f93a472 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -41,6 +41,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void min(); void max(); void angle(); + void lerp(); void debug(); void configuration(); @@ -63,6 +64,7 @@ VectorTest::VectorTest() { &VectorTest::min, &VectorTest::max, &VectorTest::angle, + &VectorTest::lerp, &VectorTest::debug, &VectorTest::configuration); } @@ -153,6 +155,13 @@ void VectorTest::angle() { rad(1.162514f)); } +void VectorTest::lerp() { + Vector3 a(-1.0f, 2.0f, 3.0f); + Vector3 b(3.0f, -2.0f, 11.0f); + + CORRADE_COMPARE(Vector3::lerp(a, b, 0.25f), Vector3(0.0f, 1.0f, 5.0f)); +} + void VectorTest::debug() { std::ostringstream o; Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 5cb7d25c2..d21fde555 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -67,6 +67,20 @@ template class Vector: public RectangularMatrix<1, si return std::acos(dot(normalizedA, normalizedB)); } + /** + * @brief Linear interpolation of two vectors + * @param a First vector + * @param b Second vector + * @param t Interpolation phase (from range @f$ [0; 1] @f$) + * + * The interpolation is done as in following: @f[ + * v_{LERP} = (1 - t) \boldsymbol v_A + t \boldsymbol v_B + * @f] + */ + inline static Vector lerp(const Vector& a, const Vector& b, T t) { + return (T(1) - t)*a + t*b; + } + /** @brief Default constructor */ inline constexpr /*implicit*/ Vector() {} @@ -345,6 +359,9 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit } \ template inline constexpr static Type from(const Math::Vector& other) { \ return Math::Vector::from(other); \ + } \ + inline static const Type lerp(const Math::Vector& a, const Math::Vector& b, T t) { \ + return Math::Vector::lerp(a, b, t); \ } \ \ inline Type& operator=(const Type& other) { \ From 7183110eee11f64ad9e08fa83da2f014686ad308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 8 Jan 2013 17:04:26 +0100 Subject: [PATCH 128/567] Doc++, @todo++ --- src/Buffer.h | 7 ++++--- src/Context.cpp | 4 ++++ src/Math/Math.h | 8 ++++++++ src/SceneGraph/Object.hpp | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index 91ca36587..235833fef 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -40,6 +40,7 @@ data updates. Default way to set or update buffer data with setData() or setSubData() is to explicitly specify data size and pass the pointer to it: @code +Buffer buffer; Vector3* data = new Vector3[200]; buffer.setData(200*sizeof(Vector3), data, Buffer::Usage::StaticDraw); @endcode @@ -265,7 +266,7 @@ class MAGNUM_EXPORT Buffer { /** * Updated frequently as output from OpenGL command and used * frequently for drawing or copying to other images. - * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::DynamicCopy" + * @requires_gles30 Only @ref Magnum::Buffer::Usage "Usage::DynamicDraw" * is available in OpenGL ES 2.0. */ DynamicCopy = GL_DYNAMIC_COPY @@ -293,10 +294,10 @@ class MAGNUM_EXPORT Buffer { * buffers aren't already bound somewhere, they are bound to * `Target::CopyRead` and `Target::CopyWrite` before the copy is * performed. - * @requires_gl31 %Extension @extension{ARB,copy_buffer} - * @requires_gles30 Buffer copying is not available in OpenGL ES 2.0. * @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or * @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access} + * @requires_gl31 %Extension @extension{ARB,copy_buffer} + * @requires_gles30 %Buffer copying is not available in OpenGL ES 2.0. */ inline static void copy(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { copyImplementation(read, write, readOffset, writeOffset, size); diff --git a/src/Context.cpp b/src/Context.cpp index d1ac1e884..050e0e77d 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -82,6 +82,10 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,texture_float), _extension(GL,ARB,depth_buffer_float), _extension(GL,ARB,texture_rg), + /** + * @todo Remove as it doesn't have the same functionality present in + * GL 3.0 and replace with ARB_framebuffer_object? + */ _extension(GL,EXT,framebuffer_object), _extension(GL,EXT,packed_depth_stencil), _extension(GL,EXT,framebuffer_blit), diff --git a/src/Math/Math.h b/src/Math/Math.h index 91052e156..9bc03cf82 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -28,6 +28,14 @@ namespace Magnum { namespace Math { +/** +@todo Vector/scalar overloaded functions (...SIMD): + - min(), max() (component-wise) + - abs() + - sin(), cos()... + - clamp(), lerp() +*/ + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Pow { diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index 697af8daa..f352d23b1 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -148,6 +148,8 @@ template std::vector Ob /* Remember object count for later */ std::size_t objectCount = objects.size(); + /** @bug What if there is one objects twice in the list */ + /* Create initial list of joints from original objects */ std::vector*> jointObjects(objects.size()); for(std::size_t i = 0; i != jointObjects.size(); ++i) { From 3e32d5ece7eaa1fc143b68f3b9311237202565e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 8 Jan 2013 17:06:21 +0100 Subject: [PATCH 129/567] Added ARB_map_buffer_range extension to the list. OpenGL 3.0 specification is awesomely confused with extensions. The ones listed in specs don't have the complete functionality and references to related ARB extensions are nowhere to be found. --- src/Context.cpp | 5 +++++ src/Extensions.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/Context.cpp b/src/Context.cpp index 050e0e77d..d88b0bcb8 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -75,8 +75,13 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,EXT,direct_state_access), _extension(GL,GREMEDY,string_marker)}; static const std::vector extensions300{ + /** + * @todo Remove as it doesn't have all functionality present in GL 3.0 + * and leave only ARB_map_buffer_range? + */ _extension(GL,APPLE,flush_buffer_range), _extension(GL,APPLE,vertex_array_object), + _extension(GL,ARB,map_buffer_range), // replaces APPLE_flush_buffer_range _extension(GL,ARB,color_buffer_float), _extension(GL,ARB,half_float_pixel), _extension(GL,ARB,texture_float), diff --git a/src/Extensions.h b/src/Extensions.h index 068f84b22..2ec893dd1 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -70,6 +70,7 @@ namespace GL { _extension(GL,ARB,draw_instanced, GL210, GL310) // #44 _extension(GL,ARB,geometry_shader4, GL210, GL320) // #47 _extension(GL,ARB,instanced_arrays, GL210, GL330) // #49 + _extension(GL,ARB,map_buffer_range, GL210, GL300) // #50 _extension(GL,ARB,texture_buffer_object, GL210, GL310) // #51 _extension(GL,ARB,texture_rg, GL210, GL300) // #53 _extension(GL,ARB,uniform_buffer_object, GL210, GL310) // #57 From 6fd67c978e88e7dd42bab7731af5e67f3f373f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 8 Jan 2013 17:10:52 +0100 Subject: [PATCH 130/567] Buffer memory mapping. I sincerely hope for glMapBuffer() being marked as deprecated. --- src/Buffer.cpp | 48 ++++++++++ src/Buffer.h | 237 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 277 insertions(+), 8 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 777d0b06b..a812b6eb7 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -29,6 +29,10 @@ Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementat #endif Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault; Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault; +Buffer::MapImplementation Buffer::mapImplementation = &Buffer::mapImplementationDefault; +Buffer::MapRangeImplementation Buffer::mapRangeImplementation = &Buffer::mapRangeImplementationDefault; +Buffer::FlushMappedRangeImplementation Buffer::flushMappedRangeImplementation = &Buffer::flushMappedRangeImplementationDefault; +Buffer::UnmapImplementation Buffer::unmapImplementation = &Buffer::unmapImplementationDefault; void Buffer::initializeContextBasedFunctionality(Context* context) { #ifndef MAGNUM_TARGET_GLES @@ -38,6 +42,10 @@ void Buffer::initializeContextBasedFunctionality(Context* context) { copyImplementation = &Buffer::copyImplementationDSA; setDataImplementation = &Buffer::setDataImplementationDSA; setSubDataImplementation = &Buffer::setSubDataImplementationDSA; + mapImplementation = &Buffer::mapImplementationDSA; + mapRangeImplementation = &Buffer::mapRangeImplementationDSA; + flushMappedRangeImplementation = &Buffer::flushMappedRangeImplementationDSA; + unmapImplementation = &Buffer::unmapImplementationDSA; } #else static_cast(context); @@ -114,4 +122,44 @@ void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const } #endif +void* Buffer::mapImplementationDefault(MapAccess access) { + return glMapBuffer(static_cast(bindInternal(_targetHint)), GLenum(access)); +} + +#ifndef MAGNUM_TARGET_GLES +void* Buffer::mapImplementationDSA(MapAccess access) { + return glMapNamedBufferEXT(_id, GLenum(access)); +} +#endif + +void* Buffer::mapRangeImplementationDefault(GLintptr offset, GLsizeiptr length, MapFlags access) { + return glMapBufferRange(static_cast(bindInternal(_targetHint)), offset, length, GLenum(access)); +} + +#ifndef MAGNUM_TARGET_GLES +void* Buffer::mapRangeImplementationDSA(GLintptr offset, GLsizeiptr length, MapFlags access) { + return glMapNamedBufferRangeEXT(_id, offset, length, GLenum(access)); +} +#endif + +void Buffer::flushMappedRangeImplementationDefault(GLintptr offset, GLsizeiptr length) { + glFlushMappedBufferRange(static_cast(bindInternal(_targetHint)), offset, length); +} + +#ifndef MAGNUM_TARGET_GLES +void Buffer::flushMappedRangeImplementationDSA(GLintptr offset, GLsizeiptr length) { + glFlushMappedNamedBufferRangeEXT(_id, offset, length); +} +#endif + +bool Buffer::unmapImplementationDefault() { + return glUnmapBuffer(static_cast(bindInternal(_targetHint))); +} + +#ifndef MAGNUM_TARGET_GLES +bool Buffer::unmapImplementationDSA() { + return glUnmapNamedBufferEXT(_id); +} +#endif + } diff --git a/src/Buffer.h b/src/Buffer.h index 235833fef..5f7bff8fe 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "Magnum.h" @@ -60,19 +61,46 @@ std::vector data; buffer.setData(data, Buffer::Usage::StaticDraw); @endcode +@subsection Buffer-data-mapping Memory mapping + +%Buffer data can be also updated asynchronously. First you need to allocate +the buffer to desired size by passing `nullptr` to setData(), e.g.: +@code +buffer.setData(200*sizeof(Vector3)), nullptr, Buffer::Usage::StaticDraw); +@endcode +Then you can map the buffer to client memory and operate with the memory +directly. After you are done with the operation, call unmap() to unmap the +buffer again. +@code +Vector3* data = static_cast(buffer.map(0, 200*sizeof(Vector3), Buffer::MapFlag::Write|Buffer::MapFlag::InvalidateBuffer)); +for(std::size_t i = 0; i != 200; ++i) + data[i] = ...; +CORRADE_INTERNAL_ASSERT(buffer.unmap()); +@endcode +If you are updating only a few discrete portions of the buffer, you can use +@ref MapFlag "MapFlag::FlushExplicit" and flushMappedRange() to reduce number +of memory operations performed by OpenGL on unmapping. Example: +@code +Vector3* data = static_cast(buffer.map(0, 200*sizeof(Vector3), Buffer::MapFlag::Write|Buffer::MapFlag::FlushExplicit)); +for(std::size_t i: {7, 27, 56, 128}) { + data[i] = ...; + buffer.flushMappedRange(i*sizeof(Vector3), sizeof(Vector3)); +} +CORRADE_INTERNAL_ASSERT(buffer.unmap()); +@endcode + @section Buffer-performance-optimization Performance optimizations The engine tracks currently bound buffers to avoid unnecessary calls to -@fn_gl{BindBuffer}. If the buffer is already bound to some target, -functions copy(), setData() and setSubData() use that target in -@fn_gl{CopyBufferSubData}, @fn_gl{BufferData} and @fn_gl{BufferSubData} -functions instead of binding the buffer to some specific target. You can also -use setTargetHint() to possibly reduce unnecessary rebinding. +@fn_gl{BindBuffer}. If the buffer is already bound to some target, functions +copy(), setData(), setSubData(), map(), flushMappedRange() and unmap() use +that target instead of binding the buffer to some specific target. You can +also use setTargetHint() to possibly reduce unnecessary rebinding. If extension @extension{EXT,direct_state_access} is available, functions -copy(), setData() and setSubData() use DSA functions to avoid unnecessary -calls to @fn_gl{BindBuffer}. See their respective documentation for more -information. +copy(), setData(), setSubData(), map(), flushMappedRange() and unmap() use DSA +functions to avoid unnecessary calls to @fn_gl{BindBuffer}. See their +respective documentation for more information. @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) @todo BindBufferRange/BindBufferOffset/BindBufferBase for transform feedback (3.0, @extension{EXT,transform_feedback}) @@ -273,6 +301,90 @@ class MAGNUM_EXPORT Buffer { #endif }; + /** + * @brief Memory mapping access + * + * @deprecated Prefer to use map(GLintptr, GLsizeiptr, MapFlags) + * instead, as it has more complete set of features. + * @see map(MapAccess) + * @requires_es_extension %Extension @es_extension{OES,mapbuffer} in + * OpenGL ES 2.0, use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)" + * in OpenGL ES 3.0 instead. + */ + enum class MapAccess: GLenum { + #ifndef MAGNUM_TARGET_GLES + /** + * Map buffer for reading only. + * @requires_gl Only @ref Magnum::Buffer::MapAccess "MapAccess::WriteOnly" + * is available in OpenGL ES 2.0. + */ + ReadOnly = GL_READ_ONLY, + #endif + + /** + * Map buffer for writing only. + */ + WriteOnly = GL_WRITE_ONLY + + #ifndef MAGNUM_TARGET_GLES + , + + /** + * Map buffer for both reading and writing. + * @requires_gl Only @ref Magnum::Buffer::MapAccess "MapAccess::WriteOnly" + * is available in OpenGL ES 2.0. + */ + ReadWrite = GL_READ_WRITE + #endif + }; + + /** + * @brief Memory mapping flag + * + * @see MapFlags, map(GLintptr, GLsizeiptr, MapFlags) + * @requires_gl30 %Extension @extension{ARB,map_buffer_range} + * @requires_gles30 %Extension @es_extension{EXT,map_buffer_range} + */ + enum class MapFlag: GLbitfield { + /** Map buffer for reading. */ + Read = GL_MAP_READ_BIT, + + /** Map buffer for writing. */ + Write = GL_MAP_WRITE_BIT, + + /** + * Previous contents of the entire buffer may be discarded. May + * not be used in combination with @ref MapFlag "MapFlag::Read". + */ + InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT, + + /** + * Previous contents of mapped range may be discarded. May not + * be used in combination with @ref MapFlag "MapFlag::Read". + */ + InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT, + + /** + * Only one or more discrete subranges of the mapping will be + * modified. See flushMappedRange() for more information. May only + * be used in conjuction with @ref MapFlag "MapFlag::Write". + */ + FlushExplicit = GL_MAP_FLUSH_EXPLICIT_BIT, + + /** + * No pending operations on the buffer should be synchronized + * before mapping. + */ + Unsynchronized = GL_MAP_UNSYNCHRONIZED_BIT + }; + + /** + * @brief Memory mapping flags + * + * @see map(GLintptr, GLsizeiptr, MapFlags) + */ + typedef Corrade::Containers::EnumSet MapFlags; + /** * @brief Unbind any buffer from given target * @param target %Target @@ -444,6 +556,85 @@ class MAGNUM_EXPORT Buffer { setSubData(offset, data.size()*sizeof(T), data.data()); } + /** + * @brief Map buffer to client memory + * @param access Access + * @return Pointer to buffer data + * + * If @extension{EXT,direct_state_access} is not available and the + * buffer is not already bound somewhere, it is bound to hinted target + * before the operation. + * @deprecated Prefer to use map(GLintptr, GLsizeiptr, MapFlags) + * instead, as it has more complete set of features. + * @see unmap(), setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{MapBuffer} + * or @fn_gl_extension{MapNamedBuffer,EXT,direct_state_access} + * @requires_es_extension %Extension @es_extension{OES,mapbuffer} in + * OpenGL ES 2.0, use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)" + * in OpenGL ES 3.0 instead. + */ + inline void* map(MapAccess access) { + return (this->*mapImplementation)(access); + } + + /** + * @brief Map buffer to client memory + * @param offset Offset into the buffer + * @param length Length of the mapped memory + * @param flags Flags. At least @ref MapFlag "MapFlag::Read" or + * @ref MapFlag "MapFlag::Write" must be specified. + * @return Pointer to buffer data + * + * If @extension{EXT,direct_state_access} is not available and the + * buffer is not already bound somewhere, it is bound to hinted target + * before the operation. + * @see flushMappedRange(), unmap(), map(MapAccess), setTargetHint(), @fn_gl{BindBuffer} + * and @fn_gl{MapBufferRange} or @fn_gl_extension{MapNamedBufferRange,EXT,direct_state_access} + * @requires_gl30 %Extension @extension{ARB,map_buffer_range} + * @requires_gles30 %Extension @es_extension{EXT,map_buffer_range} + */ + inline void* map(GLintptr offset, GLsizeiptr length, MapFlags flags) { + return (this->*mapRangeImplementation)(offset, length, flags); + } + + /** + * @brief Flush mapped range + * @param offset Offset relative to start of mapped range + * @param length Length of the flushed memory + * + * Flushes specified subsection of mapped range. Use only if you called + * map() with @ref MapFlag "MapFlag::FlushExplicit" flag. See + * @ref Buffer-data-mapping "class documentation" for usage example. + * + * If @extension{EXT,direct_state_access} is not available and the + * buffer is not already bound somewhere, it is bound to hinted target + * before the operation. + * @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{FlushMappedBufferRange} + * or @fn_gl_extension{FlushMappedNamedBufferRange,EXT,direct_state_access} + * @requires_gl30 %Extension @extension{ARB,map_buffer_range} + * @requires_gles30 %Extension @es_extension{EXT,map_buffer_range} + */ + inline void flushMappedRange(GLintptr offset, GLsizeiptr length) { + (this->*flushMappedRangeImplementation)(offset, length); + } + + /** + * @brief Unmap buffer + * @return `False` if the data have become corrupt during the time + * the buffer was mapped (e.g. after screen was resized), `true` + * otherwise. + * + * Unmaps buffer previously mapped with map(), invalidating the + * pointer returned by these functions. If @extension{EXT,direct_state_access} + * is not available and the buffer is not already bound somewhere, it + * is bound to hinted target before the operation. + * @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{UnmapBuffer} or + * @fn_gl_extension{UnmapNamedBuffer,EXT,direct_state_access} + * @requires_gles30 %Extension @es_extension{OES,mapbuffer} + */ + inline bool unmap() { + return (this->*unmapImplementation)(); + } + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); @@ -473,10 +664,40 @@ class MAGNUM_EXPORT Buffer { #endif static SetSubDataImplementation setSubDataImplementation; + typedef void*(Buffer::*MapImplementation)(MapAccess); + void MAGNUM_LOCAL * mapImplementationDefault(MapAccess access); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL * mapImplementationDSA(MapAccess access); + #endif + static MapImplementation mapImplementation; + + typedef void*(Buffer::*MapRangeImplementation)(GLintptr, GLsizeiptr, MapFlags); + void MAGNUM_LOCAL * mapRangeImplementationDefault(GLintptr offset, GLsizeiptr length, MapFlags access); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL * mapRangeImplementationDSA(GLintptr offset, GLsizeiptr length, MapFlags access); + #endif + static MapRangeImplementation mapRangeImplementation; + + typedef void(Buffer::*FlushMappedRangeImplementation)(GLintptr, GLsizeiptr); + void MAGNUM_LOCAL flushMappedRangeImplementationDefault(GLintptr offset, GLsizeiptr length); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL flushMappedRangeImplementationDSA(GLintptr offset, GLsizeiptr length); + #endif + static FlushMappedRangeImplementation flushMappedRangeImplementation; + + typedef bool(Buffer::*UnmapImplementation)(); + bool MAGNUM_LOCAL unmapImplementationDefault(); + #ifndef MAGNUM_TARGET_GLES + bool MAGNUM_LOCAL unmapImplementationDSA(); + #endif + static UnmapImplementation unmapImplementation; + GLuint _id; Target _targetHint; }; +CORRADE_ENUMSET_OPERATORS(Buffer::MapFlags) + } #endif From c6c659431b611be37b0732a62f65865c8c715f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 8 Jan 2013 23:48:55 +0100 Subject: [PATCH 131/567] Marked implemented extensions as such. Extension list is now something like internal TODO list. --- src/Context.cpp | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index d88b0bcb8..e7a74a533 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -69,126 +69,126 @@ const std::vector& Extension::extensions(Version version) { static const std::vector empty; #ifndef MAGNUM_TARGET_GLES static const std::vector extensions{ - _extension(GL,AMD,vertex_shader_layer), - _extension(GL,AMD,shader_trinary_minmax), - _extension(GL,EXT,texture_filter_anisotropic), + _extension(GL,AMD,vertex_shader_layer), // done + _extension(GL,AMD,shader_trinary_minmax), // done + _extension(GL,EXT,texture_filter_anisotropic), // done _extension(GL,EXT,direct_state_access), - _extension(GL,GREMEDY,string_marker)}; + _extension(GL,GREMEDY,string_marker)}; // done static const std::vector extensions300{ /** * @todo Remove as it doesn't have all functionality present in GL 3.0 * and leave only ARB_map_buffer_range? */ - _extension(GL,APPLE,flush_buffer_range), - _extension(GL,APPLE,vertex_array_object), - _extension(GL,ARB,map_buffer_range), // replaces APPLE_flush_buffer_range + _extension(GL,APPLE,flush_buffer_range), // done + _extension(GL,APPLE,vertex_array_object), // done + _extension(GL,ARB,map_buffer_range), // done, replaces APPLE_flush_buffer_range _extension(GL,ARB,color_buffer_float), - _extension(GL,ARB,half_float_pixel), - _extension(GL,ARB,texture_float), - _extension(GL,ARB,depth_buffer_float), - _extension(GL,ARB,texture_rg), + _extension(GL,ARB,half_float_pixel), // done + _extension(GL,ARB,texture_float), // done + _extension(GL,ARB,depth_buffer_float), // done + _extension(GL,ARB,texture_rg), // done /** * @todo Remove as it doesn't have the same functionality present in * GL 3.0 and replace with ARB_framebuffer_object? */ _extension(GL,EXT,framebuffer_object), - _extension(GL,EXT,packed_depth_stencil), - _extension(GL,EXT,framebuffer_blit), + _extension(GL,EXT,packed_depth_stencil), // done + _extension(GL,EXT,framebuffer_blit), // done _extension(GL,EXT,framebuffer_multisample), _extension(GL,EXT,gpu_shader4), - _extension(GL,EXT,packed_float), + _extension(GL,EXT,packed_float), // done _extension(GL,EXT,texture_array), - _extension(GL,EXT,texture_compression_rgtc), - _extension(GL,EXT,texture_shared_exponent), + _extension(GL,EXT,texture_compression_rgtc), // done + _extension(GL,EXT,texture_shared_exponent), // done _extension(GL,EXT,framebuffer_sRGB), _extension(GL,EXT,draw_buffers2), _extension(GL,EXT,texture_integer), _extension(GL,EXT,transform_feedback), - _extension(GL,NV,half_float), + _extension(GL,NV,half_float), // done _extension(GL,NV,depth_buffer_float), - _extension(GL,NV,conditional_render)}; + _extension(GL,NV,conditional_render)}; // done static const std::vector extensions310{ _extension(GL,ARB,texture_rectangle), _extension(GL,ARB,draw_instanced), _extension(GL,ARB,texture_buffer_object), _extension(GL,ARB,uniform_buffer_object), - _extension(GL,ARB,copy_buffer), - _extension(GL,EXT,texture_snorm), + _extension(GL,ARB,copy_buffer), // done + _extension(GL,EXT,texture_snorm), // done _extension(GL,NV,primitive_restart)}; static const std::vector extensions320{ _extension(GL,ARB,geometry_shader4), - _extension(GL,ARB,depth_clamp), + _extension(GL,ARB,depth_clamp), // done _extension(GL,ARB,draw_elements_base_vertex), - _extension(GL,ARB,fragment_coord_conventions), - _extension(GL,ARB,provoking_vertex), - _extension(GL,ARB,seamless_cube_map), + _extension(GL,ARB,fragment_coord_conventions), // done + _extension(GL,ARB,provoking_vertex), // done + _extension(GL,ARB,seamless_cube_map), // done _extension(GL,ARB,sync), _extension(GL,ARB,texture_multisample), - _extension(GL,ARB,vertex_array_bgra)}; + _extension(GL,ARB,vertex_array_bgra)}; // done static const std::vector extensions330{ _extension(GL,ARB,instanced_arrays), _extension(GL,ARB,blend_func_extended), - _extension(GL,ARB,explicit_attrib_location), - _extension(GL,ARB,occlusion_query2), + _extension(GL,ARB,explicit_attrib_location), // done + _extension(GL,ARB,occlusion_query2), // done _extension(GL,ARB,sampler_objects), - _extension(GL,ARB,shader_bit_encoding), - _extension(GL,ARB,texture_rgb10_a2ui), + _extension(GL,ARB,shader_bit_encoding), // done + _extension(GL,ARB,texture_rgb10_a2ui), // done _extension(GL,ARB,texture_swizzle), _extension(GL,ARB,timer_query), - _extension(GL,ARB,vertex_type_2_10_10_10_rev)}; + _extension(GL,ARB,vertex_type_2_10_10_10_rev)}; // done static const std::vector extensions400{ _extension(GL,ARB,draw_buffers_blend), _extension(GL,ARB,sample_shading), - _extension(GL,ARB,texture_cube_map_array), + _extension(GL,ARB,texture_cube_map_array), // done _extension(GL,ARB,texture_gather), - _extension(GL,ARB,texture_query_lod), + _extension(GL,ARB,texture_query_lod), // done _extension(GL,ARB,draw_indirect), _extension(GL,ARB,gpu_shader5), - _extension(GL,ARB,gpu_shader_fp64), + _extension(GL,ARB,gpu_shader_fp64), // done _extension(GL,ARB,shader_subroutine), _extension(GL,ARB,tessellation_shader), - _extension(GL,ARB,texture_buffer_object_rgb32), + _extension(GL,ARB,texture_buffer_object_rgb32), // done _extension(GL,ARB,transform_feedback2), _extension(GL,ARB,transform_feedback3)}; static const std::vector extensions410{ _extension(GL,ARB,ES2_compatibility), _extension(GL,ARB,get_program_binary), _extension(GL,ARB,separate_shader_objects), - _extension(GL,ARB,shader_precision), - _extension(GL,ARB,vertex_attrib_64bit), + _extension(GL,ARB,shader_precision), // done + _extension(GL,ARB,vertex_attrib_64bit), // done _extension(GL,ARB,viewport_array)}; static const std::vector extensions420{ - _extension(GL,ARB,texture_compression_bptc), + _extension(GL,ARB,texture_compression_bptc), // done _extension(GL,ARB,base_instance), - _extension(GL,ARB,shading_language_420pack), + _extension(GL,ARB,shading_language_420pack), // done _extension(GL,ARB,transform_feedback_instanced), _extension(GL,ARB,compressed_texture_pixel_storage), - _extension(GL,ARB,conservative_depth), + _extension(GL,ARB,conservative_depth), // done _extension(GL,ARB,internalformat_query), _extension(GL,ARB,map_buffer_alignment), _extension(GL,ARB,shader_atomic_counters), _extension(GL,ARB,shader_image_load_store), _extension(GL,ARB,texture_storage)}; static const std::vector extensions430{ - _extension(GL,ARB,arrays_of_arrays), + _extension(GL,ARB,arrays_of_arrays), // done _extension(GL,ARB,ES3_compatibility), _extension(GL,ARB,clear_buffer_object), _extension(GL,ARB,compute_shader), _extension(GL,ARB,copy_image), _extension(GL,KHR,debug), _extension(GL,ARB,explicit_uniform_location), - _extension(GL,ARB,fragment_layer_viewport), + _extension(GL,ARB,fragment_layer_viewport), // done _extension(GL,ARB,framebuffer_no_attachments), _extension(GL,ARB,internalformat_query2), _extension(GL,ARB,invalidate_subdata), _extension(GL,ARB,multi_draw_indirect), _extension(GL,ARB,program_interface_query), - _extension(GL,ARB,robust_buffer_access_behavior), - _extension(GL,ARB,shader_image_size), + _extension(GL,ARB,robust_buffer_access_behavior), // done + _extension(GL,ARB,shader_image_size), // done _extension(GL,ARB,shader_storage_buffer_object), _extension(GL,ARB,stencil_texturing), - _extension(GL,ARB,texture_buffer_range), - _extension(GL,ARB,texture_query_levels), + _extension(GL,ARB,texture_buffer_range), // done + _extension(GL,ARB,texture_query_levels), // done _extension(GL,ARB,texture_storage_multisample), _extension(GL,ARB,texture_view), _extension(GL,ARB,vertex_attrib_binding)}; From b400fb7766cecffb9bf56f9189f079fa5d88f53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 8 Jan 2013 23:53:10 +0100 Subject: [PATCH 132/567] ES 2.0 extension list is equivalent to GL 2.1 extension list -- empty. We assert that minimal OpenGL version is GL 2.1 / ES 2.0, thus there is no need for list of extensions implemented in these versions. --- src/Context.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index e7a74a533..dd1771115 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -195,7 +195,6 @@ const std::vector& Extension::extensions(Version version) { #undef _extension #else static const std::vector extensions; - static const std::vector extensionsES200; static const std::vector extensionsES300; #endif @@ -214,7 +213,7 @@ const std::vector& Extension::extensions(Version version) { /* case Version::GLES300: */ case Version::GL430: return extensions430; #else - case Version::GLES200: return extensionsES200; + case Version::GLES200: return empty; case Version::GLES300: return extensionsES300; #endif } From ae801ea945f27908b682d41df4bf39603697e082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 9 Jan 2013 01:03:15 +0100 Subject: [PATCH 133/567] OpenGL ES compilation fixes & workarounds. --- src/Buffer.cpp | 25 +++++++++++++++++++++++++ src/Buffer.h | 32 ++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index a812b6eb7..524a7b815 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -123,7 +123,13 @@ void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const #endif void* Buffer::mapImplementationDefault(MapAccess access) { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES return glMapBuffer(static_cast(bindInternal(_targetHint)), GLenum(access)); + #else + static_cast(access); + return nullptr; + #endif } #ifndef MAGNUM_TARGET_GLES @@ -133,7 +139,15 @@ void* Buffer::mapImplementationDSA(MapAccess access) { #endif void* Buffer::mapRangeImplementationDefault(GLintptr offset, GLsizeiptr length, MapFlags access) { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 return glMapBufferRange(static_cast(bindInternal(_targetHint)), offset, length, GLenum(access)); + #else + static_cast(offset); + static_cast(length); + static_cast(access); + return nullptr; + #endif } #ifndef MAGNUM_TARGET_GLES @@ -143,7 +157,13 @@ void* Buffer::mapRangeImplementationDSA(GLintptr offset, GLsizeiptr length, MapF #endif void Buffer::flushMappedRangeImplementationDefault(GLintptr offset, GLsizeiptr length) { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 glFlushMappedBufferRange(static_cast(bindInternal(_targetHint)), offset, length); + #else + static_cast(offset); + static_cast(length); + #endif } #ifndef MAGNUM_TARGET_GLES @@ -153,7 +173,12 @@ void Buffer::flushMappedRangeImplementationDSA(GLintptr offset, GLsizeiptr lengt #endif bool Buffer::unmapImplementationDefault() { + /** @todo Re-enable when extension wrangler is available for ES */ + #ifndef MAGNUM_TARGET_GLES2 return glUnmapBuffer(static_cast(bindInternal(_targetHint))); + #else + return false; + #endif } #ifndef MAGNUM_TARGET_GLES diff --git a/src/Buffer.h b/src/Buffer.h index 5f7bff8fe..215bea7b2 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -324,10 +324,10 @@ class MAGNUM_EXPORT Buffer { /** * Map buffer for writing only. */ - WriteOnly = GL_WRITE_ONLY - - #ifndef MAGNUM_TARGET_GLES - , + #ifdef MAGNUM_TARGET_GLES + WriteOnly = GL_WRITE_ONLY_OES + #else + WriteOnly = GL_WRITE_ONLY, /** * Map buffer for both reading and writing. @@ -347,35 +347,59 @@ class MAGNUM_EXPORT Buffer { */ enum class MapFlag: GLbitfield { /** Map buffer for reading. */ + #ifndef MAGNUM_TARGET_GLES2 Read = GL_MAP_READ_BIT, + #else + Read = GL_MAP_READ_BIT_EXT, + #endif /** Map buffer for writing. */ + #ifndef MAGNUM_TARGET_GLES2 Write = GL_MAP_WRITE_BIT, + #else + Write = GL_MAP_WRITE_BIT_EXT, + #endif /** * Previous contents of the entire buffer may be discarded. May * not be used in combination with @ref MapFlag "MapFlag::Read". */ + #ifndef MAGNUM_TARGET_GLES2 InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT, + #else + InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT_EXT, + #endif /** * Previous contents of mapped range may be discarded. May not * be used in combination with @ref MapFlag "MapFlag::Read". */ + #ifndef MAGNUM_TARGET_GLES2 InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT, + #else + InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT_EXT, + #endif /** * Only one or more discrete subranges of the mapping will be * modified. See flushMappedRange() for more information. May only * be used in conjuction with @ref MapFlag "MapFlag::Write". */ + #ifndef MAGNUM_TARGET_GLES2 FlushExplicit = GL_MAP_FLUSH_EXPLICIT_BIT, + #else + FlushExplicit = GL_MAP_FLUSH_EXPLICIT_BIT_EXT, + #endif /** * No pending operations on the buffer should be synchronized * before mapping. */ + #ifndef MAGNUM_TARGET_GLES2 Unsynchronized = GL_MAP_UNSYNCHRONIZED_BIT + #else + Unsynchronized = GL_MAP_UNSYNCHRONIZED_BIT_EXT + #endif }; /** From 3c347441e6e58843a88dc1bcb3414b9c4558f2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 9 Jan 2013 01:16:22 +0100 Subject: [PATCH 134/567] Ability to build Magnum for OpenGL ES emulated with desktop OpenGL. --- CMakeLists.txt | 10 ++++++++-- README.md | 3 +++ doc/building.dox | 14 +++++++++++--- modules/FindMagnum.cmake | 22 ++++++++++++++-------- src/CMakeLists.txt | 12 ++++++------ src/Platform/magnum-info.cpp | 3 +++ src/magnumConfigure.h.cmake | 3 ++- 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6753b6ec..ba6c5a807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ include(CMakeDependentOption) option(TARGET_GLES "Build for OpenGL ES instead of desktop OpenGL" OFF) cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF) +cmake_dependent_option(TARGET_DESKTOP_GLES "Build for OpenGL ES on desktop" OFF "TARGET_GLES" OFF) # Parts of the library option(WITH_EVERYTHING "Build everything (doesn't include *Application libraries)" ON) @@ -46,12 +47,14 @@ endif() # Check dependencies find_package(Corrade REQUIRED) -if(NOT TARGET_GLES) +if(NOT TARGET_GLES OR TARGET_DESKTOP_GLES) find_package(OpenGL REQUIRED) - find_package(GLEW REQUIRED) else() find_package(OpenGLES2 REQUIRED) endif() +if(NOT TARGET_GLES) + find_package(GLEW REQUIRED) +endif() # Configuration variables (saved later to corradeConfigure.h) if(TARGET_GLES) @@ -60,6 +63,9 @@ endif() if(TARGET_GLES2) set(MAGNUM_TARGET_GLES2 1) endif() +if(TARGET_DESKTOP_GLES) + set(MAGNUM_TARGET_DESKTOP_GLES 1) +endif() # Installation paths set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/README.md b/README.md index 067288410..5b378b3aa 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,9 @@ installed using these four commands: make make install +See Doxygen documentation for more information about enabling or disabling +additional features and targeting different platforms such as OpenGL ES. + Building and running unit tests ------------------------------- diff --git a/doc/building.dox b/doc/building.dox index 9d2d6ecda..863c405ad 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -55,9 +55,17 @@ If you want to build with another compiler (e.g. Clang), pass @subsection building-optional Enabling or disabling features -By default the engine is built for desktop OpenGL. If you want to target -OpenGL ES, set `TARGET_GLES` to `ON` or pass `-DTARGET_GLES=ON` to CMake. Note -that some features are available for desktop OpenGL only, see @ref requires-gl. +By default the engine is built for desktop OpenGL. Using `TARGET_*` CMake +parameters you can target other platforms: + + - `TARGET_GLES` - Target OpenGL ES. + - `TARGET_GLES2` - Target OpenGL ES 2.0. Currently enabled by default when + `TARGET_GLES` is set, as no customer OpenGL ES 3.0 platform exists yet. + - `TARGET_DESKTOP_GLES` - Target OpenGL ES on desktop, i.e. use OpenGL ES + emulation in desktop OpenGL library. Might not be supported in all drivers. + +Note that some features are available for desktop OpenGL only, see +@ref requires-gl. By default the engine is built with everything except @ref Platform "application libraries". Using `WITH_*` CMake parameters you can diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 9f2e0e138..8a5ed0983 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -85,13 +85,19 @@ string(FIND "${_magnumConfigure}" "#define MAGNUM_TARGET_NACL" _TARGET_NACL) if(NOT _TARGET_NACL EQUAL -1) set(MAGNUM_TARGET_NACL 1) endif() +string(FIND "${_magnumConfigure}" "#define MAGNUM_TARGET_DESKTOP_GLES" _TARGET_DESKTOP_GLES) +if(NOT _TARGET_DESKTOP_GLES EQUAL -1) + set(MAGNUM_TARGET_DESKTOP_GLES 1) +endif() -if(NOT MAGNUM_TARGET_GLES) +if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES) find_package(OpenGL REQUIRED) - find_package(GLEW REQUIRED) else() find_package(OpenGLES2 REQUIRED) endif() +if(NOT MAGNUM_TARGET_GLES) + find_package(GLEW REQUIRED) +endif() # On Windows, *Application libraries need to have ${MAGNUM_LIBRARY} listed # in dependencies also after *Application.lib static library name to avoid @@ -242,13 +248,13 @@ set(MAGNUM_INCLUDE_DIRS ${MAGNUM_INCLUDE_DIR} set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) -if(NOT MAGNUM_TARGET_GLES) - set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} - ${OPENGL_gl_LIBRARY} - ${GLEW_LIBRARY}) +if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES) + set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${OPENGL_gl_LIBRARY}) else() - set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} - ${OPENGLES2_LIBRARY}) + set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${OPENGLES2_LIBRARY}) +endif() +if(NOT MAGNUM_TARGET_GLES) + set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${GLEW_LIBRARY}) endif() # Installation dirs diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48cbbc1b7..bc04c2ab8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -119,13 +119,13 @@ add_library(Magnum SHARED set(Magnum_LIBS ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) -if(NOT TARGET_GLES) - set(Magnum_LIBS ${Magnum_LIBS} - ${OPENGL_gl_LIBRARY} - ${GLEW_LIBRARY}) +if(NOT TARGET_GLES OR TARGET_DESKTOP_GLES) + set(Magnum_LIBS ${Magnum_LIBS} ${OPENGL_gl_LIBRARY}) else() - set(Magnum_LIBS ${Magnum_LIBS} - ${OPENGLES2_LIBRARY}) + set(Magnum_LIBS ${Magnum_LIBS} ${OPENGLES2_LIBRARY}) +endif() +if(NOT TARGET_GLES) + set(Magnum_LIBS ${Magnum_LIBS} ${GLEW_LIBRARY}) endif() target_link_libraries(Magnum ${Magnum_LIBS}) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 0cd691d6c..2ad9c5b53 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -47,6 +47,9 @@ MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, a #ifdef MAGNUM_TARGET_GLES2 d << "MAGNUM_TARGET_GLES2"; #endif + #ifdef MAGNUM_TARGET_DESKTOP_GLES + d << "MAGNUM_TARGET_DESKTOP_GLES"; + #endif #ifdef MAGNUM_TARGET_NACL d << "MAGNUM_TARGET_NACL"; #endif diff --git a/src/magnumConfigure.h.cmake b/src/magnumConfigure.h.cmake index 5738c3961..18f0ef842 100644 --- a/src/magnumConfigure.h.cmake +++ b/src/magnumConfigure.h.cmake @@ -1,3 +1,4 @@ -#cmakedefine MAGNUM_TARGET_NACL #cmakedefine MAGNUM_TARGET_GLES #cmakedefine MAGNUM_TARGET_GLES2 +#cmakedefine MAGNUM_TARGET_DESKTOP_GLES +#cmakedefine MAGNUM_TARGET_NACL From cdb8893e7b8445ac83c896ce5f9002144df289f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 9 Jan 2013 01:47:23 +0100 Subject: [PATCH 135/567] Added all currently supported OpenGL ES extensions to the list. --- src/Context.cpp | 41 ++++++++++++++++++++++++++++++++++-- src/Extensions.h | 54 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index dd1771115..5bdba1420 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -194,8 +194,45 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,vertex_attrib_binding)}; #undef _extension #else - static const std::vector extensions; - static const std::vector extensionsES300; + static const std::vector extensions{ + _extension(GL,APPLE,texture_format_BGRA8888), + _extension(GL,EXT,texture_filter_anisotropic), + _extension(GL,EXT,texture_format_BGRA8888), + _extension(GL,EXT,read_format_bgra), + _extension(GL,EXT,debug_marker), + _extension(GL,EXT,separate_shader_objects), + _extension(GL,EXT,sRGB), + _extension(GL,NV,read_buffer_front), + _extension(GL,NV,read_stencil), + _extension(GL,OES,depth32), + _extension(GL,OES,mapbuffer), + _extension(GL,OES,stencil1), + _extension(GL,OES,stencil4), + _extension(GL,OES,texture_3D)}; + static const std::vector extensionsES300{ + _extension(GL,ANGLE,framebuffer_blit), + _extension(GL,APPLE,framebuffer_multisample), + _extension(GL,ARM,rgba8), + _extension(GL,EXT,texture_type_2_10_10_10_REV), + _extension(GL,EXT,blend_minmax), + _extension(GL,EXT,occlusion_query_boolean), + _extension(GL,EXT,texture_rg), + _extension(GL,EXT,map_buffer_range), + _extension(GL,NV,draw_buffers), + _extension(GL,NV,read_buffer), + _extension(GL,NV,read_depth), + _extension(GL,NV,read_depth_stencil), + _extension(GL,OES,depth24), + _extension(GL,OES,rgb8_rgba8), + _extension(GL,OES,texture_half_float_linear), + _extension(GL,OES,texture_float_linear), + _extension(GL,OES,texture_half_float), + _extension(GL,OES,texture_float), + _extension(GL,OES,vertex_half_float), + _extension(GL,OES,packed_depth_stencil), + _extension(GL,OES,depth_texture), + _extension(GL,OES,vertex_array_object), + _extension(GL,OES,required_internalformat)}; #endif switch(version) { diff --git a/src/Extensions.h b/src/Extensions.h index 2ec893dd1..75cad8bf2 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -41,7 +41,6 @@ example usage. */ namespace Extensions { -#ifndef MAGNUM_TARGET_GLES #ifndef DOXYGEN_GENERATING_OUTPUT #define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \ struct extension { \ @@ -54,6 +53,7 @@ namespace Extensions { /* IMPORTANT: don't forget to add new extensions also in Context.cpp */ namespace GL { + #ifndef MAGNUM_TARGET_GLES #line 1 namespace AMD { _extension(GL,AMD,vertex_shader_layer, GL210, None) // #417 @@ -173,13 +173,57 @@ namespace GL { _extension(GL,NV,conditional_render, GL210, GL300) // #346 /* NV_draw_texture not supported */ // #430 } + /* IMPORTANT: if this line is > 188 (57 + size), don't forget to update array size in Context.h */ + #else + #line 1 + namespace ANGLE { + _extension(GL,ANGLE,framebuffer_blit, GLES200, GLES300) // #83 + } namespace APPLE { + _extension(GL,APPLE,framebuffer_multisample, GLES200, GLES300) // #78 + _extension(GL,APPLE,texture_format_BGRA8888, GLES200, None) // #79 + } namespace ARM { + _extension(GL,ARM,rgba8, GLES200, GLES300) // #82 + } namespace EXT { + _extension(GL,EXT,texture_filter_anisotropic, GLES200, None) // #41 + _extension(GL,EXT,texture_type_2_10_10_10_REV, GLES200, GLES300) // #42 + _extension(GL,EXT,texture_format_BGRA8888, GLES200, None) // #51 + _extension(GL,EXT,blend_minmax, GLES200, GLES300) // #65 + _extension(GL,EXT,read_format_bgra, GLES200, None) // #66 + _extension(GL,EXT,debug_marker, GLES200, None) // #99 + _extension(GL,EXT,occlusion_query_boolean, GLES200, GLES300) // #100 + _extension(GL,EXT,separate_shader_objects, GLES200, None) // #101 + _extension(GL,EXT,texture_rg, GLES200, GLES300) // #103 + _extension(GL,EXT,sRGB, GLES200, None) // #105 + _extension(GL,EXT,map_buffer_range, GLES200, GLES300) // #121 + } namespace NV { + _extension(GL,NV,draw_buffers, GLES200, GLES300) // #91 + _extension(GL,NV,read_buffer, GLES200, GLES300) // #93 + _extension(GL,NV,read_buffer_front, GLES200, None) // #93 + _extension(GL,NV,read_depth, GLES200, GLES300) // #94 + _extension(GL,NV,read_stencil, GLES200, None) // #94 + _extension(GL,NV,read_depth_stencil, GLES200, GLES300) // #94 + } namespace OES { + _extension(GL,OES,depth24, GLES200, GLES300) // #24 + _extension(GL,OES,depth32, GLES200, None) // #25 + _extension(GL,OES,mapbuffer, GLES200, None) // #29 + _extension(GL,OES,rgb8_rgba8, GLES200, GLES300) // #30 + _extension(GL,OES,stencil1, GLES200, None) // #31 + _extension(GL,OES,stencil4, GLES200, None) // #32 + _extension(GL,OES,texture_3D, GLES200, None) // #34 + _extension(GL,OES,texture_half_float_linear, GLES200, GLES300) // #35 + _extension(GL,OES,texture_float_linear, GLES200, GLES300) // #35 + _extension(GL,OES,texture_half_float, GLES200, GLES300) // #36 + _extension(GL,OES,texture_float, GLES200, GLES300) // #36 + _extension(GL,OES,vertex_half_float, GLES200, GLES300) // #38 + _extension(GL,OES,packed_depth_stencil, GLES200, GLES300) // #43 + _extension(GL,OES,depth_texture, GLES200, GLES300) // #44 + _extension(GL,OES,vertex_array_object, GLES200, GLES300) // #71 + _extension(GL,OES,required_internalformat, GLES200, GLES300) // #? + } + #endif } - -/* IMPORTANT: if this line is > 185 (54 + size), don't forget to update array size in Context.h */ - #undef _extension #endif -#endif } From 3f727b4abc761c07c3b62ae849b461c335019a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 9 Jan 2013 01:48:38 +0100 Subject: [PATCH 136/567] Doc: fixed a few issues with OpenGL ES extensions. --- src/AbstractImage.h | 8 ++++---- src/AbstractTexture.h | 21 +++++++++++++++++++-- src/DefaultFramebuffer.h | 2 +- src/IndexedMesh.h | 3 ++- src/Mesh.h | 10 ++++++---- src/Renderbuffer.h | 2 +- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 8eb821569..0ab1fd61c 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -111,9 +111,9 @@ class MAGNUM_EXPORT AbstractImage { /** * Floating-point BGRA. - * @requires_es_extension %Extension @es_extension{EXT,read_format_bgra}, - * for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888} - * for texture data. + * @requires_es_extension %Extension @es_extension{EXT,read_format_bgra} + * for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888} or + * @es_extension{EXT,texture_format_BGRA8888} for texture data. */ #ifndef MAGNUM_TARGET_GLES BGRA = GL_BGRA, @@ -268,7 +268,7 @@ class MAGNUM_EXPORT AbstractImage { /** * Each component half float. For framebuffer reading only. * @requires_gl30 %Extension @extension{NV,half_float} / @extension{ARB,half_float_pixel} - * @requires_gles30 %Extension @es_extension{OES,texture_float}, + * @requires_gles30 %Extension @es_extension2{OES,texture_half_float,OES_texture_float}, * for texture data only. */ #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 5dd689f48..7425e1ac8 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -72,7 +72,17 @@ class MAGNUM_EXPORT AbstractTexture { */ enum class Filter: GLint { NearestNeighbor = GL_NEAREST, /**< Nearest neighbor filtering */ - LinearInterpolation = GL_LINEAR /**< Linear interpolation filtering */ + + /** + * Linear interpolation filtering. + * @requires_gles30 %Extension @es_extension{OES,texture_float_linear} / + * @es_extension2{OES,texture_half_float_linear,OES_texture_float_linear} + * for linear interpolation of textures with + * @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::HalfFloat" + * / @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::Float" + * in OpenGL ES 2.0. + */ + LinearInterpolation = GL_LINEAR }; /** @@ -91,6 +101,12 @@ class MAGNUM_EXPORT AbstractTexture { /** * Linear interpolation of nearest mip levels. **Unavailable on * rectangle textures.** + * @requires_gles30 %Extension @es_extension{OES,texture_float_linear} / + * @es_extension2{OES,texture_half_float_linear,OES_texture_float_linear} + * for linear interpolation of textures with + * @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::HalfFloat" + * / @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::Float" + * in OpenGL ES 2.0. */ LinearInterpolation = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST }; @@ -622,6 +638,7 @@ class MAGNUM_EXPORT AbstractTexture { /** * RGB, each component normalized unsigned 10bit. * @requires_es_extension %Extension @es_extension{OES,required_internalformat} + * and @es_extension{EXT,texture_type_2_10_10_10_REV} */ #ifndef MAGNUM_TARGET_GLES RGB10 = GL_RGB10, @@ -904,7 +921,7 @@ class MAGNUM_EXPORT AbstractTexture { /** * Depth component, 32bit. * @requires_es_extension %Extension @es_extension{OES,required_internalformat}, - * @es_extension{OES,depth_texture} and @es_extension{OES,depth24} + * @es_extension{OES,depth_texture} and @es_extension{OES,depth32} */ #ifndef MAGNUM_TARGET_GLES2 DepthComponent32 = GL_DEPTH_COMPONENT32, diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 4262fe6a4..3804931d6 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -186,7 +186,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { /** * Read from front framebuffer. - * @requires_es_extension %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} + * @requires_es_extension %Extension @es_extension2{NV,read_buffer_front,GL_NV_read_buffer} */ Front = GL_FRONT diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index d801255e6..eb051811d 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -62,7 +62,8 @@ From user point-of-view the operation is the same as for @section IndexedMesh-performance-optimization Performance optimizations -If @extension{APPLE,vertex_array_object} is supported, next to +If @extension{APPLE,vertex_array_object}, OpenGL ES 3.0 or +@es_extension{OES,vertex_array_object} on OpenGL ES 2.0 is supported, next to @ref Mesh-performance-optimization "optimizations in Mesh itself" the index buffer is bound on object construction instead of binding it in every draw() call. diff --git a/src/Mesh.h b/src/Mesh.h index 1b918a814..d802e41df 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -102,10 +102,11 @@ for more infromation) and call Mesh::draw(). @section Mesh-performance-optimization Performance optimizations -If @extension{APPLE,vertex_array_object} is supported, VAOs are used instead -of binding the buffers and specifying vertex attribute pointers in each -draw() call. The engine tracks currently bound VAO to avoid unnecessary calls -to @fn_gl{BindVertexArray}. +If @extension{APPLE,vertex_array_object}, OpenGL ES 3.0 or +@es_extension{OES,vertex_array_object} on OpenGL ES 2.0 is supported, VAOs are +used instead of binding the buffers and specifying vertex attribute pointers +in each draw() call. The engine tracks currently bound VAO to avoid +unnecessary calls to @fn_gl{BindVertexArray}. If extension @extension{EXT,direct_state_access} and VAOs are available, DSA functions are used for specifying attribute locations to avoid unnecessary @@ -113,6 +114,7 @@ calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for more information. +@see IndexedMesh @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. @todo Allow unbinding all vertex buffers with some function (not as side effect), diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 10cc29f95..54b1d3a50 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -117,7 +117,7 @@ class MAGNUM_EXPORT Renderbuffer { /** * RGBA, each component normalized unsigned byte. * @requires_gles30 %Extension @es_extension{ARM,rgba8} or - * @es_extension{OES,required_internalformat} and @es_extension{OES,rgb8_rgba8} + * @es_extension{OES,rgb8_rgba8} */ #ifndef MAGNUM_TARGET_GLES2 RGBA8 = GL_RGBA8, From aef9b16c623f1b84918d89e5d869dfc0708a3e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 10 Jan 2013 20:06:52 +0100 Subject: [PATCH 137/567] Don't allow removing vertex/index buffer from meshes. Would cause weird issues with state, it's better to just not allow it and follow KISS principle than trying to implementing it. Also crosslinked required function calls in documentation. --- src/IndexedMesh.cpp | 3 +-- src/IndexedMesh.h | 19 +++++++------------ src/Mesh.cpp | 7 ------- src/Mesh.h | 23 +++++++++++------------ 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 2a09a70b6..e6527bf78 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -67,8 +67,7 @@ void IndexedMesh::bindIndexBufferImplementationDefault() {} void IndexedMesh::bindIndexBufferImplementationVAO() { bindVAO(vao); - if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); - else Buffer::unbind(Buffer::Target::ElementArray); + _indexBuffer->bind(Buffer::Target::ElementArray); } void IndexedMesh::bindIndexedImplementationDefault() { diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index eb051811d..80e390346 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -76,22 +76,17 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @brief Constructor * @param primitive Primitive type * - * Creates indexed mesh with no index buffer, zero vertex count and - * zero index count. - * @see setPrimitive(), setVertexCount(), setIndexBuffer(), - * setIndexCount(), setIndexType() + * Creates indexed mesh with zero vertex count, zero index count and + * no vertex or index buffers. */ inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(Type::UnsignedShort) {} /** * @brief Set index buffer * - * By default there is no index buffer. Parameter @p buffer can be - * `nullptr`, in that case current index buffer is unbound from the - * mesh. - * @see MeshTools::compressIndices(), @fn_gl{BindVertexArray}, - * @fn_gl{BindBuffer} (if @extension{APPLE,vertex_array_object} - * is available) + * @see setIndexCount(), setIndexType(), MeshTools::compressIndices(), + * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if + * @extension{APPLE,vertex_array_object} is available) */ IndexedMesh* setIndexBuffer(Buffer* buffer); @@ -103,7 +98,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @return Pointer to self (for method chaining) * * Default is zero. - * @see MeshTools::compressIndices() + * @see setIndexBuffer(), setIndexType(), MeshTools::compressIndices() */ inline IndexedMesh* setIndexCount(GLsizei count) { _indexCount = count; @@ -118,7 +113,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @return Pointer to self (for method chaining) * * Default is @ref Type "Type::UnsignedShort". - * @see MeshTools::compressIndices() + * @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices() */ inline IndexedMesh* setIndexType(Type type) { _indexType = type; diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 32dde612a..d069132cb 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -77,13 +77,6 @@ Mesh& Mesh::operator=(Mesh&& other) { Mesh* Mesh::setVertexCount(GLsizei vertexCount) { _vertexCount = vertexCount; - attributes.clear(); - #ifndef MAGNUM_TARGET_GLES2 - integerAttributes.clear(); - #ifndef MAGNUM_TARGET_GLES - longAttributes.clear(); - #endif - #endif return this; } diff --git a/src/Mesh.h b/src/Mesh.h index d802e41df..9d88de758 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -117,8 +117,6 @@ more information. @see IndexedMesh @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. -@todo Allow unbinding all vertex buffers with some function (not as side effect), - similarly to unbinding index buffer in IndexedMesh */ class MAGNUM_EXPORT Mesh { friend class IndexedMesh; @@ -394,6 +392,8 @@ class MAGNUM_EXPORT Mesh { * @return Pointer to self (for method chaining) * * Default is @ref Primitive "Primitive::Triangles". + * @see setVertexCount(), addVertexBuffer(), + * addInterleavedVertexBuffer(), addVertexBufferStride() */ inline Mesh* setPrimitive(Primitive primitive) { _primitive = primitive; @@ -408,11 +408,8 @@ class MAGNUM_EXPORT Mesh { * @return Pointer to self (for method chaining) * * Default is zero. - * @attention All bound attributes are reset after calling this - * function, so if your mesh has any vertex attributes, be sure - * to call addVertexBuffer()/addInterleavedVertexBuffer() - * afterwards. - * @see MeshTools::interleave() + * @see setPrimitive(), addVertexBuffer(), addInterleavedVertexBuffer(), + * addVertexBufferStride(), MeshTools::interleave() */ Mesh* setVertexCount(GLsizei vertexCount); @@ -457,8 +454,9 @@ class MAGNUM_EXPORT Mesh { * mesh and delete it afterwards. * * @see addInterleavedVertexBuffer(), addVertexBufferStride(), - * @fn_gl{BindVertexArray}, @fn_gl{EnableVertexAttribArray}, - * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer} or + * setPrimitive(), setVertexCount(), @fn_gl{BindVertexArray}, + * @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, + * @fn_gl{VertexAttribPointer} or * @fn_gl_extension{EnableVertexArrayAttrib,EXT,direct_state_access}, * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} * if @extension{APPLE,vertex_array_object} is available @@ -520,9 +518,10 @@ class MAGNUM_EXPORT Mesh { * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. * - * @see addVertexBufferStride(), addVertexBuffer(), - * @fn_gl{BindVertexArray}, @fn_gl{EnableVertexAttribArray}, - * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer} or + * @see addVertexBufferStride(), addVertexBuffer(), setPrimitive(), + * setVertexCount(), @fn_gl{BindVertexArray}, + * @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, + * @fn_gl{VertexAttribPointer} or * @fn_gl_extension{EnableVertexArrayAttrib,EXT,direct_state_access}, * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} * if @extension{APPLE,vertex_array_object} is available From 90ba19b601e7c19b387ff714df64d36abae9b845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 11 Jan 2013 22:39:17 +0100 Subject: [PATCH 138/567] Doc: copypasta error. --- src/Renderbuffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 54b1d3a50..35df11a25 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -54,7 +54,7 @@ class MAGNUM_EXPORT Renderbuffer { /** * @brief Internal format * - * @see @ref Texture::setData() "setData()" + * @see setStorage() * @todo RGB, RGB8 ES only (ES3 + @es_extension{OES,rgb8_rgba8}) */ enum class InternalFormat: GLenum { From fdded7281d2bade01c4509cfb6e3bf1329ffbbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 11 Jan 2013 22:41:42 +0100 Subject: [PATCH 139/567] Renamed *Texture::set*Data() to set*Image(). Better consistency with OpenGL naming. --- src/AbstractImage.h | 2 +- src/AbstractTexture.cpp | 52 +++++++++++++++++------------------ src/AbstractTexture.h | 58 +++++++++++++++++++-------------------- src/CubeMapTexture.h | 16 +++++------ src/CubeMapTextureArray.h | 49 ++++++++++++++++----------------- src/Text/Font.cpp | 2 +- src/Texture.h | 39 +++++++++++++------------- 7 files changed, 109 insertions(+), 109 deletions(-) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 0ab1fd61c..dfbfbaf65 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -45,7 +45,7 @@ class MAGNUM_EXPORT AbstractImage { * * Note that some formats can be used only for framebuffer reading * (using Framebuffer::read()) and some only for texture data (using - * Texture::setData() and others). + * Texture::setImage() and others). */ /** diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index cd8cd661c..6f07fd02e 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -248,35 +248,35 @@ void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat glTextureParameterfvEXT(_id, _target, parameter, values); } -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexImage1D(target, mipLevel, static_cast(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); + glTexImage1D(target, level, static_cast(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); } -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { - glTextureImage1DEXT(_id, target, mipLevel, GLint(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); +void AbstractTexture::imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureImage1DEXT(_id, target, level, GLint(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexImage2D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(format), static_cast(type), data); + glTexImage2D(target, level, GLint(internalFormat), size.x(), size.y(), 0, static_cast(format), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { - glTextureImage2DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), 0, static_cast(format), static_cast(type), data); +void AbstractTexture::imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureImage2DEXT(_id, target, level, GLint(internalFormat), size.x(), size.y(), 0, static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { +void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glTexImage3D(target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(format), static_cast(type), data); + glTexImage3D(target, level, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(format), static_cast(type), data); #else static_cast(target); - static_cast(mipLevel); + static_cast(level); static_cast(internalFormat); static_cast(size); static_cast(format); @@ -286,41 +286,41 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint mipLevel, } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { - glTextureImage3DEXT(_id, target, mipLevel, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(format), static_cast(type), data); +void AbstractTexture::imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureImage3DEXT(_id, target, level, GLint(internalFormat), size.x(), size.y(), size.z(), 0, static_cast(format), static_cast(type), data); } #endif #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexSubImage1D(target, mipLevel, offset[0], size[0], static_cast(format), static_cast(type), data); + glTexSubImage1D(target, level, offset[0], size[0], static_cast(format), static_cast(type), data); } -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { - glTextureSubImage1DEXT(_id, target, mipLevel, offset[0], size[0], static_cast(format), static_cast(type), data); +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureSubImage1DEXT(_id, target, level, offset[0], size[0], static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint level, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); - glTexSubImage2D(target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); + glTexSubImage2D(target, level, offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { - glTextureSubImage2DEXT(_id, target, mipLevel, offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint level, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureSubImage2DEXT(_id, target, level, offset.x(), offset.y(), size.x(), size.y(), static_cast(format), static_cast(type), data); } #endif -void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { +void AbstractTexture::subImageImplementationDefault(GLenum target, GLint level, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); /** @todo Get some extension wrangler instead to avoid linker errors to glTexSubImage3D() on ES2 */ #ifndef MAGNUM_TARGET_GLES2 - glTexSubImage3D(target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(format), static_cast(type), data); + glTexSubImage3D(target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(format), static_cast(type), data); #else static_cast(target); - static_cast(mipLevel); + static_cast(level); static_cast(offset); static_cast(size); static_cast(format); @@ -330,8 +330,8 @@ void AbstractTexture::subImageImplementationDefault(GLenum target, GLint mipLeve } #ifndef MAGNUM_TARGET_GLES -void AbstractTexture::subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { - glTextureSubImage3DEXT(_id, target, mipLevel, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(format), static_cast(type), data); +void AbstractTexture::subImageImplementationDSA(GLenum target, GLint level, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { + glTextureSubImage3DEXT(_id, target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), static_cast(format), static_cast(type), data); } #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 7425e1ac8..7c2b96cc8 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -145,7 +145,7 @@ class MAGNUM_EXPORT AbstractTexture { /** * @brief Internal format * - * @see @ref Texture::setData() "setData()" + * @see @ref Texture::setImage() "setImage()" */ enum class InternalFormat: GLint { /** @@ -1175,36 +1175,36 @@ class MAGNUM_EXPORT AbstractTexture { #ifndef MAGNUM_TARGET_GLES typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static Image1DImplementation image1DImplementation; #endif typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static Image2DImplementation image2DImplementation; typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); - void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); - void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static Image3DImplementation image3DImplementation; #ifndef MAGNUM_TARGET_GLES typedef void(AbstractTexture::*SubImage1DImplementation)(GLenum, GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage1DImplementation subImage1DImplementation; #endif typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint level, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint level, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage2DImplementation subImage2DImplementation; typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); - void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); - void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint mipLevel, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint level, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint level, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); static SubImage3DImplementation subImage3DImplementation; void MAGNUM_LOCAL destroy(); @@ -1226,12 +1226,12 @@ template<> struct AbstractTexture::DataHelper<1> { (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); } - template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - (texture->*image1DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { + (texture->*image1DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, Image* image) { - (texture->*subImage1DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Math::Vector<1, GLint>& offset, Image* image) { + (texture->*subImage1DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); } }; #endif @@ -1249,16 +1249,16 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { static void setWrapping(AbstractTexture* texture, const Array2D& wrapping); - template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - (texture->*image2DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { + (texture->*image2DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) { - (texture->*subImage2DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector2i& offset, Image* image) { + (texture->*subImage2DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector2i& offset, Image* image) { - (texture->*subImage2DImplementation)(target, mipLevel, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector2i& offset, Image* image) { + (texture->*subImage2DImplementation)(target, level, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data()); } }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { @@ -1275,16 +1275,16 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { static void setWrapping(AbstractTexture* texture, const Array3D& wrapping); - template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint mipLevel, InternalFormat internalFormat, Image* image) { - (texture->*image3DImplementation)(target, mipLevel, internalFormat, image->size(), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { + (texture->*image3DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) { - (texture->*subImage3DImplementation)(target, mipLevel, offset, image->size(), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector3i& offset, Image* image) { + (texture->*subImage3DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); } - template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint mipLevel, const Vector3i& offset, Image* image) { - (texture->*subImage3DImplementation)(target, mipLevel, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data()); + template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector3i& offset, Image* image) { + (texture->*subImage3DImplementation)(target, level, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data()); } }; #endif diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index e53fa92ba..f2e9e60ee 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -51,8 +51,8 @@ Image2D positiveX({256, 256}, Image2D::Components::RGBA, Image2D::ComponentType: CubeMapTexture texture; texture.setMagnificationFilter(Texture2D::Filter::Linear) // ... - ->setData(CubeMapTexture::Coordinate::PositiveX, 0, Texture2D::Format::RGBA8, &positiveX) - ->setData(CubeMapTexture::Coordinate::NegativeX, 0, Texture2D::Format::RGBA8, &negativeX) + ->setImage(CubeMapTexture::Coordinate::PositiveX, 0, Texture2D::Format::RGBA8, &positiveX) + ->setImage(CubeMapTexture::Coordinate::NegativeX, 0, Texture2D::Format::RGBA8, &negativeX) // ... @endcode @@ -108,22 +108,22 @@ class CubeMapTexture: public AbstractTexture { } /** - * @copydoc Texture::setData(GLint, InternalFormat, Image*) + * @copydoc Texture::setImage(GLint, InternalFormat, Image*) * @param coordinate Coordinate * @return Pointer to self (for method chaining) */ - template inline CubeMapTexture* setData(Coordinate coordinate, GLint mipLevel, InternalFormat internalFormat, Image* image) { - DataHelper<2>::set(this, static_cast(coordinate), mipLevel, internalFormat, image); + template inline CubeMapTexture* setImage(Coordinate coordinate, GLint level, InternalFormat internalFormat, Image* image) { + DataHelper<2>::set(this, static_cast(coordinate), level, internalFormat, image); return this; } /** - * @copydoc Texture::setSubData(GLint, const typename DimensionTraits::VectorType&, Image*) + * @copydoc Texture::setSubImage(GLint, const typename DimensionTraits::VectorType&, Image*) * @param coordinate Coordinate * @return Pointer to self (for method chaining) */ - template inline CubeMapTexture* setSubData(Coordinate coordinate, GLint mipLevel, const Vector2i& offset, const Image* image) { - DataHelper<2>::setSub(this, static_cast(coordinate), mipLevel, offset, image); + template inline CubeMapTexture* setSubImage(Coordinate coordinate, GLint level, const Vector2i& offset, const Image* image) { + DataHelper<2>::setSub(this, static_cast(coordinate), level, offset, image); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index ef5fe0124..9c8270233 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -33,9 +33,9 @@ See CubeMapTexture documentation for introduction. @section CubeMapTextureArray-usage Usage -Common usage is to specify each layer and face separately using setSubData(). +Common usage is to specify each layer and face separately using setSubImage(). You have to allocate the memory for all layers and faces first, possibly by -passing properly sized empty Image to setData(). Example: array with 16 +passing properly sized empty Image to setImage(). Example: array with 16 layers of cube map faces, each face consisting of six 64x64 images: @code Image3D dummy({64, 64, 16*6}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, nullptr); @@ -43,15 +43,15 @@ Image3D dummy({64, 64, 16*6}, Image3D::Components::RGBA, Image3D::ComponentType: CubeMapTextureArray texture; texture.setMagnificationFilter(CubeMapTextureArray::Filter::Linear) // ... - ->setData(0, CubeMapTextureArray::Format::RGBA8, &dummy); + ->setImage(0, CubeMapTextureArray::Format::RGBA8, &dummy); for(std::size_t i = 0; i != 16; ++i) { void* dataPositiveX = ...; Image2D imagePositiveX({64, 64}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, imagePositiveX); // ... - texture->setSubData(i, CubeMapTextureArray::Coordinate::PositiveX, 0, imagePositiveX); - texture->setSubData(i, CubeMapTextureArray::Coordinate::NegativeX, 0, imageNegativeX); + texture->setSubImage(i, CubeMapTextureArray::Coordinate::PositiveX, 0, imagePositiveX); + texture->setSubImage(i, CubeMapTextureArray::Coordinate::NegativeX, 0, imageNegativeX); // ... } @@ -98,57 +98,56 @@ class CubeMapTextureArray: public AbstractTexture { } /** - * @copydoc Texture::setData(GLint, InternalFormat, Image*) + * @copydoc Texture::setImage(GLint, InternalFormat, Image*) * - * Sets texture data from three-dimensional image for all cube faces - * for all layers. Each group of 6 2D images is one cube map layer. - * The images are ordered the same way as Coordinate enum. + * Sets texture image data from three-dimensional image for all cube + * faces for all layers. Each group of 6 2D images is one cube map + * layer. The images are ordered the same way as Coordinate enum. */ - template inline CubeMapTextureArray* setData(GLint mipLevel, InternalFormat internalFormat, T* image) { - DataHelper<3>::set(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, internalFormat, image); + template inline CubeMapTextureArray* setImage(GLint level, InternalFormat internalFormat, T* image) { + DataHelper<3>::set(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, internalFormat, image); return this; } /** - * @brief Set texture subdata from 3D image - * @param mipLevel Mip level + * @brief Set texture image 3D subdata + * @param level Mip level * @param offset Offset where to put data in the texture * @param image Image3D, ImageWrapper3D, BufferImage3D or * Trade::ImageData3D * @return Pointer to self (for method chaining) * - * Sets texture subdata from given image. The image is not deleted - * afterwards. + * Sets texture image subdata for more than one level/face at once. + * The image is not deleted afterwards. * * Z coordinate of @p offset specifies layer and cube map face. If * you want to start at given face in layer *n*, you have to specify * Z coordinate as @f$ 6n + i @f$, where i is face index as specified * in Coordinate enum. * - * @see setSubData(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) + * @see setSubImage(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ - template inline CubeMapTextureArray* setSubData(GLint mipLevel, const Vector3i& offset, const Image* image) { - DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, offset, image, Vector3i(Math::Vector())); + template inline CubeMapTextureArray* setSubImage(GLint level, const Vector3i& offset, const Image* image) { + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, offset, image, Vector3i(Math::Vector())); return this; } /** - * @brief Set texture subdata from 2D image + * @brief Set texture image 2D subdata * @param layer Array layer * @param coordinate Coordinate - * @param mipLevel Mip level + * @param level Mip level * @param offset Offset where to put data in the texture * @param image Image2D, ImageWrapper2D, BufferImage2D or * Trade::ImageData2D * @return Pointer to self (for method chaining) * - * Sets texture subdata from given image. The image is not deleted - * afterwards. + * The image is not deleted afterwards. * - * @see setSubData(GLint, const Math::Vector<3, GLint>&, const Image*) + * @see setSubImage(GLint, const Math::Vector<3, GLint>&, const Image*) */ - template inline CubeMapTextureArray* setSubData(GLsizei layer, Coordinate coordinate, GLint mipLevel, const Vector2i& offset, const Image* image) { - DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, mipLevel, Vector3i(offset, layer*6+static_cast(coordinate)), image, Vector2i(Math::Vector())); + template inline CubeMapTextureArray* setSubImage(GLsizei layer, Coordinate coordinate, GLint level, const Vector2i& offset, const Image* image) { + DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, Vector3i(offset, layer*6+static_cast(coordinate)), image, Vector2i(Math::Vector())); return this; } diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 2161f4be7..757a070ad 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -86,7 +86,7 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co } /* Set texture data */ - _texture.setData(0, Texture2D::InternalFormat::R8, &image); + _texture.setImage(0, Texture2D::InternalFormat::R8, &image); } void Font::create(FontRenderer& renderer, const std::string& fontFile) { diff --git a/src/Texture.h b/src/Texture.h index c3da55f57..e6013c716 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -44,7 +44,7 @@ texture.setMagnificationFilter(Texture2D::Filter::Linear) ->setMinificationFilter(Texture2D::Filter::Linear, Texture2D::Mipmap::Linear) ->setWrapping(Texture2D::Wrapping::ClampToEdge) ->setMaxAnisotropy(Texture2D::maxSupportedAnisotropy) - ->setData(0, Texture2D::Format::RGBA8, &image) + ->setImage(0, Texture2D::Format::RGBA8, &image) ->generateMipmap(); @endcode @@ -66,9 +66,9 @@ information. You can create texture arrays by passing @ref Texture::Target "Texture2D::Target::Texture1DArray" or @ref Texture::Target "Texture3D::Target::Texture2DArray" to constructor. -It is possible to specify each layer separately using setSubData(), but you +It is possible to specify each layer separately using setSubImage(), but you have to allocate the memory for all layers first, possibly by passing properly -sized empty Image to setData(). Example: 2D texture array with 16 layers of +sized empty Image to setImage(). Example: 2D texture array with 16 layers of 64x64 images: @code Image3D dummy({64, 64, 16}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, nullptr); @@ -76,12 +76,12 @@ Image3D dummy({64, 64, 16}, Image3D::Components::RGBA, Image3D::ComponentType::U Texture3D texture(Texture3D::Target::Texture2DArray); texture.setMagnificationFilter(Texture2D::Filter::Linear) // ... - ->setData(0, Texture2D::Format::RGBA8, &dummy); + ->setImage(0, Texture2D::Format::RGBA8, &dummy); for(std::size_t i = 0; i != 16; ++i) { void* data = ...; Image2D image({64, 64}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, image); - texture->setSubData(0, Vector3i::zAxis(i), image); + texture->setSubImage(0, Vector3i::zAxis(i), image); } // ... @@ -198,38 +198,39 @@ template class Texture: public AbstractTexture { } /** - * @brief Set texture data - * @param mipLevel Mip level + * @brief Set image data + * @param level Mip level * @param internalFormat Internal texture format * @param image Image, ImageWrapper, BufferImage or * Trade::ImageData of the same dimension count * @return Pointer to self (for method chaining) * - * Sets texture data from given image. The image is not deleted - * afterwards. If @extension{EXT,direct_state_access} is not available, - * the texture is bound to some layer before the operation. + * The image is not deleted afterwards. + * + * If @extension{EXT,direct_state_access} is not available, the + * texture is bound to some layer before the operation. * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexImage1D}/ * @fn_gl{TexImage2D}/@fn_gl{TexImage3D} or * @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access} */ - template inline Texture* setData(GLint mipLevel, InternalFormat internalFormat, Image* image) { - DataHelper::set(this, _target, mipLevel, internalFormat, image); + template inline Texture* setImage(GLint level, InternalFormat internalFormat, Image* image) { + DataHelper::set(this, _target, level, internalFormat, image); return this; } /** - * @brief Set texture subdata - * @param mipLevel Mip level + * @brief Set image subdata + * @param level Mip level * @param offset Offset where to put data in the texture * @param image Image, ImageWrapper, BufferImage or * Trade::ImageData of the same or one less dimension count * @return Pointer to self (for method chaining) * - * Sets texture subdata from given image. The image is not deleted - * afterwards. The image can have either the same dimension count or - * have one dimension less, but at least one dimension. + * The image is not deleted afterwards. The image can have either the + * same dimension count or have one dimension less, but at least one + * dimension. * * If the image has one dimension less than the texture, the image is * taken as if it had the last dimension equal to 1. It can be used @@ -244,8 +245,8 @@ template class Texture: public AbstractTexture { * @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} */ - template inline Texture* setSubData(GLint mipLevel, const typename DimensionTraits::VectorType& offset, Image* image) { - DataHelper::setSub(this, _target, mipLevel, offset, image); + template inline Texture* setSubImage(GLint level, const typename DimensionTraits::VectorType& offset, Image* image) { + DataHelper::setSub(this, _target, level, offset, image); return this; } From 8837b35f58c84aabf5204928599c4f1211947924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 11 Jan 2013 23:05:36 +0100 Subject: [PATCH 140/567] Updated external OpenGL headers. --- external/GLES2/gl2ext.h | 3 ++- external/GLES3/gl3.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/external/GLES2/gl2ext.h b/external/GLES2/gl2ext.h index 8df11d9f5..9fb46cac9 100644 --- a/external/GLES2/gl2ext.h +++ b/external/GLES2/gl2ext.h @@ -1,7 +1,7 @@ #ifndef __gl2ext_h_ #define __gl2ext_h_ -/* $Revision: 19436 $ on $Date:: 2012-10-10 10:37:04 -0700 #$ */ +/* $Revision: 20040 $ on $Date:: 2013-01-03 01:43:00 -0800 #$ */ #ifdef __cplusplus extern "C" { @@ -1167,6 +1167,7 @@ typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum #endif #ifndef GL_ANGLE_instanced_arrays +#define GL_ANGLE_instanced_arrays 1 #ifdef GL_GLEXT_PROTOTYPES GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount); GL_APICALL void GL_APIENTRY glDrawElementsInstancedANGLE (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount); diff --git a/external/GLES3/gl3.h b/external/GLES3/gl3.h index 7d9b04d94..4d49393e2 100644 --- a/external/GLES3/gl3.h +++ b/external/GLES3/gl3.h @@ -2,7 +2,7 @@ #define __gl3_h_ /* - * gl3.h last updated on $Date: 2012-09-12 10:13:02 -0700 (Wed, 12 Sep 2012) $ + * gl3.h last updated on $Date: 2012-10-03 07:52:40 -0700 (Wed, 03 Oct 2012) $ */ #include @@ -796,7 +796,7 @@ typedef struct __GLsync *GLsync; #define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F #define GL_MAX_ELEMENT_INDEX 0x8D6B #define GL_NUM_SAMPLE_COUNTS 0x9380 -#define GL_TEXTURE_IMMUTABLE_LEVELS 0x8D63 +#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF /*------------------------------------------------------------------------- * Entrypoint definitions From d3208013a269af067f2d57b84ca983621e56c601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 11 Jan 2013 23:10:50 +0100 Subject: [PATCH 141/567] More strict compiler warnings. * Error when function is missing return type (not just warning). * Warn when functions in source don't have corresponding declarations in header. In case that it is not an error they should be put in anonymous namespace. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc04c2ab8..8218fc737 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -Winit-self -pedantic -std=c++0x -fvisibility=hidden") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -Winit-self -Werror=return-type -Wmissing-declarations -pedantic -std=c++0x -fvisibility=hidden") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") From 3ab53e050af3c0d9733744fe7c6907675e2cdf5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 11 Jan 2013 23:13:55 +0100 Subject: [PATCH 142/567] Doc: another copypasta error. --- src/SceneGraph/Camera2D.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 9976a8f93..591cd4261 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -57,7 +57,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { * @param object %Object holding this feature * * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). - * @see setOrthographic() + * @see setProjection() */ inline explicit Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} From 80cb4eb8e592868bfd2bd8fda078ed91de4c288c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 13:28:27 +0100 Subject: [PATCH 143/567] Reworked framebuffer attachment enums. Instead of having pair of functions for depth/stencil and color attachments this is now solved using specialized class. It is now more descriptive, as specifying color attachment is now done explicitly using Framebuffer::ColorAttachment(2) instead of just `2`. Specifying "no attachment" is now also done explicitly using Framebuffer::DrawAttachment::None instead of `-1`. Also updated related documentation. --- src/DefaultFramebuffer.h | 58 ++++---- src/Framebuffer.cpp | 52 +++---- src/Framebuffer.h | 306 ++++++++++++++++++--------------------- 3 files changed, 198 insertions(+), 218 deletions(-) diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 3804931d6..912eb73dc 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -85,32 +85,32 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #ifndef MAGNUM_TARGET_GLES /** - * Write output to back left framebuffer. + * Write output to front left buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - BackLeft = GL_BACK_LEFT, + FrontLeft = GL_FRONT_LEFT, /** - * Write output to back right framebuffer. + * Write output to front right buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - BackRight = GL_BACK_RIGHT, + FrontRight = GL_FRONT_RIGHT, /** - * Write output to front left framebuffer. + * Write output to back left buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - FrontLeft = GL_FRONT_LEFT, + BackLeft = GL_BACK_LEFT, /** - * Write output to front right framebuffer. + * Write output to back right buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - FrontRight = GL_FRONT_RIGHT, + BackRight = GL_BACK_RIGHT, #endif /** - * Write output to back framebuffer. + * Write output to back buffer. * * On desktop OpenGL, this is equal to @ref DrawAttachment "DrawAttachment::BackLeft". */ @@ -121,7 +121,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #endif /** - * Write output to front framebuffer. + * Write output to front buffer. * * On desktop OpenGL, this is equal to @ref DrawAttachment "DrawAttachment::FrontLeft". */ @@ -140,52 +140,52 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ enum class ReadAttachment: GLenum { - /** Don't read from any framebuffer */ + /** Don't read from any buffer */ None = GL_NONE, #ifndef MAGNUM_TARGET_GLES /** - * Read from back left framebuffer. + * Read from front left buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - BackLeft = GL_BACK_LEFT, + FrontLeft = GL_FRONT_LEFT, /** - * Read from back right framebuffer. + * Read from front right buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - BackRight = GL_BACK_RIGHT, + FrontRight = GL_FRONT_RIGHT, /** - * Read from front left framebuffer. + * Read from back left buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - FrontLeft = GL_FRONT_LEFT, + BackLeft = GL_BACK_LEFT, /** - * Read from front right framebuffer. + * Read from back right buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ - FrontRight = GL_FRONT_RIGHT, + BackRight = GL_BACK_RIGHT, /** - * Read from left framebuffer. + * Read from left buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ Left = GL_LEFT, /** - * Read from right framebuffer. + * Read from right buffer. * @requires_gl Stereo rendering is not available in OpenGL ES. */ Right = GL_RIGHT, #endif - /** Read from back framebuffer. */ + /** Read from back buffer. */ Back = GL_BACK, /** - * Read from front framebuffer. + * Read from front buffer. * @requires_es_extension %Extension @es_extension2{NV,read_buffer_front,GL_NV_read_buffer} */ Front = GL_FRONT @@ -194,7 +194,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { , /** - * Read from front and back framebuffer. + * Read from front and back buffer. * @requires_gl In OpenGL ES you must specify either * @ref Magnum::DefaultFramebuffer::ReadAttachment "ReadAttachment::Front" * or @ref Magnum::DefaultFramebuffer::ReadAttachment "ReadAttachment::Back". @@ -209,9 +209,9 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { /** * @brief Map shader outputs to buffer attachment * - * @p attachments is list of shader outputs mapped to framebuffer - * buffer attachments. Shader outputs which are not listed are not - * used, you can achieve the same by passing @ref DrawAttachment "DrawAttachment::None" + * @p attachments is list of shader outputs mapped to buffer + * attachments. %Shader outputs which are not listed are not used, you + * can achieve the same by passing @ref DrawAttachment "DrawAttachment::None" * as attachment. Example usage: * @code * framebuffer.mapForDraw({{MyShader::ColorOutput, DefaultFramebuffer::DrawAttachment::BackLeft}, @@ -230,7 +230,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { /** * @brief Map shader output to buffer attachment - * @param attachment Buffer attachment + * @param attachment %Buffer attachment * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -250,7 +250,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { /** * @brief Map given attachment for reading - * @param attachment Buffer attachment + * @param attachment %Buffer attachment * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 8d68e73dc..36508570f 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -34,6 +34,13 @@ Framebuffer::Texture1DImplementation Framebuffer::texture1DImplementation = &Fra Framebuffer::Texture2DImplementation Framebuffer::texture2DImplementation = &Framebuffer::texture2DImplementationDefault; Framebuffer::Texture3DImplementation Framebuffer::texture3DImplementation = &Framebuffer::texture3DImplementationDefault; +const Framebuffer::DrawAttachment Framebuffer::DrawAttachment::None = Framebuffer::DrawAttachment(GL_NONE); +const Framebuffer::BufferAttachment Framebuffer::BufferAttachment::Depth = Framebuffer::BufferAttachment(GL_DEPTH_ATTACHMENT); +const Framebuffer::BufferAttachment Framebuffer::BufferAttachment::Stencil = Framebuffer::BufferAttachment(GL_STENCIL_ATTACHMENT); +#ifndef MAGNUM_TARGET_GLES2 +const Framebuffer::BufferAttachment Framebuffer::BufferAttachment::DepthStencil = Framebuffer::BufferAttachment(GL_DEPTH_STENCIL_ATTACHMENT); +#endif + Framebuffer::Framebuffer(const Rectanglei& viewport) { _viewport = viewport; @@ -49,7 +56,7 @@ Framebuffer::~Framebuffer() { glDeleteFramebuffers(1, &_id); } -void Framebuffer::mapForDraw(std::initializer_list> attachments) { +void Framebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) @@ -59,20 +66,15 @@ void Framebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; } -void Framebuffer::attachTexture2D(DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel) { - /** @todo Check for texture target compatibility */ - (this->*texture2DImplementation)(GLenum(depthStencilAttachment), GLenum(texture->target()), texture->id(), mipLevel); -} - -void Framebuffer::attachTexture2D(std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel) { +void Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, GLint mipLevel) { /** @todo Check for texture target compatibility */ - (this->*texture2DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, GLenum(texture->target()), texture->id(), mipLevel); + (this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel); } void Framebuffer::initializeContextBasedFunctionality(Context* context) { @@ -90,39 +92,39 @@ void Framebuffer::initializeContextBasedFunctionality(Context* context) { #endif } -void Framebuffer::renderbufferImplementationDefault(GLenum attachment, Renderbuffer* renderbuffer) { - glFramebufferRenderbuffer(GLenum(bindInternal()), attachment, GL_RENDERBUFFER, renderbuffer->id()); +void Framebuffer::renderbufferImplementationDefault(BufferAttachment attachment, Renderbuffer* renderbuffer) { + glFramebufferRenderbuffer(GLenum(bindInternal()), GLenum(attachment), GL_RENDERBUFFER, renderbuffer->id()); } #ifndef MAGNUM_TARGET_GLES -void Framebuffer::renderbufferImplementationDSA(GLenum attachment, Renderbuffer* renderbuffer) { - glNamedFramebufferRenderbufferEXT(_id, attachment, GL_RENDERBUFFER, renderbuffer->id()); +void Framebuffer::renderbufferImplementationDSA(BufferAttachment attachment, Renderbuffer* renderbuffer) { + glNamedFramebufferRenderbufferEXT(_id, GLenum(attachment), GL_RENDERBUFFER, renderbuffer->id()); } -void Framebuffer::texture1DImplementationDefault(GLenum attachment, Texture1D* texture, GLint mipLevel) { - glFramebufferTexture1D(GLenum(bindInternal()), attachment, static_cast(texture->target()), texture->id(), mipLevel); +void Framebuffer::texture1DImplementationDefault(BufferAttachment attachment, Texture1D* texture, GLint mipLevel) { + glFramebufferTexture1D(GLenum(bindInternal()), GLenum(attachment), static_cast(texture->target()), texture->id(), mipLevel); } -void Framebuffer::texture1DImplementationDSA(GLenum attachment, Texture1D* texture, GLint mipLevel) { - glNamedFramebufferTexture1DEXT(_id, attachment, GLenum(texture->target()), texture->id(), mipLevel); +void Framebuffer::texture1DImplementationDSA(BufferAttachment attachment, Texture1D* texture, GLint mipLevel) { + glNamedFramebufferTexture1DEXT(_id, GLenum(attachment), GLenum(texture->target()), texture->id(), mipLevel); } #endif -void Framebuffer::texture2DImplementationDefault(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { - glFramebufferTexture2D(GLenum(bindInternal()), attachment, textureTarget, textureId, mipLevel); +void Framebuffer::texture2DImplementationDefault(BufferAttachment attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { + glFramebufferTexture2D(GLenum(bindInternal()), GLenum(attachment), textureTarget, textureId, mipLevel); } #ifndef MAGNUM_TARGET_GLES -void Framebuffer::texture2DImplementationDSA(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { - glNamedFramebufferTexture2DEXT(_id, attachment, textureTarget, textureId, mipLevel); +void Framebuffer::texture2DImplementationDSA(BufferAttachment attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel) { + glNamedFramebufferTexture2DEXT(_id, GLenum(attachment), textureTarget, textureId, mipLevel); } #endif -void Framebuffer::texture3DImplementationDefault(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer) { +void Framebuffer::texture3DImplementationDefault(BufferAttachment attachment, Texture3D* texture, GLint mipLevel, GLint layer) { /** @todo Check for texture target compatibility */ /** @todo Get some extension wrangler for glFramebufferTexture3D() (extension only) */ #ifndef MAGNUM_TARGET_GLES - glFramebufferTexture3D(GLenum(bindInternal()), attachment, static_cast(texture->target()), texture->id(), mipLevel, layer); + glFramebufferTexture3D(GLenum(bindInternal()), GLenum(attachment), static_cast(texture->target()), texture->id(), mipLevel, layer); #else static_cast(attachment); static_cast(texture); @@ -132,8 +134,8 @@ void Framebuffer::texture3DImplementationDefault(GLenum attachment, Texture3D* t } #ifndef MAGNUM_TARGET_GLES -void Framebuffer::texture3DImplementationDSA(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer) { - glNamedFramebufferTexture3DEXT(_id, attachment, GLenum(texture->target()), texture->id(), mipLevel, layer); +void Framebuffer::texture3DImplementationDSA(BufferAttachment attachment, Texture3D* texture, GLint mipLevel, GLint layer) { + glNamedFramebufferTexture3DEXT(_id, GLenum(attachment), GLenum(texture->target()), texture->id(), mipLevel, layer); } #endif diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 0fd057e81..4cdb162d2 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -46,16 +46,16 @@ Renderbuffer depthStencil; // configure the textures and allocate texture memory... -framebuffer.attachTexture2D(0, &color); -framebuffer.attachTexture2D(1, &normal); -framebuffer.attachRenderbuffer(Framebuffer::DepthStencilAttachment::DepthStencil, &depthStencil); +framebuffer.attachTexture2D(Framebuffer::ColorAttachment(0), &color); +framebuffer.attachTexture2D(Framebuffer::ColorAttachment(1), &normal); +framebuffer.attachRenderbuffer(Framebuffer::BufferAttachment::DepthStencil, &depthStencil); @endcode Then you need to map outputs of your shader to color attachments in the framebuffer: @code -framebuffer.mapForDraw({{MyShader::ColorOutput, 0}, - {MyShader::NormalOutput, 1}}); +framebuffer.mapForDraw({{MyShader::ColorOutput, Framebuffer::ColorAttachment(0)}, + {MyShader::NormalOutput, Framebuffer::ColorAttachment(1)}}); @endcode The actual @ref Platform::GlutApplication::drawEvent() "drawEvent()" might @@ -64,13 +64,13 @@ off-screen framebuffer, then bind the default and render the textures on screen: @code void drawEvent() { - defaultFramebuffer.clear(AbstractFramebuffer::Clear::Color) - framebuffer.clear(AbstractFramebuffer::Clear::Color|AbstractFramebuffer::Clear::Depth|AbstractFramebuffer::Clear::Stencil); + defaultFramebuffer.clear(DefaultFramebuffer::Clear::Color) + framebuffer.clear(Framebuffer::Clear::Color|Framebuffer::Clear::Depth|Framebuffer::Clear::Stencil); - framebuffer.bind(AbstractFramebuffer::Target::Draw); + framebuffer.bind(Framebuffer::Target::Draw); // ... - defaultFramebuffer.bind(AbstractFramebuffer::Target::Draw); + defaultFramebuffer.bind(DefaultFramebuffer::Target::Draw); // ... } @endcode @@ -91,6 +91,90 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { friend class Context; public: + /** + * @brief Color attachment + * + * @see Attachment, attachRenderbuffer(), attachTexture1D(), + * attachTexture2D(), attachCubeMapTexture(), attachTexture3D() + */ + class ColorAttachment { + friend class Framebuffer; + + public: + /** + * @brief Constructor + * @param id Color attachment id + */ + inline constexpr explicit ColorAttachment(std::uint8_t id): attachment(GL_COLOR_ATTACHMENT0 + id) {} + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit operator GLenum() const { return attachment; } + #endif + + private: + GLenum attachment; + }; + + /** + * @brief Draw attachment + * + * @see mapForDraw() + */ + class DrawAttachment { + public: + /** @brief No attachment */ + static const DrawAttachment None; + + /** @brief Color attachment */ + inline constexpr /*implicit*/ DrawAttachment(Framebuffer::ColorAttachment attachment): attachment(GLenum(attachment)) {} + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit operator GLenum() const { return attachment; } + #endif + + private: + inline constexpr explicit DrawAttachment(GLenum attachment): attachment(attachment) {} + + GLenum attachment; + }; + + /** + * @brief %Buffer attachment + * + * @see attachRenderbuffer(), attachTexture1D(), attachTexture2D(), + * attachCubeMapTexture(), attachTexture3D() + */ + class BufferAttachment { + public: + /** @brief Depth buffer */ + static const BufferAttachment Depth; + + /** @brief Stencil buffer */ + static const BufferAttachment Stencil; + + #ifndef MAGNUM_TARGET_GLES2 + /** + * @brief Both depth and stencil buffer + * + * @requires_gles30 Combined depth and stencil attachment is + * not available in OpenGL ES 2.0. + */ + static const BufferAttachment DepthStencil; + #endif + + /** @brief Color buffer */ + inline constexpr /*implicit*/ BufferAttachment(Framebuffer::ColorAttachment attachment): attachment(GLenum(attachment)) {} + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit operator GLenum() const { return attachment; } + #endif + + private: + inline constexpr explicit BufferAttachment(GLenum attachment): attachment(attachment) {} + + GLenum attachment; + }; + /** * @brief Constructor * @@ -108,15 +192,15 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { ~Framebuffer(); /** - * @brief Map shader output to color attachment + * @brief Map shader output to attachments * * @p attachments is list of shader outputs mapped to framebuffer - * color attachment IDs. Shader outputs which are not listed are not - * used, you can achieve the same by passing `-1` as color attachment - * ID. Example usage: + * color attachment IDs. %Shader outputs which are not listed are not + * used, you can achieve the same by passing Framebuffer::DrawAttachment::None + * as color attachment ID. Example usage: * @code - * framebuffer.mapForDraw({{MyShader::ColorOutput, 0}, - * {MyShader::NormalOutput, 1}}); + * framebuffer.mapForDraw({{MyShader::ColorOutput, Framebuffer::ColorAttachment(0)}, + * {MyShader::NormalOutput, Framebuffer::DrawAttachment::None}}); * @endcode * * If @extension{EXT,direct_state_access} is not available and the @@ -126,11 +210,11 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - void mapForDraw(std::initializer_list> attachments); + void mapForDraw(std::initializer_list> attachments); /** - * @brief Map shader output to color attachment - * @param attachment Color attachment ID + * @brief Map shader output to attachment + * @param attachment Draw attachment * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -142,13 +226,13 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - inline void mapForDraw(std::int8_t attachment) { - (this->*drawBufferImplementation)(static_cast(GL_COLOR_ATTACHMENT0 + attachment)); + inline void mapForDraw(DrawAttachment attachment) { + (this->*drawBufferImplementation)(GLenum(attachment)); } /** * @brief Map given color attachment for reading - * @param attachment Color attachment ID + * @param attachment Color attachment * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -157,35 +241,13 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - inline void mapForRead(std::uint8_t attachment) { - (this->*readBufferImplementation)(GL_COLOR_ATTACHMENT0 + attachment); + inline void mapForRead(ColorAttachment attachment) { + (this->*readBufferImplementation)(GLenum(attachment)); } /** - * @brief Attachment for depth/stencil part of fragment shader output - * - * @see attachRenderbuffer(), attachTexture1D(), attachTexture2D(), - * attachCubeMapTexture(), attachTexture3D() - */ - enum class DepthStencilAttachment: GLenum { - Depth = GL_DEPTH_ATTACHMENT, /**< Depth output only. */ - - Stencil = GL_STENCIL_ATTACHMENT /**< Stencil output only. */ - - #ifndef MAGNUM_TARGET_GLES2 - , - /** - * Both depth and stencil output. - * @requires_gles30 Combined depth and stencil attachment is not - * available in OpenGL ES 2.0. - */ - DepthStencil = GL_DEPTH_STENCIL_ATTACHMENT - #endif - }; - - /** - * @brief Attach renderbuffer to given framebuffer depth/stencil attachment - * @param depthStencilAttachment Depth/stencil attachment + * @brief Attach renderbuffer to given buffer + * @param attachment %Buffer attachment * @param renderbuffer %Renderbuffer * * If @extension{EXT,direct_state_access} is not available and the @@ -194,48 +256,16 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} */ - inline void attachRenderbuffer(DepthStencilAttachment depthStencilAttachment, Renderbuffer* renderbuffer) { - (this->*renderbufferImplementation)(GLenum(depthStencilAttachment), renderbuffer); - } - - /** - * @brief Attach renderbuffer to given framebuffer color attachment - * @param colorAttachment Color attachment ID (number between 0 and 15) - * @param renderbuffer %Renderbuffer - * - * If @extension{EXT,direct_state_access} is not available and the - * framebufferbuffer is not currently bound, it is bound before the - * operation. - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or - * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} - */ - inline void attachRenderbuffer(std::uint8_t colorAttachment, Renderbuffer* renderbuffer) { - (this->*renderbufferImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, renderbuffer); + inline void attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { + (this->*renderbufferImplementation)(attachment, renderbuffer); } #ifndef MAGNUM_TARGET_GLES /** - * @brief Attach 1D texture to given framebuffer depth/stencil attachment - * @param depthStencilAttachment Depth/stencil attachment - * @param texture 1D texture - * @param mipLevel Mip level - * - * If @extension{EXT,direct_state_access} is not available and the - * framebufferbuffer is not currently bound, it is bound before the - * operation. - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} or - * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} - * @requires_gl Only 2D and 3D textures are available in OpenGL ES. - */ - inline void attachTexture1D(DepthStencilAttachment depthStencilAttachment, Texture1D* texture, GLint mipLevel) { - (this->*texture1DImplementation)(GLenum(depthStencilAttachment), texture, mipLevel); - } - - /** - * @brief Attach 1D texture to given framebuffer color attachment - * @param colorAttachment Color attachment ID (number between 0 and 15) + * @brief Attach 1D texture to given buffer + * @param attachment %Buffer attachment * @param texture 1D texture - * @param mipLevel Mip level + * @param level Mip level * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -244,32 +274,16 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - inline void attachTexture1D(std::uint8_t colorAttachment, Texture1D* texture, GLint mipLevel) { - (this->*texture1DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, texture, mipLevel); + inline void attachTexture1D(BufferAttachment attachment, Texture1D* texture, GLint level) { + (this->*texture1DImplementation)(attachment, texture, level); } #endif /** - * @brief Attach 2D texture to given framebuffer depth/stencil attachment - * @param depthStencilAttachment Depth/stencil attachment - * @param texture 2D texture - * @param mipLevel Mip level. For rectangle textures it - * should be always 0. - * - * If @extension{EXT,direct_state_access} is not available and the - * framebufferbuffer is not currently bound, it is bound before the - * operation. - * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} - * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} - */ - void attachTexture2D(DepthStencilAttachment depthStencilAttachment, Texture2D* texture, GLint mipLevel); - - /** - * @brief Attach 2D texture to given framebuffer color attachment - * @param colorAttachment Color attachment ID (number between 0 and 15) + * @brief Attach 2D texture to given buffer + * @param attachment %Buffer attachment * @param texture 2D texture - * @param mipLevel Mip level. For rectangle textures it - * should be always 0. + * @param level Mip level * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -277,14 +291,14 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachTexture2D(std::uint8_t colorAttachment, Texture2D* texture, GLint mipLevel); + void attachTexture2D(BufferAttachment attachment, Texture2D* texture, GLint level); /** - * @brief Attach cube map texture to given framebuffer depth/stencil attachment - * @param depthStencilAttachment Depth/stencil attachment + * @brief Attach cube map texture to given buffer + * @param attachment %Buffer attachment * @param texture Cube map texture * @param coordinate Cube map coordinate - * @param mipLevel Mip level + * @param level Mip level * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -292,32 +306,15 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - inline void attachCubeMapTexture(DepthStencilAttachment depthStencilAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { - (this->*texture2DImplementation)(GLenum(depthStencilAttachment), GLenum(coordinate), texture->id(), mipLevel); + inline void attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint level) { + (this->*texture2DImplementation)(attachment, GLenum(coordinate), texture->id(), level); } /** - * @brief Attach cube map texture to given framebuffer color attachment - * @param colorAttachment Color attachment ID (number between 0 and 15) - * @param texture Cube map texture - * @param coordinate Cube map coordinate - * @param mipLevel Mip level - * - * If @extension{EXT,direct_state_access} is not available and the - * framebufferbuffer is not currently bound, it is bound before the - * operation. - * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} - * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} - */ - inline void attachCubeMapTexture(std::uint8_t colorAttachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint mipLevel) { - (this->*texture2DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, GLenum(coordinate), texture->id(), mipLevel); - } - - /** - * @brief Attach 3D texture to given framebuffer depth/stencil attachment - * @param depthStencilAttachment Depth/stencil attachment + * @brief Attach 3D texture to given buffer + * @param attachment %Buffer attachment * @param texture 3D texture - * @param mipLevel Mip level + * @param level Mip level * @param layer Layer of 2D image within a 3D texture * * If @extension{EXT,direct_state_access} is not available and the @@ -327,58 +324,39 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - inline void attachTexture3D(DepthStencilAttachment depthStencilAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { - /** @todo Check for texture target compatibility */ - (this->*texture3DImplementation)(GLenum(depthStencilAttachment), texture, mipLevel, layer); - } - - /** - * @brief Attach 3D texture to given framebuffer color attachment - * @param colorAttachment Color attachment ID (number between 0 and 15) - * @param texture 3D texture - * @param mipLevel Mip level - * @param layer Layer of 2D image within a 3D texture. - * - * If @extension{EXT,direct_state_access} is not available and the - * framebufferbuffer is not currently bound, it is bound before the - * operation. - * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} or - * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} - * @requires_es_extension %Extension @es_extension{OES,texture_3D} - */ - inline void attachTexture3D(std::uint8_t colorAttachment, Texture3D* texture, GLint mipLevel, GLint layer) { + inline void attachTexture3D(BufferAttachment attachment, Texture3D* texture, GLint level, GLint layer) { /** @todo Check for texture target compatibility */ - (this->*texture3DImplementation)(GL_COLOR_ATTACHMENT0 + colorAttachment, texture, mipLevel, layer); + (this->*texture3DImplementation)(attachment, texture, level, layer); } private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); - typedef void(Framebuffer::*RenderbufferImplementation)(GLenum, Renderbuffer*); - void MAGNUM_LOCAL renderbufferImplementationDefault(GLenum attachment, Renderbuffer* renderbuffer); + typedef void(Framebuffer::*RenderbufferImplementation)(BufferAttachment, Renderbuffer*); + void MAGNUM_LOCAL renderbufferImplementationDefault(BufferAttachment attachment, Renderbuffer* renderbuffer); #ifndef MAGNUM_TARGET_GLES - void MAGNUM_LOCAL renderbufferImplementationDSA(GLenum attachment, Renderbuffer* renderbuffer); + void MAGNUM_LOCAL renderbufferImplementationDSA(BufferAttachment attachment, Renderbuffer* renderbuffer); #endif static RenderbufferImplementation renderbufferImplementation; #ifndef MAGNUM_TARGET_GLES - typedef void(Framebuffer::*Texture1DImplementation)(GLenum, Texture1D*, GLint); - void MAGNUM_LOCAL texture1DImplementationDefault(GLenum attachment, Texture1D* texture, GLint mipLevel); - void MAGNUM_LOCAL texture1DImplementationDSA(GLenum attachment, Texture1D* texture, GLint mipLevel); + typedef void(Framebuffer::*Texture1DImplementation)(BufferAttachment, Texture1D*, GLint); + void MAGNUM_LOCAL texture1DImplementationDefault(BufferAttachment attachment, Texture1D* texture, GLint level); + void MAGNUM_LOCAL texture1DImplementationDSA(BufferAttachment attachment, Texture1D* texture, GLint level); static Texture1DImplementation texture1DImplementation; #endif - typedef void(Framebuffer::*Texture2DImplementation)(GLenum, GLenum, GLuint, GLint); - void MAGNUM_LOCAL texture2DImplementationDefault(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel); + typedef void(Framebuffer::*Texture2DImplementation)(BufferAttachment, GLenum, GLuint, GLint); + void MAGNUM_LOCAL texture2DImplementationDefault(BufferAttachment attachment, GLenum textureTarget, GLuint textureId, GLint level); #ifndef MAGNUM_TARGET_GLES - void MAGNUM_LOCAL texture2DImplementationDSA(GLenum attachment, GLenum textureTarget, GLuint textureId, GLint mipLevel); + void MAGNUM_LOCAL texture2DImplementationDSA(BufferAttachment attachment, GLenum textureTarget, GLuint textureId, GLint level); #endif static MAGNUM_LOCAL Texture2DImplementation texture2DImplementation; - typedef void(Framebuffer::*Texture3DImplementation)(GLenum, Texture3D*, GLint, GLint); - void MAGNUM_LOCAL texture3DImplementationDefault(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer); + typedef void(Framebuffer::*Texture3DImplementation)(BufferAttachment, Texture3D*, GLint, GLint); + void MAGNUM_LOCAL texture3DImplementationDefault(BufferAttachment attachment, Texture3D* texture, GLint level, GLint layer); #ifndef MAGNUM_TARGET_GLES - void MAGNUM_LOCAL texture3DImplementationDSA(GLenum attachment, Texture3D* texture, GLint mipLevel, GLint layer); + void MAGNUM_LOCAL texture3DImplementationDSA(BufferAttachment attachment, Texture3D* texture, GLint level, GLint layer); #endif static Texture3DImplementation texture3DImplementation; }; From 5b9b2dedef1e738d0de2d3d7a514cc2c8bdb9131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 13:31:03 +0100 Subject: [PATCH 144/567] Added EXT_discard_framebuffer ES2 extension to the list. --- src/Context.cpp | 1 + src/Extensions.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Context.cpp b/src/Context.cpp index 5bdba1420..9518f1005 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -214,6 +214,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,APPLE,framebuffer_multisample), _extension(GL,ARM,rgba8), _extension(GL,EXT,texture_type_2_10_10_10_REV), + _extension(GL,EXT,discard_framebuffer), _extension(GL,EXT,blend_minmax), _extension(GL,EXT,occlusion_query_boolean), _extension(GL,EXT,texture_rg), diff --git a/src/Extensions.h b/src/Extensions.h index 75cad8bf2..8a2540f03 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -187,6 +187,7 @@ namespace GL { _extension(GL,EXT,texture_filter_anisotropic, GLES200, None) // #41 _extension(GL,EXT,texture_type_2_10_10_10_REV, GLES200, GLES300) // #42 _extension(GL,EXT,texture_format_BGRA8888, GLES200, None) // #51 + _extension(GL,EXT,discard_framebuffer, GLES200, GLES300) // #64 _extension(GL,EXT,blend_minmax, GLES200, GLES300) // #65 _extension(GL,EXT,read_format_bgra, GLES200, None) // #66 _extension(GL,EXT,debug_marker, GLES200, None) // #99 From 77068a1810ea0edbbfffbe2261edc2d7016edff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 13:31:36 +0100 Subject: [PATCH 145/567] Added alias for linking to ES extension functions to Doxyfile. --- Doxyfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Doxyfile b/Doxyfile index 2553d0c84..8d1694bd6 100644 --- a/Doxyfile +++ b/Doxyfile @@ -202,6 +202,7 @@ ALIASES = \ "todoc=@xrefitem todoc \"Documentation todo\" \"Documentation-related todo list\"" \ "fn_gl{1}=gl\1()" \ "fn_gl_extension{3}=gl\1\2()" \ + "fn_gles_extension{3}=gl\1\2()" \ "def_gl{1}=`GL_\1`" \ "requires_gl30=@xrefitem requires-gl30 \"Requires OpenGL 3.0\" \"Functionality requiring OpenGL 3.0\"" \ "requires_gl31=@xrefitem requires-gl31 \"Requires OpenGL 3.1\" \"Functionality requiring OpenGL 3.1\"" \ From d59297aeeb667ded0e7a81ef13777aef58b85658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 13:42:38 +0100 Subject: [PATCH 146/567] Implemented ARB_invalidate_subdata GL 4.3 extension. Framebuffer invalidation is also available in OpenGL ES 3.0 and ES 2.0 using EXT_discard_framebuffer extension. --- src/AbstractFramebuffer.cpp | 21 +++++++++++ src/AbstractFramebuffer.h | 7 ++++ src/AbstractTexture.h | 33 +++++++++++++++++ src/Buffer.h | 26 ++++++++++++++ src/CubeMapTexture.h | 5 +++ src/CubeMapTextureArray.h | 7 ++++ src/DefaultFramebuffer.cpp | 20 +++++++++++ src/DefaultFramebuffer.h | 71 +++++++++++++++++++++++++++++++++++++ src/Framebuffer.cpp | 22 ++++++++++++ src/Framebuffer.h | 55 ++++++++++++++++++++++++++++ src/Texture.h | 26 +++++++++++--- 11 files changed, 288 insertions(+), 5 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 06b86d8e8..3fa25606f 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -141,6 +141,27 @@ void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, Abs } #endif +#ifndef DOXYGEN_GENERATING_OUTPUT +void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attachments) { + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glInvalidateFramebuffer(GLenum(bindInternal()), count, attachments); + #else + //glDiscardFramebufferEXT(GLenum(bindInternal()), count, attachments); + #endif +} + +void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attachments, const Rectanglei& rectangle) { + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glInvalidateSubFramebuffer(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.width(), rectangle.height()); + #else + //glDiscardSubFramebufferEXT(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.width(), rectangle.height()); + static_cast(rectangle); + #endif +} +#endif + void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context) { #ifndef MAGNUM_TARGET_GLES if(context->isExtensionSupported()) { diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index f2efec6b1..443d5982b 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -207,6 +207,10 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @brief Clear specified buffers in framebuffer * @param mask Which buffers to clear * + * To improve performance you can also use + * DefaultFramebuffer::invalidate() / Framebuffer::invalidate() instead + * of clearing given buffer if you will not use it anymore or fully + * overwrite it later. * @see Renderer::setClearColor(), Renderer::setClearDepth(), * Renderer::setClearStencil(), @fn_gl{BindFramebuffer}, * @fn_gl{Clear} @@ -261,6 +265,9 @@ class MAGNUM_EXPORT AbstractFramebuffer { typedef void(AbstractFramebuffer::*ReadBufferImplementation)(GLenum); static ReadBufferImplementation readBufferImplementation; + void MAGNUM_LOCAL invalidateImplementation(GLsizei count, GLenum* attachments); + void MAGNUM_LOCAL invalidateImplementation(GLsizei count, GLenum* attachments, const Rectanglei& rectangle); + GLuint _id; Rectanglei _viewport; #endif diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 7c2b96cc8..b4eeb267e 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1111,6 +1111,21 @@ class MAGNUM_EXPORT AbstractTexture { return this; } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Invalidate texture image + * @param level Mip level + * + * @see @ref Texture::invalidateSubImage() "invalidateSubImage()", + * @fn_gl{InvalidateTexImage} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gl Texture image invalidation is not available in OpenGL ES. + */ + inline void invalidateImage(GLint level) { + glInvalidateTexImage(_id, level); + } + #endif + /** * @brief Generate mipmap * @return Pointer to self (for method chaining) @@ -1233,6 +1248,12 @@ template<> struct AbstractTexture::DataHelper<1> { template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Math::Vector<1, GLint>& offset, Image* image) { (texture->*subImage1DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); } + + #ifndef MAGNUM_TARGET_GLES + inline static void invalidateSub(AbstractTexture* texture, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLint>& size) { + glInvalidateTexSubImage(texture->_id, level, offset[0], 0, 0, size[0], 1, 1); + } + #endif }; #endif template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { @@ -1260,6 +1281,12 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector2i& offset, Image* image) { (texture->*subImage2DImplementation)(target, level, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data()); } + + #ifndef MAGNUM_TARGET_GLES + inline static void invalidateSub(AbstractTexture* texture, GLint level, const Vector2i& offset, const Vector2i& size) { + glInvalidateTexSubImage(texture->_id, level, offset.x(), offset.y(), 0, size.x(), size.y(), 1); + } + #endif }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { enum class Target: GLenum { @@ -1286,6 +1313,12 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector3i& offset, Image* image) { (texture->*subImage3DImplementation)(target, level, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data()); } + + #ifndef MAGNUM_TARGET_GLES + inline static void invalidateSub(AbstractTexture* texture, GLint level, const Vector3i& offset, const Vector3i& size) { + glInvalidateTexSubImage(texture->_id, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z()); + } + #endif }; #endif diff --git a/src/Buffer.h b/src/Buffer.h index 215bea7b2..07a93271e 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -580,6 +580,32 @@ class MAGNUM_EXPORT Buffer { setSubData(offset, data.size()*sizeof(T), data.data()); } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Invalidate buffer data + * + * @see @fn_gl{InvalidateBufferData} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gl Buffer data invalidation is not available in OpenGL ES. + */ + inline void invalidateData() { + glInvalidateBufferData(_id); + } + + /** + * @brief Invalidate buffer subdata + * @param offset Offset into the buffer + * @param length Length of the invalidated range + * + * @see @fn_gl{InvalidateBufferData} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gl Buffer data invalidation is not available in OpenGL ES. + */ + inline void invalidateSubData(GLintptr offset, GLsizeiptr length) { + glInvalidateBufferSubData(_id, offset, length); + } + #endif + /** * @brief Map buffer to client memory * @param access Access diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index f2e9e60ee..ae3d7a51b 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -127,6 +127,11 @@ class CubeMapTexture: public AbstractTexture { return this; } + /** @copydoc Texture::invalidateSubImage() */ + inline void invalidateSubImage(GLint level, const Vector2i& offset, const Vector2i& size) { + DataHelper<2>::invalidateSub(this, level, offset, size); + } + /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT inline CubeMapTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 9c8270233..480b3dbd1 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -151,6 +151,13 @@ class CubeMapTextureArray: public AbstractTexture { return this; } + #ifndef MAGNUM_TARGET_GLES + /** @copydoc Texture::invalidateSubImage() */ + inline void invalidateSubImage(GLint level, const Vector2i& offset, const Vector2i& size) { + DataHelper<2>::invalidateSub(this, level, offset, size); + } + #endif + /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT inline CubeMapTextureArray* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index a8b0649c4..b8a940a33 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -44,6 +44,26 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list attachments) { + GLenum* _attachments = new GLenum[attachments.size()]; + for(std::size_t i = 0; i != attachments.size(); ++i) + _attachments[i] = GLenum(*(attachments.begin()+i)); + + invalidateImplementation(attachments.size(), _attachments); + + delete _attachments; +} + +void DefaultFramebuffer::invalidate(std::initializer_list attachments, const Rectanglei& rectangle) { + GLenum* _attachments = new GLenum[attachments.size()]; + for(std::size_t i = 0; i != attachments.size(); ++i) + _attachments[i] = GLenum(*(attachments.begin()+i)); + + invalidateImplementation(attachments.size(), _attachments, rectangle); + + delete _attachments; +} + void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) { Implementation::FramebufferState* state = context->state()->framebuffer; diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 912eb73dc..d2df00bf6 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -203,6 +203,50 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #endif }; + /** + * @brief Invalidation attachment + * + * @see invalidate() + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + */ + enum class InvalidationAttachment: GLenum { + #ifndef MAGNUM_TARGET_GLES + /** + * Invalidate front left buffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontLeft = GL_FRONT_LEFT, + + /** + * Invalidate front right buffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + FrontRight = GL_FRONT_RIGHT, + + /** + * Invalidate back left buffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackLeft = GL_BACK_LEFT, + + /** + * Invalidate back right buffer. + * @requires_gl Stereo rendering is not available in OpenGL ES. + */ + BackRight = GL_BACK_RIGHT, + #endif + + /** Invalidate color buffer. */ + Color = GL_COLOR, + + /** Invalidate depth bufer. */ + Depth = GL_DEPTH, + + /** Invalidate stencil buffer. */ + Stencil = GL_STENCIL + }; + explicit MAGNUM_LOCAL DefaultFramebuffer(); #ifndef MAGNUM_TARGET_GLES2 @@ -263,6 +307,33 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { (this->*readBufferImplementation)(static_cast(attachment)); } + /** + * @brief Invalidate framebuffer + * @param attachments Attachments to invalidate + * + * The framebuffer is bound to some target before the operation, if + * not already. + * @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} + * on OpenGL ES 2.0 + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + */ + void invalidate(std::initializer_list attachments); + + /** + * @brief Invalidate framebuffer rectangle + * @param attachments Attachments to invalidate + * @param rectangle %Rectangle to invalidate + * + * The framebuffer is bound to some target before the operation, if + * not already. + * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} + * on OpenGL ES 2.0 + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + */ + void invalidate(std::initializer_list attachments, const Rectanglei& rectangle); + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); }; diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 36508570f..056a08cd9 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -40,6 +40,8 @@ const Framebuffer::BufferAttachment Framebuffer::BufferAttachment::Stencil = Fra #ifndef MAGNUM_TARGET_GLES2 const Framebuffer::BufferAttachment Framebuffer::BufferAttachment::DepthStencil = Framebuffer::BufferAttachment(GL_DEPTH_STENCIL_ATTACHMENT); #endif +const Framebuffer::InvalidationAttachment Framebuffer::InvalidationAttachment::Depth = Framebuffer::InvalidationAttachment(GL_DEPTH_ATTACHMENT); +const Framebuffer::InvalidationAttachment Framebuffer::InvalidationAttachment::Stencil = Framebuffer::InvalidationAttachment(GL_STENCIL_ATTACHMENT); Framebuffer::Framebuffer(const Rectanglei& viewport) { _viewport = viewport; @@ -72,6 +74,26 @@ void Framebuffer::mapForDraw(std::initializer_list attachments) { + GLenum* _attachments = new GLenum[attachments.size()]; + for(std::size_t i = 0; i != attachments.size(); ++i) + _attachments[i] = GLenum(*(attachments.begin()+i)); + + invalidateImplementation(attachments.size(), _attachments); + + delete _attachments; +} + +void Framebuffer::invalidate(std::initializer_list attachments, const Rectanglei& rectangle) { + GLenum* _attachments = new GLenum[attachments.size()]; + for(std::size_t i = 0; i != attachments.size(); ++i) + _attachments[i] = GLenum(*(attachments.begin()+i)); + + invalidateImplementation(attachments.size(), _attachments, rectangle); + + delete _attachments; +} + void Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, GLint mipLevel) { /** @todo Check for texture target compatibility */ (this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel); diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 4cdb162d2..2bb2548ef 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -175,6 +175,34 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { GLenum attachment; }; + /** + * @brief Invalidation attachment + * + * @see invalidate() + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + */ + class InvalidationAttachment { + public: + /** @brief Invalidate depth buffer */ + static const InvalidationAttachment Depth; + + /** @brief Invalidate stencil buffer */ + static const InvalidationAttachment Stencil; + + /** @brief Invalidate color buffer */ + inline constexpr /*implicit*/ InvalidationAttachment(Framebuffer::ColorAttachment attachment): attachment(GLenum(attachment)) {} + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit operator GLenum() const { return attachment; } + #endif + + private: + inline constexpr explicit InvalidationAttachment(GLenum attachment): attachment(attachment) {} + + GLenum attachment; + }; + /** * @brief Constructor * @@ -230,6 +258,33 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { (this->*drawBufferImplementation)(GLenum(attachment)); } + /** + * @brief Invalidate framebuffer + * @param attachments Attachments to invalidate + * + * The framebuffer is bound to some target before the operation, if + * not already. + * @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} + * on OpenGL ES 2.0 + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + */ + void invalidate(std::initializer_list attachments); + + /** + * @brief Invalidate framebuffer rectangle + * @param attachments Attachments to invalidate + * @param rectangle %Rectangle to invalidate + * + * The framebuffer is bound to some target before the operation, if + * not already. + * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} + * on OpenGL ES 2.0 + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + */ + void invalidate(std::initializer_list attachments, const Rectanglei& rectangle); + /** * @brief Map given color attachment for reading * @param attachment Color attachment diff --git a/src/Texture.h b/src/Texture.h index e6013c716..96a6c9551 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -209,8 +209,8 @@ template class Texture: public AbstractTexture { * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some layer before the operation. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexImage1D}/ - * @fn_gl{TexImage2D}/@fn_gl{TexImage3D} or + * @see setSubImage(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexImage1D}/@fn_gl{TexImage2D}/@fn_gl{TexImage3D} or * @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access} @@ -239,9 +239,9 @@ template class Texture: public AbstractTexture { * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some layer before the operation. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexSubImage1D}/ - * @fn_gl{TexSubImage2D}/@fn_gl{TexSubImage3D} or - * @fn_gl_extension{TextureSubImage1D,EXT,direct_state_access}/ + * @see setImage(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexSubImage1D}/@fn_gl{TexSubImage2D}/@fn_gl{TexSubImage3D} + * or @fn_gl_extension{TextureSubImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} */ @@ -250,6 +250,22 @@ template class Texture: public AbstractTexture { return this; } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Invalidate texture subimage + * @param level Mip level + * @param offset Offset into the texture + * @param size Size of invalidated data + * + * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gl Texture image invalidation is not available in OpenGL ES. + */ + inline void invalidateSubImage(GLint level, const typename DimensionTraits::VectorType& offset, const typename DimensionTraits::VectorType& size) { + DataHelper::invalidateSub(this, level, offset, size); + } + #endif + /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT inline Texture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { From a7541e68d8dd83f77807e779a4e1b6bb74998701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 14:51:03 +0100 Subject: [PATCH 147/567] Doc++ --- src/DefaultFramebuffer.h | 12 ++++++++---- src/Framebuffer.h | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index d2df00bf6..a54c927a3 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -315,8 +315,10 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * not already. * @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use + * clear() instead where the extension is not supported. + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer}. + * Use clear() instead where the extension is not supported. */ void invalidate(std::initializer_list attachments); @@ -329,8 +331,10 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * not already. * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use + * clear() instead where the extension is not supported. + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer}. + * Use clear() instead where the extension is not supported. */ void invalidate(std::initializer_list attachments, const Rectanglei& rectangle); diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 2bb2548ef..8c4713876 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -266,8 +266,10 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * not already. * @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use + * clear() instead where the extension is not supported. + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer}. + * Use clear() instead where the extension is not supported. */ void invalidate(std::initializer_list attachments); @@ -280,8 +282,10 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * not already. * @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} * on OpenGL ES 2.0 - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use + * clear() instead where the extension is not supported. + * @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer}. + * Use clear() instead where the extension is not supported. */ void invalidate(std::initializer_list attachments, const Rectanglei& rectangle); From 5c5efea16856221ded2ad09d9ed4971e43b6e6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 14:51:56 +0100 Subject: [PATCH 148/567] Fixed CubeMapTexture*::invalidateSubImage(). The coordinates are 3D, not 2D. --- src/CubeMapTexture.h | 20 +++++++++++++++++--- src/CubeMapTextureArray.h | 18 +++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index ae3d7a51b..b9dacaa8d 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -127,10 +127,24 @@ class CubeMapTexture: public AbstractTexture { return this; } - /** @copydoc Texture::invalidateSubImage() */ - inline void invalidateSubImage(GLint level, const Vector2i& offset, const Vector2i& size) { - DataHelper<2>::invalidateSub(this, level, offset, size); + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Invalidate texture subimage + * @param level Mip level + * @param offset Offset into the texture + * @param size Size of invalidated data + * + * Z coordinate is equivalent to number of texture face, i.e. + * @ref Coordinate "Coordinate::PositiveX" is `0` and so on, in the + * same order as in the enum. + * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gl Texture image invalidation is not available in OpenGL ES. + */ + inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { + DataHelper<3>::invalidateSub(this, level, offset, size); } + #endif /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 480b3dbd1..80e42a171 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -152,9 +152,21 @@ class CubeMapTextureArray: public AbstractTexture { } #ifndef MAGNUM_TARGET_GLES - /** @copydoc Texture::invalidateSubImage() */ - inline void invalidateSubImage(GLint level, const Vector2i& offset, const Vector2i& size) { - DataHelper<2>::invalidateSub(this, level, offset, size); + /** + * @brief Invalidate texture subimage + * @param level Mip level + * @param offset Offset into the texture + * @param size Size of invalidated data + * + * Z coordinate is equivalent to layer * 6 + number of texture face, + * i.e. @ref Coordinate "Coordinate::PositiveX" is `0` and so on, in + * the same order as in the enum. + * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} + * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} + * @requires_gl Texture image invalidation is not available in OpenGL ES. + */ + inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { + DataHelper<3>::invalidateSub(this, level, offset, size); } #endif From 3829401e45563b74da4306185ae801381fb21856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 14:52:50 +0100 Subject: [PATCH 149/567] Fixed compilation on ES2. --- src/DefaultFramebuffer.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index a54c927a3..8548809df 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -238,13 +238,25 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #endif /** Invalidate color buffer. */ + #ifndef MAGNUM_TARGET_GLES2 Color = GL_COLOR, + #else + Color = GL_COLOR_EXT, + #endif /** Invalidate depth bufer. */ + #ifndef MAGNUM_TARGET_GLES2 Depth = GL_DEPTH, + #else + Depth = GL_DEPTH_EXT, + #endif /** Invalidate stencil buffer. */ + #ifndef MAGNUM_TARGET_GLES2 Stencil = GL_STENCIL + #else + Stencil = GL_STENCIL_EXT + #endif }; explicit MAGNUM_LOCAL DefaultFramebuffer(); From 78bfe51966dc515e5a0f835a1887522770fa4c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 15:48:08 +0100 Subject: [PATCH 150/567] Fixed compiler warnings. --- src/AbstractFramebuffer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 3fa25606f..e0855a4de 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -148,6 +148,8 @@ void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attach glInvalidateFramebuffer(GLenum(bindInternal()), count, attachments); #else //glDiscardFramebufferEXT(GLenum(bindInternal()), count, attachments); + static_cast(count); + static_cast(attachments); #endif } @@ -157,6 +159,8 @@ void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attach glInvalidateSubFramebuffer(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.width(), rectangle.height()); #else //glDiscardSubFramebufferEXT(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.width(), rectangle.height()); + static_cast(count); + static_cast(attachments); static_cast(rectangle); #endif } From 03f6095b9d637a2f3e2207e42e127c266690cf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 15:58:26 +0100 Subject: [PATCH 151/567] Forgot to hide DSA functions when targetting ES. --- src/AbstractTexture.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index b4eeb267e..c13cc1230 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1197,12 +1197,16 @@ class MAGNUM_EXPORT AbstractTexture { typedef void(AbstractTexture::*Image2DImplementation)(GLenum, GLint, InternalFormat, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #endif static Image2DImplementation image2DImplementation; typedef void(AbstractTexture::*Image3DImplementation)(GLenum, GLint, InternalFormat, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL imageImplementationDSA(GLenum target, GLint level, InternalFormat internalFormat, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #endif static Image3DImplementation image3DImplementation; #ifndef MAGNUM_TARGET_GLES @@ -1214,12 +1218,16 @@ class MAGNUM_EXPORT AbstractTexture { typedef void(AbstractTexture::*SubImage2DImplementation)(GLenum, GLint, const Vector2i&, const Vector2i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint level, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint level, const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #endif static SubImage2DImplementation subImage2DImplementation; typedef void(AbstractTexture::*SubImage3DImplementation)(GLenum, GLint, const Vector3i&, const Vector3i&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); void MAGNUM_LOCAL subImageImplementationDefault(GLenum target, GLint level, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #ifndef MAGNUM_TARGET_GLES void MAGNUM_LOCAL subImageImplementationDSA(GLenum target, GLint level, const Vector3i& offset, const Vector3i& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); + #endif static SubImage3DImplementation subImage3DImplementation; void MAGNUM_LOCAL destroy(); From 35a918d0501919cb41f78bd0cd446055b5d61198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 16:11:52 +0100 Subject: [PATCH 152/567] Extension-aware Buffer and *Texture data invalidation. If ARB_invalidate_subdata is not available, these functions do nothing, instead of crashing on null pointer dereference. It results in more convenient usage, enabling users to call them whenever they want, improving performance on implementations which supports that. --- src/AbstractTexture.cpp | 26 +++++++++++++++++++++++++ src/AbstractTexture.h | 40 +++++++++++++++++++++++++-------------- src/Buffer.cpp | 25 ++++++++++++++++++++++++ src/Buffer.h | 38 +++++++++++++++++++++++++++++-------- src/CubeMapTexture.h | 7 +++---- src/CubeMapTextureArray.h | 7 +++---- src/Texture.h | 6 ++---- 7 files changed, 115 insertions(+), 34 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 6f07fd02e..75530006a 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -49,6 +49,9 @@ AbstractTexture::SubImage2DImplementation AbstractTexture::subImage2DImplementat AbstractTexture::SubImage3DImplementation AbstractTexture::subImage3DImplementation = &AbstractTexture::subImageImplementationDefault; +AbstractTexture::InvalidateImplementation AbstractTexture::invalidateImplementation = &AbstractTexture::invalidateImplementationNoOp; +AbstractTexture::InvalidateSubImplementation AbstractTexture::invalidateSubImplementation = &AbstractTexture::invalidateSubImplementationNoOp; + #ifndef DOXYGEN_GENERATING_OUTPUT /* Check correctness of binary OR in setMinificationFilter(). If nobody fucks @@ -213,6 +216,13 @@ void AbstractTexture::initializeContextBasedFunctionality(Context* context) { subImage2DImplementation = &AbstractTexture::subImageImplementationDSA; subImage3DImplementation = &AbstractTexture::subImageImplementationDSA; } + + if(context->isExtensionSupported()) { + Debug() << "AbstractTexture: using" << Extensions::GL::ARB::invalidate_subdata::string() << "features"; + + invalidateImplementation = &AbstractTexture::invalidateImplementationARB; + invalidateSubImplementation = &AbstractTexture::invalidateSubImplementationARB; + } #endif } @@ -335,6 +345,22 @@ void AbstractTexture::subImageImplementationDSA(GLenum target, GLint level, cons } #endif +void AbstractTexture::invalidateImplementationNoOp(GLint) {} + +#ifndef MAGNUM_TARGET_GLES +void AbstractTexture::invalidateImplementationARB(GLint level) { + glInvalidateTexImage(_id, level); +} +#endif + +void AbstractTexture::invalidateSubImplementationNoOp(GLint, const Vector3i&, const Vector3i&) {} + +#ifndef MAGNUM_TARGET_GLES +void AbstractTexture::invalidateSubImplementationARB(GLint level, const Vector3i& offset, const Vector3i& size) { + glInvalidateTexSubImage(_id, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z()); +} +#endif + #ifndef DOXYGEN_GENERATING_OUTPUT void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D& wrapping) { #ifndef MAGNUM_TARGET_GLES diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index c13cc1230..d8021bf78 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -53,6 +53,12 @@ dedicated layers, not occupied by other textures. Always fully configure the texture before setting the texture data, so OpenGL can optimize the data to match your settings. +You can use functions invalidateImage() and @ref Texture::invalidateSubImage() "invalidateSubImage()" +if you don't need texture data anymore to avoid unnecessary memory operations +performed by OpenGL in order to preserve the data. If running on OpenGL ES or +extension @extension{ARB,invalidate_subdata} is not available, these functions +do nothing. + @todo Add glPixelStore encapsulation @todo Texture copying @todo Move constructor/assignment - how to avoid creation of empty texture and @@ -1111,20 +1117,18 @@ class MAGNUM_EXPORT AbstractTexture { return this; } - #ifndef MAGNUM_TARGET_GLES /** * @brief Invalidate texture image * @param level Mip level * + * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} + * is not available, this function does nothing. * @see @ref Texture::invalidateSubImage() "invalidateSubImage()", * @fn_gl{InvalidateTexImage} - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gl Texture image invalidation is not available in OpenGL ES. */ inline void invalidateImage(GLint level) { - glInvalidateTexImage(_id, level); + (this->*invalidateImplementation)(level); } - #endif /** * @brief Generate mipmap @@ -1230,6 +1234,20 @@ class MAGNUM_EXPORT AbstractTexture { #endif static SubImage3DImplementation subImage3DImplementation; + typedef void(AbstractTexture::*InvalidateImplementation)(GLint); + void MAGNUM_LOCAL invalidateImplementationNoOp(GLint level); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL invalidateImplementationARB(GLint level); + #endif + static InvalidateImplementation invalidateImplementation; + + typedef void(AbstractTexture::*InvalidateSubImplementation)(GLint, const Vector3i&, const Vector3i&); + void MAGNUM_LOCAL invalidateSubImplementationNoOp(GLint level, const Vector3i& offset, const Vector3i& size); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL invalidateSubImplementationARB(GLint level, const Vector3i& offset, const Vector3i& size); + #endif + static InvalidateSubImplementation invalidateSubImplementation; + void MAGNUM_LOCAL destroy(); void MAGNUM_LOCAL move(); @@ -1257,11 +1275,9 @@ template<> struct AbstractTexture::DataHelper<1> { (texture->*subImage1DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); } - #ifndef MAGNUM_TARGET_GLES inline static void invalidateSub(AbstractTexture* texture, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLint>& size) { - glInvalidateTexSubImage(texture->_id, level, offset[0], 0, 0, size[0], 1, 1); + (texture->*invalidateSubImplementation)(level, {offset[0], 0, 0}, {size[0], 1, 1}); } - #endif }; #endif template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { @@ -1290,11 +1306,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { (texture->*subImage2DImplementation)(target, level, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data()); } - #ifndef MAGNUM_TARGET_GLES inline static void invalidateSub(AbstractTexture* texture, GLint level, const Vector2i& offset, const Vector2i& size) { - glInvalidateTexSubImage(texture->_id, level, offset.x(), offset.y(), 0, size.x(), size.y(), 1); + (texture->*invalidateSubImplementation)(level, {offset, 0}, {size, 1}); } - #endif }; template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { enum class Target: GLenum { @@ -1322,11 +1336,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { (texture->*subImage3DImplementation)(target, level, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data()); } - #ifndef MAGNUM_TARGET_GLES inline static void invalidateSub(AbstractTexture* texture, GLint level, const Vector3i& offset, const Vector3i& size) { - glInvalidateTexSubImage(texture->_id, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z()); + (texture->*invalidateSubImplementation)(level, offset, size); } - #endif }; #endif diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 524a7b815..f37079450 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -29,6 +29,8 @@ Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementat #endif Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault; Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault; +Buffer::InvalidateImplementation Buffer::invalidateImplementation = &Buffer::invalidateImplementationNoOp; +Buffer::InvalidateSubImplementation Buffer::invalidateSubImplementation = &Buffer::invalidateSubImplementationNoOp; Buffer::MapImplementation Buffer::mapImplementation = &Buffer::mapImplementationDefault; Buffer::MapRangeImplementation Buffer::mapRangeImplementation = &Buffer::mapRangeImplementationDefault; Buffer::FlushMappedRangeImplementation Buffer::flushMappedRangeImplementation = &Buffer::flushMappedRangeImplementationDefault; @@ -47,6 +49,13 @@ void Buffer::initializeContextBasedFunctionality(Context* context) { flushMappedRangeImplementation = &Buffer::flushMappedRangeImplementationDSA; unmapImplementation = &Buffer::unmapImplementationDSA; } + + if(context->isExtensionSupported()) { + Debug() << "Buffer: using" << Extensions::GL::ARB::invalidate_subdata::string() << "features"; + + invalidateImplementation = &Buffer::invalidateImplementationARB; + invalidateSubImplementation = &Buffer::invalidateSubImplementationARB; + } #else static_cast(context); #endif @@ -122,6 +131,22 @@ void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const } #endif +void Buffer::invalidateImplementationNoOp() {} + +#ifndef MAGNUM_TARGET_GLES +void Buffer::invalidateImplementationARB() { + glInvalidateBufferData(_id); +} +#endif + +void Buffer::invalidateSubImplementationNoOp(GLintptr, GLsizeiptr) {} + +#ifndef MAGNUM_TARGET_GLES +void Buffer::invalidateSubImplementationARB(GLintptr offset, GLsizeiptr length) { + glInvalidateBufferSubData(_id, offset, length); +} +#endif + void* Buffer::mapImplementationDefault(MapAccess access) { /** @todo Re-enable when extension wrangler is available for ES */ #ifndef MAGNUM_TARGET_GLES diff --git a/src/Buffer.h b/src/Buffer.h index 07a93271e..a02d20088 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -102,6 +102,12 @@ copy(), setData(), setSubData(), map(), flushMappedRange() and unmap() use DSA functions to avoid unnecessary calls to @fn_gl{BindBuffer}. See their respective documentation for more information. +You can use functions invalidateData() and invalidateSubData() if you don't +need buffer data anymore to avoid unnecessary memory operations performed by +OpenGL in order to preserve the data. If running on OpenGL ES or extension +@extension{ARB,invalidate_subdata} is not available, these functions do +nothing. + @todo Support for AMD's query buffer (@extension{AMD,query_buffer_object}) @todo BindBufferRange/BindBufferOffset/BindBufferBase for transform feedback (3.0, @extension{EXT,transform_feedback}) */ @@ -363,6 +369,7 @@ class MAGNUM_EXPORT Buffer { /** * Previous contents of the entire buffer may be discarded. May * not be used in combination with @ref MapFlag "MapFlag::Read". + * @see invalidateData() */ #ifndef MAGNUM_TARGET_GLES2 InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT, @@ -373,6 +380,7 @@ class MAGNUM_EXPORT Buffer { /** * Previous contents of mapped range may be discarded. May not * be used in combination with @ref MapFlag "MapFlag::Read". + * @see invalidateSubData() */ #ifndef MAGNUM_TARGET_GLES2 InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT, @@ -584,12 +592,12 @@ class MAGNUM_EXPORT Buffer { /** * @brief Invalidate buffer data * - * @see @fn_gl{InvalidateBufferData} - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gl Buffer data invalidation is not available in OpenGL ES. + * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} + * is not available, this function does nothing. + * @see @ref MapFlag "MapFlag::InvalidateBuffer", @fn_gl{InvalidateBufferData} */ inline void invalidateData() { - glInvalidateBufferData(_id); + (this->*invalidateImplementation)(); } /** @@ -597,12 +605,12 @@ class MAGNUM_EXPORT Buffer { * @param offset Offset into the buffer * @param length Length of the invalidated range * - * @see @fn_gl{InvalidateBufferData} - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gl Buffer data invalidation is not available in OpenGL ES. + * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} + * is not available, this function does nothing. + * @see @ref MapFlag "MapFlag::InvalidateRange", @fn_gl{InvalidateBufferData} */ inline void invalidateSubData(GLintptr offset, GLsizeiptr length) { - glInvalidateBufferSubData(_id, offset, length); + (this->*invalidateSubImplementation)(offset, length); } #endif @@ -714,6 +722,20 @@ class MAGNUM_EXPORT Buffer { #endif static SetSubDataImplementation setSubDataImplementation; + typedef void(Buffer::*InvalidateImplementation)(); + void MAGNUM_LOCAL invalidateImplementationNoOp(); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL invalidateImplementationARB(); + #endif + static InvalidateImplementation invalidateImplementation; + + typedef void(Buffer::*InvalidateSubImplementation)(GLintptr, GLsizeiptr); + void MAGNUM_LOCAL invalidateSubImplementationNoOp(GLintptr offset, GLsizeiptr length); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL invalidateSubImplementationARB(GLintptr offset, GLsizeiptr length); + #endif + static InvalidateSubImplementation invalidateSubImplementation; + typedef void*(Buffer::*MapImplementation)(MapAccess); void MAGNUM_LOCAL * mapImplementationDefault(MapAccess access); #ifndef MAGNUM_TARGET_GLES diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index b9dacaa8d..0c7270520 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -127,7 +127,6 @@ class CubeMapTexture: public AbstractTexture { return this; } - #ifndef MAGNUM_TARGET_GLES /** * @brief Invalidate texture subimage * @param level Mip level @@ -137,14 +136,14 @@ class CubeMapTexture: public AbstractTexture { * Z coordinate is equivalent to number of texture face, i.e. * @ref Coordinate "Coordinate::PositiveX" is `0` and so on, in the * same order as in the enum. + * + * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} + * is not available, this function does nothing. * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gl Texture image invalidation is not available in OpenGL ES. */ inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { DataHelper<3>::invalidateSub(this, level, offset, size); } - #endif /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 80e42a171..15b95c030 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -151,7 +151,6 @@ class CubeMapTextureArray: public AbstractTexture { return this; } - #ifndef MAGNUM_TARGET_GLES /** * @brief Invalidate texture subimage * @param level Mip level @@ -161,14 +160,14 @@ class CubeMapTextureArray: public AbstractTexture { * Z coordinate is equivalent to layer * 6 + number of texture face, * i.e. @ref Coordinate "Coordinate::PositiveX" is `0` and so on, in * the same order as in the enum. + * + * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} + * is not available, this function does nothing. * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gl Texture image invalidation is not available in OpenGL ES. */ inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { DataHelper<3>::invalidateSub(this, level, offset, size); } - #endif /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Texture.h b/src/Texture.h index 96a6c9551..5e7000d7d 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -250,21 +250,19 @@ template class Texture: public AbstractTexture { return this; } - #ifndef MAGNUM_TARGET_GLES /** * @brief Invalidate texture subimage * @param level Mip level * @param offset Offset into the texture * @param size Size of invalidated data * + * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} + * is not available, this function does nothing. * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} - * @requires_gl43 %Extension @extension{ARB,invalidate_subdata} - * @requires_gl Texture image invalidation is not available in OpenGL ES. */ inline void invalidateSubImage(GLint level, const typename DimensionTraits::VectorType& offset, const typename DimensionTraits::VectorType& size) { DataHelper::invalidateSub(this, level, offset, size); } - #endif /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT From eaa87147d4679d489642f63dab73b0ac3924a544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 16:25:05 +0100 Subject: [PATCH 153/567] Doc++ This is how it should like after debug renderer rework. Don't know what got forgotten or messed up. --- src/DebugTools/ObjectRenderer.h | 3 ++- src/DebugTools/ShapeRenderer.h | 15 +-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h index b94f42025..9eb75f99a 100644 --- a/src/DebugTools/ObjectRenderer.h +++ b/src/DebugTools/ObjectRenderer.h @@ -53,7 +53,8 @@ class ObjectRendererOptions { /** @brief Object renderer -Visualizes object position, rotation and scale using colored axes. +Visualizes object position, rotation and scale using colored axes. See +@ref debug-tools-renderers for more information. @section ObjectRenderer-usage Basic usage diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 21adf2c59..04b32c69c 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -62,25 +62,12 @@ class ShapeRendererOptions { /** @brief Shape renderer -Visualizes collision shape. +Visualizes collision shape. See @ref debug-tools-renderers for more information. @section ShapeRenderer-usage Basic usage -ResourceManager must be instanced for the whole lifetime of debug -renderers. You can specify options via ShapeRendererOptions struct - add it to -the manager and then create debug renderer with the same options key. This way -you can easily share the same options with more renderers. If no options for -given key exist, default is used. - Example code: @code -// Instance the manager at first -DebugTools::ResourceManager manager; - -// Group of drawables, preferrably dedicated for debug renderers, so you can -// easily enable or disable debug draw -SceneGraph::DrawableGroup2D debugDrawables; - // Create some options DebugTools::ResourceManager::instance()->set("red", (new DebugTools::ShapeRendererOptions())->setColor({1.0f, 0.0f, 0.0f}), From 9ad15b12fbcdcbd07c4b748d9e4cf617eb498f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 16:27:44 +0100 Subject: [PATCH 154/567] Mark ARB_invalidate_subdata as done. --- src/Context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context.cpp b/src/Context.cpp index 9518f1005..9ec98767a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -180,7 +180,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,ARB,fragment_layer_viewport), // done _extension(GL,ARB,framebuffer_no_attachments), _extension(GL,ARB,internalformat_query2), - _extension(GL,ARB,invalidate_subdata), + _extension(GL,ARB,invalidate_subdata), // done _extension(GL,ARB,multi_draw_indirect), _extension(GL,ARB,program_interface_query), _extension(GL,ARB,robust_buffer_access_behavior), // done From 08d9f65b0659d4958b4395c29979bd0841eeb79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 16:38:11 +0100 Subject: [PATCH 155/567] Text: assert that {ARB,EXT}_texture_rg is supported. EXT_texture_rg is not available on my OpenGL ES 2.0 implementation, will find alternative later. At least it now compiles. --- src/Text/Font.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 757a070ad..c294641ee 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -19,6 +19,7 @@ #include FT_FREETYPE_H #include +#include "Extensions.h" #include "Image.h" #include "TextureTools/Atlas.h" @@ -86,10 +87,20 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co } /* Set texture data */ + #ifndef MAGNUM_TARGET_GLES _texture.setImage(0, Texture2D::InternalFormat::R8, &image); + #else + _texture.setImage(0, Texture2D::InternalFormat::Red, &image); + #endif } void Font::create(FontRenderer& renderer, const std::string& fontFile) { + #ifndef MAGNUM_TARGET_GLES + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); + #else + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); + #endif + /* Create FreeType font */ CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); From 52300cf40252566a083c9495029133f520d3a4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 18:24:39 +0100 Subject: [PATCH 156/567] Math: function for base-2 logarithm. Verbatim copy from Corrade, might be better to have it here too (possibly some SIMD optimizations?). --- src/Math/Math.cpp | 7 +++++++ src/Math/Math.h | 9 +++++++++ src/Math/Test/MathTest.cpp | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Math/Math.cpp b/src/Math/Math.cpp index 7e432040f..d2cdd0ce6 100644 --- a/src/Math/Math.cpp +++ b/src/Math/Math.cpp @@ -17,6 +17,13 @@ namespace Magnum { namespace Math { +std::uint32_t log2(std::uint32_t number) { + std::uint32_t log = 0; + while(number >>= 1) + ++log; + return log; +} + std::uint32_t log(std::uint32_t base, std::uint32_t number) { std::uint32_t log = 0; while(number /= base) diff --git a/src/Math/Math.h b/src/Math/Math.h index 9bc03cf82..7a9004fe1 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -58,10 +58,19 @@ template inline constexpr T pow(T base) { return Implementation::Pow()(base); } +/** + * @brief Base-2 integral logarithm + * + * Returns integral logarithm of given number with base `2`. + * @see log() + */ +std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number); + /** * @brief Integral logarithm * * Returns integral logarithm of given number with given base. + * @see log2() */ std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number); diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index e14aeaf18..044bfa350 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -28,6 +28,7 @@ class MathTest: public Corrade::TestSuite::Tester { void clamp(); void pow(); void log(); + void log2(); }; MathTest::MathTest() { @@ -35,7 +36,8 @@ MathTest::MathTest() { &MathTest::denormalize, &MathTest::clamp, &MathTest::pow, - &MathTest::log); + &MathTest::log, + &MathTest::log2); } void MathTest::normalize() { @@ -105,6 +107,10 @@ void MathTest::log() { CORRADE_COMPARE(Math::log(256, 2), 0ul); } +void MathTest::log2() { + CORRADE_COMPARE(Math::log2(2153), 11); +} + }}} CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) From 23d481afb7e5b0b6db33848fe1065b72278eca9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 19:28:43 +0100 Subject: [PATCH 157/567] Doc++ Not using @copydoc for Texture derivatives but linking manually instead. It looks better and doesn't have mixed up irrelevant information. --- src/AbstractTexture.h | 9 ++------- src/CubeMapTexture.h | 30 +++++++++++++++++++++--------- src/CubeMapTextureArray.h | 24 ++++++++++++++++-------- src/Texture.h | 3 ++- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index d8021bf78..afedd74b9 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -990,16 +990,11 @@ class MAGNUM_EXPORT AbstractTexture { */ static GLfloat maxSupportedAnisotropy(); - /** - * @brief Constructor - * @param target Target, e.g. `GL_TEXTURE_2D`. - * - * Creates one OpenGL texture. - * @see @fn_gl{GenTextures} - */ + #ifndef DOXYGEN_GENERATING_OUTPUT inline explicit AbstractTexture(GLenum target): _target(target) { glGenTextures(1, &_id); } + #endif /** * @brief Destructor diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 0c7270520..6e8f9da46 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -95,12 +95,14 @@ class CubeMapTexture: public AbstractTexture { * @brief Constructor * * Creates one cube map OpenGL texture. - * @see @def_gl{TEXTURE_CUBE_MAP} + * @see @fn_gl{GenTextures} with @def_gl{TEXTURE_CUBE_MAP} */ inline explicit CubeMapTexture(): AbstractTexture(GL_TEXTURE_CUBE_MAP) {} /** - * @copydoc Texture::setWrapping() + * @brief Set wrapping + * + * See Texture::setWrapping() for more information. */ inline CubeMapTexture* setWrapping(const Array3D& wrapping) { DataHelper<3>::setWrapping(this, wrapping); @@ -108,9 +110,15 @@ class CubeMapTexture: public AbstractTexture { } /** - * @copydoc Texture::setImage(GLint, InternalFormat, Image*) - * @param coordinate Coordinate + * @brief Set image data + * @param coordinate Coordinate + * @param level Mip level + * @param internalFormat Internal format + * @param image Image, ImageWrapper, BufferImage or + * Trade::ImageData of the same dimension count * @return Pointer to self (for method chaining) + * + * See Texture::setImage() for more information. */ template inline CubeMapTexture* setImage(Coordinate coordinate, GLint level, InternalFormat internalFormat, Image* image) { DataHelper<2>::set(this, static_cast(coordinate), level, internalFormat, image); @@ -118,9 +126,15 @@ class CubeMapTexture: public AbstractTexture { } /** - * @copydoc Texture::setSubImage(GLint, const typename DimensionTraits::VectorType&, Image*) - * @param coordinate Coordinate + * @brief Set image subdata + * @param coordinate Coordinate + * @param level Mip level + * @param offset Offset where to put data in the texture + * @param image Image, ImageWrapper, BufferImage or + * Trade::ImageData of the same or one less dimension count * @return Pointer to self (for method chaining) + * + * See Texture::setSubImage() for more information. */ template inline CubeMapTexture* setSubImage(Coordinate coordinate, GLint level, const Vector2i& offset, const Image* image) { DataHelper<2>::setSub(this, static_cast(coordinate), level, offset, image); @@ -137,9 +151,7 @@ class CubeMapTexture: public AbstractTexture { * @ref Coordinate "Coordinate::PositiveX" is `0` and so on, in the * same order as in the enum. * - * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} - * is not available, this function does nothing. - * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} + * See Texture::invalidateSubImage() for more information. */ inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { DataHelper<3>::invalidateSub(this, level, offset, size); diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 15b95c030..00f3e574f 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -85,12 +85,14 @@ class CubeMapTextureArray: public AbstractTexture { * @brief Constructor * * Creates one cube map OpenGL texture. - * @see @def_gl{TEXTURE_CUBE_MAP_ARRAY} + * @see @fn_gl{GenTextures} with @def_gl{TEXTURE_CUBE_MAP} */ inline explicit CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {} /** - * @copydoc Texture::setWrapping() + * @brief Set wrapping + * + * See Texture::setWrapping() for more information. */ inline CubeMapTextureArray* setWrapping(const Array3D& wrapping) { DataHelper<3>::setWrapping(this, wrapping); @@ -98,11 +100,18 @@ class CubeMapTextureArray: public AbstractTexture { } /** - * @copydoc Texture::setImage(GLint, InternalFormat, Image*) + * @brief Set image data + * @param level Mip level + * @param internalFormat Internal format + * @param image Image, ImageWrapper, BufferImage or + * Trade::ImageData of the same dimension count + * @return Pointer to self (for method chaining) * * Sets texture image data from three-dimensional image for all cube * faces for all layers. Each group of 6 2D images is one cube map * layer. The images are ordered the same way as Coordinate enum. + * + * See Texture::setImage() for more information. */ template inline CubeMapTextureArray* setImage(GLint level, InternalFormat internalFormat, T* image) { DataHelper<3>::set(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, internalFormat, image); @@ -118,13 +127,14 @@ class CubeMapTextureArray: public AbstractTexture { * @return Pointer to self (for method chaining) * * Sets texture image subdata for more than one level/face at once. - * The image is not deleted afterwards. * * Z coordinate of @p offset specifies layer and cube map face. If * you want to start at given face in layer *n*, you have to specify * Z coordinate as @f$ 6n + i @f$, where i is face index as specified * in Coordinate enum. * + * See Texture::setSubImage() for more information. + * * @see setSubImage(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) */ template inline CubeMapTextureArray* setSubImage(GLint level, const Vector3i& offset, const Image* image) { @@ -142,7 +152,7 @@ class CubeMapTextureArray: public AbstractTexture { * Trade::ImageData2D * @return Pointer to self (for method chaining) * - * The image is not deleted afterwards. + * See Texture::setSubImage() for more information. * * @see setSubImage(GLint, const Math::Vector<3, GLint>&, const Image*) */ @@ -161,9 +171,7 @@ class CubeMapTextureArray: public AbstractTexture { * i.e. @ref Coordinate "Coordinate::PositiveX" is `0` and so on, in * the same order as in the enum. * - * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} - * is not available, this function does nothing. - * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} + * See Texture::invalidateSubImage() for more information. */ inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { DataHelper<3>::invalidateSub(this, level, offset, size); diff --git a/src/Texture.h b/src/Texture.h index 5e7000d7d..8b3738609 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -168,6 +168,7 @@ template class Texture: public AbstractTexture { * `Target::Texture3D` based on dimension count. * * Creates one OpenGL texture. + * @see @fn_gl{GenTextures} */ inline explicit Texture(Target target = DataHelper::target()): AbstractTexture(static_cast(target)) {} @@ -200,7 +201,7 @@ template class Texture: public AbstractTexture { /** * @brief Set image data * @param level Mip level - * @param internalFormat Internal texture format + * @param internalFormat Internal format * @param image Image, ImageWrapper, BufferImage or * Trade::ImageData of the same dimension count * @return Pointer to self (for method chaining) From c8444bdbbe5d8eb92cc316001abab064f266ee91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 19:29:51 +0100 Subject: [PATCH 158/567] Added EXT_texture_storage ES2 extension to the list. --- src/Context.cpp | 1 + src/Extensions.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Context.cpp b/src/Context.cpp index 9ec98767a..46d1a623d 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -218,6 +218,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,EXT,blend_minmax), _extension(GL,EXT,occlusion_query_boolean), _extension(GL,EXT,texture_rg), + _extension(GL,EXT,texture_storage), _extension(GL,EXT,map_buffer_range), _extension(GL,NV,draw_buffers), _extension(GL,NV,read_buffer), diff --git a/src/Extensions.h b/src/Extensions.h index 8a2540f03..abca47d91 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -195,6 +195,7 @@ namespace GL { _extension(GL,EXT,separate_shader_objects, GLES200, None) // #101 _extension(GL,EXT,texture_rg, GLES200, GLES300) // #103 _extension(GL,EXT,sRGB, GLES200, None) // #105 + _extension(GL,EXT,texture_storage, GLES200, GLES300) // #108 _extension(GL,EXT,map_buffer_range, GLES200, GLES300) // #121 } namespace NV { _extension(GL,NV,draw_buffers, GLES200, GLES300) // #91 From f83c2b601bf4fb6fa4d58005b114cac778a2c07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 19:32:21 +0100 Subject: [PATCH 159/567] Implemented ARB_texture_storage. Equivalent functionality is in ES3 and also EXT_texture_storage ES2 extension. --- src/AbstractTexture.cpp | 69 +++++++++++++++++++++++++++++++++++++++ src/AbstractTexture.h | 48 +++++++++++++++++++++++---- src/CubeMapTexture.h | 15 +++++++-- src/CubeMapTextureArray.h | 24 ++++++++++---- src/Texture.h | 58 ++++++++++++++++++++++++-------- 5 files changed, 184 insertions(+), 30 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 75530006a..4c034ef00 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -33,6 +33,14 @@ AbstractTexture::ParameterfvImplementation AbstractTexture::parameterfvImplement AbstractTexture::MipmapImplementation AbstractTexture::mipmapImplementation = &AbstractTexture::mipmapImplementationDefault; #ifndef MAGNUM_TARGET_GLES +AbstractTexture::Storage1DImplementation AbstractTexture::storage1DImplementation = + &AbstractTexture::storageImplementationDefault; +#endif +AbstractTexture::Storage2DImplementation AbstractTexture::storage2DImplementation = + &AbstractTexture::storageImplementationDefault; +AbstractTexture::Storage3DImplementation AbstractTexture::storage3DImplementation = + &AbstractTexture::storageImplementationDefault; +#ifndef MAGNUM_TARGET_GLES AbstractTexture::Image1DImplementation AbstractTexture::image1DImplementation = &AbstractTexture::imageImplementationDefault; #endif @@ -209,6 +217,9 @@ void AbstractTexture::initializeContextBasedFunctionality(Context* context) { parameterfImplementation = &AbstractTexture::parameterImplementationDSA; parameterfvImplementation = &AbstractTexture::parameterImplementationDSA; mipmapImplementation = &AbstractTexture::mipmapImplementationDSA; + storage1DImplementation = &AbstractTexture::storageImplementationDSA; + storage2DImplementation = &AbstractTexture::storageImplementationDSA; + storage3DImplementation = &AbstractTexture::storageImplementationDSA; image1DImplementation = &AbstractTexture::imageImplementationDSA; image2DImplementation = &AbstractTexture::imageImplementationDSA; image3DImplementation = &AbstractTexture::imageImplementationDSA; @@ -258,6 +269,64 @@ void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat glTextureParameterfvEXT(_id, _target, parameter, values); } +void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Math::Vector< 1, GLsizei >& size) { + bindInternal(); + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glTexStorage1D(target, levels, GLenum(internalFormat), size[0]); + #else + //glTexStorage2DEXT(target, levels, GLenum(internalFormat), size.x(), size.y()); + static_cast(target); + static_cast(levels); + static_cast(internalFormat); + static_cast(size); + #endif +} + +void AbstractTexture::storageImplementationDSA(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Math::Vector< 1, GLsizei >& size) { + glTextureStorage1DEXT(_id, target, levels, GLenum(internalFormat), size[0]); +} +#endif + +void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Vector2i& size) { + bindInternal(); + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glTexStorage2D(target, levels, GLenum(internalFormat), size.x(), size.y()); + #else + //glTexStorage2DEXT(target, levels, GLenum(internalFormat), size.x(), size.y()); + static_cast(target); + static_cast(levels); + static_cast(internalFormat); + static_cast(size); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractTexture::storageImplementationDSA(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Vector2i& size) { + glTextureStorage2DEXT(_id, target, levels, GLenum(internalFormat), size.x(), size.y()); +} +#endif + +void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Vector3i& size) { + bindInternal(); + /** @todo Re-enable when extension wrangler is available for ES2 */ + #ifndef MAGNUM_TARGET_GLES2 + glTexStorage3D(target, levels, GLenum(internalFormat), size.x(), size.y(), size.z()); + #else + //glTexStorage3DEXT(target, levels, GLenum(internalFormat), size.x(), size.y(), size.z()); + static_cast(target); + static_cast(levels); + static_cast(internalFormat); + static_cast(size); + #endif +} + +#ifndef MAGNUM_TARGET_GLES +void AbstractTexture::storageImplementationDSA(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Vector3i& size) { + glTextureStorage3DEXT(_id, target, levels, GLenum(internalFormat), size.x(), size.y(), size.z()); +} + void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data) { bindInternal(); glTexImage1D(target, level, static_cast(internalFormat), size[0], 0, static_cast(format), static_cast(type), data); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index afedd74b9..b2c875343 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -42,16 +42,17 @@ repeated @fn_gl{Get} calls. If extension @extension{EXT,direct_state_access} is available, bind() uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture}. Also all texture -configuration functions use DSA functions to avoid unnecessary calls to -@fn_gl{ActiveTexture} and @fn_gl{BindTexture}. See respective function -documentation for more information. +configuration and data updating functions use DSA functions to avoid +unnecessary calls to @fn_gl{ActiveTexture} and @fn_gl{BindTexture}. See +respective function documentation for more information. To achieve least state changes, fully configure each texture in one run -- method chaining comes in handy -- and try to have often used textures in -dedicated layers, not occupied by other textures. - -Always fully configure the texture before setting the texture data, so OpenGL -can optimize the data to match your settings. +dedicated layers, not occupied by other textures. First configure the texture +and *then* set the data, so OpenGL can optimize them to match the settings. To +avoid redundant consistency checks and memory reallocations when updating +texture data, set texture storage at once using @ref Texture::setStorage() "setStorage()" +and then set data using @ref Texture::setSubImage() "setSubImage()". You can use functions invalidateImage() and @ref Texture::invalidateSubImage() "invalidateSubImage()" if you don't need texture data anymore to avoid unnecessary memory operations @@ -1187,6 +1188,27 @@ class MAGNUM_EXPORT AbstractTexture { #endif static MAGNUM_LOCAL MipmapImplementation mipmapImplementation; + #ifndef MAGNUM_TARGET_GLES + typedef void(AbstractTexture::*Storage1DImplementation)(GLenum, GLsizei, InternalFormat, const Math::Vector<1, GLsizei>&); + void MAGNUM_LOCAL storageImplementationDefault(GLenum target, GLsizei levels, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size); + void MAGNUM_LOCAL storageImplementationDSA(GLenum target, GLsizei levels, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size); + static Storage1DImplementation storage1DImplementation; + #endif + + typedef void(AbstractTexture::*Storage2DImplementation)(GLenum, GLsizei, InternalFormat, const Vector2i&); + void MAGNUM_LOCAL storageImplementationDefault(GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector2i& size); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL storageImplementationDSA(GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector2i& size); + #endif + static Storage2DImplementation storage2DImplementation; + + typedef void(AbstractTexture::*Storage3DImplementation)(GLenum, GLsizei, InternalFormat, const Vector3i&); + void MAGNUM_LOCAL storageImplementationDefault(GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector3i& size); + #ifndef MAGNUM_TARGET_GLES + void MAGNUM_LOCAL storageImplementationDSA(GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector3i& size); + #endif + static Storage3DImplementation storage3DImplementation; + #ifndef MAGNUM_TARGET_GLES typedef void(AbstractTexture::*Image1DImplementation)(GLenum, GLint, InternalFormat, const Math::Vector<1, GLsizei>&, AbstractImage::Format, AbstractImage::Type, const GLvoid*); void MAGNUM_LOCAL imageImplementationDefault(GLenum target, GLint level, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size, AbstractImage::Format format, AbstractImage::Type type, const GLvoid* data); @@ -1262,6 +1284,10 @@ template<> struct AbstractTexture::DataHelper<1> { (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); } + inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Math::Vector<1, GLsizei>& size) { + (texture->*storage1DImplementation)(target, levels, internalFormat, size); + } + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { (texture->*image1DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); } @@ -1289,6 +1315,10 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { static void setWrapping(AbstractTexture* texture, const Array2D& wrapping); + inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector2i& size) { + (texture->*storage2DImplementation)(target, levels, internalFormat, size); + } + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { (texture->*image2DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); } @@ -1319,6 +1349,10 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { static void setWrapping(AbstractTexture* texture, const Array3D& wrapping); + inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector3i& size) { + (texture->*storage3DImplementation)(target, levels, internalFormat, size); + } + template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { (texture->*image3DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); } diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 6e8f9da46..61dcd3b77 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -51,8 +51,9 @@ Image2D positiveX({256, 256}, Image2D::Components::RGBA, Image2D::ComponentType: CubeMapTexture texture; texture.setMagnificationFilter(Texture2D::Filter::Linear) // ... - ->setImage(CubeMapTexture::Coordinate::PositiveX, 0, Texture2D::Format::RGBA8, &positiveX) - ->setImage(CubeMapTexture::Coordinate::NegativeX, 0, Texture2D::Format::RGBA8, &negativeX) + ->setStorage(Math::log2(256)+1, Texture2D::Format::RGBA8, {256, 256}) + ->setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, {}, &positiveX) + ->setSubImage(CubeMapTexture::Coordinate::NegativeX, 0, {}, &negativeX) // ... @endcode @@ -109,6 +110,16 @@ class CubeMapTexture: public AbstractTexture { return this; } + /** + * @brief Set storage + * + * See Texture::setStorage() for more information. + */ + inline CubeMapTexture* setStorage(GLsizei levels, InternalFormat internalFormat, const Vector2i& size) { + DataHelper<2>::setStorage(this, _target, levels, internalFormat, size); + return this; + } + /** * @brief Set image data * @param coordinate Coordinate diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 00f3e574f..28c2feea5 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -34,24 +34,24 @@ See CubeMapTexture documentation for introduction. @section CubeMapTextureArray-usage Usage Common usage is to specify each layer and face separately using setSubImage(). -You have to allocate the memory for all layers and faces first, possibly by -passing properly sized empty Image to setImage(). Example: array with 16 -layers of cube map faces, each face consisting of six 64x64 images: +You have to allocate the memory for all layers and faces first either by +calling setStorage() or by passing properly sized empty Image to setImage(). +Example: array with 16 layers of cube map faces, each face consisting of six +64x64 images: @code Image3D dummy({64, 64, 16*6}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, nullptr); CubeMapTextureArray texture; texture.setMagnificationFilter(CubeMapTextureArray::Filter::Linear) // ... - ->setImage(0, CubeMapTextureArray::Format::RGBA8, &dummy); + ->setStorage(Math::log2(64)+1, CubeMapTextureArray::Format::RGBA8, {64, 64, 16}); for(std::size_t i = 0; i != 16; ++i) { void* dataPositiveX = ...; Image2D imagePositiveX({64, 64}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, imagePositiveX); // ... - - texture->setSubImage(i, CubeMapTextureArray::Coordinate::PositiveX, 0, imagePositiveX); - texture->setSubImage(i, CubeMapTextureArray::Coordinate::NegativeX, 0, imageNegativeX); + texture->setSubImage(i, CubeMapTextureArray::Coordinate::PositiveX, 0, {}, imagePositiveX); + texture->setSubImage(i, CubeMapTextureArray::Coordinate::NegativeX, 0, {}, imageNegativeX); // ... } @@ -99,6 +99,16 @@ class CubeMapTextureArray: public AbstractTexture { return this; } + /** + * @brief Set storage + * + * See Texture::setStorage() for more information. + */ + inline CubeMapTextureArray* setStorage(GLsizei levels, InternalFormat internalFormat, const Vector3i& size) { + DataHelper<3>::setStorage(this, _target, levels, internalFormat, size); + return this; + } + /** * @brief Set image data * @param level Mip level diff --git a/src/Texture.h b/src/Texture.h index 8b3738609..0913bd083 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -44,17 +44,18 @@ texture.setMagnificationFilter(Texture2D::Filter::Linear) ->setMinificationFilter(Texture2D::Filter::Linear, Texture2D::Mipmap::Linear) ->setWrapping(Texture2D::Wrapping::ClampToEdge) ->setMaxAnisotropy(Texture2D::maxSupportedAnisotropy) - ->setImage(0, Texture2D::Format::RGBA8, &image) + ->setStorage(Math::log2(4096)+1, Texture2D::Format::RGBA8, {4096, 4096}) + ->setSubImage(0, {}, &image) ->generateMipmap(); @endcode @attention Don't forget to fully configure the texture before use. Note that default configuration (if setMinificationFilter() is not called with another value) is to use mipmaps, so be sure to either call setMinificationFilter(), - explicitly set all mip levels or call generateMipmap(). If using rectangle - texture, you must also call setWrapping(), because the initial value is - not supported on rectangle textures. See also setMagnificationFilter() and - setBorderColor(). + explicitly specify all mip levels with setStorage() and setImage() or call + generateMipmap(). If using rectangle texture, you must also call + setWrapping(), because the initial value is not supported on rectangle + textures. See also setMagnificationFilter() and setBorderColor(). The texture is bound to layer specified by shader via bind(). In shader, the texture is used via `sampler1D`, `sampler2D` or `sampler3D` depending on @@ -67,16 +68,14 @@ You can create texture arrays by passing @ref Texture::Target "Texture2D::Target or @ref Texture::Target "Texture3D::Target::Texture2DArray" to constructor. It is possible to specify each layer separately using setSubImage(), but you -have to allocate the memory for all layers first, possibly by passing properly -sized empty Image to setImage(). Example: 2D texture array with 16 layers of -64x64 images: +have to allocate the memory for all layers first either by calling setStorage() +or by passing properly sized empty Image to setImage(). Example: 2D texture +array with 16 layers of 64x64 images: @code -Image3D dummy({64, 64, 16}, Image3D::Components::RGBA, Image3D::ComponentType::UnsignedByte, nullptr); - Texture3D texture(Texture3D::Target::Texture2DArray); texture.setMagnificationFilter(Texture2D::Filter::Linear) // ... - ->setImage(0, Texture2D::Format::RGBA8, &dummy); + ->setStorage(levels, Texture2D::Format::RGBA8, {64, 64,16}); for(std::size_t i = 0; i != 16; ++i) { void* data = ...; @@ -198,6 +197,33 @@ template class Texture: public AbstractTexture { return this; } + /** + * @brief Set storage + * @param levels Mip level count + * @param internalFormat Internal format + * @param size Size of largest mip level + * @return Pointer to self (for method chaining) + * + * Specifies entire structure of a texture at once, removing the need + * for additional consistency checks and memory reallocations when + * updating the data later. After calling this function the texture + * is immutable and calling setStorage() or setImage() is not allowed. + * + * If @extension{EXT,direct_state_access} is not available, the + * texture is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexStorage1D}/@fn_gl{TexStorage2D}/@fn_gl{TexStorage3D} + * or @fn_gl_extension{TextureStorage1D,EXT,direct_state_access}/ + * @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}/ + * @fn_gl_extension{TextureStorage3D,EXT,direct_state_access} + * @requires_gl42 %Extension @extension{ARB,texture_storage} + * @requires_gles30 %Extension @es_extension{EXT,texture_storage} + */ + inline Texture* setStorage(GLsizei levels, InternalFormat internalFormat, const typename DimensionTraits::VectorType& size) { + DataHelper::setStorage(this, _target, levels, internalFormat, size); + return this; + } + /** * @brief Set image data * @param level Mip level @@ -208,9 +234,13 @@ template class Texture: public AbstractTexture { * * The image is not deleted afterwards. * + * For better performance when generating mipmaps using + * generateMipmap() or calling setImage() more than once use + * setStorage() and setSubImage() instead. + * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some layer before the operation. - * @see setSubImage(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and * @fn_gl{TexImage1D}/@fn_gl{TexImage2D}/@fn_gl{TexImage3D} or * @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ @@ -240,8 +270,8 @@ template class Texture: public AbstractTexture { * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some layer before the operation. - * @see setImage(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and - * @fn_gl{TexSubImage1D}/@fn_gl{TexSubImage2D}/@fn_gl{TexSubImage3D} + * @see setStorage(), setImage(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} + * and @fn_gl{TexSubImage1D}/@fn_gl{TexSubImage2D}/@fn_gl{TexSubImage3D} * or @fn_gl_extension{TextureSubImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} From 7d0a5236187ad40d4edb7c5a18435aad819018c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 22:45:20 +0100 Subject: [PATCH 160/567] Moved projection matrix computation to Math namespace. --- src/Math/Matrix3.h | 12 ++++++- src/Math/Matrix4.h | 57 +++++++++++++++++++++++++++++- src/Math/Test/Matrix3Test.cpp | 10 ++++++ src/Math/Test/Matrix4Test.cpp | 32 +++++++++++++++++ src/SceneGraph/Camera2D.h | 3 +- src/SceneGraph/Camera2D.hpp | 3 +- src/SceneGraph/Camera3D.h | 37 +++++++++++-------- src/SceneGraph/Camera3D.hpp | 32 +++++++---------- src/SceneGraph/Test/CameraTest.cpp | 55 +++++++--------------------- 9 files changed, 158 insertions(+), 83 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 0e55d5169..2fa99114e 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Math { /** -@brief 3x3 matrix for affine transformations in 2D +@brief 3x3 matrix for transformations in 2D @tparam T Data type Provides functions for transformations in 2D. See Matrix4 for 3D @@ -96,6 +96,16 @@ template class Matrix3: public Matrix<3, T> { return from(Matrix<2, T>() - T(2)*normal*normal.transposed(), {}); } + /** + * @brief 2D projection matrix + * @param size Size of the view + * + * @see Matrix4::orthographicProjection(), Matrix4::perspectiveProjection() + */ + static Matrix3 projection(const Vector2& size) { + return scaling(2.0f/size); + } + /** * @brief Create matrix from rotation/scaling part and translation part * @param rotationScaling Rotation/scaling part (upper-left 2x2 diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index ce34891e0..89bd78224 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Math { /** -@brief 4x4 matrix for affine transformations in 3D +@brief 4x4 matrix for transformations in 3D @tparam T Data type Provides functions for transformations in 3D. See Matrix3 for 2D @@ -182,6 +182,61 @@ template class Matrix4: public Matrix<4, T> { return from(Matrix<3, T>() - T(2)*normal*normal.transposed(), {}); } + /** + * @brief 3D orthographic projection matrix + * @param size Size of the view + * @param near Near clipping plane + * @param far Far clipping plane + * + * @see perspectiveProjection(), Matrix3::projection() + */ + static Matrix4 orthographicProjection(const Vector2& size, T near, T far) { + Vector2 xyScale = T(2.0)/size; + T zScale = T(2.0)/(near-far); + + return Matrix4( /* Column-major! */ + xyScale.x(), T(0.0), T(0.0), T(0.0), + T(0.0), xyScale.y(), T(0.0), T(0.0), + T(0.0), T(0.0), zScale, T(0.0), + T(0.0), T(0.0), near*zScale-1, T(1.0) + ); + } + + /** + * @brief 3D perspective projection matrix + * @param size Size of near clipping plane + * @param near Near clipping plane + * @param far Far clipping plane + * + * @see orthographicProjection(), Matrix3::projection() + */ + static Matrix4 perspectiveProjection(const Vector2& size, T near, T far) { + Vector2 xyScale = 2*near/size; + T zScale = T(1.0)/(near-far); + + return Matrix4( /* Column-major! */ + xyScale.x(), T(0.0), T(0.0), T(0.0), + T(0.0), xyScale.y(), T(0.0), T(0.0), + T(0.0), T(0.0), (far+near)*zScale, T(-1.0), + T(0.0), T(0.0), (2*far*near)*zScale, T(0.0) + ); + } + + /** + * @brief 3D perspective projection matrix + * @param fov Field of view angle (horizontal, in radians) + * @param aspectRatio Aspect ratio + * @param near Near clipping plane + * @param far Far clipping plane + * + * @see orthographicProjection(), Matrix3::projection() + */ + static Matrix4 perspectiveProjection(T fov, T aspectRatio, T near, T far) { + T xyScale = 2*std::tan(fov/2)*near; + + return perspectiveProjection(Vector2(xyScale, xyScale/aspectRatio), near, far); + } + /** * @brief Create matrix from rotation/scaling part and translation part * @param rotationScaling Rotation/scaling part (upper-left 3x3 diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index bc57f5e51..0fd87ca8b 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -34,6 +34,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void scaling(); void rotation(); void reflection(); + void projection(); void fromParts(); void rotationScalingPart(); void rotationPart(); @@ -54,6 +55,7 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::scaling, &Matrix3Test::rotation, &Matrix3Test::reflection, + &Matrix3Test::projection, &Matrix3Test::fromParts, &Matrix3Test::rotationScalingPart, &Matrix3Test::rotationPart, @@ -136,6 +138,14 @@ void Matrix3Test::reflection() { CORRADE_COMPARE(actual, expected); } +void Matrix3Test::projection() { + Matrix3 expected(2.0f/4.0f, 0.0f, 0.0f, + 0.0f, 2.0f/3.0f, 0.0f, + 0.0f, 0.0f, 1.0f); + + CORRADE_COMPARE(Matrix3::projection({4.0f, 3.0f}), expected); +} + void Matrix3Test::fromParts() { Matrix2 rotationScaling( 3.0f, 5.0f, diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 7787eb49b..9d7fe88a3 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -37,6 +37,9 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotationY(); void rotationZ(); void reflection(); + void orthographicProjection(); + void perspectiveProjection(); + void perspectiveProjectionFov(); void fromParts(); void rotationScalingPart(); void rotationPart(); @@ -60,6 +63,9 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotationY, &Matrix4Test::rotationZ, &Matrix4Test::reflection, + &Matrix4Test::orthographicProjection, + &Matrix4Test::perspectiveProjection, + &Matrix4Test::perspectiveProjectionFov, &Matrix4Test::fromParts, &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, @@ -180,6 +186,32 @@ void Matrix4Test::reflection() { CORRADE_COMPARE(actual, expected); } +void Matrix4Test::orthographicProjection() { + Matrix4 expected(0.4f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.5f, 0.0f, 0.0f, + 0.0f, 0.0f, -0.25f, 0.0f, + 0.0f, 0.0f, -1.25f, 1.0f); + CORRADE_COMPARE(Matrix4::orthographicProjection({5.0f, 4.0f}, 1, 9), expected); +} + +void Matrix4Test::perspectiveProjection() { + Matrix4 expected(4.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 7.111111f, 0.0f, 0.0f, + 0.0f, 0.0f, -1.9411764f, -1.0f, + 0.0f, 0.0f, -94.1176452f, 0.0f); + + CORRADE_COMPARE(Matrix4::perspectiveProjection({16.0f, 9.0f}, 32.0f, 100), expected); +} + +void Matrix4Test::perspectiveProjectionFov() { + Matrix4 expected(4.1652994f, 0.0f, 0.0f, 0.0f, + 0.0f, 9.788454f, 0.0f, 0.0f, + 0.0f, 0.0f, -1.9411764f, -1.0f, + 0.0f, 0.0f, -94.1176452f, 0.0f); + + CORRADE_COMPARE(Matrix4::perspectiveProjection(deg(27.0f), 2.35f, 32.0f, 100), expected); +} + void Matrix4Test::fromParts() { Matrix3 rotationScaling( 3.0f, 5.0f, 8.0f, diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 591cd4261..5154b3f4a 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -66,8 +66,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { * @param size Size of the view * @return Pointer to self (for method chaining) * - * The area of given size will be scaled down to range @f$ [-1; 1] @f$ - * on all directions. + * @see Matrix3::projection() */ Camera2D* setProjection(const Math::Vector2& size); diff --git a/src/SceneGraph/Camera2D.hpp b/src/SceneGraph/Camera2D.hpp index 818e5ea19..9bea284fc 100644 --- a/src/SceneGraph/Camera2D.hpp +++ b/src/SceneGraph/Camera2D.hpp @@ -27,8 +27,7 @@ using namespace std; namespace Magnum { namespace SceneGraph { template Camera2D* Camera2D::setProjection(const Math::Vector2& size) { - /* Scale the volume down so it fits in (-1, 1) in all directions */ - AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3::scaling(2.0f/size); + AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3::projection(size); AbstractCamera<2, T>::fixAspectRatio(); return this; diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index ea0aca366..24180fd9c 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -36,7 +36,7 @@ OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` with orthographic projection and doesn't do any aspect ratio correction. Common setup example: @code SceneGraph::Camera3D<>* camera = new SceneGraph::Camera3D<>(&cameraObject); -camera->setPerspective(deg(35.0f), 0.001f, 100.0f) +camera->setPerspective({}, 0.001f, 100.0f) ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); @endcode @@ -60,35 +60,42 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { /** * @brief Constructor * @param object %Object holding this feature - * - * Sets orthographic projection to the default OpenGL cube - * (range @f$ [-1; 1] @f$ in all directions). - * @see setOrthographic(), setPerspective() */ inline explicit Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} /** * @brief Set orthographic projection - * @param size Size of the view - * @param near Near clipping plane - * @param far Far clipping plane + * @param size Size of the view + * @param near Near clipping plane + * @param far Far clipping plane * @return Pointer to self (for method chaining) * - * The volume of given size will be scaled down to range @f$ [-1; 1] @f$ - * on all directions. + * @see setPerspective(), Matrix4::orthographicProjection() */ Camera3D* setOrthographic(const Math::Vector2& size, T near, T far); /** * @brief Set perspective projection - * @param fov Field of view angle - * @param near Near clipping plane - * @param far Far clipping plane + * @param size Size of near clipping plane + * @param near Near clipping plane + * @param far Far clipping plane + * @return Pointer to self (for method chaining) + * + * @see setOrthographic(), Matrix4::perspectiveProjection() + */ + Camera3D* setPerspective(const Math::Vector2& size, T near, T far); + + /** + * @brief Set perspective projection + * @param fov Field of view angle (horizontal, in radians) + * @param aspectRatio Aspect ratio + * @param near Near clipping plane + * @param far Far clipping plane * @return Pointer to self (for method chaining) * - * @todo Aspect ratio + * @see setOrthographic(), Matrix4::perspectiveProjection() */ - Camera3D* setPerspective(T fov, T near, T far); + Camera3D* setPerspective(T fov, T aspectRatio, T near, T far); /** @brief Near clipping plane */ inline T near() const { return _near; } diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index 23bee2e44..0e97d1715 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -27,37 +27,31 @@ using namespace std; namespace Magnum { namespace SceneGraph { template Camera3D* Camera3D::setOrthographic(const Math::Vector2& size, T near, T far) { + /** @todo Get near/far from the matrix */ _near = near; _far = far; - Math::Vector2 xyScale = T(2.0)/size; - T zScale = T(2.0)/(near-far); - - AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4( - xyScale.x(), T(0.0), T(0.0), T(0.0), - T(0.0), xyScale.y(), T(0.0), T(0.0), - T(0.0), T(0.0), zScale, T(0.0), - T(0.0), T(0.0), near*zScale-1, T(1.0) - ); - + AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4::orthographicProjection(size, near, far); AbstractCamera<3, T>::fixAspectRatio(); return this; } -template Camera3D* Camera3D::setPerspective(T fov, T near, T far) { +template Camera3D* Camera3D::setPerspective(const Math::Vector2& size, T near, T far) { + /** @todo Get near/far from the matrix */ _near = near; _far = far; - T xyScale = T(1.0)/tan(fov/2); /* == near/size */ - T zScale = T(1.0)/(near-far); + AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4::perspectiveProjection(size, near, far); + AbstractCamera<3, T>::fixAspectRatio(); + return this; +} - AbstractCamera<3, T>::rawProjectionMatrix = Matrix4( - xyScale, T(0.0), T(0.0), T(0.0), - T(0.0), xyScale, T(0.0), T(0.0), - T(0.0), T(0.0), (far+near)*zScale, T(-1.0), - T(0.0), T(0.0), (2*far*near)*zScale, T(0.0) - ); +template Camera3D* Camera3D::setPerspective(T fov, T aspectRatio, T near, T far) { + /** @todo Get near/far from the matrix */ + _near = near; + _far = far; + AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4::perspectiveProjection(fov, aspectRatio, near, far); AbstractCamera<3, T>::fixAspectRatio(); return this; } diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index e0a737e24..2a3ba52f9 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -33,9 +33,9 @@ class CameraTest: public Corrade::TestSuite::Tester { void fixAspectRatio(); void defaultProjection2D(); void defaultProjection3D(); - void projection2D(); - void orthographic(); - void perspective(); + void projectionSize2D(); + void projectionSizeOrthographic(); + void projectionSizePerspective(); void projectionSizeViewport(); void draw(); }; @@ -50,9 +50,9 @@ CameraTest::CameraTest() { addTests(&CameraTest::fixAspectRatio, &CameraTest::defaultProjection2D, &CameraTest::defaultProjection3D, - &CameraTest::projection2D, - &CameraTest::orthographic, - &CameraTest::perspective, + &CameraTest::projectionSize2D, + &CameraTest::projectionSizeOrthographic, + &CameraTest::projectionSizePerspective, &CameraTest::projectionSizeViewport, &CameraTest::draw); } @@ -113,58 +113,27 @@ void CameraTest::defaultProjection3D() { CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f)); } -void CameraTest::projection2D() { +void CameraTest::projectionSize2D() { Vector2 projectionSize(4.0f, 3.0f); Object2D o; Camera2D camera(&o); camera.setProjection(projectionSize); - - Matrix3 a(2.0f/4.0f, 0.0f, 0.0f, - 0.0f, 2.0f/3.0f, 0.0f, - 0.0f, 0.0f, 1.0f); - - CORRADE_COMPARE(camera.projectionMatrix(), a); CORRADE_COMPARE(camera.projectionSize(), projectionSize); } -void CameraTest::orthographic() { - Vector2 projectionSize(5); +void CameraTest::projectionSizeOrthographic() { + Vector2 projectionSizeRectangle(5.0f, 4.0f); Object3D o; Camera3D camera(&o); - camera.setOrthographic(projectionSize, 1, 9); - - Matrix4 a(0.4f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.4f, 0.0f, 0.0f, - 0.0f, 0.0f, -0.25f, 0.0f, - 0.0f, 0.0f, -1.25f, 1.0f); - - CORRADE_COMPARE(camera.projectionMatrix(), a); - CORRADE_COMPARE(camera.projectionSize(), projectionSize); - - Vector2 projectionSizeRectangle(5.0f, 4.0f); camera.setOrthographic(projectionSizeRectangle, 1, 9); - - Matrix4 rectangle(0.4f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.5f, 0.0f, 0.0f, - 0.0f, 0.0f, -0.25f, 0.0f, - 0.0f, 0.0f, -1.25f, 1.0f); - - CORRADE_COMPARE(camera.projectionMatrix(), rectangle); CORRADE_COMPARE(camera.projectionSize(), projectionSizeRectangle); } -void CameraTest::perspective() { +void CameraTest::projectionSizePerspective() { Object3D o; Camera3D camera(&o); - camera.setPerspective(deg(27.0f), 32.0f, 100); - - Matrix4 a(4.1652994f, 0.0f, 0.0f, 0.0f, - 0.0f, 4.1652994f, 0.0f, 0.0f, - 0.0f, 0.0f, -1.9411764f, -1.0f, - 0.0f, 0.0f, -94.1176452f, 0.0f); - - CORRADE_COMPARE(camera.projectionMatrix(), a); - CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f)); + camera.setPerspective(deg(27.0f), 2.35f, 32.0f, 100); + CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f, 0.204322f)); } void CameraTest::projectionSizeViewport() { From 9a571abb37ba207c2f1aa543d7a7e90f0b8385c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 23:40:30 +0100 Subject: [PATCH 161/567] Added OES_element_index_uint ES2 extension to the list. --- src/Context.cpp | 1 + src/Extensions.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Context.cpp b/src/Context.cpp index 46d1a623d..1318757f7 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -225,6 +225,7 @@ const std::vector& Extension::extensions(Version version) { _extension(GL,NV,read_depth), _extension(GL,NV,read_depth_stencil), _extension(GL,OES,depth24), + _extension(GL,OES,element_index_uint), _extension(GL,OES,rgb8_rgba8), _extension(GL,OES,texture_half_float_linear), _extension(GL,OES,texture_float_linear), diff --git a/src/Extensions.h b/src/Extensions.h index abca47d91..3458a3e3b 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -207,6 +207,7 @@ namespace GL { } namespace OES { _extension(GL,OES,depth24, GLES200, GLES300) // #24 _extension(GL,OES,depth32, GLES200, None) // #25 + _extension(GL,OES,element_index_uint, GLES200, GLES300) // #26 _extension(GL,OES,mapbuffer, GLES200, None) // #29 _extension(GL,OES,rgb8_rgba8, GLES200, GLES300) // #30 _extension(GL,OES,stencil1, GLES200, None) // #31 From ca24fe8f4103d8ed75b844859318e18474d58726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 23:46:44 +0100 Subject: [PATCH 162/567] Mesh index type cleanup. Using specialized enum instead of global Type and shitload of type traits to handle it correctly. Removed TypeTraits::indexType() and cleaned up MeshTools::compressIndices() while at it. --- src/DebugTools/ObjectRenderer.cpp | 2 +- src/IndexedMesh.cpp | 10 ++++ src/IndexedMesh.h | 29 ++++++++-- src/MeshTools/CompressIndices.cpp | 63 +++++++++++++--------- src/MeshTools/CompressIndices.h | 32 ++--------- src/MeshTools/Test/CompressIndicesTest.cpp | 22 ++++---- src/TypeTraits.h | 22 +------- 7 files changed, 89 insertions(+), 91 deletions(-) diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 3632f65a8..39367cc56 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -160,7 +160,7 @@ template ObjectRenderer::ObjectRenderer(Sce mesh->setPrimitive(Mesh::Primitive::Lines) ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColorShader::Position(), typename Shaders::VertexColorShader::Color()) ->setIndexCount(Renderer::indices.size()) - ->setIndexType(Type::UnsignedByte) + ->setIndexType(IndexedMesh::IndexType::UnsignedByte) ->setIndexBuffer(indexBuffer); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index e6527bf78..8053cbfcf 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -26,6 +26,16 @@ namespace Magnum { IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; +std::size_t IndexedMesh::indexSize(IndexType type) { + switch(type) { + case IndexType::UnsignedByte: return 1; + case IndexType::UnsignedShort: return 2; + case IndexType::UnsignedInt: return 4; + } + + CORRADE_INTERNAL_ASSERT(false); +} + IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) { _indexBuffer = buffer; (this->*bindIndexBufferImplementation)(); diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 80e390346..090942179 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -72,6 +72,25 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { friend class Context; public: + /** + * @brief Index type + * + * @see setIndexType(), indexSize() + */ + enum class IndexType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ + UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ + + /** + * Unsigned int + * @requires_gles30 %Extension @es_extension{OES,element_index_uint} + */ + UnsignedInt = GL_UNSIGNED_INT + }; + + /** @brief Size of given index type */ + static std::size_t indexSize(IndexType type); + /** * @brief Constructor * @param primitive Primitive type @@ -79,7 +98,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * Creates indexed mesh with zero vertex count, zero index count and * no vertex or index buffers. */ - inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(Type::UnsignedShort) {} + inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(IndexType::UnsignedInt) {} /** * @brief Set index buffer @@ -106,16 +125,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { } /** @brief Index type */ - inline Type indexType() const { return _indexType; } + inline IndexType indexType() const { return _indexType; } /** * @brief Set index type * @return Pointer to self (for method chaining) * - * Default is @ref Type "Type::UnsignedShort". + * Default is @ref Type "IndexType::UnsignedInt". * @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices() */ - inline IndexedMesh* setIndexType(Type type) { + inline IndexedMesh* setIndexType(IndexType type) { _indexType = type; return this; } @@ -174,7 +193,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { Buffer* _indexBuffer; GLsizei _indexCount; - Type _indexType; + IndexType _indexType; }; } diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index af2a53e93..0ca368fbb 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -16,47 +16,62 @@ #include "CompressIndices.h" #include -#include #include -#include "IndexedMesh.h" -#include "SizeTraits.h" +#include "Math/Math.h" namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { +namespace { -std::tuple CompressIndices::operator()() const { - return SizeBasedCall(*std::max_element(indices.begin(), indices.end()))(indices); +template constexpr IndexedMesh::IndexType indexType(); +template<> inline constexpr IndexedMesh::IndexType indexType() { return IndexedMesh::IndexType::UnsignedByte; } +template<> inline constexpr IndexedMesh::IndexType indexType() { return IndexedMesh::IndexType::UnsignedShort; } +template<> inline constexpr IndexedMesh::IndexType indexType() { return IndexedMesh::IndexType::UnsignedInt; } + +template inline std::tuple compress(const std::vector& indices) { + char* buffer = new char[indices.size()*sizeof(T)]; + for(std::size_t i = 0; i != indices.size(); ++i) { + T index = static_cast(indices[i]); + std::memcpy(buffer+i*sizeof(T), &index, sizeof(T)); + } + + return std::make_tuple(indices.size(), indexType(), buffer); +} + +} +#endif + +std::tuple compressIndices(const std::vector& indices) { + std::size_t size = *std::max_element(indices.begin(), indices.end()); + + switch(Math::log(256, size)) { + case 0: + return compress(indices); + case 1: + return compress(indices); + case 2: + case 3: + return compress(indices); + + default: + CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << size << "elements.", {}); + } } -void CompressIndices::operator()(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage) const { +void compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { std::size_t indexCount; - Type indexType; + IndexedMesh::IndexType indexType; char* data; - std::tie(indexCount, indexType, data) = operator()(); + std::tie(indexCount, indexType, data) = compressIndices(indices); mesh->setIndexBuffer(buffer) ->setIndexType(indexType) ->setIndexCount(indices.size()); - buffer->setData(indexCount*TypeInfo::sizeOf(indexType), data, usage); + buffer->setData(indexCount*IndexedMesh::indexSize(indexType), data, usage); delete[] data; } -template std::tuple CompressIndices::Compressor::run(const std::vector& indices) { - /* Create smallest possible version of index buffer */ - char* buffer = new char[indices.size()*sizeof(IndexType)]; - for(std::size_t i = 0; i != indices.size(); ++i) { - IndexType index = indices[i]; - memcpy(buffer+i*sizeof(IndexType), reinterpret_cast(&index), sizeof(IndexType)); - } - - return std::make_tuple(indices.size(), TypeTraits::indexType(), buffer); -} - -} -#endif - }} diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 34ccb7991..120e1bb04 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -22,34 +22,12 @@ #include #include "Buffer.h" -#include "TypeTraits.h" +#include "IndexedMesh.h" #include "magnumMeshToolsVisibility.h" namespace Magnum { namespace MeshTools { -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - -class MAGNUM_MESHTOOLS_EXPORT CompressIndices { - public: - CompressIndices(const std::vector& indices): indices(indices) {} - - std::tuple operator()() const; - - void operator()(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage) const; - - private: - struct Compressor { - template static std::tuple run(const std::vector& indices); - }; - - const std::vector& indices; -}; - -} -#endif - /** @brief Compress vertex indices @param indices Index array @@ -74,9 +52,7 @@ delete[] data; See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -inline std::tuple compressIndices(const std::vector& indices) { - return Implementation::CompressIndices{indices}(); -} +std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); /** @brief Compress vertex indices and write them to index buffer @@ -93,9 +69,7 @@ IndexedMesh::setIndexType() on your own. @see MeshTools::interleave() */ -inline void compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { - return Implementation::CompressIndices{indices}(mesh, buffer, usage); -} +void MAGNUM_MESHTOOLS_EXPORT compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); }} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index 696e949fb..56731f2c1 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -39,14 +39,14 @@ CompressIndicesTest::CompressIndicesTest() { void CompressIndicesTest::compressChar() { std::size_t indexCount; - Type indexType; + IndexedMesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); - CORRADE_VERIFY(indexType == Type::UnsignedByte); - CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedByte); + CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), (std::vector{ 0x01, 0x02, 0x03, 0x00, 0x04 })); delete[] data; @@ -54,21 +54,21 @@ void CompressIndicesTest::compressChar() { void CompressIndicesTest::compressShort() { std::size_t indexCount; - Type indexType; + IndexedMesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); - CORRADE_VERIFY(indexType == Type::UnsignedShort); + CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedShort); if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), (std::vector{ 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00 })); } else { - CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), (std::vector{ 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, @@ -80,21 +80,21 @@ void CompressIndicesTest::compressShort() { void CompressIndicesTest::compressInt() { std::size_t indexCount; - Type indexType; + IndexedMesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); - CORRADE_VERIFY(indexType == Type::UnsignedInt); + CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedInt); if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), (std::vector{ 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 })); } else { - CORRADE_COMPARE(std::vector(data, data+indexCount*TypeInfo::sizeOf(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), (std::vector{ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02 })); diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 9366bd872..8c096feeb 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -61,15 +61,6 @@ template struct TypeTraits: Math::MathTypeTraits { */ inline constexpr static Type type(); - /** - * @brief OpenGL type ID for indices - * - * Implemented only in types which can be used for vertex indices (all - * unsigned types). This function is not present for types unusable for - * vertex indices, like GLfloat or GLint. - */ - inline constexpr static Type indexType(); - /** * @brief Size of plain OpenGL type * @@ -204,7 +195,6 @@ template<> struct TypeOf { template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedByte; } - inline constexpr static Type indexType() { return Type::UnsignedByte; } inline constexpr static std::size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t count() { return 1; } }; @@ -212,7 +202,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Byte; } - /* Can not be used for indices */ inline constexpr static std::size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t count() { return 1; } }; @@ -220,7 +209,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::UnsignedShort; } - inline constexpr static Type indexType() { return Type::UnsignedShort; } inline constexpr static std::size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t count() { return 1; } }; @@ -228,7 +216,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ inline constexpr static Type type() { return Type::Short; } - /* Can not be used for indices */ inline constexpr static std::size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t count() { return 1; } }; @@ -236,7 +223,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; inline constexpr static Type type() { return Type::UnsignedInt; } - inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static std::size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t count() { return 1; } }; @@ -244,7 +230,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; inline constexpr static Type type() { return Type::Int; } - /* Can not be used for indices */ inline constexpr static std::size_t size() { return sizeof(GLint); } inline constexpr static std::size_t count() { return 1; } }; @@ -252,7 +237,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; inline constexpr static Type type() { return Type::Float; } - /* Can not be used for indices */ inline constexpr static std::size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t count() { return 1; } }; @@ -261,7 +245,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { template<> struct TypeTraits: Math::MathTypeTraits { typedef GLdouble AttributeType; inline constexpr static Type type() { return Type::Double; } - /* Can not be used for indices */ inline constexpr static std::size_t size() { return sizeof(GLdouble); } inline constexpr static std::size_t count() { return 1; } }; @@ -273,8 +256,6 @@ namespace Implementation { /* Might be used for attributes, see below */ inline constexpr static Type type() { return TypeTraits::type(); } - /* Might be used for attributes, see below */ - /* Can not be used for indices */ inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return vectorSize; } }; @@ -320,9 +301,8 @@ namespace Implementation { template struct MatrixTypeTraits { MatrixTypeTraits() = delete; - inline constexpr static Type type() { return TypeTraits::type(); } /* Might be used for attributes, see below */ - /* Can not be used for indices */ + inline constexpr static Type type() { return TypeTraits::type(); } inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return rows; } inline constexpr static std::size_t vectors() { return cols; } From c8ef795cce7d168cd8fa17ef13c8739eeaa84b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jan 2013 23:52:30 +0100 Subject: [PATCH 163/567] Removed SizeTraits, SizeBasedCall and related mess. The implementation was really frightening and it was really used only in MeshTools::compressIndices(). Other classes like SizeTraits, Pow and Log were just waiting to be deleted, nothing of value was lost. --- src/CMakeLists.txt | 2 - src/SizeTraits.cpp | 25 ------ src/SizeTraits.h | 206 --------------------------------------------- 3 files changed, 233 deletions(-) delete mode 100644 src/SizeTraits.cpp delete mode 100644 src/SizeTraits.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8218fc737..06b292751 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,6 @@ set(Magnum_SRCS Renderbuffer.cpp Resource.cpp Shader.cpp - SizeTraits.cpp Timeline.cpp TypeTraits.cpp @@ -77,7 +76,6 @@ set(Magnum_HEADERS Resource.h ResourceManager.h Shader.h - SizeTraits.h Swizzle.h Texture.h Timeline.h diff --git a/src/SizeTraits.cpp b/src/SizeTraits.cpp deleted file mode 100644 index 8befa8477..000000000 --- a/src/SizeTraits.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "SizeTraits.h" - -namespace Magnum { - -#ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(Pow<2, 3>::value == 8, "Implementation error in Pow meta class"); -static_assert(Log<2, 9>::value == 3, "Implementation error in Log meta class"); -#endif - -} diff --git a/src/SizeTraits.h b/src/SizeTraits.h deleted file mode 100644 index f007d5e4c..000000000 --- a/src/SizeTraits.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef Magnum_SizeTraits_h -#define Magnum_SizeTraits_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::SizeTraits, Magnum::SizeBasedCall, Magnum::Pow, Magnum::Log - */ - -#include - -#include "Math/Math.h" -#include "Magnum.h" - -namespace Magnum { - -/** @todo Remove/internalize things used only in one place (Math::log, Pow, Log)? Simplify SizeTraits? */ - -/** -@brief Traits class providing suitable types for given data sizes -@tparam byte Highest byte needed (counting from zero) - -If you use indexed data, you would probably (for performance reasons) want to -use the smallest type which is able to store all indices in given range. This -class provides type suitable for given **logarithmic** size of data. For -example, if you want to store 289 elements, they occupy two bytes, so -`SizeTraits<1>::%SizeType` is `GLushort`. For convenience you can use Log class -to compute logarithms at compile time, e.g. -`SizeTraits::%value>::%SizeType`. -*/ -#ifdef DOXYGEN_GENERATING_OUTPUT -template struct SizeTraits { - /** - * @brief (Unsigned) type able to index the data - * - * Not implemented for large sizes (@f$ > 2^{32} @f$ elements), because - * OpenGL doesn't have any type which would be able to store the indices. - */ - typedef T SizeType; -}; -#else -template struct SizeTraits: public SizeTraits { - SizeTraits() = delete; -}; -#endif - -#ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct SizeTraits<0> { - SizeTraits() = delete; - typedef GLubyte SizeType; -}; -template<> struct SizeTraits<1> { - SizeTraits() = delete; - typedef GLushort SizeType; -}; -template<> struct SizeTraits<2> { - SizeTraits() = delete; - typedef GLuint SizeType; -}; -template<> struct SizeTraits<4> { - SizeTraits() = delete; - /* We don't have size type to store 2^32 values */ -}; -#endif - -/** -@brief Functor for calling templated function with type based on size -@tparam Base Base struct with templated function `run()`. See below for - example. - -If you have templated function which you want to call with type suitable for -indexing data of some size, you will probably use cascade of IFs, like this: -@code -std::size_t dataSize; -template Bar foo(Arg1 arg1, Arg2 arg2, ...); - -Bar bar; -if(dataSize < 256) - bar = foo(arg1, arg2, ...); -else if(dataSize < 65536) - bar = foo(arg1, arg2, ...); -// ... -@endcode -But this approach leads to repetitive and unmaintainable code, especially if -there are many arguments needed to pass to each function. The solution is to -use this class. The only thing you need is to rename your function to `run()` -and wrap it in a `struct`: -@code -struct Foo { - template Bar run(Arg1 arg1, Arg2 arg2, ...); -}; -@endcode -Then you can use this class to call the templated function with the right type -based on data size: -@code -bar = SizeBasedCall(dataSize)(arg1, arg2, ...); -@endcode -*/ -template struct SizeBasedCall: public Base { - /** - * @brief Constructor - * @param size Data size - */ - explicit SizeBasedCall(std::size_t size): size(size) {} - - /** - * @brief Functor - * @param arguments Arguments passed to `Base::run()` - * @return Return value of `Base::run()` - * - * Calls `Base::run()` based on data size (given in constructor). If there - * is no suitable type for indexing given data size, prints message to - * error output and returns default-constructed value. - */ - template auto operator()(Args&&... arguments) -> decltype(Base::template run(std::forward(arguments)...)) { - switch(Math::log(256, size)) { - case 0: - return Base::template run(std::forward(arguments)...); - case 1: - return Base::template run(std::forward(arguments)...); - case 2: - case 3: - return Base::template run(std::forward(arguments)...); - } - - Error() << "SizeBasedCall: no type able to index" << size << "elements."; - return decltype(Base::template run(std::forward(arguments)...))(); - } - - private: - std::size_t size; -}; - -/** -@brief Class for computing integral powers at compile time -@tparam base Base -@tparam exponent Exponent - -Useful mainly for computing template parameter value, e.g. in conjunction with -SizeTraits class. -*/ -template struct Pow { - Pow() = delete; - - /** @brief Value of the power */ - enum: std::uint32_t { - #ifndef DOXYGEN_GENERATING_OUTPUT - value = base*Pow::value - #else - value - #endif - }; -}; - -#ifndef DOXYGEN_GENERATING_OUTPUT -template struct Pow { - Pow() = delete; - - enum: std::uint32_t { value = 1 }; -}; -#endif - -/** -@brief Class for computing integral logarithms at compile time -@tparam base Base -@tparam number Number - -Useful mainly for computing template parameter value, e.g. in conjunction with -SizeTraits class. -*/ -template struct Log { - Log() = delete; - - /** @brief Value of the logarithm */ - enum: std::uint32_t { - #ifndef DOXYGEN_GENERATING_OUTPUT - value = 1+Log::value - #else - value - #endif - }; -}; - -#ifndef DOXYGEN_GENERATING_OUTPUT -template struct Log { - Log() = delete; - enum: std::uint32_t { value = 0 }; -}; -template struct Log: public Log {}; -#endif - -} - -#endif From 42f5ee4ce43b57c6d269f1f9f19d932825df99a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 13 Jan 2013 00:04:07 +0100 Subject: [PATCH 164/567] Doc++ --- src/MeshTools/CombineIndexedArrays.h | 12 +++++------- src/MeshTools/CompressIndices.h | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index a5d229614..7e4299e60 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -92,7 +92,7 @@ class CombineIndexedArrays { /** @brief Combine indexed arrays @param[in,out] indexedArrays Index and attribute arrays -@return Array with resulting indices +@return %Array with resulting indices When you have e.g. vertex, normal and texture array, each indexed with different indices, you can use this function to combine them to use the same @@ -120,13 +120,11 @@ std::vector indices = MeshTools::combineIndexedArrays( `positions`, `normals` and `textureCoordinates` will then contain combined attributes indexed with `indices`. -@attention All index arrays should have the same size, otherwise zero-length - output is generated. - -@internal Implementation note: It's done using tuples because it is more clear - which parameter is index array and which is attribute array, mainly when - both are of the same type. +The function expects that all arrays have the same size. */ +/* Implementation note: It's done using tuples because it is more clear which + parameter is index array and which is attribute array, mainly when both are + of the same type. */ template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { return Implementation::CombineIndexedArrays()(indexedArrays...); } diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 120e1bb04..6141465fb 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -41,15 +41,15 @@ sufficient. Size of the buffer can be computed from index count and type, as shown below. Example usage: @code std::size_t indexCount; -Type indexType; +IndexedMesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices); -std::size_t dataSize = indexCount*TypeInfo::sizeOf(indexType); +std::size_t dataSize = indexCount*IndexedMesh::indexSize(indexType); // ... delete[] data; @endcode -See also compressIndices(IndexedMesh*, Buffer::Usage, const std::vector&), +See also compressIndices(IndexedMesh*, Buffer*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); From 98781b50525fb9636752ae6b1848be1a210df30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 13 Jan 2013 22:43:26 +0100 Subject: [PATCH 165/567] Support for gaps in MeshTools::interleave(). --- src/MeshTools/Interleave.h | 98 +++++++++++++++++++-------- src/MeshTools/Test/InterleaveTest.cpp | 49 +++++++++++++- 2 files changed, 116 insertions(+), 31 deletions(-) diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 6f85ef2b2..90105318c 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -39,7 +39,7 @@ class Interleave { template std::tuple operator()(const T&... attributes) { /* Compute buffer size and stride */ _attributeCount = attributeCount(attributes...); - if(_attributeCount) { + if(_attributeCount && _attributeCount != ~std::size_t(0)) { _stride = stride(attributes...); /* Create output buffer */ @@ -62,29 +62,55 @@ class Interleave { } /* Specialization for only one attribute array */ - template void operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T& attribute) { + template typename std::enable_if::value, void>::type operator()(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const T& attribute) { mesh->setVertexCount(attribute.size()); buffer->setData(attribute, usage); } - template inline static std::size_t attributeCount(const T& first, const U&... next) { - CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0); + template inline static typename std::enable_if::value, std::size_t>::type attributeCount(const T& first, const U&... next) { + CORRADE_ASSERT(sizeof...(next) == 0 || attributeCount(next...) == first.size() || attributeCount(next...) == ~std::size_t(0), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.", 0); return first.size(); } - template inline static std::size_t stride(const T&, const U&... next) { + template inline static std::size_t attributeCount(std::size_t, const T&... next) { + return attributeCount(next...); + } + + template inline static std::size_t attributeCount(std::size_t) { + return ~std::size_t(0); + } + + template inline static typename std::enable_if::value, std::size_t>::type stride(const T&, const U&... next) { return sizeof(typename T::value_type) + stride(next...); } + template inline static std::size_t stride(std::size_t gap, const T&... next) { + return gap + stride(next...); + } + private: - template void write(char* startingOffset, const T& first, const U&... next) { - /* Copy the data to the buffer */ - auto it = first.begin(); + template inline void write(char* startingOffset, const T& first, const U&... next) { + write(startingOffset+writeOne(startingOffset, first), next...); + } + + /* Copy data to the buffer */ + template typename std::enable_if::value, std::size_t>::type writeOne(char* startingOffset, const T& attributeList) { + auto it = attributeList.begin(); for(std::size_t i = 0; i != _attributeCount; ++i, ++it) memcpy(startingOffset+i*_stride, reinterpret_cast(&*it), sizeof(typename T::value_type)); - write(startingOffset+sizeof(typename T::value_type), next...); + return sizeof(typename T::value_type); + } + + /* Fill gap with zeros */ + std::size_t writeOne(char* startingOffset, std::size_t gap) { + char* data = new char[gap](); + for(std::size_t i = 0; i != _attributeCount; ++i) + memcpy(startingOffset+i*_stride, data, gap); + + delete[] data; + return gap; } /* Terminator functions for recursive calls */ @@ -102,15 +128,14 @@ class Interleave { /** @brief %Interleave vertex attributes -@param attribute First attribute array -@param attributes Next attribute arrays -@return Attribute count, stride and interleaved attribute array. Deleting the - array is user responsibility. - -This function takes two or more attribute arrays and returns them interleaved, -so data for each attribute are in continuous place in memory. Size of the data -buffer can be computed from attribute count and stride, as shown below. Example -usage: + +This function takes list of attribute arrays and returns them interleaved, so +data for each attribute are in continuous place in memory. Returned tuple +contains attribute count, stride and data array. Deleting the data array is up +to the user. + +Size of the data buffer can be computed from attribute count and stride, as +shown below. Example usage: @code std::vector positions; std::vector textureCoordinates; @@ -123,28 +148,41 @@ std::size_t dataSize = attributeCount*stride; delete[] data; @endcode -The only requirements to attribute array type is that it must have typedef -`T::value_type`, forward iterator (to be used with range-based for) and -function `size()` returning count of elements. In most cases it will be -`std::vector` or `std::array`. +It's often desirable to align data for one vertex on 32bit boundaries. To +achieve that, you can specify gaps between the attributes: +@code +std::vector positions; +std::vector weights; +std::vector> vertexColors; +std::size_t attributeCount; +std::size_t stride; +char* data; +std::tie(attributeCount, stride, data) = MeshTools::interleave(positions, weights, 2, textureCoordinates, 1); +@endcode +This way vertex stride is 24 bytes, without gaps it would be 21 bytes, causing +possible performance loss. + +@attention The function expects that all arrays have the same size. + +@note The only requirements to attribute array type is that it must have + typedef `T::value_type`, forward iterator (to be used with range-based + for) and function `size()` returning count of elements. In most cases it + will be `std::vector` or `std::array`. See also interleave(Mesh*, Buffer*, Buffer::Usage, const T&...), which writes the interleaved array directly into buffer of given mesh. - -@attention Each passed array should have the same size, if not, resulting - array has zero length. */ /* enable_if to avoid clash with overloaded function below */ -template inline typename std::enable_if::value, std::tuple>::type interleave(const T& attribute, const U&... attributes) { - return Implementation::Interleave()(attribute, attributes...); +template inline typename std::enable_if::value, std::tuple>::type interleave(const T& first, const U&... next) { + return Implementation::Interleave()(first, next...); } /** @brief %Interleave vertex attributes and write them to array buffer -@param attributes Attribute arrays @param mesh Output mesh -@param buffer Output array buffer -@param usage Array buffer usage +@param buffer Output vertex buffer +@param usage Vertex buffer usage +@param attributes Attribute arrays and gaps The same as interleave(const T&, const U&...), but this function writes the output to given array buffer and updates vertex count in the mesh accordingly, diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index 09f1ba2d3..6939fb96a 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -29,14 +29,20 @@ class InterleaveTest: public Corrade::TestSuite::Tester { InterleaveTest(); void attributeCount(); + void attributeCountGaps(); void stride(); + void strideGaps(); void write(); + void writeGaps(); }; InterleaveTest::InterleaveTest() { addTests(&InterleaveTest::attributeCount, + &InterleaveTest::attributeCountGaps, &InterleaveTest::stride, - &InterleaveTest::write); + &InterleaveTest::strideGaps, + &InterleaveTest::write, + &InterleaveTest::writeGaps); } void InterleaveTest::attributeCount() { @@ -50,12 +56,24 @@ void InterleaveTest::attributeCount() { std::vector{3, 4, 5})), std::size_t(3)); } +void InterleaveTest::attributeCountGaps() { + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, 3, + std::vector{3, 4, 5}, 5)), std::size_t(3)); + + /* No arrays from which to get size */ + CORRADE_COMPARE(Implementation::Interleave::attributeCount(3, 5), ~std::size_t(0)); +} + void InterleaveTest::stride() { CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(1)); CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(4)); CORRADE_COMPARE((Implementation::Interleave::stride(std::vector(), std::vector())), std::size_t(5)); } +void InterleaveTest::strideGaps() { + CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector(), 1, std::vector(), 12)), std::size_t(20)); +} + void InterleaveTest::write() { std::size_t attributeCount; std::size_t stride; @@ -85,6 +103,35 @@ void InterleaveTest::write() { delete[] data; } +void InterleaveTest::writeGaps() { + std::size_t attributeCount; + std::size_t stride; + char* data; + std::tie(attributeCount, stride, data) = MeshTools::interleave( + std::vector{0, 1, 2}, 3, + std::vector{3, 4, 5}, + std::vector{6, 7, 8}, 2); + + CORRADE_COMPARE(attributeCount, std::size_t(3)); + CORRADE_COMPARE(stride, std::size_t(12)); + std::size_t size = attributeCount*stride; + if(!Endianness::isBigEndian()) { + CORRADE_COMPARE(std::vector(data, data+size), (std::vector{ + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 + })); + } else { + CORRADE_COMPARE(std::vector(data, data+size), (std::vector{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00 + })); + } + + delete[] data; +} + }}} CORRADE_TEST_MAIN(Magnum::MeshTools::Test::InterleaveTest) From 3b5b7c71d472e2488f17789b5d74c798b68ab4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 13 Jan 2013 23:12:52 +0100 Subject: [PATCH 166/567] Debug output and configuration value handler for IndexedMesh::IndexType. Mostly copy of what was already done for Type enum. --- src/Context.h | 2 +- src/IndexedMesh.cpp | 40 ++++++++++++++++++++++++++ src/IndexedMesh.h | 26 +++++++++++++++++ src/Test/CMakeLists.txt | 1 + src/Test/IndexedMeshTest.cpp | 55 ++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/Test/IndexedMeshTest.cpp diff --git a/src/Context.h b/src/Context.h index 53c8b7896..e072a2826 100644 --- a/src/Context.h +++ b/src/Context.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Enum Version, class Magnum::Context, Magnum::Extension, macro MAGNUM_ASSERT_VERSION_SUPPORTED(), MAGNUM_ASSERT_EXTENSION_SUPPORTED() + * @brief Enum Magnum::Version, class Magnum::Context, Magnum::Extension, macro MAGNUM_ASSERT_VERSION_SUPPORTED(), MAGNUM_ASSERT_EXTENSION_SUPPORTED() */ #include diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 8053cbfcf..099bc3065 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -87,4 +87,44 @@ void IndexedMesh::bindIndexedImplementationDefault() { void IndexedMesh::bindIndexedImplementationVAO() {} +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug operator<<(Debug debug, IndexedMesh::IndexType value) { + switch(value) { + #define _c(value) case IndexedMesh::IndexType::value: return debug << "IndexedMesh::IndexType::" #value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + } + + return debug << "IndexedMesh::IndexType::(invalid)"; +} +#endif + } + +namespace Corrade { namespace Utility { + +std::string ConfigurationValue::toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags) { + switch(value) { + #define _c(value) case Magnum::IndexedMesh::IndexType::value: return #value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + } + + return ""; +} + +Magnum::IndexedMesh::IndexType ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { + #define _c(value) if(stringValue == #value) return Magnum::IndexedMesh::IndexType::value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + + return Magnum::IndexedMesh::IndexType::UnsignedInt; +} + +}} diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 090942179..9d956f99d 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -196,6 +196,32 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { IndexType _indexType; }; +/** @debugoperator{Magnum::IndexedMesh} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, IndexedMesh::IndexType value); + } +namespace Corrade { namespace Utility { + +/** @configurationvalue{Magnum::IndexedMesh} */ +template<> struct MAGNUM_EXPORT ConfigurationValue { + ConfigurationValue() = delete; + + /** + * @brief Write enum value as string + * + * If the value is invalid, returns empty string. + */ + static std::string toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags); + + /** + * @brief Read enum value as string + * + * If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". + */ + static Magnum::IndexedMesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); +}; + +}} + #endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 743268bed..6ae07e8d8 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,6 +1,7 @@ corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) +corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum) diff --git a/src/Test/IndexedMeshTest.cpp b/src/Test/IndexedMeshTest.cpp new file mode 100644 index 000000000..6d51e341f --- /dev/null +++ b/src/Test/IndexedMeshTest.cpp @@ -0,0 +1,55 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include +#include + +#include "IndexedMesh.h" + +using namespace Corrade::Utility; + +namespace Magnum { namespace Test { + +class IndexedMeshTest: public Corrade::TestSuite::Tester { + public: + IndexedMeshTest(); + + void debug(); + void configuration(); +}; + +IndexedMeshTest::IndexedMeshTest() { + addTests(&IndexedMeshTest::debug, + &IndexedMeshTest::configuration); +} + +void IndexedMeshTest::debug() { + std::ostringstream o; + Debug(&o) << IndexedMesh::IndexType::UnsignedShort; + CORRADE_COMPARE(o.str(), "IndexedMesh::IndexType::UnsignedShort\n"); +} + +void IndexedMeshTest::configuration() { + Configuration c; + + c.setValue("type", IndexedMesh::IndexType::UnsignedByte); + CORRADE_COMPARE(c.value("type"), "UnsignedByte"); + CORRADE_COMPARE(c.value("type"), IndexedMesh::IndexType::UnsignedByte); +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::IndexedMeshTest) From 7dc0fc4a4cc1c74e131e9b2489b721c9a1a28fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 14 Jan 2013 00:22:26 +0100 Subject: [PATCH 167/567] Math: Renamed Math.h to Functions.h Math.h is reserved for forward declaration header. --- src/CMakeLists.txt | 2 +- src/Color.h | 2 +- src/DefaultFramebuffer.cpp | 1 + src/Math/CMakeLists.txt | 2 +- src/Math/{Math.cpp => Functions.cpp} | 2 +- src/Math/{Math.h => Functions.h} | 6 ++-- src/Math/Geometry/Distance.h | 2 +- src/Math/Quaternion.h | 2 +- src/Math/Test/CMakeLists.txt | 2 +- src/Math/Test/ConstantsTest.cpp | 2 +- .../Test/{MathTest.cpp => FunctionsTest.cpp} | 34 +++++++++---------- src/MeshTools/CompressIndices.cpp | 2 +- src/Physics/Capsule.cpp | 2 +- src/Physics/Sphere.cpp | 2 +- 14 files changed, 32 insertions(+), 31 deletions(-) rename src/Math/{Math.cpp => Functions.cpp} (97%) rename src/Math/{Math.h => Functions.h} (97%) rename src/Math/Test/{MathTest.cpp => FunctionsTest.cpp} (86%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 06b292751..a54f7e638 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,7 +100,7 @@ add_library(MagnumObjects OBJECT ${Magnum_SRCS}) # Files shared between main library and math unit test library set(MagnumMath_SRCS - Math/Math.cpp + Math/Functions.cpp Math/Quaternion.cpp Math/RectangularMatrix.cpp Math/Vector.cpp) diff --git a/src/Color.h b/src/Color.h index 23fabeb99..5a230794a 100644 --- a/src/Color.h +++ b/src/Color.h @@ -21,8 +21,8 @@ #include +#include "Math/Functions.h" #include "Math/MathTypeTraits.h" -#include "Math/Math.h" #include "Math/Vector4.h" #include "Magnum.h" diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index b8a940a33..ec5319425 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -19,6 +19,7 @@ #include "Implementation/State.h" #include "Implementation/FramebufferState.h" +#include "Extensions.h" namespace Magnum { diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index ed55629d2..fed15fe6c 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,6 +1,6 @@ set(MagnumMath_HEADERS Constants.h - Math.h + Functions.h MathTypeTraits.h Matrix.h Matrix3.h diff --git a/src/Math/Math.cpp b/src/Math/Functions.cpp similarity index 97% rename from src/Math/Math.cpp rename to src/Math/Functions.cpp index d2cdd0ce6..286f5d632 100644 --- a/src/Math/Math.cpp +++ b/src/Math/Functions.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Math.h" +#include "Functions.h" namespace Magnum { namespace Math { diff --git a/src/Math/Math.h b/src/Math/Functions.h similarity index 97% rename from src/Math/Math.h rename to src/Math/Functions.h index 7a9004fe1..e06f5dd36 100644 --- a/src/Math/Math.h +++ b/src/Math/Functions.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Math_Math_h -#define Magnum_Math_Math_h +#ifndef Magnum_Math_Functions_h +#define Magnum_Math_Functions_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -23,7 +23,7 @@ #include "magnumVisibility.h" /** @file - * @brief Math utilities + * @brief Functions usable with scalar and vector types */ namespace Magnum { namespace Math { diff --git a/src/Math/Geometry/Distance.h b/src/Math/Geometry/Distance.h index 48fe043a1..2268f1f95 100644 --- a/src/Math/Geometry/Distance.h +++ b/src/Math/Geometry/Distance.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Math::Geometry::Distance */ -#include "Math/Math.h" +#include "Math/Functions.h" #include "Math/Matrix.h" #include "Math/Vector3.h" diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 808413a15..d962a03ef 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -23,7 +23,7 @@ #include #include -#include "Math/Math.h" +#include "Math/Functions.h" #include "Math/MathTypeTraits.h" #include "Math/Matrix.h" #include "Math/Vector3.h" diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 760d8bcdf..185946510 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -1,5 +1,5 @@ corrade_add_test(MathConstantsTest ConstantsTest.cpp) -corrade_add_test(MathTest MathTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) corrade_add_test(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index 0baa25d12..1bfe32b72 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -16,7 +16,7 @@ #include #include "Math/Constants.h" -#include "Math/Math.h" +#include "Math/Functions.h" namespace Magnum { namespace Math { namespace Test { diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/FunctionsTest.cpp similarity index 86% rename from src/Math/Test/MathTest.cpp rename to src/Math/Test/FunctionsTest.cpp index 044bfa350..e379674dd 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -15,13 +15,13 @@ #include -#include "Math/Math.h" +#include "Math/Functions.h" namespace Magnum { namespace Math { namespace Test { -class MathTest: public Corrade::TestSuite::Tester { +class FunctionsTest: public Corrade::TestSuite::Tester { public: - MathTest(); + FunctionsTest(); void normalize(); void denormalize(); @@ -31,16 +31,16 @@ class MathTest: public Corrade::TestSuite::Tester { void log2(); }; -MathTest::MathTest() { - addTests(&MathTest::normalize, - &MathTest::denormalize, - &MathTest::clamp, - &MathTest::pow, - &MathTest::log, - &MathTest::log2); +FunctionsTest::FunctionsTest() { + addTests(&FunctionsTest::normalize, + &FunctionsTest::denormalize, + &FunctionsTest::clamp, + &FunctionsTest::pow, + &FunctionsTest::log, + &FunctionsTest::log2); } -void MathTest::normalize() { +void FunctionsTest::normalize() { /* Range for signed and unsigned */ CORRADE_COMPARE((Math::normalize(-128)), 0.0f); CORRADE_COMPARE((Math::normalize(127)), 1.0f); @@ -63,7 +63,7 @@ void MathTest::normalize() { CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); } -void MathTest::denormalize() { +void FunctionsTest::denormalize() { /* Range for signed and unsigned */ CORRADE_COMPARE(Math::denormalize(0.0f), -128); CORRADE_COMPARE(Math::denormalize(1.0f), 127); @@ -90,27 +90,27 @@ void MathTest::denormalize() { // } } -void MathTest::clamp() { +void FunctionsTest::clamp() { CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); CORRADE_COMPARE(Math::clamp(9.5f, -1.0f, 5.0f), 5.0f); } -void MathTest::pow() { +void FunctionsTest::pow() { CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); CORRADE_COMPARE(Math::pow<2>(2.0f), 4.0f); } -void MathTest::log() { +void FunctionsTest::log() { CORRADE_COMPARE(Math::log(2, 256), 8ul); CORRADE_COMPARE(Math::log(256, 2), 0ul); } -void MathTest::log2() { +void FunctionsTest::log2() { CORRADE_COMPARE(Math::log2(2153), 11); } }}} -CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) +CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsTest) diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 0ca368fbb..2c8cda63c 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -18,7 +18,7 @@ #include #include -#include "Math/Math.h" +#include "Math/Functions.h" namespace Magnum { namespace MeshTools { diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 8fc516ba6..59b54f653 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -16,7 +16,7 @@ #include "Capsule.h" #include "Math/Constants.h" -#include "Math/Math.h" +#include "Math/Functions.h" #include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Math/Geometry/Distance.h" diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 9bd6f754e..7096ff0cb 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -16,7 +16,7 @@ #include "Sphere.h" #include "Math/Constants.h" -#include "Math/Math.h" +#include "Math/Functions.h" #include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Math/Geometry/Distance.h" From cade1753042d23d8d83fd3ccb6917f51ead2fc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 14 Jan 2013 01:36:07 +0100 Subject: [PATCH 168/567] Math: finally implemented precise signed/unsigned normalization. (De)normalization from/to [0, 1] for unsigned types and from/to [-1, 1] for signed types. -1.0 is always denormalized to min+1. Also updated some tests for Color, as they depended on previous imprecise implementation. --- src/Math/Functions.h | 51 ++++++++---- src/Math/Test/FunctionsTest.cpp | 140 +++++++++++++++++++++++--------- src/Test/ColorTest.cpp | 34 ++++---- 3 files changed, 153 insertions(+), 72 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index e06f5dd36..a78e5d06c 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -75,14 +75,18 @@ std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number); std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number); /** -@brief Normalize floating-point value +@brief Normalize integral value -Converts integral value from full range of given (signed/unsigned) integral -type to value in range @f$ [0, 1] @f$. +Converts integral value from full range of given *unsigned* integral type to +value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$. + +@note For best precision, `FloatingPoint` type should be always larger that + resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` + to `std::int64_t`). @attention To ensure the integral type is correctly detected when using -literals, this function should be called with both template parameters -explicit, e.g.: + literals, this function should be called with both template parameters + explicit, e.g.: @code // Even if this is character literal, integral type is 32bit, thus a != 1.0f float a = normalize('\127'); @@ -91,32 +95,43 @@ float a = normalize('\127'); float b = normalize('\127'); @endcode -@todo Signed normalization to [-1.0, 1.0] like in OpenGL? +@see denormalize() */ -template inline constexpr typename std::enable_if::value && std::is_integral::value, FloatingPoint>::type normalize(Integral value) { - return (FloatingPoint(value)-FloatingPoint(std::numeric_limits::min()))/ - (FloatingPoint(std::numeric_limits::max()) - FloatingPoint(std::numeric_limits::min())); +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline constexpr FloatingPoint normalize(Integral value); +#else +template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_unsigned::value, FloatingPoint>::type normalize(Integral value) { + return value/FloatingPoint(std::numeric_limits::max()); } +template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_signed::value, FloatingPoint>::type normalize(Integral value) { + return std::max(value/FloatingPoint(std::numeric_limits::max()), FloatingPoint(-1)); +} +#endif + /** @brief Denormalize floating-point value Converts floating-point value in range @f$ [0, 1] @f$ to full range of given +unsigned integral type or range @f$ [-1, 1] @f$ to full range of given signed integral type. @note For best precision, `FloatingPoint` type should be always larger that -resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` to -`std::int64_t`). + 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 - (currently fails in Debug builds, but passes in Release on GCC 4.7) +@see normalize() */ -template inline constexpr typename std::enable_if::value && std::is_integral::value, Integral>::type denormalize(FloatingPoint value) { - return std::numeric_limits::min() + - round(FloatingPoint(value*std::numeric_limits::max()) - - FloatingPoint(value*std::numeric_limits::min())); +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline constexpr typename Integral denormalize(FloatingPoint value); +#else +template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_unsigned::value, Integral>::type denormalize(FloatingPoint value) { + return value*std::numeric_limits::max(); +} +template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_signed::value, Integral>::type denormalize(FloatingPoint value) { + return value*std::numeric_limits::max(); } +#endif /** @brief Clamp value */ template inline T clamp(T value, T min, T max) { diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index e379674dd..9b55ae7e2 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -23,8 +23,12 @@ class FunctionsTest: public Corrade::TestSuite::Tester { public: FunctionsTest(); - void normalize(); - void denormalize(); + void normalizeUnsigned(); + void normalizeSigned(); + void denormalizeUnsigned(); + void denormalizeSigned(); + void renormalizeUnsinged(); + void renormalizeSinged(); void clamp(); void pow(); void log(); @@ -32,62 +36,124 @@ class FunctionsTest: public Corrade::TestSuite::Tester { }; FunctionsTest::FunctionsTest() { - addTests(&FunctionsTest::normalize, - &FunctionsTest::denormalize, + addTests(&FunctionsTest::normalizeUnsigned, + &FunctionsTest::normalizeSigned, + &FunctionsTest::denormalizeUnsigned, + &FunctionsTest::denormalizeSigned, + &FunctionsTest::renormalizeUnsinged, + &FunctionsTest::renormalizeSinged, &FunctionsTest::clamp, &FunctionsTest::pow, &FunctionsTest::log, &FunctionsTest::log2); } -void FunctionsTest::normalize() { - /* Range for signed and unsigned */ - CORRADE_COMPARE((Math::normalize(-128)), 0.0f); - CORRADE_COMPARE((Math::normalize(127)), 1.0f); +void FunctionsTest::normalizeUnsigned() { CORRADE_COMPARE((Math::normalize(0)), 0.0f); CORRADE_COMPARE((Math::normalize(255)), 1.0f); - /* Between */ - CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); - CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); + 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); - /* Test overflow for large types */ - CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), 0.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), 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); + CORRADE_COMPARE((Math::normalize(8192)), 0.125002f); + CORRADE_COMPARE((Math::normalize(49152)), 0.750011f); } -void FunctionsTest::denormalize() { - /* Range for signed and unsigned */ - CORRADE_COMPARE(Math::denormalize(0.0f), -128); - CORRADE_COMPARE(Math::denormalize(1.0f), 127); +void FunctionsTest::normalizeSigned() { + CORRADE_COMPARE((Math::normalize(127)), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(-128)), -1.0f); + + CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + + 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); + + 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); + + CORRADE_COMPARE((Math::normalize(16384)), 0.500015f); + CORRADE_COMPARE((Math::normalize(-16384)), -0.500015f); +} + +void FunctionsTest::denormalizeUnsigned() { CORRADE_COMPARE(Math::denormalize(0.0f), 0); CORRADE_COMPARE(Math::denormalize(1.0f), 255); - /* Between */ - CORRADE_COMPARE(Math::denormalize(0.33f), -11141); - CORRADE_COMPARE(Math::denormalize(0.66f), 10485); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); + + CORRADE_COMPARE(Math::denormalize(0.0), 0); + CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - /* Test overflow for large types */ - CORRADE_COMPARE(Math::denormalize(0.0f), std::numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(0.0), std::numeric_limits::min()); CORRADE_COMPARE(Math::denormalize(0.0), 0); + CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(0.33f), 21626); + CORRADE_COMPARE(Math::denormalize(0.66f), 43253); +} + +void FunctionsTest::denormalizeSigned() { + CORRADE_COMPARE(Math::denormalize(-1.0f), -127); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), 127); + + CORRADE_COMPARE(Math::denormalize(-1.0f), std::numeric_limits::min()+1); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); + + 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()); - CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); -// { -// CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); -// CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); -// CORRADE_COMPARE((Math::denormalize(1.0)), numeric_limits::max()); -// } + 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()); + + CORRADE_COMPARE(Math::denormalize(-0.33f), -10813); + CORRADE_COMPARE(Math::denormalize(0.66f), 21626); +} + +void FunctionsTest::renormalizeUnsinged() { + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + + 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); +} + +void FunctionsTest::renormalizeSinged() { + CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + + CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + + 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); + + 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); } void FunctionsTest::clamp() { diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index d7ae54931..fd6aca832 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -104,16 +104,16 @@ void ColorTest::fromDenormalized() { } void ColorTest::fromNormalized() { - CORRADE_COMPARE(Color3::fromNormalized(Color3f(0.294118, 0.45098, 0.878431)), Color3(75, 115, 224)); + CORRADE_COMPARE(Color3::fromNormalized(Color3f(0.294118, 0.45098, 0.878431)), Color3(75, 114, 223)); } void ColorTest::fromHue() { - CORRADE_COMPARE(Color3::fromHSV(27.0f, 1.0f, 1.0f), Color3(255, 115, 0)); - CORRADE_COMPARE(Color3::fromHSV(86.0f, 1.0f, 1.0f), Color3(145, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(134.0f, 1.0f, 1.0f), Color3(0, 255, 60)); + CORRADE_COMPARE(Color3::fromHSV(27.0f, 1.0f, 1.0f), Color3(255, 114, 0)); + CORRADE_COMPARE(Color3::fromHSV(86.0f, 1.0f, 1.0f), Color3(144, 255, 0)); + CORRADE_COMPARE(Color3::fromHSV(134.0f, 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3::fromHSV(191.0f, 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3::fromHSV(269.0f, 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(317.0f, 1.0f, 1.0f), Color3(255, 0, 183)); + CORRADE_COMPARE(Color3::fromHSV(317.0f, 1.0f, 1.0f), Color3(255, 0, 182)); } void ColorTest::hue() { @@ -126,7 +126,7 @@ void ColorTest::hue() { } void ColorTest::fromSaturation() { - CORRADE_COMPARE(Color3::fromHSV(0.0f, 0.702f, 1.0f), Color3(255, 76, 76)); + CORRADE_COMPARE(Color3::fromHSV(0.0f, 0.702f, 1.0f), Color3(255, 75, 75)); } void ColorTest::saturation() { @@ -143,7 +143,7 @@ void ColorTest::value() { } void ColorTest::hsv() { - CORRADE_COMPARE(Color3::fromHSV(230.0f, 0.749f, 0.427f), Color3(27, 41, 109)); + CORRADE_COMPARE(Color3::fromHSV(230.0f, 0.749f, 0.427f), Color3(27, 40, 108)); float hue, saturation, value; std::tie(hue, saturation, value) = Color3(27, 41, 109).toHSV(); @@ -153,24 +153,24 @@ void ColorTest::hsv() { } void ColorTest::hsvOverflow() { - CORRADE_COMPARE(Color3::fromHSV(27.0f-360.0f, 1.0f, 1.0f), Color3(255, 115, 0)); - CORRADE_COMPARE(Color3::fromHSV(86.0f-360.0f, 1.0f, 1.0f), Color3(145, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(134.0f-360.0f, 1.0f, 1.0f), Color3(0, 255, 60)); + CORRADE_COMPARE(Color3::fromHSV(27.0f-360.0f, 1.0f, 1.0f), Color3(255, 114, 0)); + CORRADE_COMPARE(Color3::fromHSV(86.0f-360.0f, 1.0f, 1.0f), Color3(144, 255, 0)); + CORRADE_COMPARE(Color3::fromHSV(134.0f-360.0f, 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3::fromHSV(191.0f-360.0f, 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3::fromHSV(269.0f-360.0f, 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(317.0f-360.0f, 1.0f, 1.0f), Color3(255, 0, 183)); + CORRADE_COMPARE(Color3::fromHSV(317.0f-360.0f, 1.0f, 1.0f), Color3(255, 0, 182)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+27.0f, 1.0f, 1.0f), Color3(255, 115, 0)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+86.0f, 1.0f, 1.0f), Color3(145, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+134.0f, 1.0f, 1.0f), Color3(0, 255, 60)); + CORRADE_COMPARE(Color3::fromHSV(360.0f+27.0f, 1.0f, 1.0f), Color3(255, 114, 0)); + CORRADE_COMPARE(Color3::fromHSV(360.0f+86.0f, 1.0f, 1.0f), Color3(144, 255, 0)); + CORRADE_COMPARE(Color3::fromHSV(360.0f+134.0f, 1.0f, 1.0f), Color3(0, 255, 59)); CORRADE_COMPARE(Color3::fromHSV(360.0f+191.0f, 1.0f, 1.0f), Color3(0, 208, 255)); CORRADE_COMPARE(Color3::fromHSV(360.0f+269.0f, 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+317.0f, 1.0f, 1.0f), Color3(255, 0, 183)); + CORRADE_COMPARE(Color3::fromHSV(360.0f+317.0f, 1.0f, 1.0f), Color3(255, 0, 182)); } void ColorTest::hsvAlpha() { - CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(230.0f, 0.749f, 0.427f), 23), Color4(27, 41, 109, 23)); - CORRADE_COMPARE(Color4::fromHSV(230.0f, 0.749f, 0.427f, 23), Color4(27, 41, 109, 23)); + CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(230.0f, 0.749f, 0.427f), 23), Color4(27, 40, 108, 23)); + CORRADE_COMPARE(Color4::fromHSV(230.0f, 0.749f, 0.427f, 23), Color4(27, 40, 108, 23)); } void ColorTest::debug() { From 5ca096512e5ca590485336ea9b2734cc62c848a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 14 Jan 2013 02:18:10 +0100 Subject: [PATCH 169/567] Forward declaration header for Math namespace. --- doc/compilation-speedup.dox | 1 + src/AbstractShaderProgram.h | 6 ----- src/DimensionTraits.h | 12 --------- src/Magnum.h | 18 +++---------- src/Math/CMakeLists.txt | 1 + src/Math/Math.h | 50 +++++++++++++++++++++++++++++++++++++ src/TypeTraits.h | 6 ----- 7 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 src/Math/Math.h diff --git a/doc/compilation-speedup.dox b/doc/compilation-speedup.dox index bfd68db8a..23313c4be 100644 --- a/doc/compilation-speedup.dox +++ b/doc/compilation-speedup.dox @@ -19,6 +19,7 @@ some types it can be too cumbersome -- e.g. too many template parameters, typedefs etc. In this case a header with forward declarations is usually available, each namespace has its own: + - Math/Math.h - Magnum.h - DebugTools/DebugTools.h - Physics/Physics.h diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index ed646d079..2c78f8b17 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -31,12 +31,6 @@ namespace Magnum { -namespace Math { - template class RectangularMatrix; - template class Matrix; - template class Vector; -} - #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Attribute; diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index ad3975501..e2b49e430 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -23,18 +23,6 @@ namespace Magnum { -namespace Math { - template class Vector; - template class Vector2; - template class Vector3; - - template class Point2D; - template class Point3D; - - template class Matrix3; - template class Matrix4; -} - /** @brief Matrix, point and vector specializations for given dimension count */ template struct DimensionTraits { DimensionTraits() = delete; diff --git a/src/Magnum.h b/src/Magnum.h index 1f8c7d14f..d47f2b15d 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -20,8 +20,10 @@ */ #include +#include + +#include "Math/Math.h" -#include "corradeConfigure.h" #include "magnumConfigure.h" #ifndef MAGNUM_TARGET_GLES @@ -56,23 +58,9 @@ namespace Corrade { namespace Magnum { namespace Math { - template class Vector2; - template class Vector3; - template class Vector4; - template class Point2D; - template class Point3D; - template class Matrix3; - template class Matrix4; - - template class Quaternion; - template constexpr T deg(T value); template constexpr T rad(T value); template class Constants; - - namespace Geometry { - template class Rectangle; - } } /* Bring debugging facility from Corrade::Utility namespace */ diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index fed15fe6c..1d347f4d0 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,6 +1,7 @@ set(MagnumMath_HEADERS Constants.h Functions.h + Math.h MathTypeTraits.h Matrix.h Matrix3.h diff --git a/src/Math/Math.h b/src/Math/Math.h new file mode 100644 index 000000000..df38fef81 --- /dev/null +++ b/src/Math/Math.h @@ -0,0 +1,50 @@ +#ifndef Magnum_Math_Math_h +#define Magnum_Math_Math_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Forward declarations for Magnum::Math namespace + */ + +#include + +namespace Magnum { namespace Math { + +/* Class Constants used only statically */ + +template class Matrix; +template class Matrix3; +template class Matrix4; + +template class Point2D; +template class Point3D; + +template class Quaternion; + +template class RectangularMatrix; + +template class Vector; +template class Vector2; +template class Vector3; +template class Vector4; + +namespace Geometry { + template class Rectangle; +} + +}} + +#endif diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 8c096feeb..f92c89577 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -28,12 +28,6 @@ namespace Magnum { -namespace Math { - template class RectangularMatrix; - template class Matrix; - template class Vector; -} - /** @brief Traits class for plain OpenGL types From a4da7b764a23ca9756303479dd0579cbe30533e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 14 Jan 2013 15:55:41 +0100 Subject: [PATCH 170/567] Adapted to Corrade changes. --- src/Array.h | 2 +- src/DebugTools/Profiler.cpp | 2 +- src/Math/RectangularMatrix.h | 2 +- src/Math/Vector.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Array.h b/src/Array.h index e761dde90..22b8288a5 100644 --- a/src/Array.h +++ b/src/Array.h @@ -186,7 +186,7 @@ template Corrade::Utility::Debug operator<<(Co if(i != 0) debug << ", "; debug << value[i]; } - debug << ')'; + debug << ")"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); return debug; } diff --git a/src/DebugTools/Profiler.cpp b/src/DebugTools/Profiler.cpp index 288ba1392..06f128ae2 100644 --- a/src/DebugTools/Profiler.cpp +++ b/src/DebugTools/Profiler.cpp @@ -105,7 +105,7 @@ void Profiler::printStatistics() { Debug() << "Statistics for last" << measureDuration << "frames:"; for(std::size_t i = 0; i != sections.size(); ++i) - Debug() << ' ' << sections[totalSorted[i]] << std::chrono::microseconds(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; + Debug() << " " << sections[totalSorted[i]] << std::chrono::microseconds(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; } }} diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 592e062c5..46b133290 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -427,7 +427,7 @@ template Corrade::Utility::Debug op debug << typename MathTypeTraits::NumericType(value[col][row]); } } - debug << ')'; + debug << ")"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); return debug; } diff --git a/src/Math/Vector.h b/src/Math/Vector.h index d21fde555..483f335b5 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -326,7 +326,7 @@ template Corrade::Utility::Debug operator<<(Corrade:: if(i != 0) debug << ", "; debug << typename MathTypeTraits::NumericType(value[i]); } - debug << ')'; + debug << ")"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); return debug; } From 03789a5b4bfccbed85ffd21cf3422a6593d189e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 14 Jan 2013 16:05:57 +0100 Subject: [PATCH 171/567] Math: got rid of MathTypeTraits::NumericType. Was workaround for printing chars with Corrade::Utility::Debug as integers, not needed anymore. --- src/Math/MathTypeTraits.h | 18 ------------------ src/Math/RectangularMatrix.h | 2 +- src/Math/Vector.h | 2 +- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 2b54f8e3a..385fc8a0e 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -56,14 +56,6 @@ template struct MathTypeTraits { */ #ifdef DOXYGEN_GENERATING_OUTPUT - /** - * @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. - */ - typedef U NumericType; - /** * @brief Corresponding floating-point type for normalization * @@ -123,49 +115,39 @@ template struct MathTypeTraitsFloatingPoint { } template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::uint32_t NumericType; typedef float FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::int32_t NumericType; typedef float FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::uint32_t NumericType; typedef float FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::int32_t NumericType; typedef float FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::uint32_t NumericType; typedef double FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::int32_t NumericType; typedef double FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::uint64_t NumericType; typedef long double FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef std::int64_t NumericType; typedef long double FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { - typedef float NumericType; typedef float FloatingPointType; inline constexpr static float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { - typedef float NumericType; typedef double FloatingPointType; inline constexpr static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 46b133290..4bed38856 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -424,7 +424,7 @@ template Corrade::Utility::Debug op if(row != 0) debug << ",\n "; for(std::size_t col = 0; col != cols; ++col) { if(col != 0) debug << ", "; - debug << typename MathTypeTraits::NumericType(value[col][row]); + debug << value[col][row]; } } debug << ")"; diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 483f335b5..eed04f4dd 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -324,7 +324,7 @@ template Corrade::Utility::Debug operator<<(Corrade:: debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); for(std::size_t i = 0; i != size; ++i) { if(i != 0) debug << ", "; - debug << typename MathTypeTraits::NumericType(value[i]); + debug << value[i]; } debug << ")"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); From 2f2d4a4dfd9cf127f3f57cb3591f2a0ff82cdccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 Jan 2013 18:59:37 +0100 Subject: [PATCH 172/567] Removed Magnum::Type and related functionality. The enum is finally completely reimplemented for specific cases with proper values (Mesh attribute types, index types, pixel types, ...). The rest currently remaining in TypeTraits.h is used only in Mesh and AbstractShaderProgram, probably will be moved there. --- src/Test/CMakeLists.txt | 1 - src/Test/TypeTraitsTest.cpp | 55 ------------- src/TypeTraits.cpp | 94 ---------------------- src/TypeTraits.h | 151 +----------------------------------- 4 files changed, 1 insertion(+), 300 deletions(-) delete mode 100644 src/Test/TypeTraitsTest.cpp diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 6ae07e8d8..0bd72dd47 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -4,6 +4,5 @@ corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(TypeTraitsTest TypeTraitsTest.cpp LIBRARIES Magnum) set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Test/TypeTraitsTest.cpp b/src/Test/TypeTraitsTest.cpp deleted file mode 100644 index a6da165a7..000000000 --- a/src/Test/TypeTraitsTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include -#include -#include - -#include "TypeTraits.h" - -using namespace Corrade::Utility; - -namespace Magnum { namespace Test { - -class TypeTraitsTest: public Corrade::TestSuite::Tester { - public: - TypeTraitsTest(); - - void debug(); - void configuration(); -}; - -TypeTraitsTest::TypeTraitsTest() { - addTests(&TypeTraitsTest::debug, - &TypeTraitsTest::configuration); -} - -void TypeTraitsTest::debug() { - std::ostringstream o; - Debug(&o) << Type::UnsignedShort; - CORRADE_COMPARE(o.str(), "Type::UnsignedShort\n"); -} - -void TypeTraitsTest::configuration() { - Configuration c; - - c.setValue("type", Type::Byte); - CORRADE_COMPARE(c.value("type"), "Byte"); - CORRADE_COMPARE(c.value("type"), Type::Byte); -} - -}} - -CORRADE_TEST_MAIN(Magnum::Test::TypeTraitsTest) diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp index bf764d21d..d8312a764 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -16,7 +16,6 @@ #include "TypeTraits.h" #include -#include namespace Magnum { @@ -34,97 +33,4 @@ static_assert(std::is_same::value, "GLdouble is not the same a #endif #endif -std::size_t TypeInfo::sizeOf(Type type) { - switch(type) { - #define val(type) case Type::type: return TypeTraits::Type>::size(); - val(UnsignedByte) - val(Byte) - val(UnsignedShort) - val(Short) - val(UnsignedInt) - val(Int) - #ifndef MAGNUM_TARGET_GLES - val(Double) - #endif - val(Float) - #undef val - - default: return 0; - } -} - -bool TypeInfo::isIntegral(Type type) { - switch(type) { - case Type::UnsignedByte: - case Type::Byte: - case Type::UnsignedShort: - case Type::Short: - case Type::UnsignedInt: - case Type::Int: - return true; - default: - return false; - } -} - -#ifndef DOXYGEN_GENERATING_OUTPUT -Debug operator<<(Debug debug, Type value) { - switch(value) { - #define _c(value) case Type::value: return debug << "Type::" #value; - _c(UnsignedByte) - _c(Byte) - _c(UnsignedShort) - _c(Short) - _c(UnsignedInt) - _c(Int) - _c(Float) - #ifndef MAGNUM_TARGET_GLES - _c(Double) - #endif - #undef _c - } - - return debug << "Type::(invalid)"; -} -#endif - -} - -namespace Corrade { namespace Utility { - -std::string ConfigurationValue::toString(Magnum::Type value, ConfigurationValueFlags) { - switch(value) { - #define _c(value) case Magnum::Type::value: return #value; - _c(UnsignedByte) - _c(Byte) - _c(UnsignedShort) - _c(Short) - _c(UnsignedInt) - _c(Int) - _c(Float) - #ifndef MAGNUM_TARGET_GLES - _c(Double) - #endif - #undef _c - } - - return ""; } - -Magnum::Type ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { - #define _c(value) if(stringValue == #value) return Magnum::Type::value; - _c(UnsignedByte) - _c(Byte) - _c(UnsignedShort) - _c(Short) - _c(UnsignedInt) - _c(Int) - #ifndef MAGNUM_TARGET_GLES - _c(Double) - #endif - #undef _c - - return Magnum::Type::Float; -} - -}} diff --git a/src/TypeTraits.h b/src/TypeTraits.h index f92c89577..0770db5dd 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -16,7 +16,7 @@ */ /** @file /TypeTraits.h - * @brief Enum Magnum::Type, class Magnum::TypeOf, Magnum::TypeInfo, Magnum::TypeTraits + * @brief Class Magnum::TypeTraits */ #include @@ -48,13 +48,6 @@ template struct TypeTraits: Math::MathTypeTraits { */ typedef U AttributeType; - /** - * @brief OpenGL plain type ID - * - * Returns e.g. Type::UnsignedInt for GLuint. - */ - inline constexpr static Type type(); - /** * @brief Size of plain OpenGL type * @@ -76,161 +69,45 @@ template struct TypeTraits { }; #endif -/** @brief OpenGL plain types */ -enum class Type: GLenum { - UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte (char) */ - Byte = GL_BYTE, /**< Byte (char) */ - UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ - Short = GL_SHORT, /**< Short */ - UnsignedInt = GL_UNSIGNED_INT, /**< Unsigned int */ - Int = GL_INT, /**< Int */ - Float = GL_FLOAT /**< Float */ - - #ifndef MAGNUM_TARGET_GLES - , - /** - * Double - * @requires_gl Only floats are available in OpenGL ES. - */ - Double = GL_DOUBLE - #endif -}; - -/** @debugoperator{Magnum::TypeInfo} */ -Debug MAGNUM_EXPORT operator<<(Debug debug, Type value); - -/** -@brief Class for converting Type enum values to types - -When you want to use TypeTraits on type specified only as enum value, you can -use this class to convert it into type, for example these two statements -are equivalent: -@code -type = TypeTraits::Type>::imageType(); -type = TypeTraits::imageType(); -@endcode -*/ -template class TypeOf { - TypeOf() = delete; - - #ifdef DOXYGEN_GENERATING_OUTPUT - typedef U Type; /**< @brief Type */ - #endif -}; - -/** -@brief Functor for runtime information about given type - -TypeTraits alone allows to get information about given type only at compile -time, this class alows to get some information also at runtime with tiny -performance loss. -*/ -struct MAGNUM_EXPORT TypeInfo { - TypeInfo() = delete; - - /** - * @brief Size of given type - * - * These two lines provide the same information, one at compile time, - * one at runtime: - * @code - * std::size_t size = TypeTraits::size(); - * std::size_t size = TypeInfo::sizeOf(Type::UnsignedByte); - * @endcode - */ - static std::size_t sizeOf(Type type); - - /** - * @brief Whether the type is integral - * @return true for (un)signed byte, short and integer, false otherwise. - */ - static bool isIntegral(Type type); -}; - -/** @todo Other texture types, referenced in glTexImage2D function manual */ -/** @todo Using Vector3 for textures? */ - #ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct TypeOf { - TypeOf() = delete; - typedef GLubyte Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLbyte Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLushort Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLshort Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLuint Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLint Type; -}; -template<> struct TypeOf { - TypeOf() = delete; - typedef GLfloat Type; -}; -#ifndef MAGNUM_TARGET_GLES -template<> struct TypeOf { - TypeOf() = delete; - typedef GLdouble Type; -}; -#endif - template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static std::size_t size() { return sizeof(GLubyte); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::Byte; } inline constexpr static std::size_t size() { return sizeof(GLbyte); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static std::size_t size() { return sizeof(GLushort); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { /* Can not be used for attributes */ - inline constexpr static Type type() { return Type::Short; } inline constexpr static std::size_t size() { return sizeof(GLshort); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLuint AttributeType; - inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static std::size_t size() { return sizeof(GLuint); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLint AttributeType; - inline constexpr static Type type() { return Type::Int; } inline constexpr static std::size_t size() { return sizeof(GLint); } inline constexpr static std::size_t count() { return 1; } }; template<> struct TypeTraits: Math::MathTypeTraits { typedef GLfloat AttributeType; - inline constexpr static Type type() { return Type::Float; } inline constexpr static std::size_t size() { return sizeof(GLfloat); } inline constexpr static std::size_t count() { return 1; } }; @@ -238,7 +115,6 @@ template<> struct TypeTraits: Math::MathTypeTraits { #ifndef MAGNUM_TARGET_GLES template<> struct TypeTraits: Math::MathTypeTraits { typedef GLdouble AttributeType; - inline constexpr static Type type() { return Type::Double; } inline constexpr static std::size_t size() { return sizeof(GLdouble); } inline constexpr static std::size_t count() { return 1; } }; @@ -249,7 +125,6 @@ namespace Implementation { VectorTypeTraits() = delete; /* Might be used for attributes, see below */ - inline constexpr static Type type() { return TypeTraits::type(); } inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return vectorSize; } }; @@ -296,7 +171,6 @@ namespace Implementation { MatrixTypeTraits() = delete; /* Might be used for attributes, see below */ - inline constexpr static Type type() { return TypeTraits::type(); } inline constexpr static std::size_t size() { return sizeof(T); } inline constexpr static std::size_t count() { return rows; } inline constexpr static std::size_t vectors() { return cols; } @@ -336,27 +210,4 @@ template struct TypeTraits>: TypeTraits struct MAGNUM_EXPORT ConfigurationValue { - ConfigurationValue() = delete; - - /** - * @brief Writes enum value as string - * - * If the value is invalid, returns empty string. - */ - static std::string toString(Magnum::Type value, ConfigurationValueFlags); - - /** - * @brief Reads enum value as string - * - * If the value is invalid, returns @ref Magnum::Type "Magnum::Type::Float". - */ - static Magnum::Type fromString(const std::string& stringValue, ConfigurationValueFlags); -}; - -}} - #endif From 3daefd70a9361179bcf5e6d8cba5192e0e1a2bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 Jan 2013 20:04:30 +0100 Subject: [PATCH 173/567] Math: simplified internal pow() implementation. --- src/Math/Functions.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index a78e5d06c..6209b629a 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -39,12 +39,16 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Pow { - template inline constexpr T operator()(T base) const { - return base*Pow()(base); + Pow() = delete; + + template inline constexpr static T pow(T base) { + return base*Pow::pow(base); } }; template<> struct Pow<0> { - template inline constexpr T operator()(T) const { return 1; } + Pow() = delete; + + template inline constexpr static T pow(T) { return 1; } }; } #endif @@ -55,7 +59,7 @@ namespace Implementation { * Returns integral power of base to the exponent. */ template inline constexpr T pow(T base) { - return Implementation::Pow()(base); + return Implementation::Pow::pow(base); } /** From bdba6b72218aed92171ef28f434de683b0fa1c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 16 Jan 2013 21:37:50 +0100 Subject: [PATCH 174/567] Math: no need to have two versions of denormalize(), they are the same. Overlooked in cade1753042d23d8d83fd3ccb6917f51ead2fc55. --- src/Math/Functions.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index 6209b629a..c80fd1eab 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -129,10 +129,7 @@ integral type. #ifdef DOXYGEN_GENERATING_OUTPUT template inline constexpr typename Integral denormalize(FloatingPoint value); #else -template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_unsigned::value, Integral>::type denormalize(FloatingPoint value) { - return value*std::numeric_limits::max(); -} -template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_signed::value, Integral>::type denormalize(FloatingPoint value) { +template inline constexpr typename std::enable_if::value && std::is_integral::value, Integral>::type denormalize(FloatingPoint value) { return value*std::numeric_limits::max(); } #endif From ee5f8766af944355b7e3b43c59aa9454f9ff49b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 16 Jan 2013 21:53:14 +0100 Subject: [PATCH 175/567] Math: make type traits aware of long double. --- src/Math/MathTypeTraits.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 385fc8a0e..4ef7c2a4d 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -32,6 +32,14 @@ #define DOUBLE_EQUALITY_PRECISION 1.0e-12 #endif +/** +@brief Precision when testing long doubles for equality +@todo some proper value please +*/ +#ifndef LONG_DOUBLE_EQUALITY_PRECISION +#define LONG_DOUBLE_EQUALITY_PRECISION 1.0e-18 +#endif + namespace Magnum { namespace Math { /** @@ -152,6 +160,11 @@ template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloating inline constexpr static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { + typedef long double FloatingPointType; + + inline constexpr static long double epsilon() { return LONG_DOUBLE_EQUALITY_PRECISION; } +}; #endif }} From 4d6d3fde8824829a0d5c7cc27dbd9113fd78cf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 00:18:55 +0100 Subject: [PATCH 176/567] Math: scalar/vector implementation of min(), max() and clamp(). This is gonna be some ugly template hell. --- src/Math/Functions.h | 74 +++++++++++++++++++++++++++++++-- src/Math/Test/FunctionsTest.cpp | 39 +++++++++++++---- 2 files changed, 100 insertions(+), 13 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index c80fd1eab..ad9066195 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -20,6 +20,8 @@ #include #include +#include "Math/Vector.h" + #include "magnumVisibility.h" /** @file @@ -78,6 +80,73 @@ std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number); */ std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number); +/** +@{ @name Scalar/vector functions + +These functions are overloaded for both scalar and vector types. Scalar +versions function exactly as their possible STL equivalents, vector overloads +perform the operations component-wise. +*/ + +/** +@brief Minimum + +@see min(), clamp() +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T min(T a, T b); +#else +template inline typename std::enable_if::value, T>::type min(T a, T b) { + return std::min(a, b); +} +template inline Vector min(const Vector& a, const Vector& b) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::min(a[i], b[i]); + return out; +} +#endif + +/** +@brief Maximum + +@see max(), clamp() +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T max(const T& a, const T& b); +#else +template inline typename std::enable_if::value, T>::type max(T a, T b) { + return std::max(a, b); +} +template Vector max(const Vector& a, const Vector& b) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::max(a[i], b[i]); + return out; +} +#endif + +/** +@brief Clamp value + +Values smaller than @p min are set to @p min, values larger than @p max are +set to @p max. +@see min(), max() +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T clamp(const T& value, U min, U max); +#else +template inline typename std::enable_if::value, T>::type clamp(T value, T min, T max) { + return std::min(std::max(value, min), max); +} +template Vector clamp(const Vector& value, T min, T max) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::min(std::max(value[i], min), max); + return out; +} +#endif + /** @brief Normalize integral value @@ -134,10 +203,7 @@ template inline constexpr typename std::ena } #endif -/** @brief Clamp value */ -template inline T clamp(T value, T min, T max) { - return std::min(std::max(value, min), max); -} +/*@}*/ }} diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 9b55ae7e2..eff4ff119 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -16,6 +16,7 @@ #include #include "Math/Functions.h" +#include "Math/Vector3.h" namespace Magnum { namespace Math { namespace Test { @@ -23,31 +24,57 @@ class FunctionsTest: public Corrade::TestSuite::Tester { public: FunctionsTest(); + void min(); + void max(); + void clamp(); void normalizeUnsigned(); void normalizeSigned(); void denormalizeUnsigned(); void denormalizeSigned(); void renormalizeUnsinged(); void renormalizeSinged(); - void clamp(); + void pow(); void log(); void log2(); }; +typedef Math::Vector3 Vector3; +typedef Math::Vector3 Vector3i; + FunctionsTest::FunctionsTest() { - addTests(&FunctionsTest::normalizeUnsigned, + addTests(&FunctionsTest::min, + &FunctionsTest::max, + &FunctionsTest::clamp, + &FunctionsTest::normalizeUnsigned, &FunctionsTest::normalizeSigned, &FunctionsTest::denormalizeUnsigned, &FunctionsTest::denormalizeSigned, &FunctionsTest::renormalizeUnsinged, &FunctionsTest::renormalizeSinged, - &FunctionsTest::clamp, &FunctionsTest::pow, &FunctionsTest::log, &FunctionsTest::log2); } +void FunctionsTest::min() { + CORRADE_COMPARE(Math::min(5, 9), 5); + CORRADE_COMPARE(Math::min(Vector3i(5, -3, 2), Vector3i(9, -5, 18)), Vector3i(5, -5, 2)); +} + +void FunctionsTest::max() { + CORRADE_COMPARE(Math::max(5, 9), 9); + CORRADE_COMPARE(Math::max(Vector3i(5, -3, 2), Vector3i(9, -5, 18)), Vector3i(9, -3, 18)); +} + +void FunctionsTest::clamp() { + CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); + CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); + CORRADE_COMPARE(Math::clamp(9.5f, -1.0f, 5.0f), 5.0f); + + CORRADE_COMPARE(Math::clamp(Vector3(0.5f, -1.6f, 9.5f), -1.0f, 5.0f), Vector3(0.5f, -1.0f, 5.0f)); +} + void FunctionsTest::normalizeUnsigned() { CORRADE_COMPARE((Math::normalize(0)), 0.0f); CORRADE_COMPARE((Math::normalize(255)), 1.0f); @@ -156,12 +183,6 @@ void FunctionsTest::renormalizeSinged() { CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); } -void FunctionsTest::clamp() { - CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); - CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); - CORRADE_COMPARE(Math::clamp(9.5f, -1.0f, 5.0f), 5.0f); -} - void FunctionsTest::pow() { CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); From ad9a55a86726417ed789325fcd15c3dc654deae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 00:25:34 +0100 Subject: [PATCH 177/567] Doc++ --- src/Math/Constants.h | 14 +++++++------- src/Math/Functions.h | 10 +--------- src/MeshTools/CombineIndexedArrays.h | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 5e8e70e9b..d3c2a88cc 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -71,16 +71,16 @@ Usable for entering e.g. rotation: Matrix4::rotation(deg(30.0f), Vector3::yAxis()); @endcode -This function (and also rad()) is available also in Magnum namespace itself. -@see Constants, rad() - */ +@see Magnum::deg(), Constants, rad() +*/ template inline constexpr T deg(T value) { return value*Constants::pi()/180; } /** - * @brief Angle in radians - * - * See deg() for more information. - */ +@brief Angle in radians + +See deg() for more information. +@see Magnum::rad() +*/ template inline constexpr T rad(T value) { return value; } }} diff --git a/src/Math/Functions.h b/src/Math/Functions.h index ad9066195..3f26865e3 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -30,14 +30,6 @@ namespace Magnum { namespace Math { -/** -@todo Vector/scalar overloaded functions (...SIMD): - - min(), max() (component-wise) - - abs() - - sin(), cos()... - - clamp(), lerp() -*/ - #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Pow { @@ -186,7 +178,7 @@ template inline constexpr typename std::ena @brief Denormalize floating-point value Converts floating-point value in range @f$ [0, 1] @f$ to full range of given -unsigned integral type or range @f$ [-1, 1] @f$ to full range of given signed +*unsigned* integral type or range @f$ [-1, 1] @f$ to full range of given *signed* integral type. @note For best precision, `FloatingPoint` type should be always larger that diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 7e4299e60..cb8d0bbd4 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -120,7 +120,7 @@ std::vector indices = MeshTools::combineIndexedArrays( `positions`, `normals` and `textureCoordinates` will then contain combined attributes indexed with `indices`. -The function expects that all arrays have the same size. +@attention The function expects that all arrays have the same size. */ /* Implementation note: It's done using tuples because it is more clear which parameter is index array and which is attribute array, mainly when both are From ec23a3d13cf150820c1f4f6cf0caf3141f3b0351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 00:43:50 +0100 Subject: [PATCH 178/567] Minor code cleanup. --- src/Math/Functions.h | 1 - src/Math/MathTypeTraits.h | 40 +++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index 3f26865e3..c22d70c10 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -18,7 +18,6 @@ #include #include #include -#include #include "Math/Vector.h" diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 4ef7c2a4d..29ca45e00 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -100,26 +100,18 @@ template struct MathTypeTraits { */ #ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - -template struct MathTypeTraitsIntegral { - MathTypeTraitsIntegral() = delete; - inline constexpr static T epsilon() { return 1; } - - inline constexpr static bool equals(T a, T b) { - return a == b; - } -}; - -template struct MathTypeTraitsFloatingPoint { - MathTypeTraitsFloatingPoint() = delete; +/* Integral scalar types */ +namespace Implementation { + template struct MathTypeTraitsIntegral { + MathTypeTraitsIntegral() = delete; - inline static bool equals(T a, T b) { - return std::abs(a - b) < MathTypeTraits::epsilon(); - } -}; + inline constexpr static T epsilon() { return 1; } + inline constexpr static bool equals(T a, T b) { + return a == b; + } + }; } template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { @@ -128,21 +120,18 @@ template<> struct MathTypeTraits: Implementation::MathTypeTraitsIn template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef float FloatingPointType; }; - template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef float FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef float FloatingPointType; }; - template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef double FloatingPointType; }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef double FloatingPointType; }; - template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef long double FloatingPointType; }; @@ -150,6 +139,17 @@ template<> struct MathTypeTraits: Implementation::MathTypeTraitsIn typedef long double FloatingPointType; }; +/* Floating-point scalar types */ +namespace Implementation { + template struct MathTypeTraitsFloatingPoint { + MathTypeTraitsFloatingPoint() = delete; + + inline static bool equals(T a, T b) { + return std::abs(a - b) < MathTypeTraits::epsilon(); + } + }; +} + template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { typedef float FloatingPointType; From 263d8351b6bf2112e66ce3ea330546bd7032eb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 00:47:21 +0100 Subject: [PATCH 179/567] Math: vector overloads for normalize() and denormalize(). --- src/Math/Functions.h | 45 +++++++++++++++++++++++++-------- src/Math/Test/FunctionsTest.cpp | 10 ++++++++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index c22d70c10..e4416e90d 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -144,9 +144,9 @@ template Vector clamp(const Vector& Converts integral value from full range of given *unsigned* integral type to value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$. -@note For best precision, `FloatingPoint` type should be always larger that - resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` - to `std::int64_t`). +@note For best precision, resulting `FloatingPoint` type should be always + larger that `Integral` type (e.g. `double` from `std::int32_t`, `long double` + from `std::int64_t` and similarly for vector types). @attention To ensure the integral type is correctly detected when using literals, this function should be called with both template parameters @@ -162,14 +162,27 @@ float b = normalize('\127'); @see denormalize() */ #ifdef DOXYGEN_GENERATING_OUTPUT -template inline constexpr FloatingPoint normalize(Integral value); +template inline FloatingPoint normalize(const Integral& value); #else -template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_unsigned::value, FloatingPoint>::type normalize(Integral value) { +template inline typename std::enable_if::value && std::is_unsigned::value, FloatingPoint>::type normalize(Integral value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "Math::normalize(): normalization must be done from integral to floating-point type"); return value/FloatingPoint(std::numeric_limits::max()); } - -template inline constexpr typename std::enable_if::value && std::is_integral::value && std::is_signed::value, FloatingPoint>::type normalize(Integral value) { - return std::max(value/FloatingPoint(std::numeric_limits::max()), FloatingPoint(-1)); +template inline typename std::enable_if::value && std::is_signed::value, FloatingPoint>::type normalize(Integral value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "Math::normalize(): normalization must be done from integral to floating-point type"); + return Math::max(value/FloatingPoint(std::numeric_limits::max()), FloatingPoint(-1)); +} +template inline typename std::enable_if::value, FloatingPoint>::type normalize(const Integral& value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "Math::normalize(): normalization must be done from integral to floating-point type"); + return FloatingPoint::from(value)/typename FloatingPoint::Type(std::numeric_limits::max()); +} +template inline typename std::enable_if::value, FloatingPoint>::type normalize(const Integral& value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "Math::normalize(): normalization must be done from integral to floating-point type"); + return Math::max(FloatingPoint::from(value)/typename FloatingPoint::Type(std::numeric_limits::max()), FloatingPoint(-1)); } #endif @@ -182,16 +195,26 @@ integral type. @note For best precision, `FloatingPoint` type should be always larger that resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` - to `std::int64_t`). + to `std::int64_t` and similarly for vector types). + +@attention Return value for floating point numbers outside the normalized + range is undefined. @see normalize() */ #ifdef DOXYGEN_GENERATING_OUTPUT -template inline constexpr typename Integral denormalize(FloatingPoint value); +template inline Integral denormalize(const FloatingPoint& value); #else -template inline constexpr typename std::enable_if::value && std::is_integral::value, Integral>::type denormalize(FloatingPoint value) { +template inline typename std::enable_if::value, Integral>::type denormalize(FloatingPoint value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "Math::denormalize(): denormalization must be done from floating-point to integral type"); return value*std::numeric_limits::max(); } +template inline typename std::enable_if::value, Integral>::type denormalize(const FloatingPoint& value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "Math::denormalize(): denormalization must be done from floating-point to integral type"); + return Integral::from(value*std::numeric_limits::max()); +} #endif /*@}*/ diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index eff4ff119..f71362c65 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -40,6 +40,8 @@ class FunctionsTest: public Corrade::TestSuite::Tester { }; typedef Math::Vector3 Vector3; +typedef Math::Vector3 Vector3ub; +typedef Math::Vector3 Vector3b; typedef Math::Vector3 Vector3i; FunctionsTest::FunctionsTest() { @@ -90,6 +92,8 @@ void FunctionsTest::normalizeUnsigned() { CORRADE_COMPARE((Math::normalize(8192)), 0.125002f); CORRADE_COMPARE((Math::normalize(49152)), 0.750011f); + + CORRADE_COMPARE(Math::normalize(Vector3ub(0, 127, 255)), Vector3(0.0f, 0.498039f, 1.0f)); } void FunctionsTest::normalizeSigned() { @@ -111,6 +115,8 @@ void FunctionsTest::normalizeSigned() { CORRADE_COMPARE((Math::normalize(16384)), 0.500015f); CORRADE_COMPARE((Math::normalize(-16384)), -0.500015f); + + CORRADE_COMPARE(Math::normalize(Vector3b(0, -127, 64)), Vector3(0.0f, -1.0f, 0.503937f)); } void FunctionsTest::denormalizeUnsigned() { @@ -128,6 +134,8 @@ void FunctionsTest::denormalizeUnsigned() { CORRADE_COMPARE(Math::denormalize(0.33f), 21626); CORRADE_COMPARE(Math::denormalize(0.66f), 43253); + + CORRADE_COMPARE(Math::denormalize(Vector3(0.0f, 0.5f, 1.0f)), Vector3ub(0, 127, 255)); } void FunctionsTest::denormalizeSigned() { @@ -149,6 +157,8 @@ void FunctionsTest::denormalizeSigned() { CORRADE_COMPARE(Math::denormalize(-0.33f), -10813); CORRADE_COMPARE(Math::denormalize(0.66f), 21626); + + CORRADE_COMPARE(Math::denormalize(Vector3(0.0f, -1.0f, 0.5f)), Vector3b(0, -127, 63)); } void FunctionsTest::renormalizeUnsinged() { From b13d8644b4fd5861403f9d56a762889b80a6515f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 00:58:28 +0100 Subject: [PATCH 180/567] Replaced scalar normalization code in Color with Math::[de]normalize(). --- src/Color.h | 55 +++--------------------------------------- src/Test/ColorTest.cpp | 14 ----------- 2 files changed, 4 insertions(+), 65 deletions(-) diff --git a/src/Color.h b/src/Color.h index 5a230794a..27e651984 100644 --- a/src/Color.h +++ b/src/Color.h @@ -58,7 +58,7 @@ template inline typename std::enable_if::valu } } template inline typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { - return Color3::fromNormalized(fromHSV::FloatingPointType>(hsv)); + return Math::denormalize>(fromHSV::FloatingPointType>(hsv)); } /* Internal hue computing function */ @@ -95,10 +95,10 @@ template inline T value(typename std::enable_if inline typename Color3::FloatingPointType hue(typename std::enable_if::value, const Color3&>::type color) { - return hue::FloatingPointType>(Color3::FloatingPointType>::fromDenormalized(color)); + return hue::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { - return saturation::FloatingPointType>(Color3::FloatingPointType>::fromDenormalized(color)); + return saturation::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType value(typename std::enable_if::value, const Color3&>::type color) { return Math::normalize::FloatingPointType>(color.max()); @@ -112,7 +112,7 @@ template inline typename Color3::HSV toHSV(typename std::enable_if::HSV(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); } template inline typename Color3::HSV toHSV(typename std::enable_if::value, const Color3&>::type color) { - return toHSV::FloatingPointType>(Color3::FloatingPointType>::fromDenormalized(color)); + return toHSV::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } /* Default alpha value */ @@ -140,7 +140,6 @@ range @f$ [0.0, 1.0] @f$. @see Color4 @todo Hue in degrees so users can use deg() -@todo Signed normalization to [-1.0, 1.0] like in OpenGL? */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ @@ -162,36 +161,6 @@ class Color3: public Math::Vector3 { */ typedef std::tuple HSV; - /** - * @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 `std::uint8_t`. - * - * @note This function is enabled only if source type is floating-point - * and destination type is integral. - */ - template inline constexpr static typename std::enable_if::value && std::is_floating_point::value, Color3>::type fromNormalized(const Color3& color) { - return Color3(Math::denormalize(color.r()), - Math::denormalize(color.g()), - Math::denormalize(color.b())); - } - - /** - * @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 `std::uint8_t`. - * - * @note This function is enabled only if source type is integral - * and destination type is floating-point. - */ - template inline constexpr static typename std::enable_if::value && std::is_integral::value, Color3>::type fromDenormalized(const Color3& color) { - return Color3(Math::normalize(color.r()), - Math::normalize(color.g()), - Math::normalize(color.b())); - } - /** * @brief Create RGB color from HSV representation * @param hsv Hue, saturation and value @@ -308,22 +277,6 @@ class Color4: public Math::Vector4 { /** @copydoc Color3::HSV */ typedef typename Color3::HSV HSV; - /** @copydoc Color3::fromNormalized() */ - template inline constexpr static typename std::enable_if::value && std::is_floating_point::value, Color4>::type fromNormalized(const Color4& color) { - return Color4(Math::denormalize(color.r()), - Math::denormalize(color.g()), - Math::denormalize(color.b()), - Math::denormalize(color.a())); - } - - /** @copydoc Color3::fromDenormalized() */ - template inline constexpr static typename std::enable_if::value && std::is_integral::value, Color4>::type fromDenormalized(const Color4& color) { - return Color4(Math::normalize(color.r()), - Math::normalize(color.g()), - Math::normalize(color.b()), - Math::normalize(color.a())); - } - /** * @copydoc Color3::fromHSV() * @param a Alpha value, defaults to 1.0 for floating-point types diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index fd6aca832..959bc7144 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -29,9 +29,6 @@ class ColorTest: public Corrade::TestSuite::Tester { void access(); - void fromDenormalized(); - void fromNormalized(); - void fromHue(); void fromSaturation(); void fromValue(); @@ -56,9 +53,6 @@ typedef Magnum::Color4 Color4f; ColorTest::ColorTest() { addTests(&ColorTest::access, - &ColorTest::fromDenormalized, - &ColorTest::fromNormalized, - &ColorTest::fromHue, &ColorTest::fromSaturation, &ColorTest::fromValue, @@ -99,14 +93,6 @@ void ColorTest::access() { CORRADE_COMPARE(cc4.a(), 22); } -void ColorTest::fromDenormalized() { - CORRADE_COMPARE(Color3f::fromDenormalized(Color3(75, 115, 224)), Color3f(0.294118, 0.45098, 0.878431)); -} - -void ColorTest::fromNormalized() { - CORRADE_COMPARE(Color3::fromNormalized(Color3f(0.294118, 0.45098, 0.878431)), Color3(75, 114, 223)); -} - void ColorTest::fromHue() { CORRADE_COMPARE(Color3::fromHSV(27.0f, 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3::fromHSV(86.0f, 1.0f, 1.0f), Color3(144, 255, 0)); From fbeb7b02bc5d1d9d67c695effafafb9619ed549e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 12:47:56 +0100 Subject: [PATCH 181/567] Minor renaming in shader/mesh guts. Function size() will be used later for commputing size of the attribute, renaming the original to components(). --- src/AbstractShaderProgram.h | 28 ++++++++++++++-------------- src/Mesh.h | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 2c78f8b17..007472f41 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1093,24 +1093,24 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::Float; - inline constexpr static GLint size(DataOptions) { return 1; } + inline constexpr static GLint components(DataOptions) { return 1; } inline constexpr static std::size_t vectorCount() { return 1; } }; CORRADE_ENUMSET_OPERATORS(Attribute::DataOptions) template struct Attribute>: public Attribute { - inline constexpr static GLint size(DataOptions) { return vectorSize; } + inline constexpr static GLint components(DataOptions) { return vectorSize; } inline constexpr static std::size_t vectorCount() { return 1; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size(DataOptions) { return rows; } + inline constexpr static GLint components(DataOptions) { return rows; } inline constexpr static std::size_t vectorCount() { return cols; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size(DataOptions) { return matrixSize; } + inline constexpr static GLint components(DataOptions) { return matrixSize; } inline constexpr static std::size_t vectorCount() { return matrixSize; } }; @@ -1153,11 +1153,11 @@ template<> struct Attribute> { static const DataType DefaultDataType = DataType::Float; #ifndef MAGNUM_TARGET_GLES - inline constexpr static GLint size(DataOptions options) { + inline constexpr static GLint components(DataOptions options) { return options & DataOption::BGRA ? GL_BGRA : 4; } #else - inline constexpr static GLint size(DataOptions) { return 4; } + inline constexpr static GLint components(DataOptions) { return 4; } #endif inline constexpr static std::size_t vectorCount() { return 1; } @@ -1182,7 +1182,7 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::Int; - inline constexpr static GLint size() { return 1; } + inline constexpr static GLint components() { return 1; } }; template<> struct Attribute { @@ -1193,15 +1193,15 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::UnsignedInt; - inline constexpr static GLint size() { return 1; } + inline constexpr static GLint components() { return 1; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size() { return size; } + inline constexpr static GLint components() { return size; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size() { return size; } + inline constexpr static GLint components() { return size; } }; #ifndef MAGNUM_TARGET_GLES @@ -1216,22 +1216,22 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::Double; - inline constexpr static GLint size() { return 1; } + inline constexpr static GLint components() { return 1; } inline constexpr static std::size_t vectorCount() { return 1; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size() { return rows; } + inline constexpr static GLint components() { return rows; } inline constexpr static std::size_t vectorCount() { return cols; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size() { return size; } + inline constexpr static GLint components() { return size; } inline constexpr static std::size_t vectorCount() { return size; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint size() { return size; } + inline constexpr static GLint components() { return size; } inline constexpr static std::size_t vectorCount() { return size; } }; #endif diff --git a/src/Mesh.h b/src/Mesh.h index 9d88de758..6c684e661 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -632,7 +632,7 @@ class MAGNUM_EXPORT Mesh { attributes.push_back({ buffer, location+i, - Implementation::Attribute::size(attribute.dataOptions()), + Implementation::Attribute::components(attribute.dataOptions()), static_cast(attribute.dataType()), !!(attribute.dataOptions() & AbstractShaderProgram::Attribute::DataOption::Normalized), offset, @@ -648,7 +648,7 @@ class MAGNUM_EXPORT Mesh { integerAttributes.push_back({ buffer, location, - Implementation::Attribute::size(), + Implementation::Attribute::components(), static_cast(attribute.dataType()), offset, stride @@ -663,7 +663,7 @@ class MAGNUM_EXPORT Mesh { longAttributes.push_back({ buffer, location+i, - Implementation::Attribute::size(), + Implementation::Attribute::components(), static_cast(attribute.dataType()), offset, stride From f4146bea94acf87102c78870b2c7c41fc09a4071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 13:16:36 +0100 Subject: [PATCH 182/567] Forgot to rename this to match OpenGL name. It was named this way in the docs, but in the actual code not. Don't know why. --- src/AbstractShaderProgram.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 007472f41..fa07f9df0 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1134,8 +1134,8 @@ template<> struct Attribute> { #endif #ifndef MAGNUM_TARGET_GLES2 , - UnsignedAlpha2RGB10 = GL_UNSIGNED_INT_2_10_10_10_REV, - Alpha2RGB10 = GL_INT_2_10_10_10_REV + UnsignedInt2101010REV = GL_UNSIGNED_INT_2_10_10_10_REV, + Int2101010REV = GL_INT_2_10_10_10_REV #endif }; From a9d25c995f284239ace079603ac3c44bc2b45ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 13:49:07 +0100 Subject: [PATCH 183/567] Mesh: fixed attribute stride computation. The stride was computed always for resulting GLSL type (e.g. vec4) even if the data were of anoother type (e.g. std::uint8_t[4]). The code is exceptionally ugly now, time to wrap it with unit tests. --- src/AbstractShaderProgram.cpp | 81 +++++++++++++++++++++++++++++++++++ src/AbstractShaderProgram.h | 22 +++++++--- src/Mesh.h | 8 ++-- 3 files changed, 102 insertions(+), 9 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 7fe59d747..f16b5b31f 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -568,4 +568,85 @@ void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math: } #endif +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +std::size_t Attribute::size(GLint components, DataType dataType) { + switch(dataType) { + case DataType::UnsignedByte: + case DataType::Byte: + return components; + case DataType::UnsignedShort: + case DataType::Short: + case DataType::HalfFloat: + return 2*components; + case DataType::UnsignedInt: + case DataType::Int: + case DataType::Float: + return 4*components; + case DataType::Double: + return 8*components; + } + + CORRADE_INTERNAL_ASSERT(false); + return 0; +} + +std::size_t Attribute::size(GLint components, DataType dataType) { + switch(dataType) { + case DataType::UnsignedByte: + case DataType::Byte: + return components; + case DataType::UnsignedShort: + case DataType::Short: + return 2*components; + case DataType::UnsignedInt: + case DataType::Int: + return 4*components; + } + + CORRADE_INTERNAL_ASSERT(false); + return 0; +} + + +std::size_t Attribute::size(GLint components, DataType dataType) { + switch(dataType) { + case DataType::Double: + return 8*components; + } + + CORRADE_INTERNAL_ASSERT(false); + return 0; +} + +std::size_t Attribute>::size(GLint components, DataType dataType) { + switch(dataType) { + case DataType::UnsignedByte: + case DataType::Byte: + return components; + case DataType::UnsignedShort: + case DataType::Short: + case DataType::HalfFloat: + return 2*components; + case DataType::UnsignedInt: + case DataType::Int: + case DataType::Float: + return 4*components; + case DataType::Double: + return 8*components; + + case DataType::UnsignedInt2101010REV: + case DataType::Int2101010REV: + CORRADE_INTERNAL_ASSERT(components == 4); + return 4; + } + + CORRADE_INTERNAL_ASSERT(false); + return 0; +} + +} +#endif + } diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index fa07f9df0..6ba5e4866 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -436,6 +436,11 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** @brief Type of passed data */ inline constexpr DataType dataType() const { return _dataType; } + /** @brief Size of passed data */ + inline std::size_t dataSize() const { + return Implementation::Attribute::size(Implementation::Attribute::components(), _dataType); + } + /** @brief Data options */ inline constexpr DataOptions dataOptions() const { return _dataOptions; } @@ -1093,24 +1098,25 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::Float; - inline constexpr static GLint components(DataOptions) { return 1; } + inline constexpr static GLint components(DataOptions = {}) { return 1; } + static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); inline constexpr static std::size_t vectorCount() { return 1; } }; CORRADE_ENUMSET_OPERATORS(Attribute::DataOptions) template struct Attribute>: public Attribute { - inline constexpr static GLint components(DataOptions) { return vectorSize; } + inline constexpr static GLint components(DataOptions = {}) { return vectorSize; } inline constexpr static std::size_t vectorCount() { return 1; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint components(DataOptions) { return rows; } + inline constexpr static GLint components(DataOptions = {}) { return rows; } inline constexpr static std::size_t vectorCount() { return cols; } }; template struct Attribute>: public Attribute { - inline constexpr static GLint components(DataOptions) { return matrixSize; } + inline constexpr static GLint components(DataOptions = {}) { return matrixSize; } inline constexpr static std::size_t vectorCount() { return matrixSize; } }; @@ -1153,13 +1159,14 @@ template<> struct Attribute> { static const DataType DefaultDataType = DataType::Float; #ifndef MAGNUM_TARGET_GLES - inline constexpr static GLint components(DataOptions options) { + inline constexpr static GLint components(DataOptions options = {}) { return options & DataOption::BGRA ? GL_BGRA : 4; } #else inline constexpr static GLint components(DataOptions) { return 4; } #endif + static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); inline constexpr static std::size_t vectorCount() { return 1; } }; @@ -1183,6 +1190,7 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::Int; inline constexpr static GLint components() { return 1; } + static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; template<> struct Attribute { @@ -1194,6 +1202,9 @@ template<> struct Attribute { static const DataType DefaultDataType = DataType::UnsignedInt; inline constexpr static GLint components() { return 1; } + inline static std::size_t size(GLint components, DataType dataType) { + return Attribute::size(components, dataType); + } }; template struct Attribute>: public Attribute { @@ -1218,6 +1229,7 @@ template<> struct Attribute { inline constexpr static GLint components() { return 1; } inline constexpr static std::size_t vectorCount() { return 1; } + static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; template struct Attribute>: public Attribute { diff --git a/src/Mesh.h b/src/Mesh.h index 6c684e661..778ed86cf 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -597,7 +597,7 @@ class MAGNUM_EXPORT Mesh { addVertexAttribute(buffer, attribute, offset, 0); /* Add size of this attribute array to offset for next attribute */ - addVertexBufferInternal(buffer, offset+TypeTraits::count()*TypeTraits::size()*_vertexCount, attributes...); + addVertexBufferInternal(buffer, offset+attribute.dataSize()*_vertexCount, attributes...); } template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, GLintptr gap, const T&... attributes) { /* Add the gap to offset for next attribute */ @@ -606,8 +606,8 @@ class MAGNUM_EXPORT Mesh { inline void addVertexBufferInternal(Buffer*, GLintptr) {} /* Computing stride of interleaved vertex attributes */ - template inline static GLsizei strideOfInterleaved(const AbstractShaderProgram::Attribute&, const U&... attributes) { - return TypeTraits::count()*TypeTraits::size() + strideOfInterleaved(attributes...); + template inline static GLsizei strideOfInterleaved(const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { + return attribute.dataSize() + strideOfInterleaved(attributes...); } template inline static GLsizei strideOfInterleaved(GLintptr gap, const T&... attributes) { return gap + strideOfInterleaved(attributes...); @@ -619,7 +619,7 @@ class MAGNUM_EXPORT Mesh { addVertexAttribute(buffer, attribute, offset, stride); /* Add size of this attribute to offset for next attribute */ - addInterleavedVertexBufferInternal(buffer, offset+TypeTraits::count()*TypeTraits::size(), stride, attributes...); + addInterleavedVertexBufferInternal(buffer, offset+attribute.dataSize(), stride, attributes...); } template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, GLintptr gap, const T&... attributes) { /* Add the gap to offset for next attribute */ From 976377f0a4009f33654eb468c98c631a01be1230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 14:20:38 +0100 Subject: [PATCH 184/567] Moved code to check allowed attribute types to internal implementation. TypeTraits class is now not needed at all. --- src/AbstractShaderProgram.h | 57 +++++++++++++++++++++++++++++++++++-- src/Mesh.h | 8 +++--- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 6ba5e4866..cb16c0b2a 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -23,7 +23,6 @@ #include #include "Magnum.h" -#include "TypeTraits.h" #include "magnumVisibility.h" @@ -34,6 +33,7 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Attribute; + template struct AttributeTraits; } #endif @@ -266,7 +266,7 @@ mesh.draw(); Only types listed here (and their subclasses and specializations, such as @ref Matrix3 or Color4) can be used for setting uniforms and specifying -vertex attributes. See also TypeTraits::AttributeType. +vertex attributes. @section AbstractShaderProgram-performance-optimization Performance optimizations @@ -329,7 +329,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Type used in shader code. * @see DataType */ - typedef typename TypeTraits::AttributeType Type; + typedef typename Implementation::AttributeTraits::AttributeType Type; /** * @brief Data type @@ -1261,6 +1261,57 @@ template struct Attribute>: public Attribute template struct Attribute>: public Attribute> {}; template struct Attribute>: public Attribute> {}; +/* Types allowed as GLSL attributes */ +template<> struct AttributeTraits { typedef GLuint AttributeType; }; +template<> struct AttributeTraits { typedef GLint AttributeType; }; +template<> struct AttributeTraits { typedef GLfloat AttributeType; }; +#ifndef MAGNUM_TARGET_GLES +template<> struct AttributeTraits { typedef GLdouble AttributeType; }; +#endif + +/* Only some vectors can be used as attributes */ +template struct VectorAttributeTraits {}; +template<> struct VectorAttributeTraits { typedef GLuint AttributeType; }; +template<> struct VectorAttributeTraits { typedef GLint AttributeType; }; +template<> struct VectorAttributeTraits { typedef GLfloat AttributeType; }; +#ifndef MAGNUM_TARGET_GLES +template<> struct VectorAttributeTraits { typedef GLdouble AttributeType; }; +#endif + +template struct AttributeTraits>: VectorAttributeTraits {}; +template struct AttributeTraits>: VectorAttributeTraits {}; +template struct AttributeTraits>: VectorAttributeTraits {}; + +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; +template struct AttributeTraits>: AttributeTraits> {}; + +/* Only some floating-point matrices can be used as attributes */ +template struct MatrixAttributeTraits {}; +template<> struct MatrixAttributeTraits { typedef GLfloat AttributeType; }; +#ifndef MAGNUM_TARGET_GLES +template<> struct MatrixAttributeTraits { typedef GLdouble AttributeType; }; +#endif + +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +#ifndef MAGNUM_TARGET_GLES2 +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; +#endif + +template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct AttributeTraits>: MatrixAttributeTraits {}; + } #endif diff --git a/src/Mesh.h b/src/Mesh.h index 778ed86cf..5018fa63c 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -21,9 +21,9 @@ #include #include +#include #include "AbstractShaderProgram.h" -#include "TypeTraits.h" namespace Magnum { @@ -627,7 +627,7 @@ class MAGNUM_EXPORT Mesh { } inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} - template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { attributes.push_back({ buffer, @@ -644,7 +644,7 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES2 - template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { integerAttributes.push_back({ buffer, location, @@ -658,7 +658,7 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES - template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { longAttributes.push_back({ buffer, From 9ffb8081f3249c8d9be152b574c74e8642a22c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 14:23:44 +0100 Subject: [PATCH 185/567] Got rid of TypeTraits class altogether. --- src/AbstractImage.cpp | 2 - src/AbstractShaderProgram.cpp | 15 ++ src/CMakeLists.txt | 2 - src/MeshTools/Clean.h | 5 +- .../Test/CombineIndexedArraysTest.cpp | 1 + src/MeshTools/Test/SubdivideTest.cpp | 1 + src/TypeTraits.cpp | 36 --- src/TypeTraits.h | 213 ------------------ 8 files changed, 19 insertions(+), 256 deletions(-) delete mode 100644 src/TypeTraits.cpp delete mode 100644 src/TypeTraits.h diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 97599c3de..19ffdc1f4 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -17,8 +17,6 @@ #include -#include "TypeTraits.h" - namespace Magnum { std::size_t AbstractImage::pixelSize(Format format, Type type) { diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index f16b5b31f..854e86fea 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -16,6 +16,7 @@ #include "AbstractShaderProgram.h" #include +#include #include "Math/Matrix.h" #include "Shader.h" @@ -27,6 +28,20 @@ namespace Magnum { +#ifndef DOXYGEN_GENERATING_OUTPUT +static_assert(std::is_same::value, "GLubyte is not the same as std::uint8_t"); +static_assert(std::is_same::value, "GLbyte is not the same as std::int8_t"); +static_assert(std::is_same::value, "GLushort is not the same as std::uint16_t"); +static_assert(std::is_same::value, "GLshort is not the same as std::int16_t"); +static_assert(std::is_same::value, "GLuint is not the same as std::uint32_t"); +static_assert(std::is_same::value, "GLint is not the same as std::int32_t"); +static_assert(std::is_same::value, "GLsizei is not the same as std::int32_t"); +static_assert(std::is_same::value, "GLfloat is not the same as float"); +#ifndef MAGNUM_TARGET_GLES +static_assert(std::is_same::value, "GLdouble is not the same as double"); +#endif +#endif + AbstractShaderProgram::Uniform1fImplementation AbstractShaderProgram::uniform1fImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform2fvImplementation AbstractShaderProgram::uniform2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform3fvImplementation AbstractShaderProgram::uniform3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a54f7e638..5c74e2888 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,6 @@ set(Magnum_SRCS Resource.cpp Shader.cpp Timeline.cpp - TypeTraits.cpp Implementation/BufferState.cpp Implementation/State.cpp @@ -79,7 +78,6 @@ set(Magnum_HEADERS Swizzle.h Texture.h Timeline.h - TypeTraits.h magnumVisibility.h) diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 26583743c..60c940282 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -24,7 +24,6 @@ #include #include "Math/Vector.h" -#include "TypeTraits.h" namespace Magnum { namespace MeshTools { @@ -35,7 +34,7 @@ template class Clean { public: inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} - void operator()(typename Vertex::Type epsilon = TypeTraits::epsilon()) { + void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { if(indices.empty()) return; /* Get mesh bounds */ @@ -137,7 +136,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = TypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index 1758d5856..ade28f47c 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -16,6 +16,7 @@ #include #include +#include "Magnum.h" #include "MeshTools/CombineIndexedArrays.h" namespace Magnum { namespace MeshTools { namespace Test { diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 4bd09edd9..8409f2a59 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -16,6 +16,7 @@ #include #include +#include "Magnum.h" #include "MeshTools/Clean.h" #include "MeshTools/Subdivide.h" diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp deleted file mode 100644 index d8312a764..000000000 --- a/src/TypeTraits.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "TypeTraits.h" - -#include - -namespace Magnum { - -#ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(std::is_same::value, "GLubyte is not the same as std::uint8_t"); -static_assert(std::is_same::value, "GLbyte is not the same as std::int8_t"); -static_assert(std::is_same::value, "GLushort is not the same as std::uint16_t"); -static_assert(std::is_same::value, "GLshort is not the same as std::int16_t"); -static_assert(std::is_same::value, "GLuint is not the same as std::uint32_t"); -static_assert(std::is_same::value, "GLint is not the same as std::int32_t"); -static_assert(std::is_same::value, "GLsizei is not the same as std::int32_t"); -static_assert(std::is_same::value, "GLfloat is not the same as float"); -#ifndef MAGNUM_TARGET_GLES -static_assert(std::is_same::value, "GLdouble is not the same as double"); -#endif -#endif - -} diff --git a/src/TypeTraits.h b/src/TypeTraits.h deleted file mode 100644 index 0770db5dd..000000000 --- a/src/TypeTraits.h +++ /dev/null @@ -1,213 +0,0 @@ -#ifndef Magnum_TypeTraits_h -#define Magnum_TypeTraits_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file /TypeTraits.h - * @brief Class Magnum::TypeTraits - */ - -#include - -#include "Math/MathTypeTraits.h" -#include "Magnum.h" - -#include "magnumVisibility.h" - -namespace Magnum { - -/** -@brief Traits class for plain OpenGL types - -@copydetails Math::MathTypeTraits - -Where it makes sense, this class extends Math::MathTypeTraits with -OpenGL-specific traits. -*/ -#ifdef DOXYGEN_GENERATING_OUTPUT -template struct TypeTraits: Math::MathTypeTraits { - /** - * @brief Corresponding type for vertex attributes - * - * Implemented only in types which can be used for vertex attributes. This - * function is not present for types unusable for vertex attributes, like - * five-component vectors or GLdouble in OpenGL ES. See also - * @ref AbstractShaderProgram-types. - */ - typedef U AttributeType; - - /** - * @brief Size of plain OpenGL type - * - * Returns sizeof(GLfloat) for GLfloat, but also sizeof(GLfloat) for - * Vector3. See count(). - */ - inline constexpr static std::size_t size(); - - /** - * @brief Count of plain elements in this type - * - * Returns 1 for plain OpenGL types like GLint, but e.g. 3 for Vector3. - */ - inline constexpr static std::size_t count(); -}; -#else -template struct TypeTraits { - TypeTraits() = delete; -}; -#endif - -#ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct TypeTraits: Math::MathTypeTraits { - /* Can not be used for attributes */ - inline constexpr static std::size_t size() { return sizeof(GLubyte); } - inline constexpr static std::size_t count() { return 1; } -}; - -template<> struct TypeTraits: Math::MathTypeTraits { - /* Can not be used for attributes */ - inline constexpr static std::size_t size() { return sizeof(GLbyte); } - inline constexpr static std::size_t count() { return 1; } -}; - -template<> struct TypeTraits: Math::MathTypeTraits { - /* Can not be used for attributes */ - inline constexpr static std::size_t size() { return sizeof(GLushort); } - inline constexpr static std::size_t count() { return 1; } -}; - -template<> struct TypeTraits: Math::MathTypeTraits { - /* Can not be used for attributes */ - inline constexpr static std::size_t size() { return sizeof(GLshort); } - inline constexpr static std::size_t count() { return 1; } -}; - -template<> struct TypeTraits: Math::MathTypeTraits { - typedef GLuint AttributeType; - inline constexpr static std::size_t size() { return sizeof(GLuint); } - inline constexpr static std::size_t count() { return 1; } -}; - -template<> struct TypeTraits: Math::MathTypeTraits { - typedef GLint AttributeType; - inline constexpr static std::size_t size() { return sizeof(GLint); } - inline constexpr static std::size_t count() { return 1; } -}; - -template<> struct TypeTraits: Math::MathTypeTraits { - typedef GLfloat AttributeType; - inline constexpr static std::size_t size() { return sizeof(GLfloat); } - inline constexpr static std::size_t count() { return 1; } -}; - -#ifndef MAGNUM_TARGET_GLES -template<> struct TypeTraits: Math::MathTypeTraits { - typedef GLdouble AttributeType; - inline constexpr static std::size_t size() { return sizeof(GLdouble); } - inline constexpr static std::size_t count() { return 1; } -}; -#endif - -namespace Implementation { - template struct VectorTypeTraits { - VectorTypeTraits() = delete; - - /* Might be used for attributes, see below */ - inline constexpr static std::size_t size() { return sizeof(T); } - inline constexpr static std::size_t count() { return vectorSize; } - }; - - template struct VectorAttributeType {}; - - template<> struct VectorAttributeType { - typedef GLuint AttributeType; - }; - - template<> struct VectorAttributeType { - typedef GLint AttributeType; - }; - - template<> struct VectorAttributeType { - typedef GLfloat AttributeType; - }; - - #ifndef MAGNUM_TARGET_GLES - template<> struct VectorAttributeType { - typedef GLdouble AttributeType; - }; - #endif -} - -template struct TypeTraits>: Implementation::VectorTypeTraits {}; - -/* Only some vectors can be used as attributes */ -template struct TypeTraits>: Implementation::VectorTypeTraits<1, T>, Implementation::VectorAttributeType {}; -template struct TypeTraits>: Implementation::VectorTypeTraits<2, T>, Implementation::VectorAttributeType {}; -template struct TypeTraits>: Implementation::VectorTypeTraits<3, T>, Implementation::VectorAttributeType {}; -template struct TypeTraits>: Implementation::VectorTypeTraits<4, T>, Implementation::VectorAttributeType {}; - -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; - -namespace Implementation { - template struct MatrixTypeTraits { - MatrixTypeTraits() = delete; - - /* Might be used for attributes, see below */ - inline constexpr static std::size_t size() { return sizeof(T); } - inline constexpr static std::size_t count() { return rows; } - inline constexpr static std::size_t vectors() { return cols; } - }; - - template struct MatrixAttributeType {}; - - template<> struct MatrixAttributeType { - typedef GLfloat AttributeType; - }; - - #ifndef MAGNUM_TARGET_GLES - template<> struct MatrixAttributeType { - typedef GLdouble AttributeType; - }; - #endif -} - -template struct TypeTraits>: Implementation::MatrixTypeTraits {}; - -/* Only some floating-point matrices can be used as attributes */ -template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 2, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 3, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 4, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 3, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 2, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<2, 4, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 2, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<3, 4, T>, Implementation::MatrixAttributeType {}; -template struct TypeTraits>: Implementation::MatrixTypeTraits<4, 3, T>, Implementation::MatrixAttributeType {}; - -template struct TypeTraits>: TypeTraits> {}; - -template struct TypeTraits>: TypeTraits> {}; -template struct TypeTraits>: TypeTraits> {}; -#endif - -} - -#endif From d5a8cc0e3c4b119a7013636defd0a795ecf8f0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 14:59:21 +0100 Subject: [PATCH 186/567] DebugTools: fixed compilation of Profiler. Some change in recent GCC (4.7.2) caused this to fail building, now using duration_cast() instead of microseconds(). Also cleaned up the code by importing std::duration prefix. --- src/DebugTools/Profiler.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/DebugTools/Profiler.cpp b/src/DebugTools/Profiler.cpp index 06f128ae2..00602f9a8 100644 --- a/src/DebugTools/Profiler.cpp +++ b/src/DebugTools/Profiler.cpp @@ -21,6 +21,8 @@ #include "Magnum.h" +using namespace std::chrono; + namespace Magnum { namespace DebugTools { Profiler::Section Profiler::addSection(const std::string& name) { @@ -36,8 +38,8 @@ void Profiler::setMeasureDuration(std::size_t frames) { void Profiler::enable() { enabled = true; - frameData.assign(measureDuration*sections.size(), std::chrono::high_resolution_clock::duration::zero()); - totalData.assign(sections.size(), std::chrono::high_resolution_clock::duration::zero()); + frameData.assign(measureDuration*sections.size(), high_resolution_clock::duration::zero()); + totalData.assign(sections.size(), high_resolution_clock::duration::zero()); frameCount = 0; } @@ -59,14 +61,14 @@ void Profiler::stop() { save(); - previousTime = std::chrono::high_resolution_clock::time_point(); + previousTime = high_resolution_clock::time_point(); } void Profiler::save() { - auto now = std::chrono::high_resolution_clock::now(); + auto now = high_resolution_clock::now(); /* If the profiler is already running, add time to given section */ - if(previousTime != std::chrono::high_resolution_clock::time_point()) + if(previousTime != high_resolution_clock::time_point()) frameData[currentFrame*sections.size()+currentSection] += now-previousTime; /* Set current time as previous for next section */ @@ -86,7 +88,7 @@ void Profiler::nextFrame() { /* Subtract times of next frame from total and erase them */ for(std::size_t i = 0; i != sections.size(); ++i) { totalData[i] -= frameData[nextFrame*sections.size()+i]; - frameData[nextFrame*sections.size()+i] = std::chrono::high_resolution_clock::duration::zero(); + frameData[nextFrame*sections.size()+i] = high_resolution_clock::duration::zero(); } /* Advance to next frame */ @@ -105,7 +107,7 @@ void Profiler::printStatistics() { Debug() << "Statistics for last" << measureDuration << "frames:"; for(std::size_t i = 0; i != sections.size(); ++i) - Debug() << " " << sections[totalSorted[i]] << std::chrono::microseconds(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; + Debug() << " " << sections[totalSorted[i]] << duration_cast(totalData[totalSorted[i]]).count()/frameCount << u8"µs"; } }} From 8d71d12187c9a6ff28793b28d2e092629af14290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 15:15:37 +0100 Subject: [PATCH 187/567] SceneGraph: animationStopped() should be called after duration is exceeded. The test currently fails. --- src/SceneGraph/Test/AnimableTest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index d824ff4ff..600f815d4 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -144,11 +144,20 @@ class OneShotAnimable: public SceneGraph::Animable<3> { } GLfloat time; + std::string stateChanges; protected: void animationStep(GLfloat time, GLfloat) override { this->time = time; } + + void animationStarted() override { + stateChanges += "started;"; + } + + void animationStopped() override { + stateChanges += "stopped;"; + } }; void AnimableTest::step() { @@ -199,12 +208,14 @@ void AnimableTest::duration() { running and animationStep() is called */ group.step(1.0f, 0.5f); CORRADE_COMPARE(animable.state(), AnimationState::Running); + CORRADE_COMPARE(animable.stateChanges, "started;"); CORRADE_COMPARE(animable.time, 0.0f); /* Next animation step is out of duration and repeat is not enabled, animationStep() shouldn't be called and animation should be stopped */ group.step(12.75f, 0.5f); CORRADE_COMPARE(animable.state(), AnimationState::Stopped); + CORRADE_COMPARE(animable.stateChanges, "started;stopped;"); CORRADE_COMPARE(animable.time, 0.0f); } From c8cfa467c01397b037412e3c400dec72840df52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 15:16:51 +0100 Subject: [PATCH 188/567] SceneGraph: actually call animationStopped() after duration is exceeded. --- src/SceneGraph/Animable.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp index dfa060a97..f04ff6160 100644 --- a/src/SceneGraph/Animable.hpp +++ b/src/SceneGraph/Animable.hpp @@ -102,6 +102,7 @@ template void AnimableGroup::st animable->previousState = AnimationState::Stopped; animable->currentState = AnimationState::Stopped; --_runningCount; + animable->animationStopped(); continue; } From c003f0499d1a6d77c133c5d1a8beb72cab95e02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 15:20:36 +0100 Subject: [PATCH 189/567] Assert when improper pixel type is passed to AbstractImage::pixelSize(). --- src/AbstractImage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 19ffdc1f4..d7b4373e4 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -115,6 +115,7 @@ std::size_t AbstractImage::pixelSize(Format format, Type type) { CORRADE_INTERNAL_ASSERT(false); } + CORRADE_INTERNAL_ASSERT(false); return 0; } From 6e61354fde5e2bf5b048f7b9d80f074df8fd4a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 17:11:55 +0100 Subject: [PATCH 190/567] OpenGL ES compilation fixes. --- src/AbstractShaderProgram.cpp | 9 ++++++++- src/AbstractShaderProgram.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 854e86fea..2f390ade3 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -599,8 +599,10 @@ std::size_t Attribute::size(GLint components, DataType dataType) { case DataType::Int: case DataType::Float: return 4*components; + #ifndef MAGNUM_TARGET_GLES case DataType::Double: return 8*components; + #endif } CORRADE_INTERNAL_ASSERT(false); @@ -624,7 +626,7 @@ std::size_t Attribute::size(GLint components, DataType dataType) { return 0; } - +#ifndef MAGNUM_TARGET_GLES std::size_t Attribute::size(GLint components, DataType dataType) { switch(dataType) { case DataType::Double: @@ -634,6 +636,7 @@ std::size_t Attribute::size(GLint components, DataType dataType) { CORRADE_INTERNAL_ASSERT(false); return 0; } +#endif std::size_t Attribute>::size(GLint components, DataType dataType) { switch(dataType) { @@ -648,13 +651,17 @@ std::size_t Attribute>::size(GLint components, DataType case DataType::Int: case DataType::Float: return 4*components; + #ifndef MAGNUM_TARGET_GLES case DataType::Double: return 8*components; + #endif + #ifndef MAGNUM_TARGET_GLES2 case DataType::UnsignedInt2101010REV: case DataType::Int2101010REV: CORRADE_INTERNAL_ASSERT(components == 4); return 4; + #endif } CORRADE_INTERNAL_ASSERT(false); diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index cb16c0b2a..07fd6fa4f 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1163,7 +1163,7 @@ template<> struct Attribute> { return options & DataOption::BGRA ? GL_BGRA : 4; } #else - inline constexpr static GLint components(DataOptions) { return 4; } + inline constexpr static GLint components(DataOptions = {}) { return 4; } #endif static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); From d175dd105405ba52a9c7397a773370b9dd1c98db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 17:33:40 +0100 Subject: [PATCH 191/567] Updated workarounds for Doxygen 1.8.2. Removed workarounds for alias templates, variadic templates and anonymous enums, but 1.8.2 has some bug with forward declarations causing classes to appear in default namespace, breaking cross-references. --- src/DebugTools/DebugTools.h | 3 +++ src/DebugTools/ShapeRenderer.h | 3 +++ src/Magnum.h | 6 +++++ src/Math/Math.h | 3 +++ src/Math/Matrix.h | 5 ---- src/Math/Matrix3.h | 4 ---- src/Math/Matrix4.h | 4 ---- src/Math/RectangularMatrix.h | 11 +++++---- src/Math/Vector.h | 10 +++----- src/Physics/Physics.h | 3 +++ src/Primitives/Icosphere.h | 3 +++ src/SceneGraph/AbstractCamera.h | 14 +---------- src/SceneGraph/AbstractFeature.h | 14 +---------- src/SceneGraph/AbstractGroupedFeature.h | 18 +++----------- src/SceneGraph/AbstractObject.h | 14 +---------- src/SceneGraph/AbstractTransformation.h | 14 +---------- src/SceneGraph/Animable.h | 14 +---------- src/SceneGraph/AnimableGroup.h | 14 +---------- src/SceneGraph/Drawable.h | 31 +++---------------------- src/SceneGraph/FeatureGroup.h | 14 +---------- src/SceneGraph/SceneGraph.h | 3 +++ src/Shaders/AbstractTextShader.h | 11 +-------- src/Shaders/Shaders.h | 3 +++ src/Trade/AbstractImporter.h | 3 +++ 24 files changed, 53 insertions(+), 169 deletions(-) diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h index d1aeff182..31fddcd58 100644 --- a/src/DebugTools/DebugTools.h +++ b/src/DebugTools/DebugTools.h @@ -23,6 +23,8 @@ namespace Magnum { namespace DebugTools { +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class ObjectRenderer; typedef ObjectRenderer<2> ObjectRenderer2D; typedef ObjectRenderer<3> ObjectRenderer3D; @@ -35,6 +37,7 @@ template class ShapeRenderer; typedef ShapeRenderer<2> ShapeRenderer2D; typedef ShapeRenderer<3> ShapeRenderer3D; class ShapeRendererOptions; +#endif }} diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 04b32c69c..f246a87e7 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -24,7 +24,10 @@ namespace Magnum { namespace DebugTools { +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class ShapeRenderer; +#endif #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { diff --git a/src/Magnum.h b/src/Magnum.h index d47f2b15d..a0e82909b 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -57,6 +57,8 @@ namespace Corrade { namespace Magnum { +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT namespace Math { template constexpr T deg(T value); template constexpr T rad(T value); @@ -67,6 +69,7 @@ namespace Math { using Corrade::Utility::Debug; using Corrade::Utility::Warning; using Corrade::Utility::Error; +#endif /** @brief Two-component floating-point vector */ typedef Math::Vector2 Vector2; @@ -124,6 +127,8 @@ typedef Math::Geometry::Rectangle Rectanglei; using Math::deg; using Math::rad; +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT /* Forward declarations for all types in root namespace */ class AbstractFramebuffer; class AbstractImage; @@ -198,6 +203,7 @@ typedef Texture<2> Texture2D; typedef Texture<3> Texture3D; class Timeline; +#endif } diff --git a/src/Math/Math.h b/src/Math/Math.h index df38fef81..b62f82fe6 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -23,6 +23,8 @@ namespace Magnum { namespace Math { +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT /* Class Constants used only statically */ template class Matrix; @@ -44,6 +46,7 @@ template class Vector4; namespace Geometry { template class Rectangle; } +#endif }} diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index c9194f8d2..1e17d95f4 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -74,13 +74,8 @@ template class Matrix: public RectangularMatrix inline constexpr /*implicit*/ Matrix(T first, U... next): RectangularMatrix(first, next...) {} - #else - template inline constexpr /*implicit*/ Matrix(T first, U... next); - #endif /** @brief Copy constructor */ inline constexpr Matrix(const RectangularMatrix& other): RectangularMatrix(other) {} diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 2fa99114e..65014d7e7 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -134,11 +134,7 @@ template class Matrix3: public Matrix<3, T> { ) {} /** @copydoc Matrix::Matrix */ - #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr /*implicit*/ Matrix3(T first, U... next): Matrix<3, T>(first, next...) {} - #else - template inline constexpr /*implicit*/ Matrix3(T first, U... next) {} - #endif /** @brief Copy constructor */ inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {} diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 89bd78224..dbbcaaf04 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -267,11 +267,7 @@ template class Matrix4: public Matrix<4, T> { ) {} /** @copydoc Matrix::Matrix */ - #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr /*implicit*/ Matrix4(T first, U... next): Matrix<4, T>(first, next...) {} - #else - template inline constexpr /*implicit*/ Matrix4(T first, U... next) {} - #endif /** @brief Copy constructor */ inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {} diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 4bed38856..e9b7beded 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -32,7 +32,10 @@ namespace Magnum { namespace Math { /** @todo Properly test all constexpr */ +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class RectangularMatrix; +#endif #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { @@ -53,7 +56,10 @@ namespace Implementation { } #endif +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class Vector; +#endif /** @brief Rectangular matrix @@ -128,15 +134,10 @@ template class RectangularMatrix { * @param next Next values * * Note that the values are in column-major order. - * @todoc Remove workaround when Doxygen supports uniform initialization */ - #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr /*implicit*/ RectangularMatrix(T first, U... next): _data{first, next...} { static_assert(sizeof...(next)+1 == cols*rows, "Improper number of arguments passed to RectangularMatrix constructor"); } - #else - template inline constexpr RectangularMatrix(T first, U... next); - #endif /** @brief Copy constructor */ inline constexpr RectangularMatrix(const RectangularMatrix&) = default; diff --git a/src/Math/Vector.h b/src/Math/Vector.h index eed04f4dd..0bc51beac 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -91,20 +91,16 @@ template class Vector: public RectangularMatrix<1, si * @param first First value * @param next Next values */ - #ifndef DOXYGEN_GENERATING_OUTPUT template inline constexpr /*implicit*/ Vector(T first, U... next): RectangularMatrix<1, size, T>(first, next...) {} - #else - template inline constexpr /*implicit*/ Vector(T first, U... next); - #endif /** * @brief Constructor * @param value Value for all fields */ - #ifndef DOXYGEN_GENERATING_OUTPUT - template inline explicit Vector(typename std::enable_if::value && size != 1, U>::type value) { - #else + #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit Vector(T value) { + #else + template inline explicit Vector(typename std::enable_if::value && size != 1, U>::type value) { #endif for(std::size_t i = 0; i != size; ++i) (*this)[i] = value; diff --git a/src/Physics/Physics.h b/src/Physics/Physics.h index 066c0a029..5667d4491 100644 --- a/src/Physics/Physics.h +++ b/src/Physics/Physics.h @@ -23,6 +23,8 @@ namespace Magnum { namespace Physics { +/** @todoc remove when doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class AbstractShape; typedef AbstractShape<2> AbstractShape2D; typedef AbstractShape<3> AbstractShape3D; @@ -68,6 +70,7 @@ typedef ShapeGroup<3> ShapeGroup3D; template class Sphere; typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; +#endif }} diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 93eb72aeb..e5aa7ea42 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -26,7 +26,10 @@ namespace Magnum { namespace Primitives { +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class Icosphere; +#endif /** @brief 3D icosphere primitive with zero subdivisions diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 9b24759fb..2043583dd 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -163,6 +163,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature inline AbstractCamera::~AbstractCamera() {} +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional cameras @@ -170,15 +171,8 @@ Convenience alternative to %AbstractCamera<2, T>. See AbstractCamera for more information. @note Not available on GCC < 4.7. Use %AbstractCamera<2, T> instead. @see AbstractCamera3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractCamera2D = AbstractCamera<2, T>; -#endif -#else -typedef AbstractCamera<2, T = GLfloat> AbstractCamera2D; -#endif /** @brief Base for three-dimensional cameras @@ -187,15 +181,9 @@ Convenience alternative to %AbstractCamera<3, T>. See AbstractCamera for more information. @note Not available on GCC < 4.7. Use %AbstractCamera<3, T> instead. @see AbstractCamera2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractCamera3D = AbstractCamera<3, T>; #endif -#else -typedef AbstractCamera<3, T = GLfloat> AbstractCamera3D; -#endif }} diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 4d48312f2..749e620b2 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -284,6 +284,7 @@ template inline AbstractFeature template inline void AbstractFeature::clean(const typename DimensionTraits::MatrixType&) {} template inline void AbstractFeature::cleanInverted(const typename DimensionTraits::MatrixType&) {} +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional features @@ -291,15 +292,8 @@ Convenience alternative to %AbstractFeature<2, T>. See AbstractFeature for more information. @note Not available on GCC < 4.7. Use %AbstractFeature<2, T> instead. @see AbstractFeature3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractFeature2D = AbstractFeature<2, T>; -#endif -#else -typedef AbstractFeature<2, T = GLfloat> AbstractFeature2D; -#endif /** @brief Base for three-dimensional features @@ -308,15 +302,9 @@ Convenience alternative to %AbstractFeature<3, T>. See AbstractFeature for more information. @note Not available on GCC < 4.7. Use %AbstractFeature<3, T> instead. @see AbstractFeature2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractFeature3D = AbstractFeature<3, T>; #endif -#else -typedef AbstractFeature<2, T = GLfloat> AbstractFeature3D; -#endif }} diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index 5998895c7..7d7326e8a 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -92,41 +92,29 @@ class AbstractGroupedFeature: public AbstractFeature { FeatureGroup* _group; }; +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional grouped features Convenience alternative to %AbstractGroupedFeature<2, Derived, T>. See AbstractGroupedFeature for more information. -@see AbstractGroupedFeature3D @note Not available on GCC < 4.7. Use %AbstractGroupedFeature<2, Derived, T> instead. -@todoc Remove workaround when Doxygen supports alias template +@see AbstractGroupedFeature3D */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractGroupedFeature2D = AbstractGroupedFeature<2, Derived, T>; -#endif -#else -typedef AbstractGroupedFeature<2, Derived, T = GLfloat> AbstractGroupedFeature2D; -#endif /** @brief Base for three-dimensional grouped features Convenience alternative to %AbstractGroupedFeature<3, Derived, T>. See AbstractGroupedFeature for more information. -@see AbstractGroupedFeature2D @note Not available on GCC < 4.7. Use %AbstractGroupedFeature<3, Derived, T> instead. -@todoc Remove workaround when Doxygen supports alias template +@see AbstractGroupedFeature2D */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractGroupedFeature3D = AbstractGroupedFeature<3, Derived, T>; #endif -#else -typedef AbstractGroupedFeature<3, Derived, T = GLfloat> AbstractGroupedFeature3D; -#endif }} diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 64ef2aeff..e55f51154 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -179,6 +179,7 @@ template class AbstractObject /*@}*/ }; +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional objects @@ -186,15 +187,8 @@ Convenience alternative to %AbstractObject<2, T>. See AbstractObject for more information. @note Not available on GCC < 4.7. Use %AbstractObject<2, T> instead. @see AbstractObject3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractObject2D = AbstractObject<2, T>; -#endif -#else -typedef AbstractObject<2, T = GLfloat> AbstractObject2D; -#endif /** @brief Base for three-dimensional objects @@ -203,15 +197,9 @@ Convenience alternative to %AbstractObject<3, T>. See AbstractObject for more information. @note Not available on GCC < 4.7. Use %AbstractObject<3, T> instead. @see AbstractObject2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractObject3D = AbstractObject<3, T>; #endif -#else -typedef AbstractObject<3, T = GLfloat> AbstractObject3D; -#endif }} diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 4fed38811..9808195ab 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -139,6 +139,7 @@ enum class TransformationType: std::uint8_t { template inline AbstractTransformation::~AbstractTransformation() {} +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional transformations @@ -147,15 +148,8 @@ AbstractTransformation for more information. @note Not available on GCC < 4.7. Use %AbstractTransformation<2, T> instead. @see AbstractTransformation3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractTransformation2D = AbstractTransformation<2, T>; -#endif -#else -typedef AbstractTransformation<2, T = GLfloat> AbstractTransformation2D; -#endif /** @brief Base for three-dimensional transformations @@ -165,15 +159,9 @@ AbstractTransformation for more information. @note Not available on GCC < 4.7. Use %AbstractTransformation<3, T> instead. @see AbstractTransformation2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AbstractTransformation3D = AbstractTransformation<3, T>; #endif -#else -typedef AbstractTransformation<3, T = GLfloat> AbstractTransformation3D; -#endif }} diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 48a7915fc..a6fc01d90 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -302,6 +302,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature%Animable<2, T>. See Animable for more information. @note Not available on GCC < 4.7. Use %Animable<2, T> instead. @see Animable3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using Animable2D = Animable<2, T>; -#endif -#else -typedef Animable<2, T = GLfloat> Animable2D; -#endif /** @brief Three-dimensional animable @@ -326,15 +320,9 @@ Convenience alternative to %Animable<3, T>. See Animable for more information. @note Not available on GCC < 4.7. Use %Animable<3, T> instead. @see Animable2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using Animable3D = Animable<3, T>; #endif -#else -typedef Animable<3, T = GLfloat> Animable3D; -#endif }} diff --git a/src/SceneGraph/AnimableGroup.h b/src/SceneGraph/AnimableGroup.h index 6c86b3b6f..814c214cd 100644 --- a/src/SceneGraph/AnimableGroup.h +++ b/src/SceneGraph/AnimableGroup.h @@ -67,6 +67,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup: public FeatureGroup%AnimableGroup<2, T>. See Animable for more information. @note Not available on GCC < 4.7. Use %AnimableGroup<2, T> instead. @see AnimableGroup3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AnimableGroup2D = AnimableGroup<2, T>; -#endif -#else -typedef AnimableGroup<2, T = GLfloat> AnimableGroup2D; -#endif /** @brief Three-dimensional animable @@ -91,15 +85,9 @@ Convenience alternative to %AnimableGroup<3, T>. See Animable for more information. @note Not available on GCC < 4.7. Use %AnimableGroup<3, T> instead. @see AnimableGroup2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using AnimableGroup3D = AnimableGroup<3, T>; #endif -#else -typedef AnimableGroup<3, T = GLfloat> AnimableGroup3D; -#endif }} diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index bb20a3960..9a1e1cbcf 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -135,6 +135,7 @@ class Drawable: public AbstractGroupedFeature::MatrixType& transformationMatrix, AbstractCamera* camera) = 0; }; +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Two-dimensional drawable @@ -142,15 +143,8 @@ Convenience alternative to %Drawable<2, T>. See Drawable for more information. @note Not available on GCC < 4.7. Use %Drawable<2, T> instead. @see Drawable3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using Drawable2D = Drawable<2, T>; -#endif -#else -typedef Drawable<2, T = GLfloat> Drawable2D; -#endif /** @brief Three-dimensional drawable @@ -159,24 +153,17 @@ Convenience alternative to %Drawable<3, T>. See Drawable for more information. @note Not available on GCC < 4.7. Use %Drawable<3, T> instead. @see Drawable2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using Drawable3D = Drawable<3, T>; #endif -#else -typedef Drawable<3, T = GLfloat> Drawable3D; -#endif /** @brief Group of drawables See Drawable for more information. @see @ref scenegraph, DrawableGroup2D, DrawableGroup3D -@todoc Remove workaround when Doxygen supports alias template */ -#if !defined(CORRADE_GCC46_COMPATIBILITY) && !defined(DOXYGEN_GENERATING_OUTPUT) +#ifndef CORRADE_GCC46_COMPATIBILITY template using DrawableGroup = FeatureGroup, T>; #else #ifndef DOXYGEN_GENERATING_OUTPUT @@ -187,6 +174,7 @@ template class DrawableGroup: public FeatureGroup, T> {}; #endif +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Group of two-dimensional drawables @@ -194,15 +182,8 @@ Convenience alternative to %DrawableGroup<2, T>. See Drawable for more information. @note Not available on GCC < 4.7. Use %Drawable<2, T> instead. @see DrawableGroup3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using DrawableGroup2D = DrawableGroup<2, T>; -#endif -#else -typedef DrawableGroup<2, T = GLfloat> DrawableGroup2D; -#endif /** @brief Group of three-dimensional drawables @@ -211,15 +192,9 @@ Convenience alternative to %DrawableGroup<3, T>. See Drawable for more information. @note Not available on GCC < 4.7. Use %Drawable<3, T> instead. @see DrawableGroup2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using DrawableGroup3D = DrawableGroup<3, T>; #endif -#else -typedef DrawableGroup<3, T = GLfloat> DrawableGroup3D; -#endif }} diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index f91a2b6a4..8a8ddeff3 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -111,6 +111,7 @@ class FeatureGroup { std::vector features; }; +#ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional object features @@ -119,15 +120,8 @@ AbstractGroupedFeature for more information. @note Not available on GCC < 4.7. Use %FeatureGroup<2, Feature, T> instead. @see FeatureGroup3D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using FeatureGroup2D = FeatureGroup<2, Feature, T>; -#endif -#else -typedef FeatureGroup<2, Feature, T = GLfloat> FeatureGroup2D; -#endif /** @brief Base for three-dimensional object features @@ -137,15 +131,9 @@ AbstractGroupedFeature for more information. @note Not available on GCC < 4.7. Use %FeatureGroup<3, Feature, T> instead. @see FeatureGroup2D -@todoc Remove workaround when Doxygen supports alias template */ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef CORRADE_GCC46_COMPATIBILITY template using FeatureGroup3D = FeatureGroup<3, Feature, T>; #endif -#else -typedef FeatureGroup<3, Feature, T = GLfloat> FeatureGroup3D; -#endif }} diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index c958654f1..014c74383 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -27,6 +27,8 @@ namespace Magnum { namespace SceneGraph { +/** @todoc remove when doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT enum class AspectRatioPolicy: std::uint8_t; template class AbstractCamera; @@ -111,6 +113,7 @@ template class MatrixTransformation3D; template class Object; template class Scene; +#endif }} diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h index 6ecc5617d..350b519ac 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractTextShader.h @@ -38,18 +38,9 @@ template class AbstractTextShader: public AbstractShade /** @brief Texture coordinates */ typedef Attribute<1, Vector2> TextureCoordinates; - /** @todoc Remove when Doxygen is sane */ - #ifndef DOXYGEN_GENERATING_OUTPUT enum: GLint { - #else - static const GLint - #endif - FontTextureLayer = 16 /**< @brief Layer for font texture */ - #ifndef DOXYGEN_GENERATING_OUTPUT + FontTextureLayer = 16 /**< Layer for font texture */ }; - #else - ; - #endif ~AbstractTextShader() = 0; }; diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index 80052a755..fba4ef929 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -23,6 +23,8 @@ namespace Magnum { namespace Shaders { +/** @todoc remove when doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT template class AbstractTextShader; typedef AbstractTextShader<2> AbstractTextShader2D; typedef AbstractTextShader<3> AbstractTextShader3D; @@ -40,6 +42,7 @@ typedef TextShader<3> TextShader3D; template class VertexColorShader; typedef VertexColorShader<2> VertexColorShader2D; typedef VertexColorShader<3> VertexColorShader3D; +#endif }} diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 2d2557661..cb0fcc19f 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -26,6 +26,8 @@ namespace Magnum { namespace Trade { +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT class AbstractMaterialData; class CameraData; template class ImageData; @@ -36,6 +38,7 @@ class ObjectData2D; class ObjectData3D; class SceneData; class TextureData; +#endif typedef ImageData<1> ImageData1D; typedef ImageData<2> ImageData2D; From 8ce184ef7b138077d170abc9bf0b642ec8a02897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 18 Jan 2013 17:16:01 +0100 Subject: [PATCH 192/567] Debug output for AbstractImage::Format and AbstractImage::Type enums. --- src/AbstractImage.cpp | 83 ++++++++++++++++++++++++++++++++++ src/AbstractImage.h | 6 +++ src/Test/AbstractImageTest.cpp | 50 ++++++++++++++++++++ src/Test/CMakeLists.txt | 1 + 4 files changed, 140 insertions(+) create mode 100644 src/Test/AbstractImageTest.cpp diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index d7b4373e4..3cc19a3a2 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -119,4 +119,87 @@ std::size_t AbstractImage::pixelSize(Format format, Type type) { return 0; } +Debug operator<<(Debug debug, AbstractImage::Format value) { + switch(value) { + #define _c(value) case AbstractImage::Format::value: return debug << "AbstractImage::Format::" #value; + _c(Red) + #ifndef MAGNUM_TARGET_GLES + _c(Green) + _c(Blue) + #endif + _c(RG) + _c(RGB) + _c(RGBA) + #ifndef MAGNUM_TARGET_GLES + _c(BGR) + #endif + _c(BGRA) + #ifndef MAGNUM_TARGET_GLES2 + _c(RedInteger) + _c(GreenInteger) + _c(BlueInteger) + _c(RGInteger) + _c(RGBInteger) + _c(RGBAInteger) + _c(BGRInteger) + _c(BGRAInteger) + #endif + _c(DepthComponent) + _c(StencilIndex) + _c(DepthStencil) + #undef _c + } + + return debug << "AbstractImage::Format::(invalid)"; +} + +Debug operator<<(Debug debug, AbstractImage::Type value) { + switch(value) { + #define _c(value) case AbstractImage::Type::value: return debug << "AbstractImage::Type::" #value; + _c(UnsignedByte) + #ifndef MAGNUM_TARGET_GLES2 + _c(Byte) + #endif + _c(UnsignedShort) + #ifndef MAGNUM_TARGET_GLES2 + _c(Short) + #endif + _c(UnsignedInt) + #ifndef MAGNUM_TARGET_GLES2 + _c(Int) + #endif + _c(HalfFloat) + _c(Float) + #ifndef MAGNUM_TARGET_GLES2 + _c(UnsignedByte332) + _c(UnsignedByte233Rev) + #endif + _c(UnsignedShort565) + #ifndef MAGNUM_TARGET_GLES + _c(UnsignedShort565Rev) + #endif + _c(UnsignedShort4444) + _c(UnsignedShort4444Rev) + _c(UnsignedShort5551) + _c(UnsignedShort1555Rev) + #ifndef MAGNUM_TARGET_GLES + _c(UnsignedInt8888) + _c(UnsignedInt8888Rev) + _c(UnsignedInt1010102) + #endif + _c(UnsignedInt2101010Rev) + #ifndef MAGNUM_TARGET_GLES2 + _c(UnsignedInt10F11F11FRev) + _c(UnsignedInt5999Rev) + #endif + _c(UnsignedInt248) + #ifndef MAGNUM_TARGET_GLES2 + _c(Float32UnsignedInt248Rev) + #endif + #undef _c + } + + return debug << "AbstractImage::Type::(invalid)"; +} + } diff --git a/src/AbstractImage.h b/src/AbstractImage.h index dfbfbaf65..34a21b9cc 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -456,6 +456,12 @@ class MAGNUM_EXPORT AbstractImage { inline AbstractImage::~AbstractImage() {} +/** @debugoperator{Magnum::AbstractImage} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, AbstractImage::Format value); + +/** @debugoperator{Magnum::AbstractImage} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, AbstractImage::Type value); + } #endif diff --git a/src/Test/AbstractImageTest.cpp b/src/Test/AbstractImageTest.cpp new file mode 100644 index 000000000..405cf26bf --- /dev/null +++ b/src/Test/AbstractImageTest.cpp @@ -0,0 +1,50 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "AbstractImage.h" + +namespace Magnum { namespace Test { + +class AbstractImageTest: public Corrade::TestSuite::Tester { + public: + explicit AbstractImageTest(); + + void debugFormat(); + void debugType(); +}; + +AbstractImageTest::AbstractImageTest() { + addTests(&AbstractImageTest::debugFormat, + &AbstractImageTest::debugType); +} + +void AbstractImageTest::debugFormat() { + std::ostringstream o; + Debug(&o) << AbstractImage::Format::RGBA; + CORRADE_COMPARE(o.str(), "AbstractImage::Format::RGBA\n"); +} + +void AbstractImageTest::debugType() { + std::ostringstream o; + Debug(&o) << AbstractImage::Type::UnsignedShort5551; + CORRADE_COMPARE(o.str(), "AbstractImage::Type::UnsignedShort5551\n"); +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::AbstractImageTest) diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 0bd72dd47..4364e87d3 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,3 +1,4 @@ +corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum) corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) From f16a9d8310c478cb4741944ce78ce49a4cf7487c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 18 Jan 2013 17:19:22 +0100 Subject: [PATCH 193/567] Shorter convenience overload for ResourceManager::set(). --- src/ResourceManager.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 1e6e68516..0bd806a63 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -424,6 +424,16 @@ template class ResourceManager: private Implementation::Resource this->Implementation::ResourceManagerData::set(key, data, state, policy); } + /** + * @brief Set resource data + * + * Same as above function with state set to @ref ResourceDataState "ResourceDataState::Final" + * and policy to @ref ResourcePolicy "ResourcePolicy::Resident". + */ + template inline void set(ResourceKey key, T* data) { + this->Implementation::ResourceManagerData::set(key, data, ResourceDataState::Final, ResourcePolicy::Resident); + } + /** @brief Fallback for not found resources */ template inline T* fallback() { return this->Implementation::ResourceManagerData::fallback(); From 861e16e1f9944a6431b2c5cf5143462de0125935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 18 Jan 2013 17:25:50 +0100 Subject: [PATCH 194/567] Doc++, @todo+- --- src/IndexedMesh.h | 2 +- src/Magnum.h | 9 --------- src/Math/Vector.h | 2 ++ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 9d956f99d..40d9d5f09 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -131,7 +131,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * @brief Set index type * @return Pointer to self (for method chaining) * - * Default is @ref Type "IndexType::UnsignedInt". + * Default is @ref IndexType "IndexType::UnsignedInt". * @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices() */ inline IndexedMesh* setIndexType(IndexType type) { diff --git a/src/Magnum.h b/src/Magnum.h index a0e82909b..5880f51e9 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -38,15 +38,6 @@ #endif #endif -/** - * @todo Link to libGL / libGLES based on which windowcontext is used in app - * and whether GLES is enabled or not -- this allows us to use glx with - * ES on nvidia/intel. Using libGL and EGL on nvidia is whole another - * problem, though. How about windows? It won't allow unlinked DLLs, so - * probably always link Magnum itself to GL library there. How about unit - * tests not needing any of GL? -- different testing library? - */ - namespace Corrade { namespace Utility { class Debug; diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 0bc51beac..6d25c787c 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -76,6 +76,8 @@ template class Vector: public RectangularMatrix<1, si * The interpolation is done as in following: @f[ * v_{LERP} = (1 - t) \boldsymbol v_A + t \boldsymbol v_B * @f] + * @todo http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/ + * (when SIMD is in place) */ inline static Vector lerp(const Vector& a, const Vector& b, T t) { return (T(1) - t)*a + t*b; From 4c3e80b4f12c189afcadbc9150af6b4961e1de46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 01:26:48 +0100 Subject: [PATCH 195/567] SceneGraph: added AbstractObject::transformationMatrix(). Complement for Object::transformation(), usable from features which don't want/need to upcast AbstractObject pointer. --- src/SceneGraph/AbstractObject.h | 7 +++++++ src/SceneGraph/Object.h | 4 ++++ src/SceneGraph/Test/ObjectTest.cpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index e55f51154..56ab023c2 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -102,6 +102,13 @@ template class AbstractObject /** @{ @name Object transformation */ + /** + * @brief Transformation matrix + * + * @see Object::transformation() + */ + virtual typename DimensionTraits::MatrixType transformationMatrix() const = 0; + /** * @brief Transformation matrix relative to root object * diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 9b5efdc6f..e94d0e84d 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -202,6 +202,10 @@ template class Object: public AbstractObject::MatrixType transformationMatrix() const override { + return Transformation::toMatrix(Transformation::transformation()); + } + inline typename DimensionTraits::MatrixType absoluteTransformationMatrix() const override { return Transformation::toMatrix(absoluteTransformation()); } diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index bf586bb10..09248ac5d 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -110,6 +110,8 @@ void ObjectTest::absoluteTransformation() { /* Proper transformation composition */ Object3D o(&s); o.translate(Vector3::xAxis(2.0f)); + CORRADE_COMPARE(o.transformation(), Matrix4::translation(Vector3::xAxis(2.0f))); + CORRADE_COMPARE(o.transformation(), o.transformationMatrix()); Object3D o2(&o); o2.rotateY(deg(90.0f)); CORRADE_COMPARE(o2.absoluteTransformation(), From b7b955289a7cb5006cff715ce2ff21a511644769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 01:28:23 +0100 Subject: [PATCH 196/567] Math: Vector::lerp() can take `t` of arbitrary type. Usable when interpolating e.g. colors in denormalized integral form, as `t` could be only `0` or `1` in that case, which is pretty unusable. --- src/Math/Test/VectorTest.cpp | 5 +++++ src/Math/Vector.h | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index b1f93a472..56eb0083b 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -160,6 +160,11 @@ void VectorTest::lerp() { Vector3 b(3.0f, -2.0f, 11.0f); CORRADE_COMPARE(Vector3::lerp(a, b, 0.25f), Vector3(0.0f, 1.0f, 5.0f)); + + typedef Math::Vector<3, std::int32_t> Vector3ub; + Vector3ub c(0, 128, 64); + Vector3ub d(16, 0, 32); + CORRADE_COMPARE(Vector3ub::lerp(c, d, 0.25f), Vector3ub(4, 96, 56)); } void VectorTest::debug() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 6d25c787c..d7b1b6d78 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -79,8 +79,8 @@ template class Vector: public RectangularMatrix<1, si * @todo http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/ * (when SIMD is in place) */ - inline static Vector lerp(const Vector& a, const Vector& b, T t) { - return (T(1) - t)*a + t*b; + template inline static Vector lerp(const Vector& a, const Vector& b, U t) { + return (U(1) - t)*a + t*b; } /** @brief Default constructor */ @@ -358,7 +358,7 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit template inline constexpr static Type from(const Math::Vector& other) { \ return Math::Vector::from(other); \ } \ - inline static const Type lerp(const Math::Vector& a, const Math::Vector& b, T t) { \ + template inline static const Type lerp(const Math::Vector& a, const Math::Vector& b, U t) { \ return Math::Vector::lerp(a, b, t); \ } \ \ From 1d88310521f85883234e00578602758cc1139425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 20:17:10 +0100 Subject: [PATCH 197/567] Shaders: off-by-one error. Explicit attrib location is supported on GLSL >= 130, not >= 120. --- src/Shaders/compatibility.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shaders/compatibility.glsl b/src/Shaders/compatibility.glsl index c6ebfa748..2d3994a68 100644 --- a/src/Shaders/compatibility.glsl +++ b/src/Shaders/compatibility.glsl @@ -4,7 +4,7 @@ /* On NVidia and GLSL 1.20 layout qualifiers result in parsing error, even if the extension is defined as supported */ -#if !defined(GL_ES) && __VERSION__ >= 120 +#if !defined(GL_ES) && __VERSION__ >= 130 #ifdef GL_ARB_explicit_attrib_location #extension GL_ARB_explicit_attrib_location: enable From a22bf1bf4e16bebc65208582e1faa8761515196c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 20:18:03 +0100 Subject: [PATCH 198/567] Shaders: don't use explicit attribute location on GL 2.1. --- src/Shaders/FlatShader.cpp | 3 ++- src/Shaders/PhongShader.cpp | 3 ++- src/Shaders/TextShader.cpp | 3 ++- src/Shaders/VertexColorShader.cpp | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index 0999fdd1d..e962e8f5f 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -56,7 +56,8 @@ template FlatShader::FlatShader(): transfor attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { + if(!Context::current()->isExtensionSupported() || + Context::current()->version() == Version::GL210) { #else if(!Context::current()->isVersionSupported(Version::GLES300)) { #endif diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index b069eedf8..aec592bdb 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -42,7 +42,8 @@ PhongShader::PhongShader(): transformationMatrixUniform(0), projectionMatrixUnif attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { + if(!Context::current()->isExtensionSupported() || + Context::current()->version() == Version::GL210) { #else if(!Context::current()->isVersionSupported(Version::GLES300)) { #endif diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/TextShader.cpp index 4f38ba324..a5d9a950b 100644 --- a/src/Shaders/TextShader.cpp +++ b/src/Shaders/TextShader.cpp @@ -57,7 +57,8 @@ template TextShader::TextShader(): transfor AbstractTextShader::attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { + if(!Context::current()->isExtensionSupported() || + Context::current()->version() == Version::GL210) { #else if(!Context::current()->isVersionSupported(Version::GLES300)) { #endif diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index 67fcfde3b..e872a9fba 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -48,7 +48,8 @@ template VertexColorShader::VertexColorShad attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES - if(!Context::current()->isExtensionSupported()) { + if(!Context::current()->isExtensionSupported() || + Context::current()->version() == Version::GL210) { #else if(!Context::current()->isVersionSupported(Version::GLES300)) { #endif From 688251add906eef77e6cca4813f6ee539d86fe32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 16:21:25 +0100 Subject: [PATCH 199/567] Removing IndexedMesh, part 1: moved enums and related stuff to Mesh. --- src/IndexedMesh.cpp | 52 ---------------------------------- src/IndexedMesh.h | 45 ----------------------------- src/Mesh.cpp | 44 +++++++++++++++++++++++++++++ src/Mesh.h | 41 +++++++++++++++++++++++++++ src/Test/CMakeLists.txt | 1 - src/Test/IndexedMeshTest.cpp | 55 ------------------------------------ src/Test/MeshTest.cpp | 30 ++++++++++++++++---- 7 files changed, 109 insertions(+), 159 deletions(-) delete mode 100644 src/Test/IndexedMeshTest.cpp diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 099bc3065..dbd2cd321 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -15,8 +15,6 @@ #include "IndexedMesh.h" -#include - #include "Buffer.h" #include "Context.h" #include "Extensions.h" @@ -26,16 +24,6 @@ namespace Magnum { IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; -std::size_t IndexedMesh::indexSize(IndexType type) { - switch(type) { - case IndexType::UnsignedByte: return 1; - case IndexType::UnsignedShort: return 2; - case IndexType::UnsignedInt: return 4; - } - - CORRADE_INTERNAL_ASSERT(false); -} - IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) { _indexBuffer = buffer; (this->*bindIndexBufferImplementation)(); @@ -87,44 +75,4 @@ void IndexedMesh::bindIndexedImplementationDefault() { void IndexedMesh::bindIndexedImplementationVAO() {} -#ifndef DOXYGEN_GENERATING_OUTPUT -Debug operator<<(Debug debug, IndexedMesh::IndexType value) { - switch(value) { - #define _c(value) case IndexedMesh::IndexType::value: return debug << "IndexedMesh::IndexType::" #value; - _c(UnsignedByte) - _c(UnsignedShort) - _c(UnsignedInt) - #undef _c - } - - return debug << "IndexedMesh::IndexType::(invalid)"; -} -#endif - } - -namespace Corrade { namespace Utility { - -std::string ConfigurationValue::toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags) { - switch(value) { - #define _c(value) case Magnum::IndexedMesh::IndexType::value: return #value; - _c(UnsignedByte) - _c(UnsignedShort) - _c(UnsignedInt) - #undef _c - } - - return ""; -} - -Magnum::IndexedMesh::IndexType ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { - #define _c(value) if(stringValue == #value) return Magnum::IndexedMesh::IndexType::value; - _c(UnsignedByte) - _c(UnsignedShort) - _c(UnsignedInt) - #undef _c - - return Magnum::IndexedMesh::IndexType::UnsignedInt; -} - -}} diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 40d9d5f09..8b9cca1fe 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -72,25 +72,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { friend class Context; public: - /** - * @brief Index type - * - * @see setIndexType(), indexSize() - */ - enum class IndexType: GLenum { - UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ - UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ - - /** - * Unsigned int - * @requires_gles30 %Extension @es_extension{OES,element_index_uint} - */ - UnsignedInt = GL_UNSIGNED_INT - }; - - /** @brief Size of given index type */ - static std::size_t indexSize(IndexType type); - /** * @brief Constructor * @param primitive Primitive type @@ -196,32 +177,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { IndexType _indexType; }; -/** @debugoperator{Magnum::IndexedMesh} */ -Debug MAGNUM_EXPORT operator<<(Debug debug, IndexedMesh::IndexType value); - } -namespace Corrade { namespace Utility { - -/** @configurationvalue{Magnum::IndexedMesh} */ -template<> struct MAGNUM_EXPORT ConfigurationValue { - ConfigurationValue() = delete; - - /** - * @brief Write enum value as string - * - * If the value is invalid, returns empty string. - */ - static std::string toString(Magnum::IndexedMesh::IndexType value, ConfigurationValueFlags); - - /** - * @brief Read enum value as string - * - * If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". - */ - static Magnum::IndexedMesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); -}; - -}} - #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index d069132cb..fab5b9d86 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -37,6 +37,16 @@ Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &M Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; +std::size_t Mesh::indexSize(IndexType type) { + switch(type) { + case IndexType::UnsignedByte: return 1; + case IndexType::UnsignedShort: return 2; + case IndexType::UnsignedInt: return 4; + } + + CORRADE_INTERNAL_ASSERT(false); +} + Mesh::~Mesh() { /* Remove current vao from the state */ GLuint& current = Context::current()->state()->mesh->currentVAO; @@ -271,6 +281,18 @@ Debug operator<<(Debug debug, Mesh::Primitive value) { return debug << "Mesh::Primitive::(invalid)"; } + +Debug operator<<(Debug debug, Mesh::IndexType value) { + switch(value) { + #define _c(value) case Mesh::IndexType::value: return debug << "Mesh::IndexType::" #value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + } + + return debug << "Mesh::IndexType::(invalid)"; +} #endif } @@ -306,4 +328,26 @@ Magnum::Mesh::Primitive ConfigurationValue::fromString( return Magnum::Mesh::Primitive::Points; } +std::string ConfigurationValue::toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags) { + switch(value) { + #define _c(value) case Magnum::Mesh::IndexType::value: return #value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + } + + return ""; +} + +Magnum::Mesh::IndexType ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { + #define _c(value) if(stringValue == #value) return Magnum::Mesh::IndexType::value; + _c(UnsignedByte) + _c(UnsignedShort) + _c(UnsignedInt) + #undef _c + + return Magnum::Mesh::IndexType::UnsignedInt; +} + }} diff --git a/src/Mesh.h b/src/Mesh.h index 5018fa63c..99abd5a3f 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -358,6 +358,25 @@ class MAGNUM_EXPORT Mesh { TriangleFan = GL_TRIANGLE_FAN }; + /** + * @brief Index type + * + * @see setIndexType(), indexSize() + */ + enum class IndexType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ + UnsignedShort = GL_UNSIGNED_SHORT, /**< Unsigned short */ + + /** + * Unsigned int + * @requires_gles30 %Extension @es_extension{OES,element_index_uint} + */ + UnsignedInt = GL_UNSIGNED_INT + }; + + /** @brief Size of given index type */ + static std::size_t indexSize(IndexType type); + /** * @brief Constructor * @param primitive Primitive type @@ -753,6 +772,9 @@ class MAGNUM_EXPORT Mesh { /** @debugoperator{Magnum::Mesh} */ Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value); +/** @debugoperator{Magnum::Mesh} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::IndexType value); + } namespace Corrade { namespace Utility { @@ -776,6 +798,25 @@ template<> struct MAGNUM_EXPORT ConfigurationValue { static Magnum::Mesh::Primitive fromString(const std::string& stringValue, ConfigurationValueFlags); }; +/** @configurationvalue{Magnum::Mesh} */ +template<> struct MAGNUM_EXPORT ConfigurationValue { + ConfigurationValue() = delete; + + /** + * @brief Write enum value as string + * + * If the value is invalid, returns empty string. + */ + static std::string toString(Magnum::Mesh::IndexType value, ConfigurationValueFlags); + + /** + * @brief Read enum value as string + * + * If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". + */ + static Magnum::Mesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); +}; + }} #endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 4364e87d3..44d840117 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -2,7 +2,6 @@ corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum) corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) -corrade_add_test(IndexedMeshTest IndexedMeshTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Test/IndexedMeshTest.cpp b/src/Test/IndexedMeshTest.cpp deleted file mode 100644 index 6d51e341f..000000000 --- a/src/Test/IndexedMeshTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include -#include -#include - -#include "IndexedMesh.h" - -using namespace Corrade::Utility; - -namespace Magnum { namespace Test { - -class IndexedMeshTest: public Corrade::TestSuite::Tester { - public: - IndexedMeshTest(); - - void debug(); - void configuration(); -}; - -IndexedMeshTest::IndexedMeshTest() { - addTests(&IndexedMeshTest::debug, - &IndexedMeshTest::configuration); -} - -void IndexedMeshTest::debug() { - std::ostringstream o; - Debug(&o) << IndexedMesh::IndexType::UnsignedShort; - CORRADE_COMPARE(o.str(), "IndexedMesh::IndexType::UnsignedShort\n"); -} - -void IndexedMeshTest::configuration() { - Configuration c; - - c.setValue("type", IndexedMesh::IndexType::UnsignedByte); - CORRADE_COMPARE(c.value("type"), "UnsignedByte"); - CORRADE_COMPARE(c.value("type"), IndexedMesh::IndexType::UnsignedByte); -} - -}} - -CORRADE_TEST_MAIN(Magnum::Test::IndexedMeshTest) diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index 658febb17..5850c68b5 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -27,22 +27,32 @@ class MeshTest: public Corrade::TestSuite::Tester { public: MeshTest(); - void debug(); - void configuration(); + void debugPrimitive(); + void debugIndexType(); + void configurationPrimitive(); + void configurationIndexType(); }; MeshTest::MeshTest() { - addTests(&MeshTest::debug, - &MeshTest::configuration); + addTests(&MeshTest::debugPrimitive, + &MeshTest::debugIndexType, + &MeshTest::configurationPrimitive, + &MeshTest::configurationIndexType); } -void MeshTest::debug() { +void MeshTest::debugPrimitive() { std::ostringstream o; Debug(&o) << Mesh::Primitive::TriangleFan; CORRADE_COMPARE(o.str(), "Mesh::Primitive::TriangleFan\n"); } -void MeshTest::configuration() { +void MeshTest::debugIndexType() { + std::ostringstream o; + Debug(&o) << Mesh::IndexType::UnsignedShort; + CORRADE_COMPARE(o.str(), "Mesh::IndexType::UnsignedShort\n"); +} + +void MeshTest::configurationPrimitive() { Configuration c; c.setValue("primitive", Mesh::Primitive::LineStrip); @@ -50,6 +60,14 @@ void MeshTest::configuration() { CORRADE_COMPARE(c.value("primitive"), Mesh::Primitive::LineStrip); } +void MeshTest::configurationIndexType() { + Configuration c; + + c.setValue("type", Mesh::IndexType::UnsignedByte); + CORRADE_COMPARE(c.value("type"), "UnsignedByte"); + CORRADE_COMPARE(c.value("type"), Mesh::IndexType::UnsignedByte); +} + }} CORRADE_TEST_MAIN(Magnum::Test::MeshTest) From 3f1592c23d1b3c40b980268c5ff2c37d1b38c3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 16:27:27 +0100 Subject: [PATCH 200/567] Inlined Mesh::setVertexCount(). --- src/Mesh.cpp | 5 ----- src/Mesh.h | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index fab5b9d86..a083e11df 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -85,11 +85,6 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } -Mesh* Mesh::setVertexCount(GLsizei vertexCount) { - _vertexCount = vertexCount; - return this; -} - void Mesh::draw() { if(!_vertexCount) return; diff --git a/src/Mesh.h b/src/Mesh.h index 99abd5a3f..dafef3a6e 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -430,7 +430,10 @@ class MAGNUM_EXPORT Mesh { * @see setPrimitive(), addVertexBuffer(), addInterleavedVertexBuffer(), * addVertexBufferStride(), MeshTools::interleave() */ - Mesh* setVertexCount(GLsizei vertexCount); + inline Mesh* setVertexCount(GLsizei vertexCount) { + _vertexCount = vertexCount; + return this; + } /** * @brief Add buffer with non-interleaved vertex attributes for use with given shader From e4fc418db120eabbbd66e4d9fb76601974b3141e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 16:27:48 +0100 Subject: [PATCH 201/567] Properly specify pointers for all matrix attribute columns. Really need some tests for that. --- src/Mesh.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mesh.h b/src/Mesh.h index dafef3a6e..39dc43f11 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -660,9 +660,9 @@ class MAGNUM_EXPORT Mesh { offset, stride }); - } - (this->*attributePointerImplementation)(attributes.back()); + (this->*attributePointerImplementation)(attributes.back()); + } } #ifndef MAGNUM_TARGET_GLES2 From b20c83f258cb21e1681fb719593df8216c993f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 16:44:35 +0100 Subject: [PATCH 202/567] Removing IndexedMesh, part 2: moved all member variables to Mesh. As Mesh constructor is not exactly trivial, moved it to source, allowing to hide another function pointer variable. --- src/IndexedMesh.h | 44 +++++++++----------------------------------- src/Mesh.cpp | 9 ++++++++- src/Mesh.h | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 8b9cca1fe..965438429 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -79,7 +79,7 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * Creates indexed mesh with zero vertex count, zero index count and * no vertex or index buffers. */ - inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive), _indexBuffer(nullptr), _indexCount(0), _indexType(IndexType::UnsignedInt) {} + inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {} /** * @brief Set index buffer @@ -90,36 +90,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ IndexedMesh* setIndexBuffer(Buffer* buffer); - /** @brief Index count */ - inline GLsizei indexCount() const { return _indexCount; } - - /** - * @brief Set index count - * @return Pointer to self (for method chaining) - * - * Default is zero. - * @see setIndexBuffer(), setIndexType(), MeshTools::compressIndices() - */ - inline IndexedMesh* setIndexCount(GLsizei count) { - _indexCount = count; - return this; - } - - /** @brief Index type */ - inline IndexType indexType() const { return _indexType; } - - /** - * @brief Set index type - * @return Pointer to self (for method chaining) - * - * Default is @ref IndexType "IndexType::UnsignedInt". - * @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices() - */ - inline IndexedMesh* setIndexType(IndexType type) { - _indexType = type; - return this; - } - /** * @brief Draw the mesh * @@ -143,6 +113,14 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { Mesh::setVertexCount(vertexCount); return this; } + inline IndexedMesh* setIndexCount(GLsizei count) { + Mesh::setIndexCount(count); + return this; + } + inline IndexedMesh* setIndexType(IndexType type) { + Mesh::setIndexType(type); + return this; + } template inline IndexedMesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { Mesh::addVertexBuffer(buffer, attributes...); return this; @@ -171,10 +149,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { void MAGNUM_LOCAL bindIndexedImplementationDefault(); void MAGNUM_LOCAL bindIndexedImplementationVAO(); static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation; - - Buffer* _indexBuffer; - GLsizei _indexCount; - IndexType _indexType; }; } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index a083e11df..148c52c71 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -47,6 +47,10 @@ std::size_t Mesh::indexSize(IndexType type) { CORRADE_INTERNAL_ASSERT(false); } +Mesh::Mesh(Primitive primitive): _primitive(primitive), _vertexCount(0), _indexBuffer(nullptr), _indexCount(0), _indexType(IndexType::UnsignedInt) { + (this->*createImplementation)(); +} + Mesh::~Mesh() { /* Remove current vao from the state */ GLuint& current = Context::current()->state()->mesh->currentVAO; @@ -55,7 +59,7 @@ Mesh::~Mesh() { (this->*destroyImplementation)(); } -Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), attributes(std::move(other.attributes)) +Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexBuffer(other._indexBuffer), _indexCount(other._indexCount), _indexType(other._indexType), attributes(std::move(other.attributes)) #ifndef MAGNUM_TARGET_GLES2 , integerAttributes(std::move(other.integerAttributes)) #ifndef MAGNUM_TARGET_GLES @@ -72,6 +76,9 @@ Mesh& Mesh::operator=(Mesh&& other) { vao = other.vao; _primitive = other._primitive; _vertexCount = other._vertexCount; + _indexBuffer = other._indexBuffer; + _indexCount = other._indexCount; + _indexType = other._indexType; attributes = std::move(other.attributes); #ifndef MAGNUM_TARGET_GLES2 integerAttributes = std::move(other.integerAttributes); diff --git a/src/Mesh.h b/src/Mesh.h index 39dc43f11..efadddd73 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -385,9 +385,7 @@ class MAGNUM_EXPORT Mesh { * @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if * @extension{APPLE,vertex_array_object} is available) */ - inline explicit Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0) { - (this->*createImplementation)(); - } + explicit Mesh(Primitive primitive = Primitive::Triangles); /** @brief Move constructor */ Mesh(Mesh&& other); @@ -435,6 +433,36 @@ class MAGNUM_EXPORT Mesh { return this; } + /** @brief Index count */ + inline GLsizei indexCount() const { return _indexCount; } + + /** + * @brief Set index count + * @return Pointer to self (for method chaining) + * + * Default is zero. + * @see setIndexBuffer(), setIndexType(), MeshTools::compressIndices() + */ + inline Mesh* setIndexCount(GLsizei count) { + _indexCount = count; + return this; + } + + /** @brief Index type */ + inline IndexType indexType() const { return _indexType; } + + /** + * @brief Set index type + * @return Pointer to self (for method chaining) + * + * Default is @ref IndexType "IndexType::UnsignedInt". + * @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices() + */ + inline Mesh* setIndexType(IndexType type) { + _indexType = type; + return this; + } + /** * @brief Add buffer with non-interleaved vertex attributes for use with given shader * @return Pointer to self (for method chaining) @@ -716,7 +744,7 @@ class MAGNUM_EXPORT Mesh { typedef void(Mesh::*CreateImplementation)(); void MAGNUM_LOCAL createImplementationDefault(); void MAGNUM_LOCAL createImplementationVAO(); - static CreateImplementation createImplementation; + static MAGNUM_LOCAL CreateImplementation createImplementation; typedef void(Mesh::*DestroyImplementation)(); void MAGNUM_LOCAL destroyImplementationDefault(); @@ -762,6 +790,9 @@ class MAGNUM_EXPORT Mesh { GLuint vao; Primitive _primitive; GLsizei _vertexCount; + Buffer* _indexBuffer; + GLsizei _indexCount; + IndexType _indexType; std::vector attributes; #ifndef MAGNUM_TARGET_GLES2 From 9449e330d2c41f800863239e5f2e899b0fc2d396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 16:57:25 +0100 Subject: [PATCH 203/567] Saving index buffer pointer only if not using VAOs. With VAOs it is not used anyway, might remove the member variable for platforms with mandatory VAO support altogether. --- src/IndexedMesh.cpp | 16 +++++----------- src/IndexedMesh.h | 14 +++++++++----- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index dbd2cd321..99d7ddb3c 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -24,12 +24,6 @@ namespace Magnum { IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; -IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) { - _indexBuffer = buffer; - (this->*bindIndexBufferImplementation)(); - return this; -} - void IndexedMesh::draw() { if(!_indexCount) return; @@ -41,8 +35,6 @@ void IndexedMesh::draw() { } void IndexedMesh::bind() { - CORRADE_ASSERT(!_indexCount || _indexBuffer, "IndexedMesh: index buffer must be added if index count is non-zero", ); - Mesh::bind(); (this->*bindIndexedImplementation)(); } @@ -61,11 +53,13 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { #endif } -void IndexedMesh::bindIndexBufferImplementationDefault() {} +void IndexedMesh::bindIndexBufferImplementationDefault(Buffer* buffer) { + _indexBuffer = buffer; +} -void IndexedMesh::bindIndexBufferImplementationVAO() { +void IndexedMesh::bindIndexBufferImplementationVAO(Buffer* buffer) { bindVAO(vao); - _indexBuffer->bind(Buffer::Target::ElementArray); + buffer->bind(Buffer::Target::ElementArray); } void IndexedMesh::bindIndexedImplementationDefault() { diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 965438429..046a74ae1 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -83,12 +83,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { /** * @brief Set index buffer + * @return Pointer to self (for method chaining) * * @see setIndexCount(), setIndexType(), MeshTools::compressIndices(), * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - IndexedMesh* setIndexBuffer(Buffer* buffer); + inline IndexedMesh* setIndexBuffer(Buffer* buffer) { + (this->*bindIndexBufferImplementation)(buffer); + return this; + } /** * @brief Draw the mesh @@ -140,10 +144,10 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { void MAGNUM_LOCAL bind(); - typedef void(IndexedMesh::*BindIndexBufferImplementation)(); - void MAGNUM_LOCAL bindIndexBufferImplementationDefault(); - void MAGNUM_LOCAL bindIndexBufferImplementationVAO(); - static MAGNUM_LOCAL BindIndexBufferImplementation bindIndexBufferImplementation; + typedef void(IndexedMesh::*BindIndexBufferImplementation)(Buffer*); + void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer); + void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer); + static BindIndexBufferImplementation bindIndexBufferImplementation; typedef void(IndexedMesh::*BindIndexedImplementation)(); void MAGNUM_LOCAL bindIndexedImplementationDefault(); From dfb9491433d0cb14ff26a6219ff0abe4ef520ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 16:59:27 +0100 Subject: [PATCH 204/567] Saving vertex attribute parameters only if not using VAOs. Same reasoning as in previous commit. --- src/Mesh.cpp | 14 +++++++++----- src/Mesh.h | 18 +++++------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 148c52c71..07e5b0dea 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -113,8 +113,6 @@ void Mesh::bindVAO(GLuint vao) { } void Mesh::bind() { - CORRADE_ASSERT((_vertexCount != 0) || !attributes.empty(), "Mesh: attributes are bound but vertex count is zero", ); - (this->*bindImplementation)(); } @@ -187,7 +185,9 @@ void Mesh::destroyImplementationVAO() { #endif } -void Mesh::attributePointerImplementationDefault(const Attribute&) {} +void Mesh::attributePointerImplementationDefault(const Attribute& attribute) { + attributes.push_back(attribute); +} void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { bindVAO(vao); @@ -202,7 +202,9 @@ void Mesh::attributePointerImplementationDSA(const Attribute& attribute) { #endif #ifndef MAGNUM_TARGET_GLES2 -void Mesh::attributePointerImplementationDefault(const IntegerAttribute&) {} +void Mesh::attributePointerImplementationDefault(const IntegerAttribute& attribute) { + integerAttributes.push_back(attribute); +} void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) { bindVAO(vao); @@ -217,7 +219,9 @@ void Mesh::attributePointerImplementationDSA(const IntegerAttribute& attribute) #endif #ifndef MAGNUM_TARGET_GLES -void Mesh::attributePointerImplementationDefault(const LongAttribute&) {} +void Mesh::attributePointerImplementationDefault(const LongAttribute& attribute) { + longAttributes.push_back(attribute); +} void Mesh::attributePointerImplementationVAO(const LongAttribute& attribute) { bindVAO(vao); diff --git a/src/Mesh.h b/src/Mesh.h index efadddd73..b4313d2d9 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -678,8 +678,8 @@ class MAGNUM_EXPORT Mesh { inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { - for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { - attributes.push_back({ + for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) + (this->*attributePointerImplementation)(Attribute{ buffer, location+i, Implementation::Attribute::components(attribute.dataOptions()), @@ -688,14 +688,11 @@ class MAGNUM_EXPORT Mesh { offset, stride }); - - (this->*attributePointerImplementation)(attributes.back()); - } } #ifndef MAGNUM_TARGET_GLES2 template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { - integerAttributes.push_back({ + (this->*attributeIPointerImplementation)(IntegerAttribute{ buffer, location, Implementation::Attribute::components(), @@ -703,14 +700,12 @@ class MAGNUM_EXPORT Mesh { offset, stride }); - - (this->*attributeIPointerImplementation)(integerAttributes.back()); } #ifndef MAGNUM_TARGET_GLES template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { - for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) { - longAttributes.push_back({ + for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) + (this->*attributeLPointerImplementation)(LongAttribute{ buffer, location+i, Implementation::Attribute::components(), @@ -718,9 +713,6 @@ class MAGNUM_EXPORT Mesh { offset, stride }); - - (this->*attributeLPointerImplementation)(longAttributes.back()); - } } #endif #endif From a2a66803bedb7c69eefb8eb07b1cef974c61d74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 17:21:25 +0100 Subject: [PATCH 205/567] Removing IndexedMesh, part 3: moved last remaining setter to Mesh. Now only the drawing mess needs to be merged. --- src/IndexedMesh.cpp | 11 ---------- src/IndexedMesh.h | 50 --------------------------------------------- src/Mesh.cpp | 11 ++++++++++ src/Mesh.h | 18 ++++++++++++++++ 4 files changed, 29 insertions(+), 61 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 99d7ddb3c..f293be19a 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -21,7 +21,6 @@ namespace Magnum { -IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; void IndexedMesh::draw() { @@ -45,7 +44,6 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; - bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationVAO; bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; } #else @@ -53,15 +51,6 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { #endif } -void IndexedMesh::bindIndexBufferImplementationDefault(Buffer* buffer) { - _indexBuffer = buffer; -} - -void IndexedMesh::bindIndexBufferImplementationVAO(Buffer* buffer) { - bindVAO(vao); - buffer->bind(Buffer::Target::ElementArray); -} - void IndexedMesh::bindIndexedImplementationDefault() { if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); else Buffer::unbind(Buffer::Target::ElementArray); diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 046a74ae1..0c777f9c2 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -81,19 +81,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {} - /** - * @brief Set index buffer - * @return Pointer to self (for method chaining) - * - * @see setIndexCount(), setIndexType(), MeshTools::compressIndices(), - * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if - * @extension{APPLE,vertex_array_object} is available) - */ - inline IndexedMesh* setIndexBuffer(Buffer* buffer) { - (this->*bindIndexBufferImplementation)(buffer); - return this; - } - /** * @brief Draw the mesh * @@ -107,48 +94,11 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ void draw() override; - /* Overloads to remove WTF-factor from method chaining order */ - #ifndef DOXYGEN_GENERATING_OUTPUT - inline IndexedMesh* setPrimitive(Primitive primitive) { - Mesh::setPrimitive(primitive); - return this; - } - inline IndexedMesh* setVertexCount(GLsizei vertexCount) { - Mesh::setVertexCount(vertexCount); - return this; - } - inline IndexedMesh* setIndexCount(GLsizei count) { - Mesh::setIndexCount(count); - return this; - } - inline IndexedMesh* setIndexType(IndexType type) { - Mesh::setIndexType(type); - return this; - } - template inline IndexedMesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { - Mesh::addVertexBuffer(buffer, attributes...); - return this; - } - template inline IndexedMesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { - Mesh::addInterleavedVertexBuffer(buffer, offset, attributes...); - return this; - } - template inline IndexedMesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { - Mesh::addVertexBufferStride(buffer, offset, stride, attribute); - return this; - } - #endif - private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); void MAGNUM_LOCAL bind(); - typedef void(IndexedMesh::*BindIndexBufferImplementation)(Buffer*); - void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer); - void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer); - static BindIndexBufferImplementation bindIndexBufferImplementation; - typedef void(IndexedMesh::*BindIndexedImplementation)(); void MAGNUM_LOCAL bindIndexedImplementationDefault(); void MAGNUM_LOCAL bindIndexedImplementationVAO(); diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 07e5b0dea..14e2a73fb 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -34,6 +34,7 @@ Mesh::AttributeIPointerImplementation Mesh::attributeIPointerImplementation = &M Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &Mesh::attributePointerImplementationDefault; #endif #endif +Mesh::BindIndexBufferImplementation Mesh::bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationDefault; Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; @@ -159,6 +160,7 @@ void Mesh::initializeContextBasedFunctionality(Context* context) { attributeLPointerImplementation = &Mesh::attributePointerImplementationVAO; } + bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationVAO; bindImplementation = &Mesh::bindImplementationVAO; unbindImplementation = &Mesh::unbindImplementationVAO; } @@ -235,6 +237,15 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { #endif #endif +void Mesh::bindIndexBufferImplementationDefault(Buffer* buffer) { + _indexBuffer = buffer; +} + +void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) { + bindVAO(vao); + buffer->bind(Buffer::Target::ElementArray); +} + void Mesh::bindImplementationDefault() { for(const Attribute& attribute: attributes) vertexAttribPointer(attribute); diff --git a/src/Mesh.h b/src/Mesh.h index b4313d2d9..d3759c7ab 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -592,6 +592,19 @@ class MAGNUM_EXPORT Mesh { return this; } + /** + * @brief Set index buffer + * @return Pointer to self (for method chaining) + * + * @see setIndexCount(), setIndexType(), MeshTools::compressIndices(), + * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if + * @extension{APPLE,vertex_array_object} is available) + */ + inline Mesh* setIndexBuffer(Buffer* buffer) { + (this->*bindIndexBufferImplementation)(buffer); + return this; + } + /** * @brief Draw the mesh * @@ -769,6 +782,11 @@ class MAGNUM_EXPORT Mesh { #endif #endif + typedef void(Mesh::*BindIndexBufferImplementation)(Buffer*); + void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer); + void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer); + static BindIndexBufferImplementation bindIndexBufferImplementation; + typedef void(Mesh::*BindImplementation)(); void MAGNUM_LOCAL bindImplementationDefault(); void MAGNUM_LOCAL bindImplementationVAO(); From a8abbdb7d398f7855f9e0c8982187f895712d453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 17:43:54 +0100 Subject: [PATCH 206/567] Removing IndexedMesh, part 4: merged draw algorithm. Still source-compatible, next step is to merge the documentation and remove IndexedMesh stub altogether. --- src/CMakeLists.txt | 1 - src/Context.cpp | 2 -- src/IndexedMesh.cpp | 61 --------------------------------------------- src/IndexedMesh.h | 23 ----------------- src/Mesh.cpp | 24 ++++++++++++------ src/Mesh.h | 13 +++------- 6 files changed, 19 insertions(+), 105 deletions(-) delete mode 100644 src/IndexedMesh.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c74e2888..666f1c0d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,6 @@ set(Magnum_SRCS DefaultFramebuffer.cpp Framebuffer.cpp Image.cpp - IndexedMesh.cpp Mesh.cpp Query.cpp Renderbuffer.cpp diff --git a/src/Context.cpp b/src/Context.cpp index 1318757f7..bcc9518ec 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -29,7 +29,6 @@ #include "DefaultFramebuffer.h" #include "Extensions.h" #include "Framebuffer.h" -#include "IndexedMesh.h" #include "Mesh.h" #include "Renderbuffer.h" @@ -355,7 +354,6 @@ Context::Context() { DebugMarker::initializeContextBasedFunctionality(this); DefaultFramebuffer::initializeContextBasedFunctionality(this); Framebuffer::initializeContextBasedFunctionality(this); - IndexedMesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this); Renderbuffer::initializeContextBasedFunctionality(this); } diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp deleted file mode 100644 index f293be19a..000000000 --- a/src/IndexedMesh.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "IndexedMesh.h" - -#include "Buffer.h" -#include "Context.h" -#include "Extensions.h" - -namespace Magnum { - -IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; - -void IndexedMesh::draw() { - if(!_indexCount) return; - - bind(); - - glDrawElements(static_cast(primitive()), _indexCount, static_cast(_indexType), nullptr); - - unbind(); -} - -void IndexedMesh::bind() { - Mesh::bind(); - (this->*bindIndexedImplementation)(); -} - -void IndexedMesh::initializeContextBasedFunctionality(Context* context) { - /** @todo VAOs are in ES 3.0 and as extension in ES 2.0, enable them when some extension wrangler is available */ - #ifndef MAGNUM_TARGET_GLES - if(context->isExtensionSupported()) { - Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; - - bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; - } - #else - static_cast(context); - #endif -} - -void IndexedMesh::bindIndexedImplementationDefault() { - if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); - else Buffer::unbind(Buffer::Target::ElementArray); -} - -void IndexedMesh::bindIndexedImplementationVAO() {} - -} diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 0c777f9c2..ea06a9513 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -80,29 +80,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * no vertex or index buffers. */ inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {} - - /** - * @brief Draw the mesh - * - * Expects an active shader with all uniforms set. See - * @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" - * for more information. - * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, - * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} - * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} - * is available), @fn_gl{DrawElements} - */ - void draw() override; - - private: - static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); - - void MAGNUM_LOCAL bind(); - - typedef void(IndexedMesh::*BindIndexedImplementation)(); - void MAGNUM_LOCAL bindIndexedImplementationDefault(); - void MAGNUM_LOCAL bindIndexedImplementationVAO(); - static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation; }; } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 14e2a73fb..4b4da14da 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -94,13 +94,18 @@ Mesh& Mesh::operator=(Mesh&& other) { } void Mesh::draw() { - if(!_vertexCount) return; + /* Nothing to draw */ + if(!_vertexCount && !_indexCount) return; - bind(); + (this->*bindImplementation)(); + + /* Non-indexed mesh */ + if(!_indexCount) glDrawArrays(static_cast(_primitive), 0, _vertexCount); - glDrawArrays(static_cast(_primitive), 0, _vertexCount); + /* Indexed mesh */ + else glDrawElements(static_cast(_primitive), _indexCount, static_cast(_indexType), nullptr); - unbind(); + (this->*unbindImplementation)(); } void Mesh::bindVAO(GLuint vao) { @@ -113,10 +118,6 @@ void Mesh::bindVAO(GLuint vao) { #endif } -void Mesh::bind() { - (this->*bindImplementation)(); -} - void Mesh::vertexAttribPointer(const Attribute& attribute) { glEnableVertexAttribArray(attribute.location); attribute.buffer->bind(Buffer::Target::Array); @@ -247,6 +248,7 @@ void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) { } void Mesh::bindImplementationDefault() { + /* Specify vertex attributes */ for(const Attribute& attribute: attributes) vertexAttribPointer(attribute); @@ -259,6 +261,12 @@ void Mesh::bindImplementationDefault() { vertexAttribPointer(attribute); #endif #endif + + /* Bind index buffer, if the mesh is indexed */ + if(_indexCount) { + if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); + else Buffer::unbind(Buffer::Target::ElementArray); + } } void Mesh::bindImplementationVAO() { diff --git a/src/Mesh.h b/src/Mesh.h index d3759c7ab..b3956b716 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -119,7 +119,6 @@ more information. @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ class MAGNUM_EXPORT Mesh { - friend class IndexedMesh; friend class Context; Mesh(const Mesh& other) = delete; @@ -396,7 +395,7 @@ class MAGNUM_EXPORT Mesh { * @see @fn_gl{DeleteVertexArrays} (if * @extension{APPLE,vertex_array_object} is available) */ - virtual ~Mesh(); + ~Mesh(); /** @brief Move assignment */ Mesh& operator=(Mesh&& other); @@ -614,9 +613,9 @@ class MAGNUM_EXPORT Mesh { * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} - * is available), @fn_gl{DrawArrays} + * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements} */ - virtual void draw(); + void draw(); private: #ifndef DOXYGEN_GENERATING_OUTPUT @@ -732,12 +731,6 @@ class MAGNUM_EXPORT Mesh { static void MAGNUM_LOCAL bindVAO(GLuint vao); - void MAGNUM_LOCAL bind(); - - inline void unbind() { - (this->*unbindImplementation)(); - } - void MAGNUM_LOCAL vertexAttribPointer(const Attribute& attribute); #ifndef MAGNUM_TARGET_GLES2 void MAGNUM_LOCAL vertexAttribPointer(const IntegerAttribute& attribute); From dc5a4d83d91a5c338e1e4eef19d2c16e64eb5ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 18:42:19 +0100 Subject: [PATCH 207/567] Removing IndexedMesh, part 5: merged documentation, removed IndexedMesh. --- src/CMakeLists.txt | 1 - .../Implementation/AbstractBoxRenderer.cpp | 3 +- src/DebugTools/ObjectRenderer.cpp | 9 +- src/IndexedMesh.h | 87 ---------- src/Magnum.h | 1 - src/Mesh.h | 150 ++++++++++++++---- src/MeshTools/CompressIndices.cpp | 18 +-- src/MeshTools/CompressIndices.h | 17 +- src/MeshTools/Test/CompressIndicesTest.cpp | 22 +-- src/Text/TextRenderer.cpp | 9 +- src/Text/TextRenderer.h | 2 +- 11 files changed, 161 insertions(+), 158 deletions(-) delete mode 100644 src/IndexedMesh.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 666f1c0d3..833bdc617 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,7 +65,6 @@ set(Magnum_HEADERS Framebuffer.h Image.h ImageWrapper.h - IndexedMesh.h Magnum.h Mesh.h Query.h diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index e3283626b..2d74d216e 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -16,7 +16,6 @@ #include "AbstractBoxRenderer.h" #include "Buffer.h" -#include "IndexedMesh.h" #include "DebugTools/ResourceManager.h" #include "MeshTools/CompressIndices.h" #include "Primitives/Cube.h" @@ -66,7 +65,7 @@ AbstractBoxRenderer<3>::AbstractBoxRenderer() { Primitives::Cube cube; Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); - IndexedMesh* mesh = new IndexedMesh; + Mesh* mesh = new Mesh; vertexBuffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 39367cc56..5285f15e4 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -16,7 +16,6 @@ #include "ObjectRenderer.h" #include "Buffer.h" -#include "IndexedMesh.h" #include "DebugTools/ResourceManager.h" #include "MeshTools/Interleave.h" #include "SceneGraph/AbstractCamera.h" @@ -149,7 +148,7 @@ template ObjectRenderer::ObjectRenderer(Sce /* Create the mesh */ Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); - IndexedMesh* mesh = new IndexedMesh; + Mesh* mesh = new Mesh; MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, Renderer::positions, Renderer::colors); ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); @@ -158,9 +157,11 @@ template ObjectRenderer::ObjectRenderer(Sce ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); mesh->setPrimitive(Mesh::Primitive::Lines) - ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColorShader::Position(), typename Shaders::VertexColorShader::Color()) ->setIndexCount(Renderer::indices.size()) - ->setIndexType(IndexedMesh::IndexType::UnsignedByte) + ->setIndexType(Mesh::IndexType::UnsignedByte) + ->addInterleavedVertexBuffer(vertexBuffer, 0, + typename Shaders::VertexColorShader::Position(), + typename Shaders::VertexColorShader::Color()) ->setIndexBuffer(indexBuffer); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h deleted file mode 100644 index ea06a9513..000000000 --- a/src/IndexedMesh.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef Magnum_IndexedMesh_h -#define Magnum_IndexedMesh_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::IndexedMesh - */ - -#include "Mesh.h" - -#include "corradeCompatibility.h" - -namespace Magnum { - -/** -@brief Indexed mesh - -@section IndexedMesh-configuration Indexed mesh configuration - -Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you -have to call also setIndexCount() and setIndexType(). Then create index buffer -and assign it to the mesh using setIndexBuffer() or use -MeshTools::compressIndices() to conveniently fill the index buffer and set -index count and type. - -Similarly as in Mesh itself the index buffer is not managed by the mesh, so -you have to manage it on your own. On the other hand it allows you to use -one index buffer for more meshes (with different vertex data in each mesh, for -example) or store more than only index data in one buffer. - -Example usage -- creating a cube mesh, assigning vertex buffer with -interleaved vertex attributes and compressed index buffer for use with -Shaders::PhongShader: -@code -Buffer *vertexBuffer, *indexBuffer; -Mesh* mesh; - -Primitives::Cube cube; -MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, *cube.positions(0), *cube.normals(0)); -MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cube.indices()); -mesh->setPrimitive(plane.primitive()) - ->addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); -@endcode - -@section IndexedMesh-drawing Rendering meshes - -From user point-of-view the operation is the same as for -@ref Mesh-drawing "non-indexed meshes". - -@section IndexedMesh-performance-optimization Performance optimizations - -If @extension{APPLE,vertex_array_object}, OpenGL ES 3.0 or -@es_extension{OES,vertex_array_object} on OpenGL ES 2.0 is supported, next to -@ref Mesh-performance-optimization "optimizations in Mesh itself" the index -buffer is bound on object construction instead of binding it in every draw() -call. -*/ -class MAGNUM_EXPORT IndexedMesh: public Mesh { - friend class Context; - - public: - /** - * @brief Constructor - * @param primitive Primitive type - * - * Creates indexed mesh with zero vertex count, zero index count and - * no vertex or index buffers. - */ - inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {} -}; - -} - -#endif diff --git a/src/Magnum.h b/src/Magnum.h index 5880f51e9..017261599 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -172,7 +172,6 @@ typedef ImageWrapper<1> ImageWrapper1D; typedef ImageWrapper<2> ImageWrapper2D; typedef ImageWrapper<3> ImageWrapper3D; -class IndexedMesh; class Mesh; class Query; class Renderbuffer; diff --git a/src/Mesh.h b/src/Mesh.h index b3956b716..02b60c9ea 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -28,75 +28,168 @@ namespace Magnum { /** -@brief Non-indexed mesh +@brief %Mesh @section Mesh-configuration Mesh configuration -To properly configure mesh, you have to set primitive either in constructor or -using setPrimitive() and call setVertexCount(). Then create vertex buffers and -fill them with vertex data. You can also use MeshTools::interleave() to -conveniently set vertex count and buffer data. At last assign them to mesh and -@ref AbstractShaderProgram::Attribute "shader attributes" using -addVertexBuffer(), addInterleavedVertexBuffer() or addVertexBufferStride(). +You have to specify at least primitive and vertex count using setPrimitive() +and setVertexCount(). Then fill your vertex buffers with data, add them to the +mesh and specify @ref AbstractShaderProgram::Attribute "shader attribute" layout +inside the buffers using addVertexBuffer(), addInterleavedVertexBuffer() or +addVertexBufferStride(). You can also use MeshTools::interleave() in +combination with addInterleavedVertexBuffer() to conveniently fill interleaved +vertex buffer(s). The function itself calls setVertexCount(), so you don't +have to do it again. -Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, -so you have to manage it on your own. On the other hand it allows you to use -one buffer for more meshes (each mesh for example configured for different -shader) or store more than only vertex data in one buffer. +If you have indexed mesh, you need to call setIndexCount() instead of +setVertexCount() and additionaly specify also index type using setIndexType(). +Then fill your index buffer with data and add it to the mesh using +setIndexBuffer(). You can also use MeshTools::compressIndices() to +conveniently compress the indices, fill the index buffer and configure the +mesh instead of calling setIndexCount(), setIndexType() and setIndexBuffer() +manually. + +Note that neither vertex buffers nor index buffer is managed (e.g. deleted on +destruction) by the mesh, so you have to manage them on your own. On the other +hand it allows you to use one buffer for more meshes (each mesh for example +configured for different shader) or store data for more meshes in one buffer. + +If the mesh has non-zero index count, it is treated as indexed mesh, otherwise +it is treated as non-indexed mesh. If both index and vertex count is zero, the +mesh is empty and no draw commands are issued when calling draw(). + +@subsection Mesh-configuration-examples Example mesh configuration + +@subsubsection Mesh-configuration-examples-nonindexed Basic non-indexed mesh -Example usage -- filling buffer with position data, configuring the mesh and -assigning the buffer to mesh to use with custom shader: @code +// Custom shader, needing only position data class MyShader: public AbstractShaderProgram { public: typedef Attribute<0, Point3D> Position; // ... }; -Buffer* buffer; Mesh* mesh; +Buffer* vertexBuffer; +// Fill vertex buffer with position data static constexpr Point3D positions[30] = { // ... }; -buffer->setData(positions, Buffer::Usage::StaticDraw); +vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); +// Set primitive and vertex count, add the buffer and specify its layout mesh->setPrimitive(Mesh::Primitive::Triangles) ->setVertexCount(30) - ->addVertexBuffer(buffer, MyShader::Position()); + ->addVertexBuffer(vertexBuffer, 0, MyShader::Position()); @endcode -Example usage -- creating a plane mesh and assigning buffer with interleaved -vertex attributes for use with Shaders::PhongShader: +@subsubsection Mesh-configuration-examples-nonindexed-phong Interleaved vertex data + @code -Buffer* buffer; +// Non-indexed primitive with positions and normals +Primitives::Plane plane; Mesh* mesh; +Buffer* vertexBuffer; -Primitives::Plane plane; -MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, *plane.positions(0), *plane.normals(0)); +// Fill vertex buffer with interleaved position and normal data +MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, + *plane.positions(0), *plane.normals(0)); + +// Set primitive and specify layout of interleaved vertex buffer, vertex count +// has been already set by MeshTools::interleave() +mesh->setPrimitive(plane.primitive()) + ->addInterleavedVertexBuffer(buffer, 0, + Shaders::PhongShader::Position(), + Shaders::PhongShader::Normal()); +@endcode + +@subsubsection Mesh-configuration-examples-indexed-phong Indexed mesh + +@code +// Custom shader +class MyShader: public AbstractShaderProgram { + public: + typedef Attribute<0, Point3D> Position; + + // ... +}; +Buffer *vertexBuffer, *indexBuffer; +Mesh* mesh; + +// Fill vertex buffer with position data +static constexpr Point3D positions[30] = { + // ... +}; +vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); + +// Fill index buffer with index data +static constexpr GLubyte indices[75] = { + // ... +}; +indexBuffer->setData(indices, Buffer::Usage::StaticDraw); + +// Set primitive, index count and type, add the buffers +mesh->setPrimitive(Mesh::Primitive::Triangles) + ->setIndexCount(75) + ->setIndexType(Mesh::IndexType::UnsignedByte) + ->addVertexBuffer(vertexBuffer, 0, MyShader::Position()) + ->setIndexBuffer(indexBuffer); +@endcode + +@code +// Indexed primitive +Primitives::Cube cube; +Buffer *vertexBuffer, *indexBuffer; +Mesh* mesh; + +// Fill vertex buffer with interleaved position and normal data +MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, + *cube.positions(0), *cube.normals(0)); + +// Fill index buffer with compressed index data +MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, + *cube.indices()); + +// Set primitive and specify layout of interleaved vertex buffer. Index count, +// type and index buffer has been already set by MeshTools::compressIndices(). mesh->setPrimitive(plane.primitive()) - ->addInterleavedVertexBuffer(buffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); + ->addInterleavedVertexBuffer(vertexBuffer, 0, + Shaders::PhongShader::Position(), + Shaders::PhongShader::Normal()); @endcode -Example usage -- passing color attribute as normalized unsigned byte with BGRA -component ordering (e.g. directly from @ref Trade::TgaImporter "TGA file"): +@subsubsection Mesh-configuration-examples-data-options Specific formats of vertex data + @code +// Custom shader with colors specified as four floating-point values class MyShader: public AbstractShaderProgram { public: typedef Attribute<1, Color4<>> Color; // ... }; -Buffer* buffer; Mesh* mesh; +Buffer* colorBuffer; + +// Fill vertex buffer with colors specified as four-byte BGRA (e.g. directly +// from TGA file) +GLubyte colors[4*30] = { + // ... +}; +colorBuffer.setData(colors, Buffer::Usage::StaticDraw); -mesh->addVertexBuffer(buffer, MyShader::Color(Type::UsignedByte, MyShader::Color::Normalized|MyShader::Color::BGRA)); +// Specify layout of color buffer -- each component is unsigned byte, we want +// to normalize them from [0, 255] to [0.0f, 1.0f] and reorder from BGRA +mesh->addVertexBuffer(colorBuffer, 0, + MyShader::Color(MyShader::Color::DataType::UsignedByte, MyShader::Color::DataOption::Normalized|MyShader::Color::DataOption::BGRA)); @endcode @section Mesh-drawing Rendering meshes Basic workflow is: bind specific framebuffer for drawing (if needed), set up -respective shader and bind required textures (see +respective shader, bind required textures (see @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" for more infromation) and call Mesh::draw(). @@ -114,7 +207,6 @@ calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for more information. -@see IndexedMesh @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ @@ -849,7 +941,7 @@ template<> struct MAGNUM_EXPORT ConfigurationValue { /** * @brief Read enum value as string * - * If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". + * If the value is invalid, returns @ref Magnum::Mesh::IndexType "Mesh::IndexType::UnsignedInt". */ static Magnum::Mesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); }; diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 2c8cda63c..7d3890517 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -25,12 +25,12 @@ namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace { -template constexpr IndexedMesh::IndexType indexType(); -template<> inline constexpr IndexedMesh::IndexType indexType() { return IndexedMesh::IndexType::UnsignedByte; } -template<> inline constexpr IndexedMesh::IndexType indexType() { return IndexedMesh::IndexType::UnsignedShort; } -template<> inline constexpr IndexedMesh::IndexType indexType() { return IndexedMesh::IndexType::UnsignedInt; } +template constexpr Mesh::IndexType indexType(); +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedByte; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedShort; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedInt; } -template inline std::tuple compress(const std::vector& indices) { +template inline std::tuple compress(const std::vector& indices) { char* buffer = new char[indices.size()*sizeof(T)]; for(std::size_t i = 0; i != indices.size(); ++i) { T index = static_cast(indices[i]); @@ -43,7 +43,7 @@ template inline std::tuple } #endif -std::tuple compressIndices(const std::vector& indices) { +std::tuple compressIndices(const std::vector& indices) { std::size_t size = *std::max_element(indices.begin(), indices.end()); switch(Math::log(256, size)) { @@ -60,16 +60,16 @@ std::tuple compressIndices(const std } } -void compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { +void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { std::size_t indexCount; - IndexedMesh::IndexType indexType; + Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = compressIndices(indices); mesh->setIndexBuffer(buffer) ->setIndexType(indexType) ->setIndexCount(indices.size()); - buffer->setData(indexCount*IndexedMesh::indexSize(indexType), data, usage); + buffer->setData(indexCount*Mesh::indexSize(indexType), data, usage); delete[] data; } diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 6141465fb..c68b991e6 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -22,7 +22,7 @@ #include #include "Buffer.h" -#include "IndexedMesh.h" +#include "Mesh.h" #include "magnumMeshToolsVisibility.h" @@ -41,18 +41,18 @@ sufficient. Size of the buffer can be computed from index count and type, as shown below. Example usage: @code std::size_t indexCount; -IndexedMesh::IndexType indexType; +Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices); -std::size_t dataSize = indexCount*IndexedMesh::indexSize(indexType); +std::size_t dataSize = indexCount*Mesh::indexSize(indexType); // ... delete[] data; @endcode -See also compressIndices(IndexedMesh*, Buffer*, Buffer::Usage, const std::vector&), +See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); +std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); /** @brief Compress vertex indices and write them to index buffer @@ -63,13 +63,12 @@ std::tuple MAGNUM_MESHTOOLS_EXPORT c The same as compressIndices(const std::vector&), but this function writes the output to given index buffer and updates index count and -type in the mesh accordingly, so you don't have to call -IndexedMesh::setIndexBuffer(), IndexedMesh::setIndexCount() and -IndexedMesh::setIndexType() on your own. +type in the mesh accordingly, so you don't have to call Mesh::setIndexBuffer(), +Mesh::setIndexCount() and Mesh::setIndexType() on your own. @see MeshTools::interleave() */ -void MAGNUM_MESHTOOLS_EXPORT compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); }} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index 56731f2c1..da0459b2c 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -39,14 +39,14 @@ CompressIndicesTest::CompressIndicesTest() { void CompressIndicesTest::compressChar() { std::size_t indexCount; - IndexedMesh::IndexType indexType; + Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); - CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedByte); - CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), + CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte); + CORRADE_COMPARE(std::vector(data, data+indexCount*Mesh::indexSize(indexType)), (std::vector{ 0x01, 0x02, 0x03, 0x00, 0x04 })); delete[] data; @@ -54,21 +54,21 @@ void CompressIndicesTest::compressChar() { void CompressIndicesTest::compressShort() { std::size_t indexCount; - IndexedMesh::IndexType indexType; + Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); - CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedShort); + CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort); if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*Mesh::indexSize(indexType)), (std::vector{ 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00 })); } else { - CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*Mesh::indexSize(indexType)), (std::vector{ 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, @@ -80,21 +80,21 @@ void CompressIndicesTest::compressShort() { void CompressIndicesTest::compressInt() { std::size_t indexCount; - IndexedMesh::IndexType indexType; + Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); - CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedInt); + CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt); if(!Endianness::isBigEndian()) { - CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*Mesh::indexSize(indexType)), (std::vector{ 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 })); } else { - CORRADE_COMPARE(std::vector(data, data+indexCount*IndexedMesh::indexSize(indexType)), + CORRADE_COMPARE(std::vector(data, data+indexCount*Mesh::indexSize(indexType)), (std::vector{ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02 })); diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 053cb5845..aacbba97d 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -20,7 +20,6 @@ #include "Math/Point2D.h" #include "Math/Point3D.h" -#include "IndexedMesh.h" #include "Swizzle.h" #include "MeshTools/CompressIndices.h" #include "MeshTools/Interleave.h" @@ -139,8 +138,8 @@ template std::tuple IndexedMesh TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { - IndexedMesh mesh; +template Mesh TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { + Mesh mesh; std::vector::PointType> positions; std::vector textureCoordinates; @@ -150,7 +149,9 @@ template IndexedMesh TextRenderer::render(F MeshTools::interleave(&mesh, vertexBuffer, usage, positions, textureCoordinates); MeshTools::compressIndices(&mesh, indexBuffer, usage, indices); mesh.setPrimitive(Mesh::Primitive::Triangles) - ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::AbstractTextShader::Position(), typename Shaders::AbstractTextShader::TextureCoordinates()); + ->addInterleavedVertexBuffer(vertexBuffer, 0, + typename Shaders::AbstractTextShader::Position(), + typename Shaders::AbstractTextShader::TextureCoordinates()); return mesh; } diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 81016d362..26322df2c 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -62,7 +62,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * @return Indexed mesh prepared for use with Shaders::AbstractTextShader * subclasses */ - static IndexedMesh render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + static Mesh render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); private: #ifndef DOXYGEN_GENERATING_OUTPUT From c593594c3f5a69cc955c3162c2ed76bdafb55221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 20:20:42 +0100 Subject: [PATCH 208/567] Doc++ --- src/AbstractImage.cpp | 2 ++ src/Mesh.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 3cc19a3a2..681a62e91 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -119,6 +119,7 @@ std::size_t AbstractImage::pixelSize(Format format, Type type) { return 0; } +#ifndef DOXYGEN_GENERATING_OUTPUT Debug operator<<(Debug debug, AbstractImage::Format value) { switch(value) { #define _c(value) case AbstractImage::Format::value: return debug << "AbstractImage::Format::" #value; @@ -201,5 +202,6 @@ Debug operator<<(Debug debug, AbstractImage::Type value) { return debug << "AbstractImage::Type::(invalid)"; } +#endif } diff --git a/src/Mesh.h b/src/Mesh.h index 02b60c9ea..f33b95cbf 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -588,8 +588,9 @@ class MAGNUM_EXPORT Mesh { * mesh->vertexCount(), Shaders::PhongShader::Normal()); * @endcode * - * @attention Non-zero vertex count must be set before calling this - * function. + * @attention The actual vertex count must be set before calling this + * function, otherwise vertex data positions in the buffer will + * be miscalculated. * @attention The buffer passed as parameter is not managed by the * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. From 834d08bdea813a8f59e2b83a02656c3acbb44495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 20:49:43 +0100 Subject: [PATCH 209/567] Emit fake glViewport() call for the first time if ApiTrace is detected. --- src/DefaultFramebuffer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index ec5319425..dac3e572a 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -72,6 +72,12 @@ void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); defaultFramebuffer._viewport = state->viewport = Rectanglei::fromSize({viewport[0], viewport[1]}, {viewport[2], viewport[3]}); + + /* Fake initial glViewport() call for ApiTrace */ + #ifndef MAGNUM_TARGET_GLES + if(context->isExtensionSupported()) + glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + #endif } } From 0c4d433f70d6d6e019874f835d0db5faff8d8dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 21:28:29 +0100 Subject: [PATCH 210/567] Quick dirty fix for element array buffer binding in VAOs. If no DSA is available and element array buffer was bound previously (e.g. because data were uploaded to it), after binding VAO the binding point is apparently reset to 0. But our state tracking thinks that the buffer is still bound and thus doesn't bind it explicitly again when asked for it. It causes crash in the driver, because it tries to read from zero adress in client memory instead of bound buffer. Needs to be solved properly, when I found out an clean solution. --- src/Mesh.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 4b4da14da..e23f5418b 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -20,6 +20,7 @@ #include "Buffer.h" #include "Context.h" #include "Extensions.h" +#include "Implementation/BufferState.h" #include "Implementation/MeshState.h" #include "Implementation/State.h" @@ -244,6 +245,11 @@ void Mesh::bindIndexBufferImplementationDefault(Buffer* buffer) { void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) { bindVAO(vao); + + /* Reset ElementArray binding to force explicit glBindBuffer call later */ + /** @todo Do this cleaner way */ + Context::current()->state()->buffer->bindings[Implementation::BufferState::indexForTarget(Buffer::Target::ElementArray)] = 0; + buffer->bind(Buffer::Target::ElementArray); } From ddb8cd505215b1daec7b0b28e94db29d0fd479b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 22:44:23 +0100 Subject: [PATCH 211/567] Blind fix for some image formats not present in ES3. I want ES3 in Mesa now so I can test that already. --- src/AbstractImage.cpp | 2 +- src/AbstractImage.h | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 681a62e91..5a0c320d5 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -103,7 +103,7 @@ std::size_t AbstractImage::pixelSize(Format format, Type type) { case Format::RGBAInteger: #endif case Format::BGRA: - #ifndef MAGNUM_TARGET_GLES2 + #ifndef MAGNUM_TARGET_GLES case Format::BGRAInteger: #endif return 4*size; diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 34a21b9cc..44b828b5c 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -130,21 +130,25 @@ class MAGNUM_EXPORT AbstractImage { */ RedInteger = GL_RED_INTEGER, + #ifndef MAGNUM_TARGET_GLES /** * Integer green channel. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gles30 Only floating-point image data are available - * in OpenGL ES 2.0. + * @requires_gl Only @ref Format "Format::RedInteger" is available + * in OpenGL ES 3.0, only floating-point image data are + * available in OpenGL ES 2.0. */ GreenInteger = GL_GREEN_INTEGER, /** * Integer blue channel. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gles30 Only floating-point image data are available - * in OpenGL ES 2.0. + * @requires_gl Only @ref Format "Format::RedInteger" is available + * in OpenGL ES 3.0, only floating-point image data are + * available in OpenGL ES 2.0. */ BlueInteger = GL_BLUE_INTEGER, + #endif /** * Integer red and green channel. @@ -171,22 +175,26 @@ class MAGNUM_EXPORT AbstractImage { */ RGBAInteger = GL_RGBA_INTEGER, + #ifndef MAGNUM_TARGET_GLES /** * Integer BGR. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gles30 Only floating-point image data are available - * in OpenGL ES 2.0. + * @requires_gl Only @ref Format "Format::RGBInteger" is available + * in OpenGL ES 3.0, only floating-point image data are + * available in OpenGL ES 2.0. */ BGRInteger = GL_BGR_INTEGER, /** * Integer BGRA. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gles30 Only floating-point image data are available - * in OpenGL ES 2.0. + * @requires_gl Only @ref Format "Format::RGBAInteger" is + * available in OpenGL ES 3.0, only floating-point image data + * are available in OpenGL ES 2.0. */ BGRAInteger = GL_BGRA_INTEGER, #endif + #endif /** * Depth component. For framebuffer reading only. From 389ed07806737801c72487e3a238355a5305b928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 23:56:50 +0100 Subject: [PATCH 212/567] SceneGraph: initial per-transformation unit tests. --- src/SceneGraph/Test/CMakeLists.txt | 6 +- .../EuclideanMatrixTransformation2DTest.cpp | 63 +++++++++++++++++++ .../EuclideanMatrixTransformation3DTest.cpp | 63 +++++++++++++++++++ .../Test/MatrixTransformation2DTest.cpp | 63 +++++++++++++++++++ .../Test/MatrixTransformation3DTest.cpp | 63 +++++++++++++++++++ 5 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp create mode 100644 src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp create mode 100644 src/SceneGraph/Test/MatrixTransformation2DTest.cpp create mode 100644 src/SceneGraph/Test/MatrixTransformation3DTest.cpp diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index aa0efa333..86f50974f 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -1,4 +1,8 @@ corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) -corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphEuclideanMatrixTr___2DTest EuclideanMatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphEuclideanMatrixTr___3DTest EuclideanMatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphMatrixTransformation2DTest MatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphMatrixTransformation3DTest MatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp new file mode 100644 index 000000000..86cc2e87f --- /dev/null +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/EuclideanMatrixTransformation2D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { + public: + explicit EuclideanMatrixTransformation2DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() { + addTests(&EuclideanMatrixTransformation2DTest::fromMatrix, + &EuclideanMatrixTransformation2DTest::toMatrix, + &EuclideanMatrixTransformation2DTest::compose, + &EuclideanMatrixTransformation2DTest::inverted); +} + +void EuclideanMatrixTransformation2DTest::fromMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::fromMatrix(m), m); +} + +void EuclideanMatrixTransformation2DTest::toMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::toMatrix(m), m); +} + +void EuclideanMatrixTransformation2DTest::compose() { + Matrix3 parent = Matrix3::rotation(deg(17.0f)); + Matrix3 child = Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::compose(parent, child), parent*child); +} + +void EuclideanMatrixTransformation2DTest::inverted() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp new file mode 100644 index 000000000..7c396d6a2 --- /dev/null +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/EuclideanMatrixTransformation3D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { + public: + explicit EuclideanMatrixTransformation3DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() { + addTests(&EuclideanMatrixTransformation3DTest::fromMatrix, + &EuclideanMatrixTransformation3DTest::toMatrix, + &EuclideanMatrixTransformation3DTest::compose, + &EuclideanMatrixTransformation3DTest::inverted); +} + +void EuclideanMatrixTransformation3DTest::fromMatrix() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::fromMatrix(m), m); +} + +void EuclideanMatrixTransformation3DTest::toMatrix() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::toMatrix(m), m); +} + +void EuclideanMatrixTransformation3DTest::compose() { + Matrix4 parent = Matrix4::rotationX(deg(17.0f)); + Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::compose(parent, child), parent*child); +} + +void EuclideanMatrixTransformation3DTest::inverted() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation3DTest) diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp new file mode 100644 index 000000000..e8ea6aa2d --- /dev/null +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/MatrixTransformation2D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class MatrixTransformation2DTest: public Corrade::TestSuite::Tester { + public: + explicit MatrixTransformation2DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +MatrixTransformation2DTest::MatrixTransformation2DTest() { + addTests(&MatrixTransformation2DTest::fromMatrix, + &MatrixTransformation2DTest::toMatrix, + &MatrixTransformation2DTest::compose, + &MatrixTransformation2DTest::inverted); +} + +void MatrixTransformation2DTest::fromMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::fromMatrix(m), m); +} + +void MatrixTransformation2DTest::toMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::toMatrix(m), m); +} + +void MatrixTransformation2DTest::compose() { + Matrix3 parent = Matrix3::rotation(deg(17.0f)); + Matrix3 child = Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::compose(parent, child), parent*child); +} + +void MatrixTransformation2DTest::inverted() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp new file mode 100644 index 000000000..0baf7850c --- /dev/null +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/MatrixTransformation3D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class MatrixTransformation3DTest: public Corrade::TestSuite::Tester { + public: + explicit MatrixTransformation3DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +MatrixTransformation3DTest::MatrixTransformation3DTest() { + addTests(&MatrixTransformation3DTest::fromMatrix, + &MatrixTransformation3DTest::toMatrix, + &MatrixTransformation3DTest::compose, + &MatrixTransformation3DTest::inverted); +} + +void MatrixTransformation3DTest::fromMatrix() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); + CORRADE_COMPARE(MatrixTransformation3D<>::fromMatrix(m), m); +} + +void MatrixTransformation3DTest::toMatrix() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); + CORRADE_COMPARE(MatrixTransformation3D<>::toMatrix(m), m); +} + +void MatrixTransformation3DTest::compose() { + Matrix4 parent = Matrix4::rotationX(deg(17.0f)); + Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(MatrixTransformation3D<>::compose(parent, child), parent*child); +} + +void MatrixTransformation3DTest::inverted() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); + CORRADE_COMPARE(MatrixTransformation3D<>::inverted(m)*m, Matrix4()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation3DTest) From 196c68ccf19fe28d17fff08829c82d879da6ef0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 00:23:04 +0100 Subject: [PATCH 213/567] DebugTools: added missing 3D alternatives. They are implemented internally, but I somehow forgot to add them to the switch. --- src/DebugTools/ShapeRenderer.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index bb5f6fe6a..75048b220 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -47,8 +47,18 @@ template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractSha } } -template<> void createDebugMesh(ShapeRenderer<3>*, Physics::AbstractShape<3>* shape) { +template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractShape<3>* shape) { switch(shape->type()) { + case Physics::AbstractShape3D::Type::AxisAlignedBox: + renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(*static_cast(shape))); + case Physics::AbstractShape3D::Type::Box: + renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast(shape))); + break; + case Physics::AbstractShape3D::Type::ShapeGroup: { + Physics::ShapeGroup3D* group = static_cast(shape); + if(group->first()) createDebugMesh(renderer, group->first()); + if(group->second()) createDebugMesh(renderer, group->second()); + } break; default: Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; } From dc798b73207f8f08a9f00e8b9f2b55a7783bd78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 00:29:08 +0100 Subject: [PATCH 214/567] Shaders: added missing 3D version of FlatShader vertex shader. Fragment shader is common for both 2D and 3D. --- src/Shaders/CMakeLists.txt | 2 +- src/Shaders/FlatShader.cpp | 18 +++++------------- .../{FlatShader2D.frag => FlatShader.frag} | 0 src/Shaders/FlatShader3D.vert | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) rename src/Shaders/{FlatShader2D.frag => FlatShader.frag} (100%) create mode 100644 src/Shaders/FlatShader3D.vert diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 5ea5c8577..95a50b182 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,5 +1,5 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders - FlatShader2D.vert FlatShader2D.frag + FlatShader2D.vert FlatShader3D.vert FlatShader.frag PhongShader.vert PhongShader.frag TextShader2D.vert TextShader2D.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index e962e8f5f..70b32361f 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -23,17 +23,9 @@ namespace Magnum { namespace Shaders { namespace { - template struct ShaderName {}; - - template<> struct ShaderName<2> { - constexpr static const char* vertex() { return "FlatShader2D.vert"; } - constexpr static const char* fragment() { return "FlatShader2D.frag"; } - }; - - template<> struct ShaderName<3> { - constexpr static const char* vertex() { return "FlatShader3D.vert"; } - constexpr static const char* fragment() { return "FlatShader3D.frag"; } - }; + template constexpr const char* vertexShaderName(); + template<> constexpr const char* vertexShaderName<2>() { return "FlatShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "FlatShader3D.vert"; } } template FlatShader::FlatShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { @@ -47,12 +39,12 @@ template FlatShader::FlatShader(): transfor Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); - vertexShader.addSource(rs.get(ShaderName::vertex())); + vertexShader.addSource(rs.get(vertexShaderName())); attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); - fragmentShader.addSource(rs.get(ShaderName::fragment())); + fragmentShader.addSource(rs.get("FlatShader.frag")); attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/FlatShader2D.frag b/src/Shaders/FlatShader.frag similarity index 100% rename from src/Shaders/FlatShader2D.frag rename to src/Shaders/FlatShader.frag diff --git a/src/Shaders/FlatShader3D.vert b/src/Shaders/FlatShader3D.vert new file mode 100644 index 000000000..69eaead28 --- /dev/null +++ b/src/Shaders/FlatShader3D.vert @@ -0,0 +1,19 @@ +#ifndef NEW_GLSL +#define in attribute +#endif + +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat4 transformationProjectionMatrix; +#else +uniform highp mat4 transformationProjectionMatrix; +#endif + +#ifdef EXPLICIT_ATTRIB_LOCATION +layout(location = 0) in highp vec4 position; +#else +in highp vec4 position; +#endif + +void main() { + gl_Position = transformationProjectionMatrix*position; +} From 64a064572471cd3f02658cc3e59637b71c28324b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 01:10:14 +0100 Subject: [PATCH 215/567] DebugTools: ObjectShape must contain shape when creating renderer. --- src/DebugTools/ShapeRenderer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 75048b220..d2dc636a5 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -68,6 +68,7 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha #endif template ShapeRenderer::ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { + CORRADE_INTERNAL_ASSERT(shape->shape() != nullptr); Implementation::createDebugMesh(this, shape->shape()); } From c52f64b381e59f616559d6a256ceeb1a4edc7463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 01:25:59 +0100 Subject: [PATCH 216/567] SceneGraph: testing everything in transformations. --- .../EuclideanMatrixTransformation2DTest.cpp | 82 +++++++++++- .../EuclideanMatrixTransformation3DTest.cpp | 98 +++++++++++++- .../Test/MatrixTransformation2DTest.cpp | 108 ++++++++++++++- .../Test/MatrixTransformation3DTest.cpp | 124 +++++++++++++++++- 4 files changed, 408 insertions(+), 4 deletions(-) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp index 86cc2e87f..d772b969e 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -17,9 +17,13 @@ #include "Math/Constants.h" #include "SceneGraph/EuclideanMatrixTransformation2D.h" +#include "SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { +typedef Object> Object2D; +typedef Scene> Scene2D; + class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { public: explicit EuclideanMatrixTransformation2DTest(); @@ -28,13 +32,25 @@ class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { void toMatrix(); void compose(); void inverted(); + + void setTransformation(); + void translate(); + void rotate(); + void reflect(); + void normalizeRotation(); }; EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() { addTests(&EuclideanMatrixTransformation2DTest::fromMatrix, &EuclideanMatrixTransformation2DTest::toMatrix, &EuclideanMatrixTransformation2DTest::compose, - &EuclideanMatrixTransformation2DTest::inverted); + &EuclideanMatrixTransformation2DTest::inverted, + + &EuclideanMatrixTransformation2DTest::setTransformation, + &EuclideanMatrixTransformation2DTest::translate, + &EuclideanMatrixTransformation2DTest::rotate, + &EuclideanMatrixTransformation2DTest::reflect, + &EuclideanMatrixTransformation2DTest::normalizeRotation); } void EuclideanMatrixTransformation2DTest::fromMatrix() { @@ -58,6 +74,70 @@ void EuclideanMatrixTransformation2DTest::inverted() { CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3()); } +void EuclideanMatrixTransformation2DTest::setTransformation() { + /* Dirty after setting transformation */ + Object2D o; + o.setClean(); + o.rotate(deg(17.0f)); + CORRADE_VERIFY(o.isDirty()); + + /* Scene cannot be transformed */ + Scene2D s; + s.setClean(); + s.rotate(deg(17.0f)); + CORRADE_VERIFY(!s.isDirty()); + CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); +} + +void EuclideanMatrixTransformation2DTest::translate() { + { + Object2D o; + o.rotate(deg(17.0f)); + o.translate({1.0f, -0.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + } { + Object2D o; + o.rotate(deg(17.0f)); + o.translate({1.0f, -0.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } +} + +void EuclideanMatrixTransformation2DTest::rotate() { + { + Object2D o; + o.translate({1.0f, -0.3f}); + o.rotate(deg(17.0f)); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } { + Object2D o; + o.translate({1.0f, -0.3f}); + o.rotate(deg(17.0f), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + } +} + +void EuclideanMatrixTransformation2DTest::reflect() { + { + Object2D o; + o.rotate(deg(17.0f)); + o.reflect(Vector2(-1.0f/Constants::sqrt2())); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f))); + } { + Object2D o; + o.rotate(deg(17.0f)); + o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); + } +} + +void EuclideanMatrixTransformation2DTest::normalizeRotation() { + Object2D o; + o.rotate(deg(17.0f)); + o.normalizeRotation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))); +} + }}} CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp index 7c396d6a2..ee1e79e0e 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -17,9 +17,13 @@ #include "Math/Constants.h" #include "SceneGraph/EuclideanMatrixTransformation3D.h" +#include "SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { +typedef Object> Object3D; +typedef Scene> Scene3D; + class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { public: explicit EuclideanMatrixTransformation3DTest(); @@ -28,13 +32,25 @@ class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { void toMatrix(); void compose(); void inverted(); + + void setTransformation(); + void translate(); + void rotate(); + void reflect(); + void normalizeRotation(); }; EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() { addTests(&EuclideanMatrixTransformation3DTest::fromMatrix, &EuclideanMatrixTransformation3DTest::toMatrix, &EuclideanMatrixTransformation3DTest::compose, - &EuclideanMatrixTransformation3DTest::inverted); + &EuclideanMatrixTransformation3DTest::inverted, + + &EuclideanMatrixTransformation3DTest::setTransformation, + &EuclideanMatrixTransformation3DTest::translate, + &EuclideanMatrixTransformation3DTest::rotate, + &EuclideanMatrixTransformation3DTest::reflect, + &EuclideanMatrixTransformation3DTest::normalizeRotation); } void EuclideanMatrixTransformation3DTest::fromMatrix() { @@ -58,6 +74,86 @@ void EuclideanMatrixTransformation3DTest::inverted() { CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4()); } +void EuclideanMatrixTransformation3DTest::setTransformation() { + /* Dirty after setting transformation */ + Object3D o; + o.setClean(); + o.rotateX(deg(17.0f)); + CORRADE_VERIFY(o.isDirty()); + + /* Scene cannot be transformed */ + Scene3D s; + s.setClean(); + s.rotateX(deg(17.0f)); + CORRADE_VERIFY(!s.isDirty()); + CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); +} + +void EuclideanMatrixTransformation3DTest::translate() { + { + Object3D o; + o.rotateX(deg(17.0f)); + o.translate({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + } { + Object3D o; + o.rotateX(deg(17.0f)); + o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + } +} + +void EuclideanMatrixTransformation3DTest::rotate() { + { + Object3D o; + o.translate({1.0f, -0.3f, 2.3f}); + o.rotateX(deg(17.0f)) + ->rotateY(deg(25.0f)) + ->rotateZ(deg(-23.0f)) + ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), + Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* + Matrix4::rotationZ(deg(-23.0f))* + Matrix4::rotationY(deg(25.0f))* + Matrix4::rotationX(deg(17.0f))* + Matrix4::translation({1.0f, -0.3f, 2.3f})); + } { + Object3D o; + o.translate({1.0f, -0.3f, 2.3f}); + o.rotateX(deg(17.0f), TransformationType::Local) + ->rotateY(deg(25.0f), TransformationType::Local) + ->rotateZ(deg(-23.0f), TransformationType::Local) + ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), + Matrix4::translation({1.0f, -0.3f, 2.3f})* + Matrix4::rotationX(deg(17.0f))* + Matrix4::rotationY(deg(25.0f))* + Matrix4::rotationZ(deg(-23.0f))* + Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + } +} + +void EuclideanMatrixTransformation3DTest::reflect() { + { + Object3D o; + o.rotateX(deg(17.0f)); + o.reflect(Vector3(-1.0f/Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f))); + } { + Object3D o; + o.rotateX(deg(17.0f)); + o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); + } +} + +void EuclideanMatrixTransformation3DTest::normalizeRotation() { + Object3D o; + o.rotateX(deg(17.0f)); + o.normalizeRotation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))); +} + }}} CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation3DTest) diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp index e8ea6aa2d..1960ad713 100644 --- a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -17,9 +17,13 @@ #include "Math/Constants.h" #include "SceneGraph/MatrixTransformation2D.h" +#include "SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { +typedef Object> Object2D; +typedef Scene> Scene2D; + class MatrixTransformation2DTest: public Corrade::TestSuite::Tester { public: explicit MatrixTransformation2DTest(); @@ -28,13 +32,27 @@ class MatrixTransformation2DTest: public Corrade::TestSuite::Tester { void toMatrix(); void compose(); void inverted(); + + void setTransformation(); + void transform(); + void translate(); + void rotate(); + void scale(); + void reflect(); }; MatrixTransformation2DTest::MatrixTransformation2DTest() { addTests(&MatrixTransformation2DTest::fromMatrix, &MatrixTransformation2DTest::toMatrix, &MatrixTransformation2DTest::compose, - &MatrixTransformation2DTest::inverted); + &MatrixTransformation2DTest::inverted, + + &MatrixTransformation2DTest::setTransformation, + &MatrixTransformation2DTest::transform, + &MatrixTransformation2DTest::translate, + &MatrixTransformation2DTest::rotate, + &MatrixTransformation2DTest::scale, + &MatrixTransformation2DTest::reflect); } void MatrixTransformation2DTest::fromMatrix() { @@ -58,6 +76,94 @@ void MatrixTransformation2DTest::inverted() { CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3()); } +void MatrixTransformation2DTest::setTransformation() { + /* Dirty after setting transformation */ + Object2D o; + o.setClean(); + CORRADE_VERIFY(!o.isDirty()); + o.setTransformation(Matrix3::rotation(deg(17.0f))); + CORRADE_VERIFY(o.isDirty()); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))); + + /* Scene cannot be transformed */ + Scene2D s; + s.setClean(); + CORRADE_VERIFY(!s.isDirty()); + s.setTransformation(Matrix3::rotation(deg(17.0f))); + CORRADE_VERIFY(!s.isDirty()); + CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); +} + +void MatrixTransformation2DTest::transform() { + { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.transform(Matrix3::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + } { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.transform(Matrix3::translation({1.0f, -0.3f}), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } +} + +void MatrixTransformation2DTest::translate() { + { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.translate({1.0f, -0.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + } { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.translate({1.0f, -0.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } +} + +void MatrixTransformation2DTest::rotate() { + { + Object2D o; + o.setTransformation(Matrix3::translation({1.0f, -0.3f})); + o.rotate(deg(17.0f)); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } { + Object2D o; + o.setTransformation(Matrix3::translation({1.0f, -0.3f})); + o.rotate(deg(17.0f), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + } +} + +void MatrixTransformation2DTest::scale() { + { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.scale({1.0f, -0.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + } { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.scale({1.0f, -0.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::scaling({1.0f, -0.3f})); + } +} + +void MatrixTransformation2DTest::reflect() { + { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.reflect(Vector2(-1.0f/Constants::sqrt2())); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f))); + } { + Object2D o; + o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); + } +} + }}} CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index 0baf7850c..a3dcf35a8 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -17,9 +17,13 @@ #include "Math/Constants.h" #include "SceneGraph/MatrixTransformation3D.h" +#include "SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { +typedef Object> Object3D; +typedef Scene> Scene3D; + class MatrixTransformation3DTest: public Corrade::TestSuite::Tester { public: explicit MatrixTransformation3DTest(); @@ -28,13 +32,27 @@ class MatrixTransformation3DTest: public Corrade::TestSuite::Tester { void toMatrix(); void compose(); void inverted(); + + void setTransformation(); + void transform(); + void translate(); + void rotate(); + void scale(); + void reflect(); }; MatrixTransformation3DTest::MatrixTransformation3DTest() { addTests(&MatrixTransformation3DTest::fromMatrix, &MatrixTransformation3DTest::toMatrix, &MatrixTransformation3DTest::compose, - &MatrixTransformation3DTest::inverted); + &MatrixTransformation3DTest::inverted, + + &MatrixTransformation3DTest::setTransformation, + &MatrixTransformation3DTest::transform, + &MatrixTransformation3DTest::translate, + &MatrixTransformation3DTest::rotate, + &MatrixTransformation3DTest::scale, + &MatrixTransformation3DTest::reflect); } void MatrixTransformation3DTest::fromMatrix() { @@ -58,6 +76,110 @@ void MatrixTransformation3DTest::inverted() { CORRADE_COMPARE(MatrixTransformation3D<>::inverted(m)*m, Matrix4()); } +void MatrixTransformation3DTest::setTransformation() { + /* Dirty after setting transformation */ + Object3D o; + o.setClean(); + CORRADE_VERIFY(!o.isDirty()); + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + CORRADE_VERIFY(o.isDirty()); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))); + + /* Scene cannot be transformed */ + Scene3D s; + s.setClean(); + CORRADE_VERIFY(!s.isDirty()); + s.setTransformation(Matrix4::rotationX(deg(17.0f))); + CORRADE_VERIFY(!s.isDirty()); + CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); +} + +void MatrixTransformation3DTest::transform() { + { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + } { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f}), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + } +} + +void MatrixTransformation3DTest::translate() { + { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.translate({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + } { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + } +} + +void MatrixTransformation3DTest::rotate() { + { + Object3D o; + o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); + o.rotateX(deg(17.0f)) + ->rotateY(deg(25.0f)) + ->rotateZ(deg(-23.0f)) + ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), + Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* + Matrix4::rotationZ(deg(-23.0f))* + Matrix4::rotationY(deg(25.0f))* + Matrix4::rotationX(deg(17.0f))* + Matrix4::translation({1.0f, -0.3f, 2.3f})); + } { + Object3D o; + o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); + o.rotateX(deg(17.0f), TransformationType::Local) + ->rotateY(deg(25.0f), TransformationType::Local) + ->rotateZ(deg(-23.0f), TransformationType::Local) + ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), + Matrix4::translation({1.0f, -0.3f, 2.3f})* + Matrix4::rotationX(deg(17.0f))* + Matrix4::rotationY(deg(25.0f))* + Matrix4::rotationZ(deg(-23.0f))* + Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + } +} + +void MatrixTransformation3DTest::scale() { + { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.scale({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::scaling({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + } { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.scale({1.0f, -0.3f, 2.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::scaling({1.0f, -0.3f, 2.3f})); + } +} + +void MatrixTransformation3DTest::reflect() { + { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.reflect(Vector3(-1.0f/Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f))); + } { + Object3D o; + o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); + } +} + }}} CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation3DTest) From 1415f70a7fc488186cf9b0b42e2d5ae2ae156baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 11:48:36 +0100 Subject: [PATCH 217/567] Doc++ --- src/AbstractImage.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 44b828b5c..57a02caa4 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -134,16 +134,16 @@ class MAGNUM_EXPORT AbstractImage { /** * Integer green channel. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gl Only @ref Format "Format::RedInteger" is available - * in OpenGL ES 3.0, only floating-point image data are - * available in OpenGL ES 2.0. + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::RedInteger" + * is available in OpenGL ES 3.0, only floating-point image + * data are available in OpenGL ES 2.0. */ GreenInteger = GL_GREEN_INTEGER, /** * Integer blue channel. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gl Only @ref Format "Format::RedInteger" is available + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::RedInteger" is available * in OpenGL ES 3.0, only floating-point image data are * available in OpenGL ES 2.0. */ @@ -179,18 +179,18 @@ class MAGNUM_EXPORT AbstractImage { /** * Integer BGR. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gl Only @ref Format "Format::RGBInteger" is available - * in OpenGL ES 3.0, only floating-point image data are - * available in OpenGL ES 2.0. + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::RGBInteger" + * is available in OpenGL ES 3.0, only floating-point image + * data are available in OpenGL ES 2.0. */ BGRInteger = GL_BGR_INTEGER, /** * Integer BGRA. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gl Only @ref Format "Format::RGBAInteger" is - * available in OpenGL ES 3.0, only floating-point image data - * are available in OpenGL ES 2.0. + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::RGBAInteger" + * is available in OpenGL ES 3.0, only floating-point image + * data are available in OpenGL ES 2.0. */ BGRAInteger = GL_BGRA_INTEGER, #endif From fecb5eec29cbc32d1e67dd2f37f3f773463c5be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 11:55:52 +0100 Subject: [PATCH 218/567] DebugTools: simplified renderers example code. ResourceManager::set() can autodetect the type passed and it now has also more convenient overload. --- doc/debug-tools.dox | 5 ++--- src/DebugTools/ObjectRenderer.h | 5 ++--- src/DebugTools/ShapeRenderer.h | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/debug-tools.dox b/doc/debug-tools.dox index 97e439783..d09612c4f 100644 --- a/doc/debug-tools.dox +++ b/doc/debug-tools.dox @@ -38,9 +38,8 @@ DebugTools::ResourceManager manager; SceneGraph::DrawableGroup3D debugDrawables; // Create renderer options which will be referenced later by "my" resource key -DebugTools::ResourceManager::instance()->set("my", - (new DebugTools::ObjectRendererOptions())->setSize(0.3f), - ResourceDataState::Final, ResourcePolicy::Persistent); +DebugTools::ResourceManager::instance()->set("my", + (new DebugTools::ObjectRendererOptions())->setSize(0.3f)); // Create debug renderer for given object, use "my" options for it. The // renderer is automatically added to the object features and also to diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h index 9eb75f99a..4dadf32af 100644 --- a/src/DebugTools/ObjectRenderer.h +++ b/src/DebugTools/ObjectRenderer.h @@ -61,9 +61,8 @@ Visualizes object position, rotation and scale using colored axes. See Example code: @code // Create some options -DebugTools::ResourceManager::instance()->set("my", - (new DebugTools::ObjectRendererOptions())->setSize(0.3f), - ResourceDataState::Final, ResourcePolicy::Persistent); +DebugTools::ResourceManager::instance()->set("my", + (new DebugTools::ObjectRendererOptions())->setSize(0.3f)); // Create debug renderer for given object, use "my" options for it Object3D* object; diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index f246a87e7..78051fb7b 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -72,9 +72,8 @@ Visualizes collision shape. See @ref debug-tools-renderers for more information. Example code: @code // Create some options -DebugTools::ResourceManager::instance()->set("red", - (new DebugTools::ShapeRendererOptions())->setColor({1.0f, 0.0f, 0.0f}), - ResourceDataState::Final, ResourcePolicy::Persistent); +DebugTools::ResourceManager::instance()->set("red", + (new DebugTools::ShapeRendererOptions())->setColor({1.0f, 0.0f, 0.0f})); // Create debug renderer for given shape, use "red" options for it Physics::ObjectShape2D* shape; From 55477b98feb998bf491b744945bb50025625fec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 11:57:50 +0100 Subject: [PATCH 219/567] DebugTools: don't use CORRADE_INTERNAL_ASSERT() for user-triggered error. What was I thinking... Also updated the documentation to warn about it. --- src/DebugTools/ShapeRenderer.cpp | 2 +- src/DebugTools/ShapeRenderer.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index d2dc636a5..89895a6c1 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -68,7 +68,7 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha #endif template ShapeRenderer::ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { - CORRADE_INTERNAL_ASSERT(shape->shape() != nullptr); + CORRADE_ASSERT(shape->shape() != nullptr, "DebugTools::ShapeRenderer: cannot create renderer for empty shape", ); Implementation::createDebugMesh(this, shape->shape()); } diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 78051fb7b..5223dbafc 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -90,7 +90,7 @@ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public: /** * @brief Constructor - * @param shape Shape for which to create debug renderer + * @param shape Object for which to create debug renderer * @param options Options resource key. See * @ref ShapeRenderer-usage "class documentation" for more * information. @@ -98,6 +98,8 @@ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: * * The renderer is automatically added to shape's object features, * @p shape must be available for the whole lifetime of the renderer. + * + * @attention Passed object must have assigned shape. */ explicit ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); From 0cba8db268000258d76f3e1faacaffb2e477dc47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 12:10:08 +0100 Subject: [PATCH 220/567] Shaders: added missing 3D version of text shader. --- src/Shaders/CMakeLists.txt | 2 +- src/Shaders/TextShader.cpp | 18 ++++--------- .../{TextShader2D.frag => TextShader.frag} | 0 src/Shaders/TextShader2D.vert | 2 +- src/Shaders/TextShader3D.vert | 25 +++++++++++++++++++ 5 files changed, 32 insertions(+), 15 deletions(-) rename src/Shaders/{TextShader2D.frag => TextShader.frag} (100%) create mode 100644 src/Shaders/TextShader3D.vert diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 95a50b182..f4591c4fe 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,7 +1,7 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders FlatShader2D.vert FlatShader3D.vert FlatShader.frag PhongShader.vert PhongShader.frag - TextShader2D.vert TextShader2D.frag + TextShader2D.vert TextShader3D.vert TextShader.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) set(MagnumShaders_SRCS diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/TextShader.cpp index a5d9a950b..e1265e784 100644 --- a/src/Shaders/TextShader.cpp +++ b/src/Shaders/TextShader.cpp @@ -24,17 +24,9 @@ namespace Magnum { namespace Shaders { namespace { - template struct ShaderName {}; - - template<> struct ShaderName<2> { - constexpr static const char* vertex() { return "TextShader2D.vert"; } - constexpr static const char* fragment() { return "TextShader2D.frag"; } - }; - - template<> struct ShaderName<3> { - constexpr static const char* vertex() { return "TextShader3D.vert"; } - constexpr static const char* fragment() { return "TextShader3D.frag"; } - }; + template constexpr const char* vertexShaderName(); + template<> constexpr const char* vertexShaderName<2>() { return "TextShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "TextShader3D.vert"; } } template TextShader::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { @@ -48,12 +40,12 @@ template TextShader::TextShader(): transfor Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); - vertexShader.addSource(rs.get(ShaderName::vertex())); + vertexShader.addSource(rs.get(vertexShaderName())); AbstractTextShader::attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); - fragmentShader.addSource(rs.get(ShaderName::fragment())); + fragmentShader.addSource(rs.get("TextShader.frag")); AbstractTextShader::attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/TextShader2D.frag b/src/Shaders/TextShader.frag similarity index 100% rename from src/Shaders/TextShader2D.frag rename to src/Shaders/TextShader.frag diff --git a/src/Shaders/TextShader2D.vert b/src/Shaders/TextShader2D.vert index 9d030d59d..98ee96d84 100644 --- a/src/Shaders/TextShader2D.vert +++ b/src/Shaders/TextShader2D.vert @@ -20,6 +20,6 @@ in mediump vec2 textureCoordinates; out vec2 fragmentTextureCoordinates; void main() { - gl_Position = vec4(transformationProjectionMatrix*position, 0.0).xywz; + gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); fragmentTextureCoordinates = textureCoordinates; } diff --git a/src/Shaders/TextShader3D.vert b/src/Shaders/TextShader3D.vert new file mode 100644 index 000000000..5204e41b4 --- /dev/null +++ b/src/Shaders/TextShader3D.vert @@ -0,0 +1,25 @@ +#ifndef NEW_GLSL +#define in attribute +#define out varying +#endif + +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 0) uniform mat4 transformationProjectionMatrix; +#else +uniform highp mat4 transformationProjectionMatrix; +#endif + +#ifdef EXPLICIT_ATTRIB_LOCATION +layout(location = 0) in highp vec4 position; +layout(location = 1) in mediump vec2 textureCoordinates; +#else +in highp vec4 position; +in mediump vec2 textureCoordinates; +#endif + +out vec2 fragmentTextureCoordinates; + +void main() { + gl_Position = transformationProjectionMatrix*position; + fragmentTextureCoordinates = textureCoordinates; +} From 80661e4e619b96c7028f48ddc7ec24b706f7e6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 15:23:12 +0100 Subject: [PATCH 221/567] Trade: resource names are handled by importer, not *Data classes. In most cases the names aren't even supported/used and thus it is wasteful to have them in all *Data classes. If the importer wants to support them, it would reimplement *name() functions instead. --- src/Primitives/Capsule.cpp | 4 +- src/Primitives/Cube.cpp | 2 +- src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Plane.cpp | 2 +- src/Primitives/Square.cpp | 2 +- src/Trade/AbstractImporter.h | 148 ++++++++++++++++++++++++++----- src/Trade/AbstractMaterialData.h | 7 +- src/Trade/CameraData.h | 13 --- src/Trade/ImageData.h | 7 +- src/Trade/LightData.h | 13 --- src/Trade/MeshData2D.h | 7 +- src/Trade/MeshData3D.h | 7 +- src/Trade/MeshObjectData2D.h | 3 +- src/Trade/MeshObjectData3D.h | 3 +- src/Trade/ObjectData2D.h | 14 ++- src/Trade/ObjectData3D.h | 12 +-- src/Trade/PhongMaterialData.h | 3 +- src/Trade/SceneData.h | 7 +- src/Trade/TextureData.h | 13 --- 19 files changed, 151 insertions(+), 118 deletions(-) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 3f1fcca20..94863a6d3 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Primitives { -Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), 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; @@ -48,7 +48,7 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std topFaceRing(); } -Capsule::Capsule(std::uint32_t segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(std::uint32_t segments, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 993200ebb..1d5e721e3 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new std::vector{ +Cube::Cube(): MeshData3D(Mesh::Primitive::Triangles, new std::vector{ 0, 1, 2, 0, 2, 3, /* +Z */ 4, 5, 6, 4, 6, 7, /* +X */ 8, 9, 10, 8, 10, 11, /* +Y */ diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index e637db8e4..f5cc0c1f3 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D("", Mesh::Primitive::Triangles, new std::vector{ +Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index d50a994a4..aec78371c 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData3D("", Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ +Plane::Plane(): MeshData3D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index 73d8b1f2b..57c601237 100644 --- a/src/Primitives/Square.cpp +++ b/src/Primitives/Square.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { -Square::Square(): MeshData2D("", Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ +Square::Square(): MeshData2D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ {1.0f, -1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index cb0fcc19f..764fe5bed 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -130,10 +130,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief %Scene ID for given name * * If no scene for given name exists, returns -1. - * @see SceneData::name() + * @see sceneName() */ virtual std::int32_t sceneForName(const std::string& name); + /** + * @brief %Scene name + * @param id %Scene ID, from range [0, sceneCount()). + * + * @see sceneForName() + */ + virtual std::string sceneName(std::uint32_t id); + /** * @brief %Scene * @param id %Scene ID, from range [0, sceneCount()). @@ -149,10 +157,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief %Light ID for given name * * If no light for given name exists, returns -1. - * @see LightData::name() + * @see lightName() */ virtual std::int32_t lightForName(const std::string& name); + /** + * @brief %Light name + * @param id %Light ID, from range [0, lightCount()). + * + * @see lightForName() + */ + virtual std::string lightName(std::uint32_t id); + /** * @brief %Light * @param id %Light ID, from range [0, lightCount()). @@ -161,20 +177,28 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { */ virtual LightData* light(std::uint32_t id); - /** @brief %Camera count */ + /** @brief Camera count */ virtual inline std::uint32_t cameraCount() const { return 0; } /** - * @brief %Camera ID for given name + * @brief Camera ID for given name * * If no camera for given name exists, returns -1. - * @see CameraData::name() + * @see cameraName() */ virtual std::int32_t cameraForName(const std::string& name); /** - * @brief %Camera - * @param id %Camera ID, from range [0, cameraCount()). + * @brief Camera name + * @param id Camera ID, from range [0, cameraCount()). + * + * @see cameraForName() + */ + virtual std::string cameraName(std::uint32_t id); + + /** + * @brief Camera + * @param id Camera ID, from range [0, cameraCount()). * * Returns pointer to given camera or nullptr, if no such camera * exists. @@ -188,13 +212,21 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Two-dimensional object ID for given name * * If no scene for given name exists, returns -1. - * @see ObjectData2D::name() + * @see object2DName() */ virtual std::int32_t object2DForName(const std::string& name); + /** + * @brief Two-dimensional object name + * @param id Object ID, from range [0, object2DCount()). + * + * @see object2DForName() + */ + virtual std::string object2DName(std::uint32_t id); + /** * @brief Two-dimensional object - * @param id %Object ID, from range [0, object2DCount()). + * @param id Object ID, from range [0, object2DCount()). * * Returns pointer to given object or nullptr, if no such object * exists. @@ -208,13 +240,21 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Three-dimensional object ID for given name * * If no scene for given name exists, returns -1. - * @see ObjectData3D::name() + * @see object3DName() */ virtual std::int32_t object3DForName(const std::string& name); + /** + * @brief Three-dimensional object name + * @param id Object ID, from range [0, object3DCount()). + * + * @see object3DForName() + */ + virtual std::string object3DName(std::uint32_t id); + /** * @brief Three-dimensional object - * @param id %Object ID, from range [0, object3DCount()). + * @param id Object ID, from range [0, object3DCount()). * * Returns pointer to given object or nullptr, if no such object * exists. @@ -228,13 +268,21 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Two-dimensional mesh ID for given name * * If no mesh for given name exists, returns -1. - * @see MeshData2D::name() + * @see mesh2DName() */ virtual std::int32_t mesh2DForName(const std::string& name); + /** + * @brief Two-dimensional mesh name + * @param id %Mesh ID, from range [0, mesh2DCount()). + * + * @see mesh2DForName() + */ + virtual std::string mesh2DName(std::uint32_t id); + /** * @brief Two-dimensional mesh - * @param id %Mesh ID, from range [0, meshCount()). + * @param id %Mesh ID, from range [0, mesh2DCount()). * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ @@ -247,13 +295,21 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Three-dimensional mesh ID for given name * * If no mesh for given name exists, returns -1. - * @see MeshData3D::name() + * @see mesh3DName() */ virtual std::int32_t mesh3DForName(const std::string& name); + /** + * @brief Three-dimensional mesh name + * @param id %Mesh ID, from range [0, mesh3DCount()). + * + * @see mesh3DForName() + */ + virtual std::string mesh3DName(std::uint32_t id); + /** * @brief Three-dimensional mesh - * @param id %Mesh ID, from range [0, meshCount()). + * @param id %Mesh ID, from range [0, mesh3DCount()). * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ @@ -266,10 +322,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Material ID for given name * * If no material for given name exists, returns -1. - * @see AbstractMaterialData::name() + * @see materialName() */ virtual std::int32_t materialForName(const std::string& name); + /** + * @brief Material name + * @param id Material ID, from range [0, materialCount()). + * + * @see materialForName() + */ + virtual std::string materialName(std::uint32_t id); + /** * @brief Material * @param id Material ID, from range [0, materialCount()). @@ -286,10 +350,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief %Texture ID for given name * * If no texture for given name exists, returns -1. - * @see TextureData::name() + * @see textureName() */ virtual std::int32_t textureForName(const std::string& name); + /** + * @brief %Texture name + * @param id %Texture ID, from range [0, textureCount()). + * + * @see textureForName() + */ + virtual std::string textureName(std::uint32_t id); + /** * @brief %Texture * @param id %Texture ID, from range [0, textureCount()). @@ -306,10 +378,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief One-dimensional image ID for given name * * If no image for given name exists, returns -1. - * @see ImageData1D::name() + * @see image1Dname() */ virtual std::int32_t image1DForName(const std::string& name); + /** + * @brief One-dimensional image name + * @param id %Image ID, from range [0, image1DCount()). + * + * @see image1DForName() + */ + virtual std::string image1DName(std::uint32_t id); + /** * @brief One-dimensional image * @param id %Image ID, from range [0, image1DCount()). @@ -325,10 +405,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Two-dimensional image ID for given name * * If no image for given name exists, returns -1. - * @see ImageData2D::name() + * @see image2DName() */ virtual std::int32_t image2DForName(const std::string& name); + /** + * @brief Two-dimensional image name + * @param id %Image ID, from range [0, image2DCount()). + * + * @see image2DForName() + */ + virtual std::string image2DName(std::uint32_t id); + /** * @brief Two-dimensional image * @param id %Image ID, from range [0, image2DCount()). @@ -344,10 +432,18 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @brief Three-dimensional image ID for given name * * If no image for given name exists, returns -1. - * @see ImageData3D::name() + * @see image3DName() */ virtual std::int32_t image3DForName(const std::string& name); + /** + * @brief Three-dimensional image name + * @param id %Image ID, from range [0, image3DCount()). + * + * @see image3DForName() + */ + virtual std::string image3DName(std::uint32_t id); + /** * @brief Three-dimensional image * @param id %Image ID, from range [0, image3DCount()). @@ -363,28 +459,40 @@ CORRADE_ENUMSET_OPERATORS(AbstractImporter::Features) /* Implementations for inline functions with unused parameters */ inline std::int32_t AbstractImporter::sceneForName(const std::string&) { return -1; } +inline std::string AbstractImporter::sceneName(std::uint32_t) { return {}; } inline SceneData* AbstractImporter::scene(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::lightForName(const std::string&) { return -1; } +inline std::string AbstractImporter::lightName(std::uint32_t) { return {}; } inline LightData* AbstractImporter::light(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::cameraForName(const std::string&) { return -1; } +inline std::string AbstractImporter::cameraName(std::uint32_t) { return {}; } inline CameraData* AbstractImporter::camera(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::object2DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::object2DName(std::uint32_t) { return {}; } inline ObjectData2D* AbstractImporter::object2D(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::object3DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::object3DName(std::uint32_t) { return {}; } inline ObjectData3D* AbstractImporter::object3D(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::mesh2DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::mesh2DName(std::uint32_t) { return {}; } inline MeshData2D* AbstractImporter::mesh2D(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::mesh3DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::mesh3DName(std::uint32_t) { return {}; } inline MeshData3D* AbstractImporter::mesh3D(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::materialForName(const std::string&) { return -1; } +inline std::string AbstractImporter::materialName(std::uint32_t) { return {}; } inline AbstractMaterialData* AbstractImporter::material(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::textureForName(const std::string&) { return -1; } +inline std::string AbstractImporter::textureName(std::uint32_t) { return {}; } inline TextureData* AbstractImporter::texture(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::image1DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::image1DName(std::uint32_t) { return {}; } inline ImageData1D* AbstractImporter::image1D(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::image2DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::image2DName(std::uint32_t) { return {}; } inline ImageData2D* AbstractImporter::image2D(std::uint32_t) { return nullptr; } inline std::int32_t AbstractImporter::image3DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::image3DName(std::uint32_t) { return {}; } inline ImageData3D* AbstractImporter::image3D(std::uint32_t) { return nullptr; } }} diff --git a/src/Trade/AbstractMaterialData.h b/src/Trade/AbstractMaterialData.h index 0e0b17c69..483625742 100644 --- a/src/Trade/AbstractMaterialData.h +++ b/src/Trade/AbstractMaterialData.h @@ -42,22 +42,17 @@ class AbstractMaterialData { /** * @brief Constructor - * @param name Material name * @param type Material type */ - inline AbstractMaterialData(const std::string& name, Type type): _name(name), _type(type) {} + inline AbstractMaterialData(Type type): _type(type) {} /** @brief Destructor */ virtual ~AbstractMaterialData() = 0; - /** @brief Material name */ - inline std::string name() const { return _name; } - /** @brief Material type */ inline Type type() const { return _type; } private: - std::string _name; Type _type; }; diff --git a/src/Trade/CameraData.h b/src/Trade/CameraData.h index 914832e4d..4fcf2e7e1 100644 --- a/src/Trade/CameraData.h +++ b/src/Trade/CameraData.h @@ -31,19 +31,6 @@ class MAGNUM_EXPORT CameraData { CameraData(CameraData&& other) = delete; CameraData& operator=(const CameraData& other) = delete; CameraData& operator=(CameraData&& other) = delete; - - public: - /** - * @brief Constructor - * @param name %Camera name - */ - inline CameraData(const std::string& name): _name(name) {} - - /** @brief %Camera name */ - inline std::string name() const { return _name; } - - private: - std::string _name; }; }} diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index b92c5039c..bd41ecf74 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -38,7 +38,6 @@ template class ImageData: public AbstractImage { /** * @brief Constructor - * @param name %Image name * @param size %Image size * @param format Format of pixel data * @param type Data type of pixel data @@ -47,14 +46,11 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageData(const std::string& name, const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _name(name), _size(size), _data(reinterpret_cast(data)) {} + inline ImageData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline ~ImageData() { delete[] _data; } - /** @brief %Image name */ - inline std::string name() const { return _name; } - /** @brief %Image size */ inline typename DimensionTraits::VectorType size() const { return _size; } @@ -63,7 +59,6 @@ template class ImageData: public AbstractImage { inline const void* data() const { return _data; } /**< @overload */ private: - std::string _name; Math::Vector _size; char* _data; }; diff --git a/src/Trade/LightData.h b/src/Trade/LightData.h index 824dde363..51e93998d 100644 --- a/src/Trade/LightData.h +++ b/src/Trade/LightData.h @@ -31,19 +31,6 @@ class MAGNUM_EXPORT LightData { LightData(LightData&& other) = delete; LightData& operator=(const LightData& other) = delete; LightData& operator=(LightData&& other) = delete; - - public: - /** - * @brief Constructor - * @param name %Light name - */ - inline LightData(const std::string& name): _name(name) {} - - /** @brief %Light name */ - inline std::string name() const { return _name; } - - private: - std::string _name; }; }} diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index 4e812f136..1ad8f30d3 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -42,7 +42,6 @@ class MAGNUM_EXPORT MeshData2D { public: /** * @brief Constructor - * @param name %Mesh name * @param primitive Primitive * @param indices Array with indices or 0, if this is not * indexed mesh @@ -51,14 +50,11 @@ class MAGNUM_EXPORT MeshData2D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData2D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + inline MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData2D(); - /** @brief %Mesh name */ - inline std::string name() const { return _name; } - /** @brief Primitive */ inline Mesh::Primitive primitive() const { return _primitive; } @@ -94,7 +90,6 @@ class MAGNUM_EXPORT MeshData2D { inline const std::vector* textureCoords2D(std::uint32_t id) const { return _textureCoords2D[id]; } /**< @overload */ private: - std::string _name; Mesh::Primitive _primitive; std::vector* _indices; std::vector*> _positions; diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 1de247976..cf454d968 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -42,7 +42,6 @@ class MAGNUM_EXPORT MeshData3D { public: /** * @brief Constructor - * @param name %Mesh name * @param primitive Primitive * @param indices Array with indices or 0, if this is not * indexed mesh @@ -52,14 +51,11 @@ class MAGNUM_EXPORT MeshData3D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData3D(const std::string& name, Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _name(name), _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Destructor */ ~MeshData3D(); - /** @brief %Mesh name */ - inline std::string name() const { return _name; } - /** @brief Primitive */ inline Mesh::Primitive primitive() const { return _primitive; } @@ -107,7 +103,6 @@ class MAGNUM_EXPORT MeshData3D { inline const std::vector* textureCoords2D(std::uint32_t id) const { return _textureCoords2D[id]; } /**< @overload */ private: - std::string _name; Mesh::Primitive _primitive; std::vector* _indices; std::vector*> _positions; diff --git a/src/Trade/MeshObjectData2D.h b/src/Trade/MeshObjectData2D.h index dff0770b0..ac99eb223 100644 --- a/src/Trade/MeshObjectData2D.h +++ b/src/Trade/MeshObjectData2D.h @@ -38,7 +38,6 @@ class MeshObjectData2D: public ObjectData2D { public: /** * @brief Constructor - * @param name %Mesh object name * @param children Child objects * @param transformation Transformation (relative to parent) * @param instance Instance ID @@ -46,7 +45,7 @@ class MeshObjectData2D: public ObjectData2D { * * Creates object with mesh instance type. */ - inline MeshObjectData2D(const std::string& name, const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData2D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData2D(const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData2D(children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ inline std::uint32_t material() const { return _material; } diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h index acec3ed31..8c1f381a1 100644 --- a/src/Trade/MeshObjectData3D.h +++ b/src/Trade/MeshObjectData3D.h @@ -38,7 +38,6 @@ class MeshObjectData3D: public ObjectData3D { public: /** * @brief Constructor - * @param name %Mesh object name * @param children Child objects * @param transformation Transformation (relative to parent) * @param instance Instance ID @@ -46,7 +45,7 @@ class MeshObjectData3D: public ObjectData3D { * * Creates object with mesh instance type. */ - inline MeshObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData3D(name, children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData3D(const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData3D(children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ inline std::uint32_t material() const { return _material; } diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h index 8cc1b9226..49c049d31 100644 --- a/src/Trade/ObjectData2D.h +++ b/src/Trade/ObjectData2D.h @@ -19,7 +19,9 @@ * @brief Class Magnum::Trade::ObjectData2D */ -#include "Math/Matrix4.h" +#include + +#include "Math/Matrix3.h" #include "Magnum.h" namespace Magnum { namespace Trade { @@ -47,28 +49,23 @@ class ObjectData2D { /** * @brief Constructor - * @param name Object name * @param children Child objects * @param transformation Transformation (relative to parent) * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation, InstanceType instanceType, std::uint32_t instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData2D(const std::vector& children, const Matrix3& transformation, InstanceType instanceType, std::uint32_t instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance - * @param name Object name * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData2D(const std::string& name, const std::vector& children, const Matrix3& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData2D(const std::vector& children, const Matrix3& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ inline virtual ~ObjectData2D() {} - /** @brief %Object name */ - inline std::string name() const { return _name; } - /** @brief Child objects */ inline std::vector& children() { return _children; } @@ -92,7 +89,6 @@ class ObjectData2D { inline std::int32_t instanceId() const { return _instanceId; } private: - std::string _name; std::vector _children; Matrix3 _transformation; InstanceType _instanceType; diff --git a/src/Trade/ObjectData3D.h b/src/Trade/ObjectData3D.h index 0f125b672..2db3a0d29 100644 --- a/src/Trade/ObjectData3D.h +++ b/src/Trade/ObjectData3D.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Trade::ObjectData3D */ +#include + #include "Math/Matrix4.h" #include "Magnum.h" @@ -48,28 +50,23 @@ class ObjectData3D { /** * @brief Constructor - * @param name Object name * @param children Child objects * @param transformation Transformation (relative to parent) * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation, InstanceType instanceType, std::uint32_t instanceId): _name(name), _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData3D(const std::vector& children, const Matrix4& transformation, InstanceType instanceType, std::uint32_t instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance - * @param name Object name * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData3D(const std::string& name, const std::vector& children, const Matrix4& transformation): _name(name), _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData3D(const std::vector& children, const Matrix4& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ inline virtual ~ObjectData3D() {} - /** @brief %Object name */ - inline std::string name() const { return _name; } - /** @brief Child objects */ inline std::vector& children() { return _children; } @@ -93,7 +90,6 @@ class ObjectData3D { inline std::int32_t instanceId() const { return _instanceId; } private: - std::string _name; std::vector _children; Matrix4 _transformation; InstanceType _instanceType; diff --git a/src/Trade/PhongMaterialData.h b/src/Trade/PhongMaterialData.h index 21896cba3..f726f1c3b 100644 --- a/src/Trade/PhongMaterialData.h +++ b/src/Trade/PhongMaterialData.h @@ -32,13 +32,12 @@ class PhongMaterialData: public AbstractMaterialData { public: /** * @brief Constructor - * @param name Material name * @param ambientColor Ambient color * @param diffuseColor Diffuse color * @param specularColor Specular color * @param shininess Shininess */ - PhongMaterialData(const std::string& name, const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, GLfloat shininess): AbstractMaterialData(name, Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {} + PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, GLfloat shininess): AbstractMaterialData(Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {} /** @brief Ambient color */ inline Vector3 ambientColor() const { return _ambientColor; } diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index 226fa327a..17ad448eb 100644 --- a/src/Trade/SceneData.h +++ b/src/Trade/SceneData.h @@ -36,14 +36,10 @@ class MAGNUM_EXPORT SceneData { public: /** * @brief Constructor - * @param name Scene name * @param children2D Two-dimensional child objects * @param children3D Three-dimensional child objects */ - inline SceneData(const std::string& name, const std::vector& children2D, const std::vector& children3D): _name(name), _children2D(children2D), _children3D(children3D) {} - - /** @brief Scene name */ - inline std::string name() const { return _name; } + inline SceneData(const std::vector& children2D, const std::vector& children3D): _children2D(children2D), _children3D(children3D) {} /** @brief Two-dimensional child objects */ inline const std::vector& children2D() const { return _children2D; } @@ -52,7 +48,6 @@ class MAGNUM_EXPORT SceneData { inline const std::vector& children3D() const { return _children3D; } private: - std::string _name; std::vector _children2D, _children3D; }; diff --git a/src/Trade/TextureData.h b/src/Trade/TextureData.h index d2e9ed825..1dc4f16d0 100644 --- a/src/Trade/TextureData.h +++ b/src/Trade/TextureData.h @@ -31,19 +31,6 @@ class MAGNUM_EXPORT TextureData { TextureData(TextureData&& other) = delete; TextureData& operator=(const TextureData& other) = delete; TextureData& operator=(TextureData&& other) = delete; - - public: - /** - * @brief Constructor - * @param name %Texture name - */ - inline TextureData(const std::string& name): _name(name) {} - - /** @brief %Texture name */ - inline std::string name() const { return _name; } - - private: - std::string _name; }; }} From 82f3b948af7f6ee993826da14febf7777272c213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 17:16:42 +0100 Subject: [PATCH 222/567] Trade: debug output for ObjectData*D::InstanceType enum. --- src/CMakeLists.txt | 4 ++- src/Trade/CMakeLists.txt | 5 ++++ src/Trade/ObjectData2D.cpp | 34 +++++++++++++++++++++++ src/Trade/ObjectData2D.h | 3 +++ src/Trade/ObjectData3D.cpp | 35 ++++++++++++++++++++++++ src/Trade/ObjectData3D.h | 3 +++ src/Trade/Test/CMakeLists.txt | 2 ++ src/Trade/Test/ObjectData2DTest.cpp | 42 +++++++++++++++++++++++++++++ src/Trade/Test/ObjectData3DTest.cpp | 42 +++++++++++++++++++++++++++++ 9 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 src/Trade/ObjectData2D.cpp create mode 100644 src/Trade/ObjectData3D.cpp create mode 100644 src/Trade/Test/CMakeLists.txt create mode 100644 src/Trade/Test/ObjectData2DTest.cpp create mode 100644 src/Trade/Test/ObjectData3DTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 833bdc617..1f20f218e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,9 @@ set(Magnum_SRCS Trade/AbstractImporter.cpp Trade/MeshData2D.cpp - Trade/MeshData3D.cpp) + Trade/MeshData3D.cpp + Trade/ObjectData2D.cpp + Trade/ObjectData3D.cpp) # Desktop-only code if(NOT TARGET_GLES) diff --git a/src/Trade/CMakeLists.txt b/src/Trade/CMakeLists.txt index 12b1fd60d..11d7bac8f 100644 --- a/src/Trade/CMakeLists.txt +++ b/src/Trade/CMakeLists.txt @@ -14,3 +14,8 @@ set(MagnumTrade_HEADERS SceneData.h TextureData.h) install(FILES ${MagnumTrade_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Trade) + +if(BUILD_TESTS) + enable_testing() + add_subdirectory(Test) +endif() diff --git a/src/Trade/ObjectData2D.cpp b/src/Trade/ObjectData2D.cpp new file mode 100644 index 000000000..bf71a36cc --- /dev/null +++ b/src/Trade/ObjectData2D.cpp @@ -0,0 +1,34 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ObjectData2D.h" + +namespace Magnum { namespace Trade { + +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug operator<<(Debug debug, ObjectData2D::InstanceType value) { + switch(value) { + #define _c(value) case ObjectData2D::InstanceType::value: return debug << "Trade::ObjectData2D::InstanceType::" #value; + _c(Camera) + _c(Mesh) + _c(Empty) + #undef _c + } + + return debug << "ObjectData2D::InstanceType::(invalid)"; +} +#endif + +}} diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h index 49c049d31..40ae13a97 100644 --- a/src/Trade/ObjectData2D.h +++ b/src/Trade/ObjectData2D.h @@ -95,6 +95,9 @@ class ObjectData2D { std::int32_t _instanceId; }; +/** @debugoperator{Magnum::Trade::ObjectData2D} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, ObjectData2D::InstanceType value); + }} #endif diff --git a/src/Trade/ObjectData3D.cpp b/src/Trade/ObjectData3D.cpp new file mode 100644 index 000000000..ee4fc9fae --- /dev/null +++ b/src/Trade/ObjectData3D.cpp @@ -0,0 +1,35 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ObjectData3D.h" + +namespace Magnum { namespace Trade { + +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug operator<<(Debug debug, ObjectData3D::InstanceType value) { + switch(value) { + #define _c(value) case ObjectData3D::InstanceType::value: return debug << "Trade::ObjectData3D::InstanceType::" #value; + _c(Camera) + _c(Light) + _c(Mesh) + _c(Empty) + #undef _c + } + + return debug << "ObjectData3D::InstanceType::(invalid)"; +} +#endif + +}} diff --git a/src/Trade/ObjectData3D.h b/src/Trade/ObjectData3D.h index 2db3a0d29..e6862cb52 100644 --- a/src/Trade/ObjectData3D.h +++ b/src/Trade/ObjectData3D.h @@ -96,6 +96,9 @@ class ObjectData3D { std::int32_t _instanceId; }; +/** @debugoperator{Magnum::Trade::ObjectData3D} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, ObjectData3D::InstanceType value); + }} #endif diff --git a/src/Trade/Test/CMakeLists.txt b/src/Trade/Test/CMakeLists.txt new file mode 100644 index 000000000..84ba62f24 --- /dev/null +++ b/src/Trade/Test/CMakeLists.txt @@ -0,0 +1,2 @@ +corrade_add_test(TradeObjectData2DTest ObjectData2DTest.cpp LIBRARIES Magnum) +corrade_add_test(TradeObjectData3DTest ObjectData3DTest.cpp LIBRARIES Magnum) diff --git a/src/Trade/Test/ObjectData2DTest.cpp b/src/Trade/Test/ObjectData2DTest.cpp new file mode 100644 index 000000000..81e35b922 --- /dev/null +++ b/src/Trade/Test/ObjectData2DTest.cpp @@ -0,0 +1,42 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Trade/ObjectData2D.h" + +namespace Magnum { namespace Trade { namespace Test { + +class ObjectData2DTest: public Corrade::TestSuite::Tester { + public: + explicit ObjectData2DTest(); + + void debug(); +}; + +ObjectData2DTest::ObjectData2DTest() { + addTests(&ObjectData2DTest::debug); +} + +void ObjectData2DTest::debug() { + std::ostringstream o; + Debug(&o) << ObjectData2D::InstanceType::Empty; + CORRADE_COMPARE(o.str(), "Trade::ObjectData2D::InstanceType::Empty\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::ObjectData2DTest) diff --git a/src/Trade/Test/ObjectData3DTest.cpp b/src/Trade/Test/ObjectData3DTest.cpp new file mode 100644 index 000000000..95636e0cb --- /dev/null +++ b/src/Trade/Test/ObjectData3DTest.cpp @@ -0,0 +1,42 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Trade/ObjectData3D.h" + +namespace Magnum { namespace Trade { namespace Test { + +class ObjectData3DTest: public Corrade::TestSuite::Tester { + public: + explicit ObjectData3DTest(); + + void debug(); +}; + +ObjectData3DTest::ObjectData3DTest() { + addTests(&ObjectData3DTest::debug); +} + +void ObjectData3DTest::debug() { + std::ostringstream o; + Debug(&o) << ObjectData3D::InstanceType::Light; + CORRADE_COMPARE(o.str(), "Trade::ObjectData3D::InstanceType::Light\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::ObjectData3DTest) From e29b60863292402a84b985d3772513c02e0b77d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 22 Jan 2013 16:34:01 +0100 Subject: [PATCH 223/567] Proper passing of image data to textures. Explicitly unbinding pixel unpack buffer when passing data from client memory and binding it when passing data from BufferImage. --- src/AbstractTexture.cpp | 15 +++++++++++++++ src/AbstractTexture.h | 37 +++++++++++++++++++++++++++++-------- src/BufferImage.h | 14 -------------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 4c034ef00..f6872fa59 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -15,6 +15,8 @@ #include "AbstractTexture.h" +#include "Buffer.h" +#include "BufferImage.h" #include "Context.h" #include "Extensions.h" #include "Implementation/State.h" @@ -431,6 +433,19 @@ void AbstractTexture::invalidateSubImplementationARB(GLint level, const Vector3i #endif #ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_TARGET_GLES2 +namespace Implementation { + template GLvoid* ImageHelper>::dataOrPixelUnpackBuffer(BufferImage* image) { + image->buffer()->bind(Buffer::Target::PixelUnpack); + return nullptr; + } + + template class ImageHelper; + template class ImageHelper; + template class ImageHelper; +} +#endif + void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D& wrapping) { #ifndef MAGNUM_TARGET_GLES CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping.x() == Wrapping::ClampToEdge || wrapping.x() == Wrapping::ClampToBorder) && (wrapping.y() == Wrapping::ClampToEdge || wrapping.y() == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index b2c875343..7bdf8ab78 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -20,6 +20,9 @@ */ #include "Array.h" +#ifndef MAGNUM_TARGET_GLES2 +#include "Buffer.h" +#endif #include "Color.h" #include "AbstractImage.h" @@ -64,6 +67,7 @@ do nothing. @todo Texture copying @todo Move constructor/assignment - how to avoid creation of empty texture and then deleting it immediately? +@todo ES2 - proper support for pixel unpack buffer when extension is in headers */ class MAGNUM_EXPORT AbstractTexture { friend class Context; @@ -1272,6 +1276,23 @@ class MAGNUM_EXPORT AbstractTexture { }; #ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct ImageHelper { + inline static GLvoid* dataOrPixelUnpackBuffer(Image* image) { + #ifndef MAGNUM_TARGET_GLES2 + Buffer::unbind(Buffer::Target::PixelUnpack); + #endif + return image->data(); + } + }; + + #ifndef MAGNUM_TARGET_GLES2 + template struct MAGNUM_EXPORT ImageHelper> { + static GLvoid* dataOrPixelUnpackBuffer(BufferImage* image); + }; + #endif +} + #ifndef MAGNUM_TARGET_GLES template<> struct AbstractTexture::DataHelper<1> { enum class Target: GLenum { @@ -1289,11 +1310,11 @@ template<> struct AbstractTexture::DataHelper<1> { } template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { - (texture->*image1DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); + (texture->*image1DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Math::Vector<1, GLint>& offset, Image* image) { - (texture->*subImage1DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); + (texture->*subImage1DImplementation)(target, level, offset, image->size(), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } inline static void invalidateSub(AbstractTexture* texture, GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLint>& size) { @@ -1320,15 +1341,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { } template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { - (texture->*image2DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); + (texture->*image2DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector2i& offset, Image* image) { - (texture->*subImage2DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); + (texture->*subImage2DImplementation)(target, level, offset, image->size(), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector2i& offset, Image* image) { - (texture->*subImage2DImplementation)(target, level, offset, Vector2i(image->size(), 1), image->format(), image->type(), image->data()); + (texture->*subImage2DImplementation)(target, level, offset, Vector2i(image->size(), 1), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } inline static void invalidateSub(AbstractTexture* texture, GLint level, const Vector2i& offset, const Vector2i& size) { @@ -1354,15 +1375,15 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { } template inline static typename std::enable_if::type set(AbstractTexture* texture, GLenum target, GLint level, InternalFormat internalFormat, Image* image) { - (texture->*image3DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), image->data()); + (texture->*image3DImplementation)(target, level, internalFormat, image->size(), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector3i& offset, Image* image) { - (texture->*subImage3DImplementation)(target, level, offset, image->size(), image->format(), image->type(), image->data()); + (texture->*subImage3DImplementation)(target, level, offset, image->size(), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } template inline static typename std::enable_if::type setSub(AbstractTexture* texture, GLenum target, GLint level, const Vector3i& offset, Image* image) { - (texture->*subImage3DImplementation)(target, level, offset, Vector3i(image->size(), 1), image->format(), image->type(), image->data()); + (texture->*subImage3DImplementation)(target, level, offset, Vector3i(image->size(), 1), image->format(), image->type(), Implementation::ImageHelper::dataOrPixelUnpackBuffer(image)); } inline static void invalidateSub(AbstractTexture* texture, GLint level, const Vector3i& offset, const Vector3i& size) { diff --git a/src/BufferImage.h b/src/BufferImage.h index 63911d2b8..743f31dac 100644 --- a/src/BufferImage.h +++ b/src/BufferImage.h @@ -56,20 +56,6 @@ template class MAGNUM_EXPORT BufferImage: public Abstra /** @brief %Image size */ inline typename DimensionTraits::VectorType size() const { return _size; } - /** - * @brief Data - * - * Binds the buffer to @ref Buffer::Target "pixel unpack - * target" and returns nullptr, so it can be used for texture updating - * functions the same way as Image::data(). - * - * @see Buffer::bind(Target) - */ - inline void* data() { - _buffer.bind(Buffer::Target::PixelUnpack); - return nullptr; - } - /** @brief %Image buffer */ inline Buffer* buffer() { return &_buffer; } From ea2faa91b7f9a5b1c629909747fb113f442cabac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 22 Jan 2013 16:38:29 +0100 Subject: [PATCH 224/567] Explicit offset also in Mesh::addVertexBuffer(). The offset is present in all other functions, adding it just for consistency (although it is redundant here). --- src/DebugTools/Implementation/AbstractBoxRenderer.cpp | 4 ++-- src/Mesh.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index 2d74d216e..988f2de64 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -45,7 +45,7 @@ AbstractBoxRenderer<2>::AbstractBoxRenderer() { mesh->setPrimitive(square.primitive()) ->setVertexCount(square.positions(0)->size()) - ->addVertexBuffer(buffer, Shaders::FlatShader2D::Position()); + ->addVertexBuffer(buffer, 0, Shaders::FlatShader2D::Position()); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } @@ -75,7 +75,7 @@ AbstractBoxRenderer<3>::AbstractBoxRenderer() { mesh->setPrimitive(cube.primitive()) ->setVertexCount(cube.positions(0)->size()) - ->addVertexBuffer(vertexBuffer, Shaders::FlatShader3D::Position()); + ->addVertexBuffer(vertexBuffer, 0, Shaders::FlatShader3D::Position()); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } diff --git a/src/Mesh.h b/src/Mesh.h index f33b95cbf..ca5f37bd2 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -560,7 +560,7 @@ class MAGNUM_EXPORT Mesh { * * Attribute list is combination of * @ref AbstractShaderProgram::Attribute "attribute definitions" - * (specified in implementation of given shader) and offsets between + * (specified in implementation of given shader) and gaps between * attribute arrays. * * See @ref Mesh-configuration "class documentation" for simple usage @@ -574,7 +574,7 @@ class MAGNUM_EXPORT Mesh { * Mesh* mesh; * Buffer* buffer; * mesh->addVertexBuffer(buffer, - * 35, // skip other data + * 35, // offset of the data * Shaders::PhongShader::Position(), // position array * sizeof(Vector2)*mesh->vertexCount(), // skip texture coordinate array * Shaders::PhongShader::Normal()); // normal array @@ -603,10 +603,10 @@ class MAGNUM_EXPORT Mesh { * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} * if @extension{APPLE,vertex_array_object} is available */ - template inline Mesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { + template inline Mesh* addVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", this); - addVertexBufferInternal(buffer, 0, attributes...); + addVertexBufferInternal(buffer, offset, attributes...); return this; } From b9513d28cb6de985d2b5ae3165a580cd7d23cbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 Jan 2013 23:16:22 +0100 Subject: [PATCH 225/567] Merged index type setting to Mesh::setIndexBuffer() and added offset. Now addVertexBuffer() etc. and setIndexBuffer() are even more similar. --- src/DebugTools/ObjectRenderer.cpp | 3 +- src/Mesh.cpp | 20 +++++++---- src/Mesh.h | 56 +++++++++++-------------------- src/MeshTools/CompressIndices.cpp | 5 ++- src/MeshTools/CompressIndices.h | 6 ++-- 5 files changed, 39 insertions(+), 51 deletions(-) diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 5285f15e4..f0a98e9a4 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -158,11 +158,10 @@ template ObjectRenderer::ObjectRenderer(Sce mesh->setPrimitive(Mesh::Primitive::Lines) ->setIndexCount(Renderer::indices.size()) - ->setIndexType(Mesh::IndexType::UnsignedByte) ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColorShader::Position(), typename Shaders::VertexColorShader::Color()) - ->setIndexBuffer(indexBuffer); + ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index e23f5418b..4cc89e5f2 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -49,7 +49,7 @@ std::size_t Mesh::indexSize(IndexType type) { CORRADE_INTERNAL_ASSERT(false); } -Mesh::Mesh(Primitive primitive): _primitive(primitive), _vertexCount(0), _indexBuffer(nullptr), _indexCount(0), _indexType(IndexType::UnsignedInt) { +Mesh::Mesh(Primitive primitive): _primitive(primitive), _vertexCount(0), _indexCount(0), indexOffset(0), indexType(IndexType::UnsignedInt), indexBuffer(nullptr) { (this->*createImplementation)(); } @@ -61,7 +61,7 @@ Mesh::~Mesh() { (this->*destroyImplementation)(); } -Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexBuffer(other._indexBuffer), _indexCount(other._indexCount), _indexType(other._indexType), attributes(std::move(other.attributes)) +Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount), indexOffset(other.indexOffset), indexType(other.indexType), indexBuffer(other.indexBuffer), attributes(std::move(other.attributes)) #ifndef MAGNUM_TARGET_GLES2 , integerAttributes(std::move(other.integerAttributes)) #ifndef MAGNUM_TARGET_GLES @@ -78,9 +78,10 @@ Mesh& Mesh::operator=(Mesh&& other) { vao = other.vao; _primitive = other._primitive; _vertexCount = other._vertexCount; - _indexBuffer = other._indexBuffer; _indexCount = other._indexCount; - _indexType = other._indexType; + indexOffset = other.indexOffset; + indexType = other.indexType; + indexBuffer = other.indexBuffer; attributes = std::move(other.attributes); #ifndef MAGNUM_TARGET_GLES2 integerAttributes = std::move(other.integerAttributes); @@ -94,6 +95,13 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } +Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type) { + indexOffset = offset; + indexType = type; + (this->*bindIndexBufferImplementation)(buffer); + return this; +} + void Mesh::draw() { /* Nothing to draw */ if(!_vertexCount && !_indexCount) return; @@ -104,7 +112,7 @@ void Mesh::draw() { if(!_indexCount) glDrawArrays(static_cast(_primitive), 0, _vertexCount); /* Indexed mesh */ - else glDrawElements(static_cast(_primitive), _indexCount, static_cast(_indexType), nullptr); + else glDrawElements(static_cast(_primitive), _indexCount, static_cast(indexType), reinterpret_cast(indexOffset)); (this->*unbindImplementation)(); } @@ -240,7 +248,7 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { #endif void Mesh::bindIndexBufferImplementationDefault(Buffer* buffer) { - _indexBuffer = buffer; + indexBuffer = buffer; } void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) { diff --git a/src/Mesh.h b/src/Mesh.h index ca5f37bd2..f98b13c79 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -42,12 +42,10 @@ vertex buffer(s). The function itself calls setVertexCount(), so you don't have to do it again. If you have indexed mesh, you need to call setIndexCount() instead of -setVertexCount() and additionaly specify also index type using setIndexType(). -Then fill your index buffer with data and add it to the mesh using -setIndexBuffer(). You can also use MeshTools::compressIndices() to +setVertexCount(). Then fill your index buffer with data and specify its layout +using setIndexBuffer(). You can also use MeshTools::compressIndices() to conveniently compress the indices, fill the index buffer and configure the -mesh instead of calling setIndexCount(), setIndexType() and setIndexBuffer() -manually. +mesh instead of calling setIndexCount() and setIndexBuffer() manually. Note that neither vertex buffers nor index buffer is managed (e.g. deleted on destruction) by the mesh, so you have to manage them on your own. On the other @@ -130,12 +128,11 @@ static constexpr GLubyte indices[75] = { }; indexBuffer->setData(indices, Buffer::Usage::StaticDraw); -// Set primitive, index count and type, add the buffers +// Set primitive, index count, add the buffers mesh->setPrimitive(Mesh::Primitive::Triangles) ->setIndexCount(75) - ->setIndexType(Mesh::IndexType::UnsignedByte) ->addVertexBuffer(vertexBuffer, 0, MyShader::Position()) - ->setIndexBuffer(indexBuffer); + ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte); @endcode @code @@ -152,8 +149,8 @@ MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cube.indices()); -// Set primitive and specify layout of interleaved vertex buffer. Index count, -// type and index buffer has been already set by MeshTools::compressIndices(). +// Set primitive and specify layout of interleaved vertex buffer. Index count +// and index buffer has been already specified by MeshTools::compressIndices(). mesh->setPrimitive(plane.primitive()) ->addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::PhongShader::Position(), @@ -452,7 +449,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Index type * - * @see setIndexType(), indexSize() + * @see setIndexBuffer(), indexSize() */ enum class IndexType: GLenum { UnsignedByte = GL_UNSIGNED_BYTE, /**< Unsigned byte */ @@ -532,28 +529,13 @@ class MAGNUM_EXPORT Mesh { * @return Pointer to self (for method chaining) * * Default is zero. - * @see setIndexBuffer(), setIndexType(), MeshTools::compressIndices() + * @see setIndexBuffer(), MeshTools::compressIndices() */ inline Mesh* setIndexCount(GLsizei count) { _indexCount = count; return this; } - /** @brief Index type */ - inline IndexType indexType() const { return _indexType; } - - /** - * @brief Set index type - * @return Pointer to self (for method chaining) - * - * Default is @ref IndexType "IndexType::UnsignedInt". - * @see setIndexBuffer(), setIndexCount(), MeshTools::compressIndices() - */ - inline Mesh* setIndexType(IndexType type) { - _indexType = type; - return this; - } - /** * @brief Add buffer with non-interleaved vertex attributes for use with given shader * @return Pointer to self (for method chaining) @@ -686,16 +668,16 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set index buffer + * @param buffer Index buffer + * @param offset Offset into the buffer + * @param type Index data type * @return Pointer to self (for method chaining) * - * @see setIndexCount(), setIndexType(), MeshTools::compressIndices(), + * @see setIndexCount(), MeshTools::compressIndices(), * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - inline Mesh* setIndexBuffer(Buffer* buffer) { - (this->*bindIndexBufferImplementation)(buffer); - return this; - } + Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type); /** * @brief Draw the mesh @@ -871,7 +853,7 @@ class MAGNUM_EXPORT Mesh { typedef void(Mesh::*BindIndexBufferImplementation)(Buffer*); void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer); void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer); - static BindIndexBufferImplementation bindIndexBufferImplementation; + static MAGNUM_LOCAL BindIndexBufferImplementation bindIndexBufferImplementation; typedef void(Mesh::*BindImplementation)(); void MAGNUM_LOCAL bindImplementationDefault(); @@ -885,10 +867,10 @@ class MAGNUM_EXPORT Mesh { GLuint vao; Primitive _primitive; - GLsizei _vertexCount; - Buffer* _indexBuffer; - GLsizei _indexCount; - IndexType _indexType; + GLsizei _vertexCount, _indexCount; + GLintptr indexOffset; + IndexType indexType; + Buffer* indexBuffer; std::vector attributes; #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 7d3890517..60ce595be 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -66,9 +66,8 @@ void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std: char* data; std::tie(indexCount, indexType, data) = compressIndices(indices); - mesh->setIndexBuffer(buffer) - ->setIndexType(indexType) - ->setIndexCount(indices.size()); + mesh->setIndexCount(indices.size()) + ->setIndexBuffer(buffer, 0, indexType); buffer->setData(indexCount*Mesh::indexSize(indexType), data, usage); delete[] data; diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index c68b991e6..a0ee59b1e 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -62,9 +62,9 @@ std::tuple MAGNUM_MESHTOOLS_EXPORT compress @param indices Index array The same as compressIndices(const std::vector&), but this -function writes the output to given index buffer and updates index count and -type in the mesh accordingly, so you don't have to call Mesh::setIndexBuffer(), -Mesh::setIndexCount() and Mesh::setIndexType() on your own. +function writes the output to given buffer, updates index count and specifies +index buffer in the mesh, so you don't have to call Mesh::setIndexCount() +and Mesh::setIndexBuffer() on your own. @see MeshTools::interleave() */ From a1c37258d62d686b4b8d72bbbd5756a41a1920a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 Jan 2013 23:31:22 +0100 Subject: [PATCH 226/567] Added missing const. --- src/AbstractTexture.cpp | 2 +- src/AbstractTexture.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index f6872fa59..6693f37da 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -435,7 +435,7 @@ void AbstractTexture::invalidateSubImplementationARB(GLint level, const Vector3i #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_TARGET_GLES2 namespace Implementation { - template GLvoid* ImageHelper>::dataOrPixelUnpackBuffer(BufferImage* image) { + template const GLvoid* ImageHelper>::dataOrPixelUnpackBuffer(BufferImage* image) { image->buffer()->bind(Buffer::Target::PixelUnpack); return nullptr; } diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 7bdf8ab78..9d7c8a118 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1278,7 +1278,7 @@ class MAGNUM_EXPORT AbstractTexture { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct ImageHelper { - inline static GLvoid* dataOrPixelUnpackBuffer(Image* image) { + inline static const GLvoid* dataOrPixelUnpackBuffer(Image* image) { #ifndef MAGNUM_TARGET_GLES2 Buffer::unbind(Buffer::Target::PixelUnpack); #endif @@ -1288,7 +1288,7 @@ namespace Implementation { #ifndef MAGNUM_TARGET_GLES2 template struct MAGNUM_EXPORT ImageHelper> { - static GLvoid* dataOrPixelUnpackBuffer(BufferImage* image); + static const GLvoid* dataOrPixelUnpackBuffer(BufferImage* image); }; #endif } From d20682f3e5b394b6132ce0428015a1dd1a179155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 Jan 2013 23:32:43 +0100 Subject: [PATCH 227/567] Mesh: don't allow specifying index data from client memory. --- src/Mesh.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 4cc89e5f2..ed361d67f 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -277,10 +277,7 @@ void Mesh::bindImplementationDefault() { #endif /* Bind index buffer, if the mesh is indexed */ - if(_indexCount) { - if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); - else Buffer::unbind(Buffer::Target::ElementArray); - } + if(_indexCount) indexBuffer->bind(Buffer::Target::ElementArray); } void Mesh::bindImplementationVAO() { From f07e4743f976a6aefed4cc1d653b9859810b0f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 00:21:06 +0100 Subject: [PATCH 228/567] Ability to specify index range in Mesh::setIndexBuffer(). --- src/DebugTools/ObjectRenderer.cpp | 2 +- src/Mesh.cpp | 40 +++++++++++++++++++++++----- src/Mesh.h | 43 +++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index f0a98e9a4..137df6a73 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -161,7 +161,7 @@ template ObjectRenderer::ObjectRenderer(Sce ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColorShader::Position(), typename Shaders::VertexColorShader::Color()) - ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte); + ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, Renderer::positions.size()); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index ed361d67f..2275d197d 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -49,7 +49,12 @@ std::size_t Mesh::indexSize(IndexType type) { CORRADE_INTERNAL_ASSERT(false); } -Mesh::Mesh(Primitive primitive): _primitive(primitive), _vertexCount(0), _indexCount(0), indexOffset(0), indexType(IndexType::UnsignedInt), indexBuffer(nullptr) { +Mesh::Mesh(Primitive primitive): _primitive(primitive), _vertexCount(0), _indexCount(0) + #ifndef MAGNUM_TARGET_GLES2 + , indexStart(0), indexEnd(0) + #endif + , indexOffset(0), indexType(IndexType::UnsignedInt), indexBuffer(nullptr) +{ (this->*createImplementation)(); } @@ -61,7 +66,11 @@ Mesh::~Mesh() { (this->*destroyImplementation)(); } -Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount), indexOffset(other.indexOffset), indexType(other.indexType), indexBuffer(other.indexBuffer), attributes(std::move(other.attributes)) +Mesh::Mesh(Mesh&& other): vao(other.vao), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount) + #ifndef MAGNUM_TARGET_GLES2 + , indexStart(other.indexStart), indexEnd(other.indexEnd) + #endif + , indexOffset(other.indexOffset), indexType(other.indexType), indexBuffer(other.indexBuffer), attributes(std::move(other.attributes)) #ifndef MAGNUM_TARGET_GLES2 , integerAttributes(std::move(other.integerAttributes)) #ifndef MAGNUM_TARGET_GLES @@ -79,6 +88,10 @@ Mesh& Mesh::operator=(Mesh&& other) { _primitive = other._primitive; _vertexCount = other._vertexCount; _indexCount = other._indexCount; + #ifndef MAGNUM_TARGET_GLES2 + indexStart = other.indexStart; + indexEnd = other.indexEnd; + #endif indexOffset = other.indexOffset; indexType = other.indexType; indexBuffer = other.indexBuffer; @@ -95,9 +108,16 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } -Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type) { +Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, GLuint start, GLuint end) { indexOffset = offset; indexType = type; + #ifndef MAGNUM_TARGET_GLES2 + indexStart = start; + indexEnd = end; + #else + static_cast(start); + static_cast(end); + #endif (this->*bindIndexBufferImplementation)(buffer); return this; } @@ -109,10 +129,18 @@ void Mesh::draw() { (this->*bindImplementation)(); /* Non-indexed mesh */ - if(!_indexCount) glDrawArrays(static_cast(_primitive), 0, _vertexCount); + if(!_indexCount) + glDrawArrays(static_cast(_primitive), 0, _vertexCount); + + #ifndef MAGNUM_TARGET_GLES2 + /* Indexed mesh with specified range */ + else if(indexEnd) + glDrawRangeElements(static_cast(_primitive), indexStart, indexEnd, _indexCount, static_cast(indexType), reinterpret_cast(indexOffset)); + #endif - /* Indexed mesh */ - else glDrawElements(static_cast(_primitive), _indexCount, static_cast(indexType), reinterpret_cast(indexOffset)); + /* Indexed mesh without specified range */ + else + glDrawElements(static_cast(_primitive), _indexCount, static_cast(indexType), reinterpret_cast(indexOffset)); (this->*unbindImplementation)(); } diff --git a/src/Mesh.h b/src/Mesh.h index f98b13c79..81c06e13f 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -117,7 +117,7 @@ Buffer *vertexBuffer, *indexBuffer; Mesh* mesh; // Fill vertex buffer with position data -static constexpr Point3D positions[30] = { +static constexpr Point3D positions[300] = { // ... }; vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); @@ -128,11 +128,11 @@ static constexpr GLubyte indices[75] = { }; indexBuffer->setData(indices, Buffer::Usage::StaticDraw); -// Set primitive, index count, add the buffers +// Set primitive, index count, specify the buffers mesh->setPrimitive(Mesh::Primitive::Triangles) ->setIndexCount(75) ->addVertexBuffer(vertexBuffer, 0, MyShader::Position()) - ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte); + ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229); @endcode @code @@ -204,6 +204,10 @@ calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for more information. +If index range is specified in setIndexBuffer(), range-based version of +drawing commands are used on desktop OpenGL and OpenGL ES 3.0. See also draw() +for more information. + @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ @@ -671,13 +675,39 @@ class MAGNUM_EXPORT Mesh { * @param buffer Index buffer * @param offset Offset into the buffer * @param type Index data type + * @param start Minimum array index contained in the buffer + * @param end Maximum array index contained in the buffer * @return Pointer to self (for method chaining) * + * The smaller range is specified with @p start and @p end the less + * memory operations are needed (and possibly some optimizations), + * improving draw performance. Specifying `0` for both parameters + * behaves the same as setIndexBuffer(Buffer*, GLintptr, IndexType). + * On OpenGL ES 2.0 this function behaves always as + * setIndexBuffer(Buffer*, GLintptr, IndexType), as this functionality + * is not available there. * @see setIndexCount(), MeshTools::compressIndices(), * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type); + Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, GLuint start, GLuint end); + + /** + * @brief Set index buffer + * @param buffer Index buffer + * @param offset Offset into the buffer + * @param type Index data type + * @return Pointer to self (for method chaining) + * + * Prefer to use setIndexBuffer(Buffer*, GLintptr, IndexType, GLuint, GLuint) + * for better performance. + * @see setIndexCount(), MeshTools::compressIndices(), + * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if + * @extension{APPLE,vertex_array_object} is available) + */ + inline Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type) { + return setIndexBuffer(buffer, offset, type, 0, 0); + } /** * @brief Draw the mesh @@ -688,7 +718,7 @@ class MAGNUM_EXPORT Mesh { * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} - * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements} + * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements}. */ void draw(); @@ -868,6 +898,9 @@ class MAGNUM_EXPORT Mesh { GLuint vao; Primitive _primitive; GLsizei _vertexCount, _indexCount; + #ifndef MAGNUM_TARGET_GLES2 + GLuint indexStart, indexEnd; + #endif GLintptr indexOffset; IndexType indexType; Buffer* indexBuffer; From 09b115679b7d21b9bbfb3747e83db9fb91e413d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 00:48:37 +0100 Subject: [PATCH 229/567] MeshTools: making use of index range in compressIndices(). --- src/MeshTools/CompressIndices.cpp | 26 ++++++++++++++++---------- src/MeshTools/CompressIndices.h | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 60ce595be..b76c5af3e 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -40,13 +40,8 @@ template inline std::tuple compres return std::make_tuple(indices.size(), indexType(), buffer); } -} -#endif - -std::tuple compressIndices(const std::vector& indices) { - std::size_t size = *std::max_element(indices.begin(), indices.end()); - - switch(Math::log(256, size)) { +std::tuple compressIndicesInternal(const std::vector& indices, std::uint32_t max) { + switch(Math::log(256, max)) { case 0: return compress(indices); case 1: @@ -56,18 +51,29 @@ std::tuple compressIndices(const std::vecto return compress(indices); default: - CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << size << "elements.", {}); + CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {}); } } +} +#endif + +std::tuple compressIndices(const std::vector& indices) { + return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end())); +} + void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { + auto minmax = std::minmax_element(indices.begin(), indices.end()); + + /** @todo Performance hint when range can be represented by smaller value? */ + std::size_t indexCount; Mesh::IndexType indexType; char* data; - std::tie(indexCount, indexType, data) = compressIndices(indices); + std::tie(indexCount, indexType, data) = compressIndicesInternal(indices, *minmax.second); mesh->setIndexCount(indices.size()) - ->setIndexBuffer(buffer, 0, indexType); + ->setIndexBuffer(buffer, 0, indexType, *minmax.first, *minmax.second); buffer->setData(indexCount*Mesh::indexSize(indexType), data, usage); delete[] data; diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index a0ee59b1e..ac67d5849 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -63,8 +63,8 @@ std::tuple MAGNUM_MESHTOOLS_EXPORT compress The same as compressIndices(const std::vector&), but this function writes the output to given buffer, updates index count and specifies -index buffer in the mesh, so you don't have to call Mesh::setIndexCount() -and Mesh::setIndexBuffer() on your own. +index buffer with proper index range in the mesh, so you don't have to call +Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own. @see MeshTools::interleave() */ From 58f936386fe17253068ffc8db26f7c4342b67aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 13:07:57 +0100 Subject: [PATCH 230/567] Doc++ --- src/SceneGraph/AbstractCamera.h | 5 +++-- src/SceneGraph/Animable.h | 17 +++++++++-------- src/SceneGraph/Camera2D.h | 5 +++-- src/SceneGraph/Camera3D.h | 5 +++-- src/SceneGraph/Object.h | 5 +++-- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 2043583dd..458bf4029 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -53,8 +53,9 @@ instantiatable, use Camera2D or Camera3D subclasses instead. @section AbstractCamera-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use AbstractCamera.hpp implementation -file to avoid linker errors. See also relevant sections in +For other specializations (e.g. using `double` type) you have to use +AbstractCamera.hpp implementation file to avoid linker errors. See also +relevant sections in @ref Camera2D-explicit-specializations "Camera2D" and @ref Camera3D-explicit-specializations "Camera3D" class documentation or @ref compilation-speedup-hpp for more information. diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index a6fc01d90..ae2414fd8 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -80,9 +80,9 @@ class AnimableObject: public Object3D, SceneGraph::Animable3D<> { @endcode Then add the object to your scene and some animation group. You can also use -AnimableGroup::add() and AnimableGroup::remove(). The animation is initially -in stopped state and without repeat, see setState(), setRepeated() and -setRepeatCount() for more information. +AnimableGroup::add() and AnimableGroup::remove() instead of passing the group +in the constructor. The animation is initially in stopped state and without +repeat, see setState(), setRepeated() and setRepeatCount() for more information. @code Scene3D scene; SceneGraph::AnimableGroup3D<> animables; @@ -113,15 +113,16 @@ void MyApplication::drawEvent() { AnimableGroup is optimized for case when no animation is running - it just puts itself to rest and waits until some animation changes its state to -running again. If you put animations which are not pernamently running to -separate group, they will not be traversed when calling AnimableGroup::step(), -saving precious frame time. +@ref AnimationState "AnimationState::Running" again. If you put animations +which are not pernamently running to separate group, they will not be always +traversed when calling AnimableGroup::step(), saving precious frame time. @section Animable-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into %SceneGraph library. -For other specializations you have to use Animable.hpp implementation file to -avoid linker errors. See also @ref compilation-speedup-hpp for more information. +For other specializations (e.g. using `double` type) you have to use +Animable.hpp implementation file to avoid linker errors. See also +@ref compilation-speedup-hpp for more information. - @ref Animable "Animable<2, GLfloat>", @ref AnimableGroup "AnimableGroup<2, GLfloat>" - @ref Animable "Animable<3, GLfloat>", @ref AnimableGroup "AnimableGroup<3, GLfloat>" diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 5154b3f4a..37775924f 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -38,8 +38,9 @@ camera->setProjection({4.0f/3.0f, 1.0f}) @section Camera2D-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use Camera2D.hpp implementation file to -avoid linker errors. See @ref compilation-speedup-hpp for more information. +For other specializations (e.g. using `double` type) you have to use +Camera2D.hpp implementation file to avoid linker errors. See +@ref compilation-speedup-hpp for more information. - @ref Camera2D "Camera2D" diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 24180fd9c..4551d6bcb 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -43,8 +43,9 @@ camera->setPerspective({}, 0.001f, 100.0f) @section Camera3D-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use Camera3D.hpp implementation file to -avoid linker errors. See @ref compilation-speedup-hpp for more information. +For other specializations (e.g. using `double` type) you have to use +Camera3D.hpp implementation file to avoid linker errors. See +@ref compilation-speedup-hpp for more information. - @ref Camera3D "Camera3D" diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index e94d0e84d..9a8346d49 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -68,8 +68,9 @@ for(Object* child = o->firstChild(); child; child = child->nextSibling()) { @section Object-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use Object.hpp implementation file to -avoid linker errors. See @ref compilation-speedup-hpp for more information. +For other specializations (e.g. using `double` type or special transformation +class) you have to use Object.hpp implementation file to avoid linker errors. +See @ref compilation-speedup-hpp for more information. - @ref MatrixTransformation2D "Object>" - @ref MatrixTransformation3D "Object>" From 5e8625bd980129891f1e98543a8a2e0886057b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 13:08:27 +0100 Subject: [PATCH 231/567] SceneGraph: don't pass duration in Animable constructor. It gets lost in the whole parameter list, using protected function setDuration() instead. Default is `0.0f`, which means infinite duration. --- src/SceneGraph/Animable.h | 30 +++++++++++++++++++--------- src/SceneGraph/Animable.hpp | 2 +- src/SceneGraph/Test/AnimableTest.cpp | 12 +++++++---- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index ae2414fd8..a0e51de2e 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -60,8 +60,8 @@ which takes care of running the animations. First thing is add Animable feature to some object and implement animationStep(). You can do it conveniently using multiple inheritance (see -@ref scenegraph-features for introduction). You need to pass animation -duration to constructor, animationStep() provides both absolute animation +@ref scenegraph-features for introduction). Override animationStep() to +implement your animation, the function provides both absolute animation time and time delta. Example: @code typedef SceneGraph::Object> Object3D; @@ -69,7 +69,8 @@ typedef SceneGraph::Scene> Scene3D; class AnimableObject: public Object3D, SceneGraph::Animable3D<> { public: - AnimableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Animable3D<>(this, 10.0f, group) { + AnimableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Animable3D<>(this, group) { + setDuration(10.0f); // ... } @@ -141,15 +142,13 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* object, GLfloat duration, AnimableGroup* group = nullptr); + explicit Animable(AbstractObject* object, AnimableGroup* group = nullptr); /** @brief Animation duration */ inline GLfloat duration() const { return _duration; } @@ -213,6 +212,19 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* group() const; protected: + /** + * @brief Set animation duration + * @return Pointer to self (for method chaining) + * + * Sets duration of the animation cycle in seconds. Set to `0.0f` for + * infinite non-repeating animation. Default is `0.0f`. + */ + /* Protected so only animation implementer can change it */ + inline Animable* setDuration(GLfloat duration) { + _duration = duration; + return this; + } + /** * @brief Perform animation step * @param time Time from start of the animation @@ -294,7 +306,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature Animable::Animable(AbstractObject* object, GLfloat duration, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(duration), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} +template Animable::Animable(AbstractObject* object, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(0.0f), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} template Animable* Animable::setState(AnimationState state) { if(currentState == state) return this; diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index 600f815d4..1c4840fb1 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -51,7 +51,9 @@ AnimableTest::AnimableTest() { void AnimableTest::state() { class StateTrackingAnimable: public SceneGraph::Animable<3> { public: - StateTrackingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 1.0f, group) {} + StateTrackingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group) { + setDuration(1.0f); + } std::string trackedState; @@ -139,7 +141,8 @@ void AnimableTest::state() { class OneShotAnimable: public SceneGraph::Animable<3> { public: - OneShotAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 10.0f, group), time(-1.0f) { + OneShotAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f) { + setDuration(10.0f); setState(AnimationState::Running); } @@ -163,7 +166,7 @@ class OneShotAnimable: public SceneGraph::Animable<3> { void AnimableTest::step() { class InifiniteAnimable: public SceneGraph::Animable<3> { public: - InifiniteAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 0.0f, group), time(-1.0f), delta(0.0f) {} + InifiniteAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f), delta(0.0f) {} GLfloat time, delta; @@ -222,7 +225,8 @@ void AnimableTest::duration() { void AnimableTest::repeat() { class RepeatingAnimable: public SceneGraph::Animable<3> { public: - RepeatingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, 10.0f, group), time(-1.0f) { + RepeatingAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f) { + setDuration(10.0f); setState(AnimationState::Running); setRepeated(true); } From 2267627242ab78b77b42150dbcd6e907f8facaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 15:14:36 +0100 Subject: [PATCH 232/567] Text: return rendered rectangle from TextRenderer::render(). --- src/Text/TextRenderer.cpp | 22 ++++++++++++++-------- src/Text/TextRenderer.h | 13 ++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index aacbba97d..b81a0c6c8 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -30,7 +30,7 @@ namespace Magnum { namespace Text { namespace { -std::tuple, std::vector, std::vector> renderInternal(Font& font, GLfloat size, const std::string& text) { +std::tuple, std::vector, std::vector, Rectangle> renderInternal(Font& font, GLfloat size, const std::string& text) { /* Prepare HarfBuzz buffer */ hb_buffer_t *buffer = hb_buffer_create(); hb_buffer_set_unicode_funcs(buffer, hb_icu_get_unicode_funcs()); @@ -106,10 +106,14 @@ std::tuple, std::vector, std::vector typename DimensionTraits::PointType point(const Vector2& vec); @@ -124,10 +128,11 @@ template<> inline Point3D point<3>(const Vector2& vec) { } -template std::tuple::PointType>, std::vector, std::vector> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { +template std::tuple::PointType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { std::vector positions, textureCoordinates; std::vector indices; - std::tie(positions, textureCoordinates, indices) = renderInternal(font, size, text); + Rectangle rectangle; + std::tie(positions, textureCoordinates, indices, rectangle) = renderInternal(font, size, text); /* Create PointXD from Vector2 */ std::vector::PointType> positionsXD; @@ -135,16 +140,17 @@ template std::tuple(position)); - return std::make_tuple(std::move(positionsXD), std::move(textureCoordinates), std::move(indices)); + return std::make_tuple(std::move(positionsXD), std::move(textureCoordinates), std::move(indices), rectangle); } -template Mesh TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { +template std::tuple TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { Mesh mesh; std::vector::PointType> positions; std::vector textureCoordinates; std::vector indices; - std::tie(positions, textureCoordinates, indices) = render(font, size, text); + Rectangle rectangle; + std::tie(positions, textureCoordinates, indices, rectangle) = render(font, size, text); MeshTools::interleave(&mesh, vertexBuffer, usage, positions, textureCoordinates); MeshTools::compressIndices(&mesh, indexBuffer, usage, indices); @@ -153,7 +159,7 @@ template Mesh TextRenderer::render(Font& fo typename Shaders::AbstractTextShader::Position(), typename Shaders::AbstractTextShader::TextureCoordinates()); - return mesh; + return std::make_tuple(std::move(mesh), rectangle); } template class TextRenderer<2>; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 26322df2c..629dce858 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -47,9 +47,11 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * @param font %Font to use * @param size %Font size * @param text %Text to render - * @return Tuple with vertex positions, texture coordinates and indices + * + * Returns tuple with vertex positions, texture coordinates, indices + * and rectangle spanning the rendered text. */ - static std::tuple::PointType>, std::vector, std::vector> render(Font& font, GLfloat size, const std::string& text); + static std::tuple::PointType>, std::vector, std::vector, Rectangle> render(Font& font, GLfloat size, const std::string& text); /** * @brief Render text @@ -59,10 +61,11 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * @param vertexBuffer %Buffer where to store vertices * @param indexBuffer %Buffer where to store indices * @param usage Usage of vertex and index buffer - * @return Indexed mesh prepared for use with Shaders::AbstractTextShader - * subclasses + * + * Returns mesh prepared for use with Shaders::AbstractTextShader + * subclasses and rectangle spanning the rendered text. */ - static Mesh render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + static std::tuple render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); private: #ifndef DOXYGEN_GENERATING_OUTPUT From 177898f93c50d72623ecd2c49fd8f7fbc8b63a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 15:15:06 +0100 Subject: [PATCH 233/567] SceneGraph: code cleanup, documentation, fixed assertions. The original assertion didn't actually check anything, because the list was always empty. Moved/copied it to relevant places. --- src/SceneGraph/Object.hpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index f352d23b1..902ba3e83 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -144,20 +144,36 @@ template std::vector std::vector Object::transformations(std::vector*> objects, const typename Transformation::DataType& initialTransformation) const { + CORRADE_ASSERT(objects.size() < 0xFFFFu, "SceneGraph::Object::transformations(): too large scene", {}); + /* Remember object count for later */ std::size_t objectCount = objects.size(); /** @bug What if there is one objects twice in the list */ - /* Create initial list of joints from original objects */ - std::vector*> jointObjects(objects.size()); - for(std::size_t i = 0; i != jointObjects.size(); ++i) { - jointObjects[i] = static_cast*>(objects[i]); - CORRADE_INTERNAL_ASSERT(jointObjects[i]->counter == 0xFFFFu); - jointObjects[i]->counter = i; - jointObjects[i]->flags |= Flag::Joint; + /* Mark all original objects as joints and create initial list of joints + from them */ + for(std::size_t i = 0; i != objects.size(); ++i) { + CORRADE_INTERNAL_ASSERT(objects[i]->counter == 0xFFFFu); + objects[i]->counter = i; + objects[i]->flags |= Flag::Joint; } + std::vector*> jointObjects(objects); /* Scene object */ const Scene* scene = this->scene(); @@ -186,6 +202,8 @@ template std::vector Ob /* If not already marked as joint, mark it as such and add it to list of joint objects */ if(!(parent->flags & Flag::Joint)) { + CORRADE_ASSERT(jointObjects.size() < 0xFFFFu, + "SceneGraph::Object::transformations(): too large scene", {}); CORRADE_INTERNAL_ASSERT(parent->counter == 0xFFFFu); parent->counter = jointObjects.size(); parent->flags |= Flag::Joint; @@ -199,8 +217,6 @@ template std::vector Ob if(it == objects.end()) it = objects.begin(); } - CORRADE_ASSERT(objects.size() < 0xFFFFu, "SceneGraph::Object::transformations(): too large scene", {}); - /* Array of absolute transformations in joints */ std::vector jointTransformations(jointObjects.size()); From b86f107396a0023729a02cb35a8001adf5312e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 18:51:33 +0100 Subject: [PATCH 234/567] SceneGraph: split object transformations test into more functions. --- src/SceneGraph/Test/ObjectTest.cpp | 55 +++++++++++++++++++----------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 09248ac5d..0ee556cb1 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -30,6 +30,8 @@ class ObjectTest: public Corrade::TestSuite::Tester { void scene(); void absoluteTransformation(); void transformations(); + void transformationsRelative(); + void transformationsOrphan(); void setClean(); void bulkSetClean(); }; @@ -56,6 +58,8 @@ ObjectTest::ObjectTest() { &ObjectTest::scene, &ObjectTest::absoluteTransformation, &ObjectTest::transformations, + &ObjectTest::transformationsRelative, + &ObjectTest::transformationsOrphan, &ObjectTest::setClean, &ObjectTest::bulkSetClean); } @@ -164,32 +168,43 @@ void ObjectTest::transformations() { initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), initial*Matrix4::rotationZ(deg(30.0f)), })); +} - { - CORRADE_EXPECT_FAIL("Transformations not relative to scene are not yet implemented."); - - /* Transformation relative to another object */ - CORRADE_COMPARE(second.transformations({&third}), std::vector{ - Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f)) - }); - - /* Transformation relative to another object, not part of any scene (but should work) */ - Object3D orphanParent1; - orphanParent1.rotate(deg(31.0f), Vector3(1.0f).normalized()); - Object3D orphanParent(&orphanParent1); - Object3D orphan1(&orphanParent); - orphan1.scale(Vector3::xScale(3.0f)); - Object3D orphan2(&orphanParent); - orphan2.translate(Vector3::zAxis(5.0f)); - CORRADE_COMPARE(orphan1.transformations({&orphan2}), std::vector{ - Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f)) - }); - } +void ObjectTest::transformationsRelative() { + CORRADE_EXPECT_FAIL("Transformations not relative to scene are not yet implemented."); + Scene3D s; + Object3D first(&s); + first.rotateZ(deg(30.0f)); + Object3D second(&first); + second.scale(Vector3(0.5f)); + Object3D third(&first); + third.translate(Vector3::xAxis(5.0f)); + + /* Transformation relative to another object */ + CORRADE_COMPARE(second.transformations({&third}), std::vector{ + Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f)) + }); + + /* Transformation relative to another object, not part of any scene (but should work) */ + Object3D orphanParent1; + orphanParent1.rotate(deg(31.0f), Vector3(1.0f).normalized()); + Object3D orphanParent(&orphanParent1); + Object3D orphan1(&orphanParent); + orphan1.scale(Vector3::xScale(3.0f)); + Object3D orphan2(&orphanParent); + orphan2.translate(Vector3::zAxis(5.0f)); + CORRADE_COMPARE(orphan1.transformations({&orphan2}), std::vector{ + Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f)) + }); +} + +void ObjectTest::transformationsOrphan() { std::ostringstream o; Error::setOutput(&o); /* Transformation of objects not part of the same scene */ + Scene3D s; Object3D orphan; CORRADE_COMPARE(s.transformations({&orphan}), std::vector()); CORRADE_COMPARE(o.str(), "SceneGraph::Object::transformations(): the objects are not part of the same tree\n"); From 59a3a7029df0524d93fe5015113c668356da93ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 18:52:17 +0100 Subject: [PATCH 235/567] SceneGraph: allow duplicate occurences in Object::transformations(). Fixes common case where one Object has multiple Drawable features attached (one for regular mesh and one e.g. debug renderer). --- src/SceneGraph/Object.hpp | 26 ++++++++++++++++++++++---- src/SceneGraph/Test/ObjectTest.cpp | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index 902ba3e83..e0911bbd3 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -169,7 +169,10 @@ template std::vector Ob /* Mark all original objects as joints and create initial list of joints from them */ for(std::size_t i = 0; i != objects.size(); ++i) { - CORRADE_INTERNAL_ASSERT(objects[i]->counter == 0xFFFFu); + /* Multiple occurences of one object in the array, don't overwrite it + with different counter */ + if(objects[i]->counter != 0xFFFFu) continue; + objects[i]->counter = i; objects[i]->flags |= Flag::Joint; } @@ -184,8 +187,13 @@ template std::vector Ob /* Mark all objects up the hierarchy as visited */ auto it = objects.begin(); while(!objects.empty()) { + /* Already visited, remove and continue to next (duplicate occurence) */ + if((*it)->flags & Flag::Visited) { + it = objects.erase(it); + continue; + } + /* Mark the object as visited */ - CORRADE_INTERNAL_ASSERT(!((*it)->flags & Flag::Visited)); (*it)->flags |= Flag::Visited; Object* parent = (*it)->parent(); @@ -224,9 +232,18 @@ template std::vector Ob for(std::size_t i = 0; i != jointTransformations.size(); ++i) computeJointTransformation(jointObjects, jointTransformations, i, initialTransformation); + /* Copy transformation for second or next occurences from first occurence + of duplicate object */ + for(std::size_t i = 0; i != objectCount; ++i) { + if(jointObjects[i]->counter != i) + jointTransformations[i] = jointTransformations[jointObjects[i]->counter]; + } + /* All visited marks are now cleaned, clean joint marks and counters */ for(auto i: jointObjects) { - CORRADE_INTERNAL_ASSERT(i->flags & Flag::Joint); + /* All not-already cleaned objects (...duplicate occurences) should + have joint mark */ + CORRADE_INTERNAL_ASSERT(i->counter = 0xFFFFu || i->flags & Flag::Joint); i->flags &= ~Flag::Joint; i->counter = 0xFFFFu; } @@ -239,7 +256,8 @@ template std::vector Ob template typename Transformation::DataType Object::computeJointTransformation(const std::vector*>& jointObjects, std::vector& jointTransformations, const std::size_t joint, const typename Transformation::DataType& initialTransformation) const { Object* o = jointObjects[joint]; - /* Transformation already computed ("unvisited" by this function before), done */ + /* Transformation already computed ("unvisited" by this function before + either due to recursion or duplicate object occurences), done */ if(!(o->flags & Flag::Visited)) return jointTransformations[joint]; /* Initialize transformation */ diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 0ee556cb1..322d4014b 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -32,6 +32,7 @@ class ObjectTest: public Corrade::TestSuite::Tester { void transformations(); void transformationsRelative(); void transformationsOrphan(); + void transformationsDuplicate(); void setClean(); void bulkSetClean(); }; @@ -60,6 +61,7 @@ ObjectTest::ObjectTest() { &ObjectTest::transformations, &ObjectTest::transformationsRelative, &ObjectTest::transformationsOrphan, + &ObjectTest::transformationsDuplicate, &ObjectTest::setClean, &ObjectTest::bulkSetClean); } @@ -210,6 +212,23 @@ void ObjectTest::transformationsOrphan() { CORRADE_COMPARE(o.str(), "SceneGraph::Object::transformations(): the objects are not part of the same tree\n"); } +void ObjectTest::transformationsDuplicate() { + Scene3D s; + Object3D first(&s); + first.rotateZ(deg(30.0f)); + Object3D second(&first); + second.scale(Vector3(0.5f)); + Object3D third(&first); + third.translate(Vector3::xAxis(5.0f)); + + Matrix4 firstExpected = Matrix4::rotationZ(deg(30.0f)); + Matrix4 secondExpected = Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)); + Matrix4 thirdExpected = Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)); + CORRADE_COMPARE(s.transformations({&second, &third, &second, &first, &third}), (std::vector{ + secondExpected, thirdExpected, secondExpected, firstExpected, thirdExpected + })); +} + void ObjectTest::setClean() { Scene3D scene; From 85b715e115e8190ca0570943c8649ff43a263577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 20:35:22 +0100 Subject: [PATCH 236/567] Trade: added forward declaration header. --- doc/compilation-speedup.dox | 1 + src/Trade/AbstractImporter.h | 20 ++------------ src/Trade/CMakeLists.txt | 3 ++- src/Trade/Trade.h | 51 ++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/Trade/Trade.h diff --git a/doc/compilation-speedup.dox b/doc/compilation-speedup.dox index 23313c4be..99abac95e 100644 --- a/doc/compilation-speedup.dox +++ b/doc/compilation-speedup.dox @@ -26,6 +26,7 @@ available, each namespace has its own: - SceneGraph/SceneGraph.h - Shaders/Shaders.h - Text/Text.h + - Trade/Trade.h @section compilation-speedup-templates Templates diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 764fe5bed..f31d18dbd 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -22,28 +22,12 @@ #include #include +#include "Trade/Trade.h" + #include "magnumVisibility.h" namespace Magnum { namespace Trade { -/** @todoc Remove `ifndef` when Doxygen is sane again */ -#ifndef DOXYGEN_GENERATING_OUTPUT -class AbstractMaterialData; -class CameraData; -template class ImageData; -class LightData; -class MeshData2D; -class MeshData3D; -class ObjectData2D; -class ObjectData3D; -class SceneData; -class TextureData; -#endif - -typedef ImageData<1> ImageData1D; -typedef ImageData<2> ImageData2D; -typedef ImageData<3> ImageData3D; - /** @brief Base for importer plugins diff --git a/src/Trade/CMakeLists.txt b/src/Trade/CMakeLists.txt index 11d7bac8f..52cb96bb3 100644 --- a/src/Trade/CMakeLists.txt +++ b/src/Trade/CMakeLists.txt @@ -12,7 +12,8 @@ set(MagnumTrade_HEADERS ObjectData3D.h PhongMaterialData.h SceneData.h - TextureData.h) + TextureData.h + Trade.h) install(FILES ${MagnumTrade_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Trade) if(BUILD_TESTS) diff --git a/src/Trade/Trade.h b/src/Trade/Trade.h new file mode 100644 index 000000000..b629b96d8 --- /dev/null +++ b/src/Trade/Trade.h @@ -0,0 +1,51 @@ +#ifndef Magnum_Trade_Trade_h +#define Magnum_Trade_Trade_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Forward declarations for Magnum::Trade namespace + */ + +#include + +namespace Magnum { namespace Trade { + +/** @todoc Remove `ifndef` when Doxygen is sane again */ +#ifndef DOXYGEN_GENERATING_OUTPUT +class AbstractImporter; +class AbstractMaterialData; +class CameraData; + +template class ImageData; +typedef ImageData<1> ImageData1D; +typedef ImageData<2> ImageData2D; +typedef ImageData<3> ImageData3D; + +class LightData; +class MeshData2D; +class MeshData3D; +class MeshObjectData2D; +class MeshObjectData3D; +class ObjectData2D; +class ObjectData3D; +class PhongMaterialData; +class SceneData; +class TextureData; +#endif + +}} + +#endif From 547c8a24da55bfd25eb67a17cb52f31146912062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 20:35:45 +0100 Subject: [PATCH 237/567] Trade: defaulted move constructor/assignment. Hope they will work as expected. Copying is still forbidden, as it brings serious performance impact for no useful reason. --- src/Trade/MeshData2D.h | 8 ++++++-- src/Trade/MeshData3D.h | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index 1ad8f30d3..b3457956d 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -35,9 +35,7 @@ type. */ class MAGNUM_EXPORT MeshData2D { MeshData2D(const MeshData2D& other) = delete; - MeshData2D(MeshData2D&& other) = delete; MeshData2D& operator=(const MeshData2D& other) = delete; - MeshData2D& operator=(MeshData2D&& other) = delete; public: /** @@ -52,9 +50,15 @@ class MAGNUM_EXPORT MeshData2D { */ inline MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + /** @brief Move constructor */ + MeshData2D(MeshData2D&&) = default; + /** @brief Destructor */ ~MeshData2D(); + /** @brief Move assignment */ + MeshData2D& operator=(MeshData2D&&) = default; + /** @brief Primitive */ inline Mesh::Primitive primitive() const { return _primitive; } diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index cf454d968..0d83b152a 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -35,9 +35,7 @@ type. */ class MAGNUM_EXPORT MeshData3D { MeshData3D(const MeshData3D& other) = delete; - MeshData3D(MeshData3D&& other) = delete; MeshData3D& operator=(const MeshData3D& other) = delete; - MeshData3D& operator=(MeshData3D&& other) = delete; public: /** @@ -53,9 +51,15 @@ class MAGNUM_EXPORT MeshData3D { */ inline MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + /** @brief Move constructor */ + MeshData3D(MeshData3D&&) = default; + /** @brief Destructor */ ~MeshData3D(); + /** @brief Move assignment */ + MeshData3D& operator=(MeshData3D&&) = default; + /** @brief Primitive */ inline Mesh::Primitive primitive() const { return _primitive; } From ac6182b3296c5ae852e110bd698cba8d44b69d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 20:37:52 +0100 Subject: [PATCH 238/567] Primitives: Cube can be now solid or wireframe. --- src/Primitives/Cube.cpp | 158 +++++++++++++++++++++++----------------- src/Primitives/Cube.h | 23 ++++-- 2 files changed, 108 insertions(+), 73 deletions(-) diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 1d5e721e3..51d5a4c02 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -16,76 +16,98 @@ #include "Cube.h" #include "Math/Point3D.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D(Mesh::Primitive::Triangles, new std::vector{ - 0, 1, 2, 0, 2, 3, /* +Z */ - 4, 5, 6, 4, 6, 7, /* +X */ - 8, 9, 10, 8, 10, 11, /* +Y */ - 12, 13, 14, 12, 14, 15, /* -Z */ - 16, 17, 18, 16, 18, 19, /* -Y */ - 20, 21, 22, 20, 22, 23 /* -X */ -}, {new std::vector{ - {-1.0f, -1.0f, 1.0f}, - { 1.0f, -1.0f, 1.0f}, - { 1.0f, 1.0f, 1.0f}, /* +Z */ - {-1.0f, 1.0f, 1.0f}, - - { 1.0f, -1.0f, 1.0f}, - { 1.0f, -1.0f, -1.0f}, - { 1.0f, 1.0f, -1.0f}, /* +X */ - { 1.0f, 1.0f, 1.0f}, - - {-1.0f, 1.0f, 1.0f}, - { 1.0f, 1.0f, 1.0f}, - { 1.0f, 1.0f, -1.0f}, /* +Y */ - {-1.0f, 1.0f, -1.0f}, - - { 1.0f, -1.0f, -1.0f}, - {-1.0f, -1.0f, -1.0f}, - {-1.0f, 1.0f, -1.0f}, /* -Z */ - { 1.0f, 1.0f, -1.0f}, - - {-1.0f, -1.0f, -1.0f}, - { 1.0f, -1.0f, -1.0f}, - { 1.0f, -1.0f, 1.0f}, /* -Y */ - {-1.0f, -1.0f, 1.0f}, - - {-1.0f, -1.0f, -1.0f}, - {-1.0f, -1.0f, 1.0f}, - {-1.0f, 1.0f, 1.0f}, /* -X */ - {-1.0f, 1.0f, -1.0f} -}}, {new std::vector{ - { 0.0f, 0.0f, 1.0f}, - { 0.0f, 0.0f, 1.0f}, - { 0.0f, 0.0f, 1.0f}, /* +Z */ - { 0.0f, 0.0f, 1.0f}, - - { 1.0f, 0.0f, 0.0f}, - { 1.0f, 0.0f, 0.0f}, - { 1.0f, 0.0f, 0.0f}, /* +X */ - { 1.0f, 0.0f, 0.0f}, - - { 0.0f, 1.0f, 0.0f}, - { 0.0f, 1.0f, 0.0f}, - { 0.0f, 1.0f, 0.0f}, /* +Y */ - { 0.0f, 1.0f, 0.0f}, - - { 0.0f, 0.0f, -1.0f}, - { 0.0f, 0.0f, -1.0f}, - { 0.0f, 0.0f, -1.0f}, /* -Z */ - { 0.0f, 0.0f, -1.0f}, - - { 0.0f, -1.0f, 0.0f}, - { 0.0f, -1.0f, 0.0f}, - { 0.0f, -1.0f, 0.0f}, /* -Y */ - { 0.0f, -1.0f, 0.0f}, - - {-1.0f, 0.0f, 0.0f}, - {-1.0f, 0.0f, 0.0f}, - {-1.0f, 0.0f, 0.0f}, /* -X */ - {-1.0f, 0.0f, 0.0f} -}}, {}) {} +Trade::MeshData3D Cube::solid() { + return Trade::MeshData3D(Mesh::Primitive::Triangles, new std::vector{ + 0, 1, 2, 0, 2, 3, /* +Z */ + 4, 5, 6, 4, 6, 7, /* +X */ + 8, 9, 10, 8, 10, 11, /* +Y */ + 12, 13, 14, 12, 14, 15, /* -Z */ + 16, 17, 18, 16, 18, 19, /* -Y */ + 20, 21, 22, 20, 22, 23 /* -X */ + }, {new std::vector{ + {-1.0f, -1.0f, 1.0f}, + { 1.0f, -1.0f, 1.0f}, + { 1.0f, 1.0f, 1.0f}, /* +Z */ + {-1.0f, 1.0f, 1.0f}, + + { 1.0f, -1.0f, 1.0f}, + { 1.0f, -1.0f, -1.0f}, + { 1.0f, 1.0f, -1.0f}, /* +X */ + { 1.0f, 1.0f, 1.0f}, + + {-1.0f, 1.0f, 1.0f}, + { 1.0f, 1.0f, 1.0f}, + { 1.0f, 1.0f, -1.0f}, /* +Y */ + {-1.0f, 1.0f, -1.0f}, + + { 1.0f, -1.0f, -1.0f}, + {-1.0f, -1.0f, -1.0f}, + {-1.0f, 1.0f, -1.0f}, /* -Z */ + { 1.0f, 1.0f, -1.0f}, + + {-1.0f, -1.0f, -1.0f}, + { 1.0f, -1.0f, -1.0f}, + { 1.0f, -1.0f, 1.0f}, /* -Y */ + {-1.0f, -1.0f, 1.0f}, + + {-1.0f, -1.0f, -1.0f}, + {-1.0f, -1.0f, 1.0f}, + {-1.0f, 1.0f, 1.0f}, /* -X */ + {-1.0f, 1.0f, -1.0f} + }}, {new std::vector{ + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, /* +Z */ + { 0.0f, 0.0f, 1.0f}, + + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, /* +X */ + { 1.0f, 0.0f, 0.0f}, + + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, /* +Y */ + { 0.0f, 1.0f, 0.0f}, + + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, /* -Z */ + { 0.0f, 0.0f, -1.0f}, + + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, /* -Y */ + { 0.0f, -1.0f, 0.0f}, + + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, /* -X */ + {-1.0f, 0.0f, 0.0f} + }}, {}); +} + +Trade::MeshData3D Cube::wireframe() { + return Trade::MeshData3D(Mesh::Primitive::Lines, new std::vector{ + 0, 1, 1, 2, 2, 3, 3, 0, /* +Z */ + 4, 5, 5, 6, 6, 7, 7, 4, /* -Z */ + 1, 5, 2, 6, /* +X */ + 0, 4, 3, 7 /* -X */ + }, {new std::vector{ + {-1.0f, -1.0f, 1.0f}, + { 1.0f, -1.0f, 1.0f}, + { 1.0f, 1.0f, 1.0f}, + {-1.0f, 1.0f, 1.0f}, + + {-1.0f, -1.0f, -1.0f}, + { 1.0f, -1.0f, -1.0f}, + { 1.0f, 1.0f, -1.0f}, + {-1.0f, 1.0f, -1.0f} + }}, {}, {}); +} }} diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index b62606c16..734471e52 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -19,19 +19,32 @@ * @brief Class Magnum::Primitives::Cube */ -#include "Trade/MeshData3D.h" +#include "Trade/Trade.h" namespace Magnum { namespace Primitives { /** @brief 3D cube primitive -2x2x2 cube. Indexed triangle mesh with flat normals. +2x2x2 cube. */ -class Cube: public Trade::MeshData3D { +class Cube { public: - /** @brief Constructor */ - explicit Cube(); + /** + * @brief Solid cube + * + * Indexed triangle mesh with flat normals. + */ + static Trade::MeshData3D solid(); + + /** + * @brief Wireframe cube + * + * Indexed line mesh. + */ + static Trade::MeshData3D wireframe(); + + Cube() = delete; }; }} From 25b752a31116997d94c7b4c1f30151a34f635b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 20:38:25 +0100 Subject: [PATCH 239/567] Primitives: Plane can be now solid or wireframe. --- src/Primitives/Plane.cpp | 34 +++++++++++++++++++++++----------- src/Primitives/Plane.h | 22 ++++++++++++++++++---- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index aec78371c..8bcd58c4c 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -16,19 +16,31 @@ #include "Plane.h" #include "Math/Point3D.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { -Plane::Plane(): MeshData3D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ - {1.0f, -1.0f, 0.0f}, - {1.0f, 1.0f, 0.0f}, - {-1.0f, -1.0f, 0.0f}, - {-1.0f, 1.0f, 0.0f} -}}, {new std::vector{ - {0.0f, 0.0f, 1.0f}, - {0.0f, 0.0f, 1.0f}, - {0.0f, 0.0f, 1.0f}, - {0.0f, 0.0f, 1.0f} -}}, {}) {} +Trade::MeshData3D Plane::solid() { + return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ + {1.0f, -1.0f, 0.0f}, + {1.0f, 1.0f, 0.0f}, + {-1.0f, -1.0f, 0.0f}, + {-1.0f, 1.0f, 0.0f} + }}, {new std::vector{ + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f} + }}, {}); +} + +Trade::MeshData3D Plane::wireframe() { + return Trade::MeshData3D(Mesh::Primitive::LineLoop, nullptr, {new std::vector{ + {-1.0f, -1.0f, 0.0f}, + {1.0f, -1.0f, 0.0f}, + {1.0f, 1.0f, 0.0f}, + {-1.0f, 1.0f, 0.0f} + }}, {}, {}); +} }} diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index 9de4f9a2b..b19ef792a 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Primitives::Plane */ -#include "Trade/MeshData3D.h" +#include "Trade/Trade.h" namespace Magnum { namespace Primitives { @@ -28,10 +28,24 @@ namespace Magnum { namespace Primitives { 2x2 plane as triangle strip, non-indexed with normals in positive Z direction. */ -class Plane: public Trade::MeshData3D { +class Plane { public: - /** @brief Constructor */ - explicit Plane(); + /** + * @brief Solid plane + * + * Non-indexed @ref Mesh::Primitive "TriangleStrip" with normals in + * positive Z direction. + */ + static Trade::MeshData3D solid(); + + /** + * @brief Wireframe plane + * + * Non-indexed @ref Mesh::Primitive "LineLoop". + */ + static Trade::MeshData3D wireframe(); + + Plane() = delete; }; }} From 0f27fb536f2cdfa102985eba5bd25e6c3846a5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 20:38:45 +0100 Subject: [PATCH 240/567] Primitives: Square can be now solid or wireframe. --- src/Primitives/Square.cpp | 24 ++++++++++++++++++------ src/Primitives/Square.h | 23 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index 57c601237..fe2dcd971 100644 --- a/src/Primitives/Square.cpp +++ b/src/Primitives/Square.cpp @@ -16,14 +16,26 @@ #include "Square.h" #include "Math/Point2D.h" +#include "Trade/MeshData2D.h" namespace Magnum { namespace Primitives { -Square::Square(): MeshData2D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ - {1.0f, -1.0f}, - {1.0f, 1.0f}, - {-1.0f, -1.0f}, - {-1.0f, 1.0f} -}}, {}) {} +Trade::MeshData2D Square::solid() { + return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ + {1.0f, -1.0f}, + {1.0f, 1.0f}, + {-1.0f, -1.0f}, + {-1.0f, 1.0f} + }}, {}); +} + +Trade::MeshData2D Square::wireframe() { + return Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {new std::vector{ + {-1.0f, -1.0f}, + {1.0f, -1.0f}, + {1.0f, 1.0f}, + {-1.0f, 1.0f} + }}, {}); +} }} diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index 7d3f96754..6bd77a172 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -19,19 +19,32 @@ * @brief Class Magnum::Primitives::Square */ -#include "Trade/MeshData2D.h" +#include "Trade/Trade.h" namespace Magnum { namespace Primitives { /** @brief 2D square primitive -2x2 square as triangle strip, non-indexed. +2x2 square. */ -class Square: public Trade::MeshData2D { +class Square { public: - /** @brief Constructor */ - explicit Square(); + /** + * @brief Solid square + * + * Non-indexed @ref Mesh::Primitive "TriangleStrip". + */ + static Trade::MeshData2D solid(); + + /** + * @brief Wireframe square + * + * Non-indexed @ref Mesh::Primitive "LineLoop." + */ + static Trade::MeshData2D wireframe(); + + Square() = delete; }; }} From c3bbf03917a90ea2f219a565a74749e478009ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 20:39:13 +0100 Subject: [PATCH 241/567] DebugTools: using wireframe primitives in ShapeRenderer. --- src/DebugTools/Implementation/AbstractBoxRenderer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index 988f2de64..e62bbc87a 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -21,6 +21,8 @@ #include "Primitives/Cube.h" #include "Primitives/Square.h" #include "Shaders/FlatShader.h" +#include "Trade/MeshData2D.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace DebugTools { namespace Implementation { @@ -36,7 +38,7 @@ AbstractBoxRenderer<2>::AbstractBoxRenderer() { if(mesh) return; /* Create the mesh */ - Primitives::Square square; + Trade::MeshData2D square = Primitives::Square::wireframe(); Buffer* buffer = new Buffer(Buffer::Target::Array); Mesh* mesh = new Mesh; @@ -62,7 +64,7 @@ AbstractBoxRenderer<3>::AbstractBoxRenderer() { if(mesh) return; /* Create the mesh */ - Primitives::Cube cube; + Trade::MeshData3D cube = Primitives::Cube::wireframe(); Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); Mesh* mesh = new Mesh; From b69f729e75e319af19c29e5771634c21449f55f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 21:31:38 +0100 Subject: [PATCH 242/567] SceneGraph: thinko in FeatureGroup destructor. FeatureGroup shouldn't delete the features, as all features are deleted in Object destructor anyway and no feature can be created without explicitly attaching it to some Object (and it also cannot be detached). Moreover, when the group contains two features belogning to one object and one feature is added using multiple inheritance, on group destruction the object gets deleted along with the feature, removing also the other feature, which breaks the for cycle in group destructor. --- src/SceneGraph/FeatureGroup.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 8a8ddeff3..ad1a94bbb 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -47,13 +47,10 @@ class FeatureGroup { /** * @brief Destructor * - * Deletes all features belogning to this group. + * Removes all features belogning to this group, but not deletes them. */ inline virtual ~FeatureGroup() { - for(auto i: features) { - i->_group = nullptr; - delete i; - } + for(auto i: features) i->_group = nullptr; } /** @brief Whether the group is empty */ From 377170212cfd70e3684cf27c5b8f64d58c03c9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 21:52:27 +0100 Subject: [PATCH 243/567] DebugTools: render boxes with proper size. Cube and Square primitives have 2x2(x2) size, thus to render box with size 1x1(x1) we have to set scale to 0.5. --- src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 345f69642..25a69c435 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -24,9 +24,10 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { + /* Half scale, because the box is 2x2(x2) */ typename DimensionTraits::MatrixType transformation = DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* - DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()); + DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()/2); this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*transformation) ->setColor(options->color()) ->use(); From 96884d5ac784e6ece05e706866d2604631dccdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 22:04:43 +0100 Subject: [PATCH 244/567] DebugTools: render also non-axis-aligned boxes with proper size. Yay for this convoluted mess (but hey, it's generic code working for both 2D and 3D!). --- src/DebugTools/Implementation/BoxRenderer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 4a0b98675..8fc1a7dcf 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -24,7 +24,8 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { - this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) + this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()* + DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(0.5f))) ->setColor(options->color()) ->use(); this->mesh->draw(); From 99efc0cb62d820ca54d9c07667298b94cf8e3033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 01:20:36 +0100 Subject: [PATCH 245/567] DebugTools: common mesh building implementation for all shape renderers. --- .../Implementation/AbstractBoxRenderer.cpp | 63 ++--------------- .../Implementation/AbstractBoxRenderer.h | 16 +---- .../Implementation/AbstractShapeRenderer.cpp | 70 +++++++++++++++++++ .../Implementation/AbstractShapeRenderer.h | 21 +++++- .../Implementation/AxisAlignedBoxRenderer.cpp | 2 + .../Implementation/AxisAlignedBoxRenderer.h | 2 +- src/DebugTools/Implementation/BoxRenderer.cpp | 2 + src/DebugTools/Implementation/BoxRenderer.h | 2 +- 8 files changed, 103 insertions(+), 75 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index e62bbc87a..e04c76c54 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -15,73 +15,22 @@ #include "AbstractBoxRenderer.h" -#include "Buffer.h" -#include "DebugTools/ResourceManager.h" -#include "MeshTools/CompressIndices.h" #include "Primitives/Cube.h" #include "Primitives/Square.h" -#include "Shaders/FlatShader.h" #include "Trade/MeshData2D.h" #include "Trade/MeshData3D.h" namespace Magnum { namespace DebugTools { namespace Implementation { -AbstractBoxRenderer<2>::AbstractBoxRenderer() { - /* Shader */ - shader = ResourceManager::instance()->get("FlatShader2D"); - if(!shader) ResourceManager::instance()->set(shader.key(), - new Shaders::FlatShader2D, ResourceDataState::Final, ResourcePolicy::Resident); - - /* Mesh and vertex buffer */ - mesh = ResourceManager::instance()->get("box2d"); - buffer = ResourceManager::instance()->get("box2d"); - if(mesh) return; - - /* Create the mesh */ - Trade::MeshData2D square = Primitives::Square::wireframe(); - Buffer* buffer = new Buffer(Buffer::Target::Array); - Mesh* mesh = new Mesh; - - buffer->setData(*square.positions(0), Buffer::Usage::StaticDraw); - ResourceManager::instance()->set(this->buffer.key(), buffer, ResourceDataState::Final, ResourcePolicy::Manual); - - mesh->setPrimitive(square.primitive()) - ->setVertexCount(square.positions(0)->size()) - ->addVertexBuffer(buffer, 0, Shaders::FlatShader2D::Position()); - ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); +AbstractBoxRenderer<2>::AbstractBoxRenderer(): AbstractShapeRenderer<2>("box2d", "box2d-vertices", "box2d-indices") { + if(!mesh) this->createResources(Primitives::Square::wireframe()); } -AbstractBoxRenderer<3>::AbstractBoxRenderer() { - /* Shader */ - shader = ResourceManager::instance()->get("FlatShader3D"); - if(!shader) ResourceManager::instance()->set(shader.key(), - new Shaders::FlatShader3D, ResourceDataState::Final, ResourcePolicy::Resident); - - /* Mesh and vertex buffer */ - mesh = ResourceManager::instance()->get("box3d"); - vertexBuffer = ResourceManager::instance()->get("box3d-vertices"); - indexBuffer = ResourceManager::instance()->get("box3d-indices"); - if(mesh) return; - - /* Create the mesh */ - Trade::MeshData3D cube = Primitives::Cube::wireframe(); - Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); - Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); - Mesh* mesh = new Mesh; - - vertexBuffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); - ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); - - MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cube.indices()); - ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); - - mesh->setPrimitive(cube.primitive()) - ->setVertexCount(cube.positions(0)->size()) - ->addVertexBuffer(vertexBuffer, 0, Shaders::FlatShader3D::Position()); - ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); +AbstractBoxRenderer<3>::AbstractBoxRenderer(): AbstractShapeRenderer<3>("box3d", "box3d-vertices", "box3d-indices") { + if(!mesh) this->createResources(Primitives::Cube::wireframe()); } -AbstractBoxRenderer<2>::~AbstractBoxRenderer() {} -AbstractBoxRenderer<3>::~AbstractBoxRenderer() {} +template class AbstractBoxRenderer<2>; +template class AbstractBoxRenderer<3>; }}} diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.h b/src/DebugTools/Implementation/AbstractBoxRenderer.h index 5f2ecfe8c..cc6f2a9a4 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.h +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.h @@ -24,30 +24,16 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template class AbstractBoxRenderer {}; +template class AbstractBoxRenderer; template<> class AbstractBoxRenderer<2>: public AbstractShapeRenderer<2> { public: AbstractBoxRenderer(); - - ~AbstractBoxRenderer(); - - protected: - Resource mesh; - Resource shader; - Resource buffer; }; template<> class AbstractBoxRenderer<3>: public AbstractShapeRenderer<3> { public: AbstractBoxRenderer(); - - ~AbstractBoxRenderer(); - - protected: - Resource mesh; - Resource shader; - Resource vertexBuffer, indexBuffer; }; }}} diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index a1cf63dbb..390ab8955 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -16,14 +16,84 @@ #include "AbstractShapeRenderer.h" #include "AbstractShaderProgram.h" +#include "Buffer.h" #include "Mesh.h" #include "DebugTools/ResourceManager.h" +#include "MeshTools/CompressIndices.h" #include "Shaders/FlatShader.h" +#include "Trade/MeshData2D.h" +#include "Trade/MeshData3D.h" namespace Magnum { namespace DebugTools { namespace Implementation { +namespace { + +template ResourceKey shaderName(); +template<> inline ResourceKey shaderName<2>() { return ResourceKey("FlatShader2D"); } +template<> inline ResourceKey shaderName<3>() { return ResourceKey("FlatShader3D"); } + +template void create(typename MeshData::Type&, Resource&, Resource&, Resource&); + +template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, Resource& indexBufferResource, Resource& vertexBufferResource) { + /* Vertex buffer */ + Buffer* buffer = new Buffer(Buffer::Target::Array); + buffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(vertexBufferResource.key(), buffer, ResourceDataState::Final, ResourcePolicy::Manual); + + /* Mesh configuration */ + Mesh* mesh = new Mesh; + mesh->setPrimitive(data.primitive()) + ->setVertexCount(data.positions(0)->size()) + ->addVertexBuffer(buffer, 0, Shaders::FlatShader2D::Position()); + ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); + + /* Index buffer, if present */ + if(data.indices()) { + Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); + MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices()); + ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + } +} + +template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, Resource& indexBufferResource, Resource& vertexBufferResource) { + /* Vertex buffer */ + Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); + vertexBuffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(vertexBufferResource.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + /* Mesh configuration */ + Mesh* mesh = new Mesh; + mesh->setPrimitive(data.primitive()) + ->setVertexCount(data.positions(0)->size()) + ->addVertexBuffer(vertexBuffer, 0, Shaders::FlatShader3D::Position()); + ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); + + /* Index buffer, if needed */ + if(data.indices()) { + Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); + MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices()); + ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + } +} + +} + +template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey meshKey, ResourceKey vertexBufferKey, ResourceKey indexBufferKey) { + shader = ResourceManager::instance()->get>(shaderName()); + mesh = ResourceManager::instance()->get(meshKey); + vertexBuffer = ResourceManager::instance()->get(vertexBufferKey); + indexBuffer = ResourceManager::instance()->get(indexBufferKey); + + if(!shader) ResourceManager::instance()->set(shaderName(), + new Shaders::FlatShader, ResourceDataState::Final, ResourcePolicy::Resident); +} + template AbstractShapeRenderer::~AbstractShapeRenderer() {} +template void AbstractShapeRenderer::createResources(typename MeshData::Type data) { + create(data, this->mesh, this->vertexBuffer, this->indexBuffer); +} + template class AbstractShapeRenderer<2>; template class AbstractShapeRenderer<3>; diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index ee2c15a23..3d384f6e2 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -16,16 +16,35 @@ */ #include "DimensionTraits.h" -#include "SceneGraph/SceneGraph.h" +#include "Resource.h" #include "DebugTools/DebugTools.h" +#include "SceneGraph/SceneGraph.h" +#include "Shaders/Shaders.h" +#include "Trade/Trade.h" namespace Magnum { namespace DebugTools { namespace Implementation { +template struct MeshData; + +template<> struct MeshData<2> { typedef Trade::MeshData2D Type; }; +template<> struct MeshData<3> { typedef Trade::MeshData3D Type; }; + template class AbstractShapeRenderer { public: + AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer); virtual ~AbstractShapeRenderer(); virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; + + protected: + /* Call only if the mesh resource isn't already present */ + void createResources(typename MeshData::Type data); + + Resource> shader; + Resource mesh; + + private: + Resource indexBuffer, vertexBuffer; }; }}} diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 25a69c435..07544a5a5 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -23,6 +23,8 @@ namespace Magnum { namespace DebugTools { namespace Implementation { +template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} + template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { /* Half scale, because the box is 2x2(x2) */ typename DimensionTraits::MatrixType transformation = diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index cf1120433..4a8b75665 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -25,7 +25,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template class AxisAlignedBoxRenderer: public AbstractBoxRenderer { public: - inline AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} + AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox); void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 8fc1a7dcf..821c056ff 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -23,6 +23,8 @@ namespace Magnum { namespace DebugTools { namespace Implementation { +template BoxRenderer::BoxRenderer(Physics::Box& box): box(box) {} + template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(0.5f))) diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index acaf154f6..6d69c1d56 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -25,7 +25,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template class BoxRenderer: public AbstractBoxRenderer { public: - inline BoxRenderer(Physics::Box& box): box(box) {} + BoxRenderer(Physics::Box& box); void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; From 22750b262d3571306b92cf6cbb4e52c06d625d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 11:17:33 +0100 Subject: [PATCH 246/567] Minor #include cleanup. --- src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp | 1 + src/DebugTools/Implementation/AxisAlignedBoxRenderer.h | 2 +- src/DebugTools/Implementation/BoxRenderer.cpp | 1 + src/DebugTools/Implementation/BoxRenderer.h | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 07544a5a5..7d28cd1a7 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -18,6 +18,7 @@ #include "Mesh.h" #include "DebugTools/ResourceManager.h" #include "DebugTools/ShapeRenderer.h" +#include "Physics/AxisAlignedBox.h" #include "SceneGraph/AbstractCamera.h" #include "Shaders/FlatShader.h" diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index 4a8b75665..00034d75b 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -17,7 +17,7 @@ #include "AbstractBoxRenderer.h" -#include "Physics/AxisAlignedBox.h" +#include "Physics/Physics.h" #include "corradeCompatibility.h" diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 821c056ff..1562d5f90 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -18,6 +18,7 @@ #include "Mesh.h" #include "DebugTools/ResourceManager.h" #include "DebugTools/ShapeRenderer.h" +#include "Physics/Box.h" #include "SceneGraph/AbstractCamera.h" #include "Shaders/FlatShader.h" diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index 6d69c1d56..a97969090 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -17,7 +17,7 @@ #include "AbstractBoxRenderer.h" -#include "Physics/Box.h" +#include "Physics/Physics.h" #include "corradeCompatibility.h" From 4139f701463d2ce752b7680ce8ab591079e8bb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 14:50:21 +0100 Subject: [PATCH 247/567] DebugTools: minor code cleanup. --- .../Implementation/AbstractShapeRenderer.cpp | 10 +++++----- .../Implementation/AxisAlignedBoxRenderer.cpp | 1 - src/DebugTools/Implementation/BoxRenderer.cpp | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index 390ab8955..8f92ad157 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -28,9 +28,9 @@ namespace Magnum { namespace DebugTools { namespace Implementation { namespace { -template ResourceKey shaderName(); -template<> inline ResourceKey shaderName<2>() { return ResourceKey("FlatShader2D"); } -template<> inline ResourceKey shaderName<3>() { return ResourceKey("FlatShader3D"); } +template ResourceKey shaderKey(); +template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } +template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } template void create(typename MeshData::Type&, Resource&, Resource&, Resource&); @@ -79,12 +79,12 @@ template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, } template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey meshKey, ResourceKey vertexBufferKey, ResourceKey indexBufferKey) { - shader = ResourceManager::instance()->get>(shaderName()); + shader = ResourceManager::instance()->get>(shaderKey()); mesh = ResourceManager::instance()->get(meshKey); vertexBuffer = ResourceManager::instance()->get(vertexBufferKey); indexBuffer = ResourceManager::instance()->get(indexBufferKey); - if(!shader) ResourceManager::instance()->set(shaderName(), + if(!shader) ResourceManager::instance()->set(shaderKey(), new Shaders::FlatShader, ResourceDataState::Final, ResourcePolicy::Resident); } diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 7d28cd1a7..629e12fd8 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -16,7 +16,6 @@ #include "AxisAlignedBoxRenderer.h" #include "Mesh.h" -#include "DebugTools/ResourceManager.h" #include "DebugTools/ShapeRenderer.h" #include "Physics/AxisAlignedBox.h" #include "SceneGraph/AbstractCamera.h" diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 1562d5f90..3ed6493d9 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -16,7 +16,6 @@ #include "BoxRenderer.h" #include "Mesh.h" -#include "DebugTools/ResourceManager.h" #include "DebugTools/ShapeRenderer.h" #include "Physics/Box.h" #include "SceneGraph/AbstractCamera.h" From 25da008f9b09e5f02a7933549a80dacb066becf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 14:50:43 +0100 Subject: [PATCH 248/567] DebugTools: don't set resource key for unused index buffer for 2D box. --- src/DebugTools/Implementation/AbstractBoxRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index e04c76c54..90a3ed261 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -AbstractBoxRenderer<2>::AbstractBoxRenderer(): AbstractShapeRenderer<2>("box2d", "box2d-vertices", "box2d-indices") { +AbstractBoxRenderer<2>::AbstractBoxRenderer(): AbstractShapeRenderer<2>("box2d", "box2d-vertices", {}) { if(!mesh) this->createResources(Primitives::Square::wireframe()); } From 7d830a17aa28d196c26fddddb3a732bc406e06a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 14:52:27 +0100 Subject: [PATCH 249/567] DebugTools: simplified and optimized internal shape rendering. All rendering code computed the transformation/projection matrix the same way, resulting in redundant calculations. Also the `transformationMatrix` parameter of internal draw() function was never used. --- src/DebugTools/Implementation/AbstractShapeRenderer.h | 2 +- src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp | 5 ++--- src/DebugTools/Implementation/AxisAlignedBoxRenderer.h | 2 +- src/DebugTools/Implementation/BoxRenderer.cpp | 5 ++--- src/DebugTools/Implementation/BoxRenderer.h | 2 +- src/DebugTools/ShapeRenderer.cpp | 6 ++++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index 3d384f6e2..1f530a86f 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -34,7 +34,7 @@ template class AbstractShapeRenderer { AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer); virtual ~AbstractShapeRenderer(); - virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) = 0; + virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) = 0; protected: /* Call only if the mesh resource isn't already present */ diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 629e12fd8..09d4af8b7 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -18,19 +18,18 @@ #include "Mesh.h" #include "DebugTools/ShapeRenderer.h" #include "Physics/AxisAlignedBox.h" -#include "SceneGraph/AbstractCamera.h" #include "Shaders/FlatShader.h" namespace Magnum { namespace DebugTools { namespace Implementation { template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} -template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { +template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the box is 2x2(x2) */ typename DimensionTraits::MatrixType transformation = DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()/2); - this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*transformation) + this->shader->setTransformationProjectionMatrix(projectionMatrix*transformation) ->setColor(options->color()) ->use(); this->mesh->draw(); diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index 00034d75b..c826a24dc 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -27,7 +27,7 @@ template class AxisAlignedBoxRenderer: public AbstractB public: AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox); - void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: Physics::AxisAlignedBox& axisAlignedBox; diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 3ed6493d9..57d7bf51c 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -18,15 +18,14 @@ #include "Mesh.h" #include "DebugTools/ShapeRenderer.h" #include "Physics/Box.h" -#include "SceneGraph/AbstractCamera.h" #include "Shaders/FlatShader.h" namespace Magnum { namespace DebugTools { namespace Implementation { template BoxRenderer::BoxRenderer(Physics::Box& box): box(box) {} -template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { - this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()* +template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { + this->shader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation()* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(0.5f))) ->setColor(options->color()) ->use(); diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index a97969090..6330ad519 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -27,7 +27,7 @@ template class BoxRenderer: public AbstractBoxRenderer< public: BoxRenderer(Physics::Box& box); - void draw(Resource& options, const typename DimensionTraits::MatrixType& transformation, typename SceneGraph::AbstractCamera* camera) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: Physics::Box& box; diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 89895a6c1..698137893 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -21,6 +21,7 @@ #include "Physics/Box.h" #include "Physics/ObjectShape.h" #include "Physics/ShapeGroup.h" +#include "SceneGraph/AbstractCamera.h" #include "Implementation/AxisAlignedBoxRenderer.h" #include "Implementation/BoxRenderer.h" @@ -76,8 +77,9 @@ template ShapeRenderer::~ShapeRenderer() { for(auto i: renderers) delete i; } -template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { - for(auto i: renderers) i->draw(options, transformationMatrix, camera); +template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType&, SceneGraph::AbstractCamera* camera) { + typename DimensionTraits::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix(); + for(auto i: renderers) i->draw(options, projectionMatrix); } template class ShapeRenderer<2>; From 12e539ff12d83ad32bec6daccd43a11d3b6b7580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 14:54:59 +0100 Subject: [PATCH 250/567] DebugTools: missing break in switch. I don't know why this didn't crash or fail miserably before. --- src/DebugTools/ShapeRenderer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 698137893..1f4851897 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -35,6 +35,7 @@ template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractSha switch(shape->type()) { case Physics::AbstractShape2D::Type::AxisAlignedBox: renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast(shape))); + break; case Physics::AbstractShape2D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast(shape))); break; @@ -52,6 +53,7 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha switch(shape->type()) { case Physics::AbstractShape3D::Type::AxisAlignedBox: renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(*static_cast(shape))); + break; case Physics::AbstractShape3D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast(shape))); break; From 6cbf3439c8611e19edffb0271be42748743d0d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 15:02:07 +0100 Subject: [PATCH 251/567] Doc++ --- src/DebugTools/Implementation/BoxRenderer.cpp | 1 + src/DebugTools/ObjectRenderer.h | 4 ++++ src/DebugTools/ShapeRenderer.h | 7 ++++++- src/Primitives/Capsule.h | 2 +- src/Primitives/Cube.h | 4 ++-- src/Primitives/Cylinder.h | 6 +++--- src/Primitives/Icosphere.h | 4 ++-- src/Primitives/Plane.h | 2 +- src/Primitives/UVSphere.h | 3 ++- 9 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 57d7bf51c..291019d2d 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -25,6 +25,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template BoxRenderer::BoxRenderer(Physics::Box& box): box(box) {} template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { + /* Half scale, because the box is 2x2(x2) */ this->shader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation()* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(0.5f))) ->setColor(options->color()) diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h index 4dadf32af..8aab17f1d 100644 --- a/src/DebugTools/ObjectRenderer.h +++ b/src/DebugTools/ObjectRenderer.h @@ -15,6 +15,10 @@ GNU Lesser General Public License version 3 for more details. */ +/** @file + * @brief Class Magnum::DebugTools::ObjectRenderer, Magnum::DebugTools::ObjectRendererOptions, typedef Magnum::DebugTools::ObjectRenderer2D, Magnum::DebugTools::ObjectRenderer3D + */ + #include "Resource.h" #include "SceneGraph/Drawable.h" #include "Shaders/Shaders.h" diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 5223dbafc..b863d32fd 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -15,6 +15,10 @@ GNU Lesser General Public License version 3 for more details. */ +/** @file + * @brief Class Magnum::DebugTools::ShapeRenderer, Magnum::DebugTools::ShapeRendererOptions, typedef Magnum::DebugTools::ShapeRenderer2D, Magnum::DebugTools::ShapeRenderer3D + */ + #include "Color.h" #include "Resource.h" #include "SceneGraph/Drawable.h" @@ -65,7 +69,8 @@ class ShapeRendererOptions { /** @brief Shape renderer -Visualizes collision shape. See @ref debug-tools-renderers for more information. +Visualizes collision shapes using wireframe primitives. See +@ref debug-tools-renderers for more information. @section ShapeRenderer-usage Basic usage diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 94650a039..dc00e9272 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D capsule primitive -%Cylinder along Y axis with hemispheres instead of caps. Indexed triangle mesh +%Cylinder along Y axis with hemispheres instead of caps. Indexed @ref Mesh::Primitive "Triangles" with normals and optional 2D texture coordinates. */ class Capsule: public Trade::MeshData3D { diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index 734471e52..c46899fb7 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -33,14 +33,14 @@ class Cube { /** * @brief Solid cube * - * Indexed triangle mesh with flat normals. + * Indexed @ref Mesh::Primitive "Triangles" with flat normals. */ static Trade::MeshData3D solid(); /** * @brief Wireframe cube * - * Indexed line mesh. + * Indexed @ref Mesh::Primitive "Lines". */ static Trade::MeshData3D wireframe(); diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index 542d3c8c5..b1063de92 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Primitives::UVSphere + * @brief Class Magnum::Primitives::Cylinder */ #include @@ -28,8 +28,8 @@ namespace Magnum { namespace Primitives { /** @brief 3D cylinder primitive -Indexed triangle mesh with normals, optional 2D texture coordinates and -optional capped ends. +Indexed @ref Mesh::Primitive "Triangles" with normals, optional 2D texture +coordinates and optional capped ends. */ class Cylinder: public Capsule { public: diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index e5aa7ea42..08760c1f2 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -34,7 +34,7 @@ template class Icosphere; /** @brief 3D icosphere primitive with zero subdivisions -Indexed triangle mesh with normals. +Indexed @ref Mesh::Primitive "Triangles" with normals. */ template<> class Icosphere<0>: public Trade::MeshData3D { public: @@ -46,7 +46,7 @@ template<> class Icosphere<0>: public Trade::MeshData3D { @brief 3D icosphere primitive @tparam subdivisions Number of subdivisions -Indexed triangle mesh with normals. +Indexed @ref Mesh::Primitive "Triangles" with normals. */ #ifndef DOXYGEN_GENERATING_OUTPUT template class Icosphere: public Icosphere<0> { diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index b19ef792a..59f22bdf5 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D plane primitive -2x2 plane as triangle strip, non-indexed with normals in positive Z direction. +2x2 plane. */ class Plane { public: diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index 5a55cda1d..d2e77c4d6 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -26,7 +26,8 @@ namespace Magnum { namespace Primitives { /** @brief 3D UV sphere primitive -Indexed triangle mesh with normals and optional 2D texture coordinates. +Indexed @ref Mesh::Primitive "Triangles" with normals and optional 2D texture +coordinates. */ class UVSphere: public Capsule { public: From bdeb1d7ac15005f4f1a4c4f998a6c55ede91e252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 15:09:03 +0100 Subject: [PATCH 252/567] Another #include cleanup. This will break some stuff. --- src/Primitives/Cylinder.cpp | 1 + src/Primitives/Icosphere.cpp | 26 +++++++++++++------------- src/Trade/MeshData2D.cpp | 2 ++ src/Trade/MeshData2D.h | 1 - src/Trade/MeshData3D.cpp | 2 ++ src/Trade/MeshData3D.h | 1 - 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 025242e39..0b9b2488d 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -16,6 +16,7 @@ #include "Cylinder.h" #include "Math/Constants.h" +#include "Math/Point3D.h" namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index f5cc0c1f3..d5e79bbf8 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -15,7 +15,7 @@ #include "Icosphere.h" -#include "Math/Vector4.h" +#include "Math/Point3D.h" namespace Magnum { namespace Primitives { @@ -41,18 +41,18 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vecto 3, 9, 8, 4, 8, 0 }, {new std::vector}, {new std::vector{ - Vector3(0, -0.525731f, 0.850651f), - Vector3(0.850651f, 0, 0.525731f), - Vector3(0.850651f, 0, -0.525731f), - Vector3(-0.850651f, 0, -0.525731f), - Vector3(-0.850651f, 0, 0.525731f), - Vector3(-0.525731f, 0.850651f, 0), - Vector3(0.525731f, 0.850651f, 0), - Vector3(0.525731f, -0.850651f, 0), - Vector3(-0.525731f, -0.850651f, 0), - Vector3(0, -0.525731f, -0.850651f), - Vector3(0, 0.525731f, -0.850651f), - Vector3(0, 0.525731f, 0.850651f) + {0.0f, -0.525731f, 0.850651f}, + {0.850651f, 0.0f, 0.525731f}, + {0.850651f, 0.0f, -0.525731f}, + {-0.850651f, 0.0f, -0.525731f}, + {-0.850651f, 0.0f, 0.525731f}, + {-0.525731f, 0.850651f, 0.0f}, + {0.525731f, 0.850651f, 0.0f}, + {0.525731f, -0.850651f, 0.0f}, + {-0.525731f, -0.850651f, 0.0f}, + {0.0f, -0.525731f, -0.850651f}, + {0.0f, 0.525731f, -0.850651f}, + {0.0f, 0.525731f, 0.850651f} }}, {}) { positions(0)->assign(normals(0)->begin(), normals(0)->end()); } diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp index 8fee8177d..b143396bb 100644 --- a/src/Trade/MeshData2D.cpp +++ b/src/Trade/MeshData2D.cpp @@ -15,6 +15,8 @@ #include "MeshData2D.h" +#include "Math/Point2D.h" + namespace Magnum { namespace Trade { MeshData2D::~MeshData2D() { diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index b3457956d..c41ae1697 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -21,7 +21,6 @@ #include -#include "Math/Point2D.h" #include "Mesh.h" namespace Magnum { namespace Trade { diff --git a/src/Trade/MeshData3D.cpp b/src/Trade/MeshData3D.cpp index 65d59fbd9..e76968720 100644 --- a/src/Trade/MeshData3D.cpp +++ b/src/Trade/MeshData3D.cpp @@ -15,6 +15,8 @@ #include "MeshData3D.h" +#include "Math/Point3D.h" + namespace Magnum { namespace Trade { MeshData3D::~MeshData3D() { diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 0d83b152a..eed0c1650 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -21,7 +21,6 @@ #include -#include "Math/Point3D.h" #include "Mesh.h" namespace Magnum { namespace Trade { From cd148cb3ff7674a5353f29dd81b4ec4dc810ffb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 15:10:08 +0100 Subject: [PATCH 253/567] Primitives: added crosshair primitive. --- src/Primitives/CMakeLists.txt | 2 ++ src/Primitives/Crosshair.cpp | 40 +++++++++++++++++++++++++ src/Primitives/Crosshair.h | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 src/Primitives/Crosshair.cpp create mode 100644 src/Primitives/Crosshair.h diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index 10d36351e..189052ec1 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -1,5 +1,6 @@ set(MagnumPrimitives_SRCS Capsule.cpp + Crosshair.cpp Cube.cpp Cylinder.cpp Icosphere.cpp @@ -8,6 +9,7 @@ set(MagnumPrimitives_SRCS UVSphere.cpp) set(MagnumPrimitives_HEADERS Capsule.h + Crosshair.h Cube.h Cylinder.h Icosphere.h diff --git a/src/Primitives/Crosshair.cpp b/src/Primitives/Crosshair.cpp new file mode 100644 index 000000000..26b323d65 --- /dev/null +++ b/src/Primitives/Crosshair.cpp @@ -0,0 +1,40 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Crosshair.h" + +#include "Math/Point2D.h" +#include "Math/Point3D.h" +#include "Trade/MeshData2D.h" +#include "Trade/MeshData3D.h" + +namespace Magnum { namespace Primitives { + +Trade::MeshData2D Crosshair2D::wireframe() { + return Trade::MeshData2D(Mesh::Primitive::Lines, nullptr, {new std::vector{ + {-1.0f, 0.0f}, {1.0f, 0.0f}, + { 0.0f, -1.0f}, {0.0f, 1.0f} + }}, {}); +} + +Trade::MeshData3D Crosshair3D::wireframe() { + return Trade::MeshData3D(Mesh::Primitive::Lines, nullptr, {new std::vector{ + {-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, + { 0.0f, 0.0f, -1.0f}, {0.0f, 0.0f, 1.0f} + }}, {}, {}); +} + +}} diff --git a/src/Primitives/Crosshair.h b/src/Primitives/Crosshair.h new file mode 100644 index 000000000..55c9841ff --- /dev/null +++ b/src/Primitives/Crosshair.h @@ -0,0 +1,56 @@ +#ifndef Magnum_Primitives_Cube_h +#define Magnum_Primitives_Cube_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Primitives::Crosshair2D, Magnum::Primitives::Crosshair3D + */ + +#include "Trade/Trade.h" + +namespace Magnum { namespace Primitives { + +/** +@brief 2D crosshair primitive + +2x2 wireframe crosshair (two crossed lines), non-indexed +@ref Mesh::Primitive "Lines". +*/ +class Crosshair2D { + public: + /** @brief Wireframe crosshair */ + static Trade::MeshData2D wireframe(); + + Crosshair2D() = delete; +}; + +/** +@brief 3D crosshair primitive + +2x2x2 wireframe crosshair (three crossed lines), non-indexed +@ref Mesh::Primitive "Lines". +*/ +class Crosshair3D { + public: + /** @brief Wireframe crosshair */ + static Trade::MeshData3D wireframe(); + + Crosshair3D() = delete; +}; + +}} + +#endif From 79f77ca665c56370f78f128e50a39f7546b4f53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 15:12:29 +0100 Subject: [PATCH 254/567] DebugTools: added point size to ShapeRendererOptions. --- src/DebugTools/ShapeRenderer.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index b863d32fd..0420344db 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -48,6 +48,8 @@ See ShapeRenderer documentation for more information. */ class ShapeRendererOptions { public: + inline constexpr ShapeRendererOptions(): _pointSize(0.25f) {} + /** @brief Color of rendered shape */ inline constexpr Color3<> color() const { return _color; } @@ -62,8 +64,24 @@ class ShapeRendererOptions { return this; } + /** @brief Point size */ + inline constexpr GLfloat pointSize() const { return _pointSize; } + + /** + * @brief Set point size + * @return Pointer to self (for method chaining) + * + * Size of rendered crosshairs, representing Physics::Point shapes. + * Default is `0.25f`. + */ + inline ShapeRendererOptions* pointSize(GLfloat size) { + _pointSize = size; + return this; + } + private: Color3<> _color; + GLfloat _pointSize; }; /** From 540c322f5ba80c3b893e3c9641e1ff626dcce6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 15:16:10 +0100 Subject: [PATCH 255/567] DebugTools: support for Point shape in ShapeRenderer. --- src/DebugTools/CMakeLists.txt | 3 +- .../Implementation/PointRenderer.cpp | 59 +++++++++++++++++++ src/DebugTools/Implementation/PointRenderer.h | 38 ++++++++++++ src/DebugTools/ShapeRenderer.cpp | 8 +++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/DebugTools/Implementation/PointRenderer.cpp create mode 100644 src/DebugTools/Implementation/PointRenderer.h diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 3f828e7dd..3c6f7ade9 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -7,7 +7,8 @@ set(MagnumDebugTools_SRCS Implementation/AbstractBoxRenderer.cpp Implementation/AbstractShapeRenderer.cpp Implementation/AxisAlignedBoxRenderer.cpp - Implementation/BoxRenderer.cpp) + Implementation/BoxRenderer.cpp + Implementation/PointRenderer.cpp) set(MagnumDebugTools_HEADERS DebugTools.h diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp new file mode 100644 index 000000000..b13f9456b --- /dev/null +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -0,0 +1,59 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "PointRenderer.h" + +#include "Mesh.h" +#include "DebugTools/ShapeRenderer.h" +#include "Physics/Point.h" +#include "Primitives/Crosshair.h" +#include "Shaders/FlatShader.h" +#include "Trade/MeshData2D.h" +#include "Trade/MeshData3D.h" + +namespace Magnum { namespace DebugTools { namespace Implementation { + +namespace { + template ResourceKey meshKey(); + template<> inline ResourceKey meshKey<2>() { return ResourceKey("point2d"); } + template<> inline ResourceKey meshKey<3>() { return ResourceKey("point3d"); } + + template ResourceKey vertexBufferKey(); + template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("point2d-vertices"); } + template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); } + + template typename MeshData::Type meshData(); + template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Crosshair2D::wireframe(); } + template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); } +} + +template PointRenderer::PointRenderer(Physics::Point& point): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), point(point) { + if(!this->mesh) this->createResources(meshData()); +} + +template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { + /* Half scale, because the point is 2x2(x2) */ + this->shader->setTransformationProjectionMatrix(projectionMatrix* + DimensionTraits::MatrixType::translation(point.transformedPosition())* + DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->pointSize()/2))) + ->setColor(options->color()) + ->use(); + this->mesh->draw(); +} + +template class PointRenderer<2>; +template class PointRenderer<3>; + +}}} diff --git a/src/DebugTools/Implementation/PointRenderer.h b/src/DebugTools/Implementation/PointRenderer.h new file mode 100644 index 000000000..31e22c746 --- /dev/null +++ b/src/DebugTools/Implementation/PointRenderer.h @@ -0,0 +1,38 @@ +#ifndef Magnum_DebugTools_Implementation_PointRenderer_h +#define Magnum_DebugTools_Implementation_PointRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AbstractShapeRenderer.h" + +#include "Physics/Physics.h" + +#include "corradeCompatibility.h" + +namespace Magnum { namespace DebugTools { namespace Implementation { + +template class PointRenderer: public AbstractShapeRenderer { + public: + PointRenderer(Physics::Point& point); + + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + + private: + Physics::Point& point; +}; + +}}} + +#endif diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 1f4851897..54a6cf21a 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -20,11 +20,13 @@ #include "Physics/AxisAlignedBox.h" #include "Physics/Box.h" #include "Physics/ObjectShape.h" +#include "Physics/Point.h" #include "Physics/ShapeGroup.h" #include "SceneGraph/AbstractCamera.h" #include "Implementation/AxisAlignedBoxRenderer.h" #include "Implementation/BoxRenderer.h" +#include "Implementation/PointRenderer.h" namespace Magnum { namespace DebugTools { @@ -39,6 +41,9 @@ template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractSha case Physics::AbstractShape2D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast(shape))); break; + case Physics::AbstractShape2D::Type::Point: + renderer->renderers.push_back(new Implementation::PointRenderer<2>(*static_cast(shape))); + break; case Physics::AbstractShape2D::Type::ShapeGroup: { Physics::ShapeGroup2D* group = static_cast(shape); if(group->first()) createDebugMesh(renderer, group->first()); @@ -57,6 +62,9 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha case Physics::AbstractShape3D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast(shape))); break; + case Physics::AbstractShape3D::Type::Point: + renderer->renderers.push_back(new Implementation::PointRenderer<3>(*static_cast(shape))); + break; case Physics::AbstractShape3D::Type::ShapeGroup: { Physics::ShapeGroup3D* group = static_cast(shape); if(group->first()) createDebugMesh(renderer, group->first()); From 604c5f35ee6de6dc482d40ade084df62d6b583c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 16:27:00 +0100 Subject: [PATCH 256/567] DebugTools: oops, swapped order of parameters. --- src/DebugTools/Implementation/AbstractShapeRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index 8f92ad157..2a37ace5d 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -34,7 +34,7 @@ template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D" template void create(typename MeshData::Type&, Resource&, Resource&, Resource&); -template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, Resource& indexBufferResource, Resource& vertexBufferResource) { +template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, Resource& vertexBufferResource, Resource& indexBufferResource) { /* Vertex buffer */ Buffer* buffer = new Buffer(Buffer::Target::Array); buffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); @@ -55,7 +55,7 @@ template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, } } -template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, Resource& indexBufferResource, Resource& vertexBufferResource) { +template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, Resource& vertexBufferResource, Resource& indexBufferResource) { /* Vertex buffer */ Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); vertexBuffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); From f8d71941fdbe9fd99543c20c92898df38197fe31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 16:28:20 +0100 Subject: [PATCH 257/567] DebugTools: assertions for non-empty resource key when it is needed. Shape renderer can specify empty resource key if index buffer won't be used. --- src/DebugTools/Implementation/AbstractShapeRenderer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index 2a37ace5d..b32dc0c1f 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -47,8 +47,9 @@ template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, ->addVertexBuffer(buffer, 0, Shaders::FlatShader2D::Position()); ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); - /* Index buffer, if present */ + /* Index buffer, if needed, if not, resource key doesn't have to be set */ if(data.indices()) { + CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey()); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices()); ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); @@ -68,8 +69,9 @@ template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, ->addVertexBuffer(vertexBuffer, 0, Shaders::FlatShader3D::Position()); ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); - /* Index buffer, if needed */ + /* Index buffer, if needed, if not, resource key doesn't have to be set */ if(data.indices()) { + CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey()); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices()); ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); From 5707a138d169f6bd18a0767d061fa51de8ab167e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 16:29:26 +0100 Subject: [PATCH 258/567] Print also resource key when attempting to overwrite final resource. --- src/ResourceManager.h | 2 +- src/Test/ResourceManagerTest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 0bd806a63..380b2af7a 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -157,7 +157,7 @@ namespace Implementation { /* Cannot change resource with already final state */ CORRADE_ASSERT(it == _data.end() || it->second.state != ResourceDataState::Final, - "ResourceManager::set(): cannot change already final resource", ); + "ResourceManager::set(): cannot change already final resource" << key, ); /* If nothing is referencing reference-counted resource, we're done */ if(policy == ResourcePolicy::ReferenceCounted && (it == _data.end() || it->second.referenceCount == 0)) { diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 79a2c308f..fb676037d 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -162,7 +162,7 @@ void ResourceManagerTest::basic() { Error::setOutput(&out); rm.set(answerKey, new std::int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource\n"); + CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource " + answerKey.hexString() + '\n'); /* But non-final can be changed */ rm.set(questionKey, new std::int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); From ee732676656aff282e16f15a99df3921f219eea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 18:00:42 +0100 Subject: [PATCH 259/567] Physics: convenience overload for ObjectShape::setShape(). Will allow for more convenient usage of e.g. ShapeGroup operators: Physics::ObjectShape3D* shape; shape->setShape(Physics::Sphere3D({}, 0.75f) || Physics::AxisAlignedBox3D({}, {3.0f, 1.5f, 2.0f})); --- src/Physics/ObjectShape.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 259ee93ef..23e0d69a3 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -65,6 +65,25 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShape: publi return this; } + /** + * @brief Set shape + * @return Pointer to self (for method chaining) + * + * Convenience overload for setShape(AbstractShape*), allowing you to + * use e.g. ShapeGroup operators: + * @code + * Physics::ObjectShape3D* shape; + * shape->setShape(Physics::Sphere3D({}, 0.75f) || Physics::AxisAlignedBox3D({}, {3.0f, 1.5f, 2.0f})); + * @endcode + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + template inline ObjectShape* setShape(T&& shape) { + #else + template inline typename std::enable_if, T>::value, ObjectShape*>::type setShape(T&& shape) { + #endif + return setShape(new T(std::move(shape))); + } + inline ObjectShapeGroup* group() { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } From 29806b94158c45d78d59b48822c74235a0d5bfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 18:02:35 +0100 Subject: [PATCH 260/567] Doc++ --- src/Mesh.h | 19 ++++++++++--------- src/Physics/ObjectShape.h | 27 +++++++++++++++++++++++++-- src/Physics/ObjectShapeGroup.h | 17 ++++++++++++++--- src/SceneGraph/Animable.h | 7 ++++++- src/SceneGraph/Drawable.h | 2 +- src/SceneGraph/Object.h | 2 +- 6 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/Mesh.h b/src/Mesh.h index 81c06e13f..40a6658a3 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -250,9 +250,9 @@ class MAGNUM_EXPORT Mesh { * @see setProvokingVertex() * @requires_gl32 %Extension @extension{ARB,provoking_vertex}. Older * versions behave always like - * ProvokingMode::%LastVertexConvention. + * @ref Magnum::Mesh::ProvokingVertex "ProvokingVertex::LastVertexConvention". * @requires_gl OpenGL ES behaves always like - * ProvokingMode::%LastVertexConvention. + * @ref Magnum::Mesh::ProvokingVertex "ProvokingVertex::LastVertexConvention". */ enum class ProvokingVertex: GLenum { /** @brief Use first vertex of each polygon. */ @@ -265,7 +265,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set provoking vertex * - * Initial value is ProvokingMode::%LastVertexConvention. + * Initial value is @ref ProvokingVertex "ProvokingVertex::LastVertexConvention". * @see @fn_gl{ProvokingVertex} * @requires_gl32 %Extension @extension{ARB,provoking_vertex}. Older * versions behave always like the default. @@ -281,9 +281,8 @@ class MAGNUM_EXPORT Mesh { * @brief Polygon mode * * @see setPolygonMode() - * @requires_gl OpenGL ES behaves always like - * PolygonMode::%Fill. See setPrimitive() for possible - * workaround. + * @requires_gl OpenGL ES behaves always like @ref Magnum::Mesh::PolygonMode "PolygonMode::Fill". + * See setPrimitive() for possible workaround. */ enum class PolygonMode: GLenum { /** @@ -308,7 +307,7 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set polygon drawing mode * - * Initial value is `PolygonMode::%Fill`. + * Initial value is @ref PolygonMode "PolygonMode::Fill". * @see @fn_gl{PolygonMode} * @requires_gl OpenGL ES behaves always like the default. See * setPrimitive() for possible workaround. @@ -332,13 +331,15 @@ class MAGNUM_EXPORT Mesh { /** * Offset lines. - * @requires_gl Only PolygonOffset::%Fill is supported. + * @requires_gl Only @ref Magnum::Mesh::PolygonOffsetMode "PolygonOffsetMode::Fill" + * is available in OpenGL ES. */ Line = GL_POLYGON_OFFSET_LINE, /** * Offset points. - * @requires_gl Only PolygonOffset::%Fill is supported. + * @requires_gl Only @ref Magnum::Mesh::PolygonOffsetMode "PolygonOffsetMode::Fill" + * is available in OpenGL ES. */ Point = GL_POLYGON_OFFSET_POINT #endif diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 23e0d69a3..6bba9209e 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -29,8 +29,25 @@ namespace Magnum { namespace Physics { /** @brief Object shape -Adds shape for collision detection to object. -@see ObjectShape2D, ObjectShape3D +Adds shape for collision detection to object. Each %ObjectShape is part of +some ObjectShapeGroup, which essentially maintains a set of objects which can +collide with each other. + +@section ObjectShape-usage Usage + +Add the feature to the object and some shape group (you can also use +ObjectShapeGroup::add() and ObjectShapeGroup::remove() later) and then set +desired object shape using setShape(). +@code +Physics::ObjectShapeGroup3D shapes; + +Object3D* object; +auto shape = new Physics::ObjectShape3D(object, &shapes); +shape->setShape(Physics::Sphere3D({}, 0.75f) || Physics::AxisAlignedBox3D({}, {3.0f, 1.5f, 2.0f})); +@endcode + +@see @ref scenegraph, ObjectShape2D, ObjectShape3D, ObjectShapeGroup2D, + ObjectShapeGroup3D, DebugTools::ShapeRenderer */ template class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { public: @@ -84,10 +101,16 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShape: publi return setShape(new T(std::move(shape))); } + /** + * @brief Object shape group containing this shape + * + * If the shape doesn't belong to any group, returns `nullptr`. + */ inline ObjectShapeGroup* group() { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } + /** @overload */ inline const ObjectShapeGroup* group() const { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 6747704e0..0553263da 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -32,7 +32,8 @@ namespace Magnum { namespace Physics { /** @brief Group of object shapes -@see ObjectShapeGroup2D, ObjectShapeGroup3D +See ObjectShape for more information. +@see @ref scenegraph, ObjectShapeGroup2D, ObjectShapeGroup3D */ template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { friend class ObjectShape; @@ -74,10 +75,20 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: bool dirty; }; -/** @brief Group of two-dimensional shaped objects */ +/** +@brief Group of two-dimensional shaped objects + +See ObjectShape for more information. +@see ObjectShapeGroup3D +*/ typedef ObjectShapeGroup<2> ObjectShapeGroup2D; -/** @brief Group of three-dimensional shaped objects */ +/** +@brief Group of three-dimensional shaped objects + +See ObjectShape for more information. +@see ObjectShapeGroup2D +*/ typedef ObjectShapeGroup<3> ObjectShapeGroup3D; }} diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index a0e51de2e..5b4a74edc 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -208,8 +208,13 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* group(); - const AnimableGroup* group() const; + const AnimableGroup* group() const; /**< @overload */ protected: /** diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 9a1e1cbcf..416efd140 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -26,7 +26,7 @@ namespace Magnum { namespace SceneGraph { /** @brief %Drawable -Adds drawing feature to object. Each %Drawable is part of some DrawableGroup +Adds drawing function to the object. Each %Drawable is part of some DrawableGroup and the whole group is drawn with particular camera using AbstractCamera::draw(). @section Drawable-usage Usage diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 9a8346d49..64f77332b 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -77,7 +77,7 @@ See @ref compilation-speedup-hpp for more information. - @ref EuclideanMatrixTransformation2D "Object>" - @ref EuclideanMatrixTransformation3D "Object>" -@see Scene, AbstractFeature, AbstractTransformation +@see Scene, AbstractFeature, AbstractTransformation, DebugTools::ObjectRenderer */ template class Object: public AbstractObject, public Transformation #ifndef DOXYGEN_GENERATING_OUTPUT From 4cda770f4fcbeda27b08be1632a8cf553694bd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 19:48:36 +0100 Subject: [PATCH 261/567] Physics: fixed cyclic header dependency. --- src/Physics/ObjectShape.cpp | 8 ++++++++ src/Physics/ObjectShape.h | 12 +++--------- src/Physics/ObjectShapeGroup.h | 5 +---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index 41469f188..fb1a800fc 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -30,6 +30,14 @@ template ObjectShape::~ObjectShape() { delete _shape; } +template ObjectShapeGroup* ObjectShape::group() { + return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); +} + +template const ObjectShapeGroup* ObjectShape::group() const { + return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); +} + template void ObjectShape::markDirty() { group()->setDirty(); } diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 6bba9209e..0f7aa6e31 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -20,7 +20,7 @@ */ #include "SceneGraph/AbstractGroupedFeature.h" -#include "ObjectShapeGroup.h" +#include "Physics/Physics.h" #include "magnumPhysicsVisibility.h" @@ -106,14 +106,8 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShape: publi * * If the shape doesn't belong to any group, returns `nullptr`. */ - inline ObjectShapeGroup* group() { - return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); - } - - /** @overload */ - inline const ObjectShapeGroup* group() const { - return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); - } + ObjectShapeGroup* group(); + const ObjectShapeGroup* group() const; /**< @overload */ protected: /** Marks also the group as dirty */ diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 0553263da..0c864cbb7 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -22,8 +22,8 @@ #include #include +#include "Physics/ObjectShape.h" #include "SceneGraph/FeatureGroup.h" -#include "Physics.h" #include "magnumPhysicsVisibility.h" @@ -93,7 +93,4 @@ typedef ObjectShapeGroup<3> ObjectShapeGroup3D; }} -/* Make the definition complete */ -#include "ObjectShape.h" - #endif From eb1dff499cfbb4bb53f3ba1a4b944b934ad28f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 25 Jan 2013 19:50:00 +0100 Subject: [PATCH 262/567] Doc: added link to PowerVR hardware best practices. --- doc/best-practices.dox | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/best-practices.dox b/doc/best-practices.dox index 2c06f6ce7..e406f70ef 100644 --- a/doc/best-practices.dox +++ b/doc/best-practices.dox @@ -38,5 +38,9 @@ cannot be later rebound to @ref Buffer::Target "Target::Element". However, internally (e.g. for setting data or copying). To avoid this, set target hint to desired target, either in constructor or using Buffer::setTargetHint(). +@subsection best-practices-powervr PowerVR hardware + +- [PowerVR Performance Recommendations](http://www.imgtec.com/powervr/insider/docs/PowerVR.Performance%20Recommendations.1.0.28.External.pdf) [PDF] + */ } From ba547fb7f8ca3d75dac6e20a3fc4f41529b06f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 00:55:10 +0100 Subject: [PATCH 263/567] Primitives: the library is now shared instead of static. Saves 2.5M of ~16M of debug build size. --- src/Primitives/CMakeLists.txt | 7 +++--- src/Primitives/Capsule.h | 4 ++- src/Primitives/Crosshair.h | 6 +++-- src/Primitives/Cube.h | 4 ++- src/Primitives/Cylinder.h | 4 ++- src/Primitives/Icosphere.h | 4 ++- src/Primitives/Plane.h | 4 ++- src/Primitives/Square.h | 4 ++- src/Primitives/UVSphere.h | 4 ++- src/Primitives/magnumPrimitivesVisibility.h | 28 +++++++++++++++++++++ 10 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 src/Primitives/magnumPrimitivesVisibility.h diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index 189052ec1..19f05fff9 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -15,10 +15,11 @@ set(MagnumPrimitives_HEADERS Icosphere.h Plane.h Square.h - UVSphere.h) + UVSphere.h -add_library(MagnumPrimitives STATIC ${MagnumPrimitives_SRCS}) -set_target_properties(MagnumPrimitives PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") + magnumPrimitivesVisibility.h) + +add_library(MagnumPrimitives SHARED ${MagnumPrimitives_SRCS}) target_link_libraries(MagnumPrimitives Magnum) install(TARGETS MagnumPrimitives DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index dc00e9272..a9cd054da 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -21,6 +21,8 @@ #include "Trade/MeshData3D.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -53,7 +55,7 @@ class Capsule: public Trade::MeshData3D { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - explicit Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); + explicit MAGNUM_PRIMITIVES_EXPORT Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: Capsule(std::uint32_t segments, TextureCoords textureCoords); diff --git a/src/Primitives/Crosshair.h b/src/Primitives/Crosshair.h index 55c9841ff..22b7e2e09 100644 --- a/src/Primitives/Crosshair.h +++ b/src/Primitives/Crosshair.h @@ -21,6 +21,8 @@ #include "Trade/Trade.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -29,7 +31,7 @@ namespace Magnum { namespace Primitives { 2x2 wireframe crosshair (two crossed lines), non-indexed @ref Mesh::Primitive "Lines". */ -class Crosshair2D { +class MAGNUM_PRIMITIVES_EXPORT Crosshair2D { public: /** @brief Wireframe crosshair */ static Trade::MeshData2D wireframe(); @@ -43,7 +45,7 @@ class Crosshair2D { 2x2x2 wireframe crosshair (three crossed lines), non-indexed @ref Mesh::Primitive "Lines". */ -class Crosshair3D { +class MAGNUM_PRIMITIVES_EXPORT Crosshair3D { public: /** @brief Wireframe crosshair */ static Trade::MeshData3D wireframe(); diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index c46899fb7..ed6cb1669 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -21,6 +21,8 @@ #include "Trade/Trade.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -28,7 +30,7 @@ namespace Magnum { namespace Primitives { 2x2x2 cube. */ -class Cube { +class MAGNUM_PRIMITIVES_EXPORT Cube { public: /** * @brief Solid cube diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index b1063de92..a5b35beb8 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -23,6 +23,8 @@ #include "Primitives/Capsule.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -58,7 +60,7 @@ class Cylinder: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - explicit Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); + explicit MAGNUM_PRIMITIVES_EXPORT Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); private: void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal); diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 08760c1f2..79f5583e3 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -24,11 +24,13 @@ #include "MeshTools/Clean.h" #include "Trade/MeshData3D.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class Icosphere; +template class MAGNUM_PRIMITIVES_EXPORT Icosphere; #endif /** diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index 59f22bdf5..72970ed66 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -21,6 +21,8 @@ #include "Trade/Trade.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -28,7 +30,7 @@ namespace Magnum { namespace Primitives { 2x2 plane. */ -class Plane { +class MAGNUM_PRIMITIVES_EXPORT Plane { public: /** * @brief Solid plane diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index 6bd77a172..4d81f9b90 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -21,6 +21,8 @@ #include "Trade/Trade.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -28,7 +30,7 @@ namespace Magnum { namespace Primitives { 2x2 square. */ -class Square { +class MAGNUM_PRIMITIVES_EXPORT Square { public: /** * @brief Solid square diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index d2e77c4d6..d2cd6400e 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -21,6 +21,8 @@ #include "Primitives/Capsule.h" +#include "Primitives/magnumPrimitivesVisibility.h" + namespace Magnum { namespace Primitives { /** @@ -40,7 +42,7 @@ class UVSphere: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - explicit UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); + explicit MAGNUM_PRIMITIVES_EXPORT UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); }; }} diff --git a/src/Primitives/magnumPrimitivesVisibility.h b/src/Primitives/magnumPrimitivesVisibility.h new file mode 100644 index 000000000..cf8191277 --- /dev/null +++ b/src/Primitives/magnumPrimitivesVisibility.h @@ -0,0 +1,28 @@ +#ifndef Magnum_Primitives_magnumPrimitivesVisibility_h +#define Magnum_Primitives_magnumPrimitivesVisibility_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#ifdef _WIN32 + #ifdef MagnumPrimitives_EXPORTS + #define MAGNUM_PRIMITIVES_EXPORT __declspec(dllexport) + #else + #define MAGNUM_PRIMITIVES_EXPORT __declspec(dllimport) + #endif +#else + #define MAGNUM_PRIMITIVES_EXPORT __attribute__ ((visibility ("default"))) +#endif + +#endif From 679ca80af57722417d76f2e09b4b80f4fd82135b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 00:59:31 +0100 Subject: [PATCH 264/567] SceneGraph: minor cleanup. --- src/SceneGraph/Animable.h | 2 +- src/SceneGraph/Camera3D.hpp | 2 -- src/SceneGraph/magnumSceneGraphVisibility.h | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 5b4a74edc..000130d33 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -28,7 +28,7 @@ namespace Magnum { namespace SceneGraph { /** @brief Animation state -@see Animatable::setState() +@see Animable::setState() */ enum class AnimationState: std::uint8_t { /** diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index 0e97d1715..2ca805a09 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -22,8 +22,6 @@ #include "AbstractCamera.hpp" #include "Camera3D.h" -using namespace std; - namespace Magnum { namespace SceneGraph { template Camera3D* Camera3D::setOrthographic(const Math::Vector2& size, T near, T far) { diff --git a/src/SceneGraph/magnumSceneGraphVisibility.h b/src/SceneGraph/magnumSceneGraphVisibility.h index cd1be31fa..fca3dc0bc 100644 --- a/src/SceneGraph/magnumSceneGraphVisibility.h +++ b/src/SceneGraph/magnumSceneGraphVisibility.h @@ -21,10 +21,10 @@ #else #define MAGNUM_SCENEGRAPH_EXPORT __declspec(dllimport) #endif - #define SCENEGRAPH_LOCAL + #define MAGNUM_SCENEGRAPH_LOCAL #else #define MAGNUM_SCENEGRAPH_EXPORT __attribute__ ((visibility ("default"))) - #define SCENEGRAPH_LOCAL __attribute__ ((visibility ("hidden"))) + #define MAGNUM_SCENEGRAPH_LOCAL __attribute__ ((visibility ("hidden"))) #endif #endif From 63086fdebef0e190dcec3204309a07832ff1e5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 01:34:12 +0100 Subject: [PATCH 265/567] SceneGraph: de-inlined some constructors & destructor, hidden internals. Might help reducing application size. --- src/SceneGraph/AbstractCamera.h | 6 +----- src/SceneGraph/AbstractCamera.hpp | 6 ++++++ src/SceneGraph/AbstractObject.h | 8 +++++--- src/SceneGraph/AbstractTransformation.h | 8 ++++---- src/SceneGraph/Animable.h | 2 ++ src/SceneGraph/Animable.hpp | 2 ++ src/SceneGraph/CMakeLists.txt | 3 ++- src/SceneGraph/Camera.cpp | 8 ++++---- src/SceneGraph/Camera2D.h | 2 +- src/SceneGraph/Camera2D.hpp | 2 ++ src/SceneGraph/Camera3D.h | 2 +- src/SceneGraph/Camera3D.hpp | 2 ++ src/SceneGraph/Object.cpp | 25 +++++++++++++++++++++++++ src/SceneGraph/Object.h | 6 +++--- src/SceneGraph/Object.hpp | 7 +++++++ 15 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 src/SceneGraph/Object.cpp diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 458bf4029..e15793dde 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -76,9 +76,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature* object): AbstractFeature(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) { - AbstractFeature::setCachedTransformations(AbstractFeature::CachedTransformation::InvertedAbsolute); - } + explicit AbstractCamera(AbstractObject* object); virtual ~AbstractCamera() = 0; @@ -162,8 +160,6 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature inline AbstractCamera::~AbstractCamera() {} - #ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional cameras diff --git a/src/SceneGraph/AbstractCamera.hpp b/src/SceneGraph/AbstractCamera.hpp index bbd6166e1..934dad4a3 100644 --- a/src/SceneGraph/AbstractCamera.hpp +++ b/src/SceneGraph/AbstractCamera.hpp @@ -63,6 +63,12 @@ template typename DimensionTraits AbstractCamera::AbstractCamera(AbstractObject* object): AbstractFeature(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) { + AbstractFeature::setCachedTransformations(AbstractFeature::CachedTransformation::InvertedAbsolute); +} + +template AbstractCamera::~AbstractCamera() {} + template AbstractCamera* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 56ab023c2..7f3d711da 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -25,6 +25,8 @@ #include "DimensionTraits.h" #include "SceneGraph.h" +#include "SceneGraph/magnumSceneGraphVisibility.h" + namespace Magnum { namespace SceneGraph { /** @@ -46,7 +48,7 @@ for(AbstractFeature* feature = o->firstFeature(); feature; feature = feature->ne @see AbstractObject2D, AbstractObject3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractObject: private Corrade::Containers::LinkedList> +template class MAGNUM_SCENEGRAPH_EXPORT AbstractObject: private Corrade::Containers::LinkedList> #else template class AbstractObject #endif @@ -59,8 +61,8 @@ template class AbstractObject /** @brief Feature object type */ typedef AbstractFeature FeatureType; - explicit AbstractObject() = default; - inline virtual ~AbstractObject() {} + explicit AbstractObject(); + virtual ~AbstractObject(); /** @brief Whether this object has features */ inline bool hasFeatures() const { diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 9808195ab..d3eab7d49 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -24,6 +24,8 @@ #include "DimensionTraits.h" #include "SceneGraph.h" +#include "SceneGraph/magnumSceneGraphVisibility.h" + namespace Magnum { namespace SceneGraph { /** @@ -46,7 +48,7 @@ template #else template #endif -class AbstractTransformation { +class MAGNUM_SCENEGRAPH_EXPORT AbstractTransformation { public: /** @brief Underlying floating-point type */ typedef T Type; @@ -54,7 +56,7 @@ class AbstractTransformation { /** @brief Dimension count */ static const std::uint8_t Dimensions = dimensions; - explicit AbstractTransformation() = default; + explicit AbstractTransformation(); virtual ~AbstractTransformation() = 0; #ifdef DOXYGEN_GENERATING_OUTPUT @@ -137,8 +139,6 @@ enum class TransformationType: std::uint8_t { Local = 0x01 }; -template inline AbstractTransformation::~AbstractTransformation() {} - #ifndef CORRADE_GCC46_COMPATIBILITY /** @brief Base for two-dimensional transformations diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 000130d33..959dbf32a 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -150,6 +150,8 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* object, AnimableGroup* group = nullptr); + ~Animable(); + /** @brief Animation duration */ inline GLfloat duration() const { return _duration; } diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp index a5ef42eb2..c1a3f11f5 100644 --- a/src/SceneGraph/Animable.hpp +++ b/src/SceneGraph/Animable.hpp @@ -28,6 +28,8 @@ namespace Magnum { namespace SceneGraph { template Animable::Animable(AbstractObject* object, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(0.0f), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} +template Animable::~Animable() {} + template Animable* Animable::setState(AnimationState state) { if(currentState == state) return this; diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index d8f3b047a..42d69ab81 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -2,7 +2,8 @@ set(MagnumSceneGraph_SRCS Animable.cpp Camera.cpp EuclideanMatrixTransformation2D.cpp - EuclideanMatrixTransformation3D.cpp) + EuclideanMatrixTransformation3D.cpp + Object.cpp) set(MagnumSceneGraph_HEADERS AbstractCamera.h AbstractCamera.hpp diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 1bdc04553..6d46a42c7 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -19,10 +19,10 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT -template class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera<2, GLfloat>; -template class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera<3, GLfloat>; -template class MAGNUM_SCENEGRAPH_EXPORT Camera2D; -template class MAGNUM_SCENEGRAPH_EXPORT Camera3D; +template class AbstractCamera<2, GLfloat>; +template class AbstractCamera<3, GLfloat>; +template class Camera2D; +template class Camera3D; #endif }} diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 37775924f..6674703e1 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -60,7 +60,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). * @see setProjection() */ - inline explicit Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} + explicit Camera2D(AbstractObject<2, T>* object); /** * @brief Set projection diff --git a/src/SceneGraph/Camera2D.hpp b/src/SceneGraph/Camera2D.hpp index 9bea284fc..0241ec8b4 100644 --- a/src/SceneGraph/Camera2D.hpp +++ b/src/SceneGraph/Camera2D.hpp @@ -26,6 +26,8 @@ using namespace std; namespace Magnum { namespace SceneGraph { +template Camera2D::Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} + template Camera2D* Camera2D::setProjection(const Math::Vector2& size) { AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3::projection(size); diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 4551d6bcb..4bd1cb309 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -62,7 +62,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { * @brief Constructor * @param object %Object holding this feature */ - inline explicit Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} + explicit Camera3D(AbstractObject<3, T>* object); /** * @brief Set orthographic projection diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index 2ca805a09..42e2f5d9d 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -24,6 +24,8 @@ namespace Magnum { namespace SceneGraph { +template Camera3D::Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object) {} + template Camera3D* Camera3D::setOrthographic(const Math::Vector2& size, T near, T far) { /** @todo Get near/far from the matrix */ _near = near; diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp new file mode 100644 index 000000000..8bfe038a2 --- /dev/null +++ b/src/SceneGraph/Object.cpp @@ -0,0 +1,25 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Object.hpp" + +namespace Magnum { namespace SceneGraph { + +template class AbstractObject<2>; +template class AbstractObject<3>; +template class AbstractTransformation<2>; +template class AbstractTransformation<3>; + +}} diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 64f77332b..e3975ef8b 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -79,7 +79,7 @@ See @ref compilation-speedup-hpp for more information. @see Scene, AbstractFeature, AbstractTransformation, DebugTools::ObjectRenderer */ -template class Object: public AbstractObject, public Transformation +template class MAGNUM_SCENEGRAPH_EXPORT Object: public AbstractObject, public Transformation #ifndef DOXYGEN_GENERATING_OUTPUT , private Corrade::Containers::LinkedList>, private Corrade::Containers::LinkedListItem, Object> #endif @@ -241,11 +241,11 @@ template class Object: public AbstractObject::MatrixType> transformationMatrices(const std::vector*>& objects, const typename DimensionTraits::MatrixType& initialTransformationMatrix = typename DimensionTraits::MatrixType()) const override; - typename Transformation::DataType computeJointTransformation(const std::vector*>& jointObjects, std::vector& jointTransformations, const std::size_t joint, const typename Transformation::DataType& initialTransformation) const; + typename Transformation::DataType MAGNUM_SCENEGRAPH_LOCAL computeJointTransformation(const std::vector*>& jointObjects, std::vector& jointTransformations, const std::size_t joint, const typename Transformation::DataType& initialTransformation) const; void setClean(const std::vector*>& objects) const override; - void setClean(const typename Transformation::DataType& absoluteTransformation); + void MAGNUM_SCENEGRAPH_LOCAL setClean(const typename Transformation::DataType& absoluteTransformation); typedef Implementation::ObjectFlag Flag; typedef Implementation::ObjectFlags Flags; diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index e0911bbd3..72c45dfec 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -19,6 +19,7 @@ * @brief @ref compilation-speedup-hpp "Template implementation" for Object.h */ +#include "AbstractTransformation.h" #include "Object.h" #include @@ -28,6 +29,12 @@ namespace Magnum { namespace SceneGraph { +template AbstractObject::AbstractObject() {} +template AbstractObject::~AbstractObject() {} + +template inline AbstractTransformation::AbstractTransformation() {} +template inline AbstractTransformation::~AbstractTransformation() {} + template Scene* Object::scene() { return static_cast*>(sceneObject()); } From 60eaa3f7d4285337bf37fa7caea2d3ae2caeddf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 01:40:56 +0100 Subject: [PATCH 266/567] Aaargh. --- src/DebugTools/ShapeRenderer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 0420344db..20b280e47 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -74,7 +74,7 @@ class ShapeRendererOptions { * Size of rendered crosshairs, representing Physics::Point shapes. * Default is `0.25f`. */ - inline ShapeRendererOptions* pointSize(GLfloat size) { + inline ShapeRendererOptions* setPointSize(GLfloat size) { _pointSize = size; return this; } From 0ed0f261b4dec1b92f82a08cdd5da6987d35c6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 14:24:13 +0100 Subject: [PATCH 267/567] Math: matrix/vector rework, part 1: synchronized unit tests. They now test the same functionality in two places, but the functionality will be implemented differently for matrix and vector. --- src/Math/Test/RectangularMatrixTest.cpp | 89 ++++++++-------- src/Math/Test/VectorTest.cpp | 129 ++++++++++++++++++++---- 2 files changed, 158 insertions(+), 60 deletions(-) diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 24fc78fba..86bc8e61a 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -27,12 +27,14 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { public: RectangularMatrixTest(); - void construct(); + void constructFromData(); + void constructDefault(); + void constructConversion(); void constructFromVectors(); - void constructFrom(); - void constructZero(); void data(); + void compare(); + void negative(); void addSubtract(); void multiplyDivide(); @@ -51,12 +53,14 @@ typedef RectangularMatrix<2, 2, std::int32_t> Matrix2i; typedef Vector<4, float> Vector4; RectangularMatrixTest::RectangularMatrixTest() { - addTests(&RectangularMatrixTest::construct, + addTests(&RectangularMatrixTest::constructFromData, + &RectangularMatrixTest::constructDefault, + &RectangularMatrixTest::constructConversion, &RectangularMatrixTest::constructFromVectors, - &RectangularMatrixTest::constructFrom, - &RectangularMatrixTest::constructZero, &RectangularMatrixTest::data, + &RectangularMatrixTest::compare, + &RectangularMatrixTest::negative, &RectangularMatrixTest::addSubtract, &RectangularMatrixTest::multiplyDivide, @@ -68,7 +72,7 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::configuration); } -void RectangularMatrixTest::construct() { +void RectangularMatrixTest::constructFromData() { float m[] = { 3.0f, 5.0f, 8.0f, 4.0f, 4.0f, 4.0f, 7.0f, 3.0f, @@ -84,20 +88,20 @@ void RectangularMatrixTest::construct() { CORRADE_COMPARE(Matrix3x4::from(m), expected); } -void RectangularMatrixTest::constructFromVectors() { - Matrix3x4 actual = Matrix3x4::from(Vector4(1.0f, 2.0f, 3.0f, 4.0f), - Vector4(5.0f, 6.0f, 7.0f, 8.0f), - Vector4(9.0f, 10.0f, 11.0f, 12.0f)); +void RectangularMatrixTest::constructDefault() { + Matrix4x3 zero; - Matrix3x4 expected(1.0f, 2.0f, 3.0f, 4.0f, - 5.0f, 6.0f, 7.0f, 8.0f, - 9.0f, 10.0f, 11.0f, 12.0f); + Matrix4x3 zeroExpected( + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f + ); - CORRADE_COMPARE(actual, expected); + CORRADE_COMPARE(zero, zeroExpected); } - -void RectangularMatrixTest::constructFrom() { +void RectangularMatrixTest::constructConversion() { Matrix2 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); Matrix2 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); Matrix2i integral(1, 2, -15, 7); @@ -106,27 +110,24 @@ void RectangularMatrixTest::constructFrom() { CORRADE_COMPARE(Matrix2::from(integral), floatingPointRounded); } -void RectangularMatrixTest::constructZero() { - Matrix4x3 zero; +void RectangularMatrixTest::constructFromVectors() { + Matrix3x4 actual = Matrix3x4::from(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); - Matrix4x3 zeroExpected( - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f - ); + Matrix3x4 expected(1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f); - CORRADE_COMPARE(zero, zeroExpected); + CORRADE_COMPARE(actual, expected); } void RectangularMatrixTest::data() { Matrix3x4 m; - Vector4 vector(4.0f, 5.0f, 6.0f, 7.0f); m[2] = vector; m[1][1] = 1.0f; - m(0, 2) = 1.5f; CORRADE_COMPARE(m(1, 1), 1.0f); @@ -142,6 +143,14 @@ void RectangularMatrixTest::data() { CORRADE_COMPARE(m, expected); } +void RectangularMatrixTest::compare() { + CORRADE_VERIFY(Matrix2(1.0f, -3.0f, 5.0f, -10.0f) == Matrix2(1.0f + MathTypeTraits::epsilon()/2, -3.0f, 5.0f, -10.0f)); + CORRADE_VERIFY(Matrix2(1.0f, -1.0f, 5.0f, -10.0f) != Matrix2(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); + + CORRADE_VERIFY(Matrix2i(1, -3, 5, -10) == Matrix2i(1, -3, 5, -10)); + CORRADE_VERIFY(Matrix2i(1, -3, 5, -10) != Matrix2i(1, -2, 5, -10)); +} + void RectangularMatrixTest::negative() { CORRADE_COMPARE(-Matrix2(1.0f, -3.0f, 5.0f, -10.0f), Matrix2(-1.0f, 3.0f, -5.0f, 10.0f)); } @@ -155,34 +164,34 @@ void RectangularMatrixTest::addSubtract() { -9.0f, 11.0f, 0.25f, 0.0f, -8.0f, 19.0f, -3.0f, -5.0f, 2.0f); - Matrix4x3 e(-4.0f, 1.5f, 12.0f, + Matrix4x3 c(-4.0f, 1.5f, 12.0f, -5.0f, 16.0f, 7.25f, 8.0f, 1.0f, 30.0f, 9.0f, 8.0f, 17.0f); - CORRADE_COMPARE(a + b, e); - CORRADE_COMPARE(e - b, a); + CORRADE_COMPARE(a + b, c); + CORRADE_COMPARE(c - b, a); } void RectangularMatrixTest::multiplyDivide() { - Matrix2 vec(1.0f, 2.0f, 3.0f, 4.0f); + Matrix2 matrix(1.0f, 2.0f, 3.0f, 4.0f); Matrix2 multiplied(-1.5f, -3.0f, -4.5f, -6.0f); - CORRADE_COMPARE(vec*-1.5f, multiplied); - CORRADE_COMPARE(-1.5f*vec, multiplied); - CORRADE_COMPARE(multiplied/-1.5f, vec); + CORRADE_COMPARE(matrix*-1.5f, multiplied); + CORRADE_COMPARE(-1.5f*matrix, multiplied); + CORRADE_COMPARE(multiplied/-1.5f, matrix); - Math::RectangularMatrix<1, 1, std::int8_t> vecChar(32); + Math::RectangularMatrix<1, 1, std::int8_t> matrixChar(32); Math::RectangularMatrix<1, 1, std::int8_t> multipliedChar(-48); - CORRADE_COMPARE(vecChar*-1.5f, multipliedChar); - CORRADE_COMPARE(multipliedChar/-1.5f, vecChar); - CORRADE_COMPARE(-1.5f*vecChar, multipliedChar); + CORRADE_COMPARE(matrixChar*-1.5f, multipliedChar); + CORRADE_COMPARE(multipliedChar/-1.5f, matrixChar); + CORRADE_COMPARE(-1.5f*matrixChar, multipliedChar); /* Divide vector with number and inverse */ Matrix2 divisor(1.0f, 2.0f, -4.0f, 8.0f); Matrix2 result(1.0f, 0.5f, -0.25f, 0.125f); CORRADE_COMPARE(1.0f/divisor, result); - CORRADE_COMPARE(-1550.0f/multipliedChar, vecChar); + CORRADE_COMPARE(-1550.0f/multipliedChar, matrixChar); } void RectangularMatrixTest::multiply() { diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 56eb0083b..03fead6d7 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -28,18 +28,30 @@ class VectorTest: public Corrade::TestSuite::Tester { public: VectorTest(); - void construct(); + void constructFromData(); + void constructDefault(); + void constructConversion(); + void data(); + + void negative(); + void addSubtract(); + void multiplyDivide(); + void multiplyDivideComponentWise(); + + void compare(); void compareComponentWise(); + void dot(); - void multiplyDivideComponentWise(); void dotSelf(); void length(); void normalized(); - void projected(); + void sum(); void product(); void min(); void max(); + + void projected(); void angle(); void lerp(); @@ -47,35 +59,78 @@ class VectorTest: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Vector<4, float> Vector4; typedef Vector<3, float> Vector3; +typedef Vector<4, float> Vector4; +typedef Vector<4, std::int32_t> Vector4i; VectorTest::VectorTest() { - addTests(&VectorTest::construct, + addTests(&VectorTest::constructFromData, + &VectorTest::constructDefault, + &VectorTest::constructConversion, + &VectorTest::data, + + &VectorTest::negative, + &VectorTest::addSubtract, + &VectorTest::multiplyDivide, + &VectorTest::multiplyDivideComponentWise, + + &VectorTest::compare, &VectorTest::compareComponentWise, + &VectorTest::dot, - &VectorTest::multiplyDivideComponentWise, &VectorTest::dotSelf, &VectorTest::length, &VectorTest::normalized, - &VectorTest::projected, + &VectorTest::sum, &VectorTest::product, &VectorTest::min, &VectorTest::max, + + &VectorTest::projected, &VectorTest::angle, &VectorTest::lerp, + &VectorTest::debug, &VectorTest::configuration); } -void VectorTest::construct() { - CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); - +void VectorTest::constructFromData() { float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; CORRADE_COMPARE(Vector4::from(data), Vector4(1.0f, 2.0f, 3.0f, 4.0f)); } +void VectorTest::constructDefault() { + CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); +} + +void VectorTest::constructConversion() { + Vector4 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); + Vector4i integral(1, 2, -15, 7); + + CORRADE_COMPARE(Vector4i::from(floatingPoint), integral); + CORRADE_COMPARE(Vector4::from(integral), floatingPointRounded); +} + +void VectorTest::data() { + Vector4 vector(4.0f, 5.0f, 6.0f, 7.0f); + vector[2] = 1.0f; + vector[3] = 1.5f; + + CORRADE_COMPARE(vector[2], 1.0f); + CORRADE_COMPARE(vector[3], 1.5f); + CORRADE_COMPARE(vector, Vector4(4.0f, 5.0f, 1.0f, 1.5f)); +} + +void VectorTest::compare() { + CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + MathTypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); + + CORRADE_VERIFY(Vector4i(1, -3, 5, -10) == Vector4i(1, -3, 5, -10)); + CORRADE_VERIFY(Vector4i(1, -3, 5, -10) != Vector4i(1, -2, 5, -10)); +} + void VectorTest::compareComponentWise() { CORRADE_VERIFY(Vector4(1.0f, -2.0f, -5.0f, 7.0f) < Vector4(1.1f, -1.0f, 3.0f, 8.0f)); CORRADE_VERIFY(!(Vector4(1.0f, -2.0f, -5.0f, 7.0f) < Vector4(1.1f, -1.0f, 3.0f, 7.0f))); @@ -90,8 +145,38 @@ void VectorTest::compareComponentWise() { CORRADE_VERIFY(!(Vector4(1.1f, -1.0f, 3.0f, 7.0f) > Vector4(1.0f, -2.0f, -5.0f, 7.0f))); } -void VectorTest::dot() { - CORRADE_COMPARE(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}), 15.25f); +void VectorTest::negative() { + CORRADE_COMPARE(-Vector4(1.0f, -3.0f, 5.0f, -10.0f), Vector4(-1.0f, 3.0f, -5.0f, 10.0f)); +} + +void VectorTest::addSubtract() { + Vector4 a(1.0f, -3.0f, 5.0f, -10.0f); + Vector4 b(7.5f, 33.0f, -15.0f, 0.0f); + Vector4 c(8.5f, 30.0f, -10.0f, -10.0f); + + CORRADE_COMPARE(a + b, c); + CORRADE_COMPARE(c - b, a); +} + +void VectorTest::multiplyDivide() { + Vector4 vector(1.0f, 2.0f, 3.0f, 4.0f); + Vector4 multiplied(-1.5f, -3.0f, -4.5f, -6.0f); + + CORRADE_COMPARE(vector*-1.5f, multiplied); + CORRADE_COMPARE(-1.5f*vector, multiplied); + CORRADE_COMPARE(multiplied/-1.5f, vector); + + Math::Vector<1, std::int8_t> vectorChar(32); + Math::Vector<1, std::int8_t> multipliedChar(-48); + CORRADE_COMPARE(vectorChar*-1.5f, multipliedChar); + CORRADE_COMPARE(multipliedChar/-1.5f, vectorChar); + CORRADE_COMPARE(-1.5f*vectorChar, multipliedChar); + + /* Divide vector with number and inverse */ + Vector4 divisor(1.0f, 2.0f, -4.0f, 8.0f); + Vector4 result(1.0f, 0.5f, -0.25f, 0.125f); + CORRADE_COMPARE(1.0f/divisor, result); + CORRADE_COMPARE(-1550.0f/multipliedChar, vectorChar); } void VectorTest::multiplyDivideComponentWise() { @@ -103,6 +188,10 @@ void VectorTest::multiplyDivideComponentWise() { CORRADE_COMPARE(multiplied/multiplier, vec); } +void VectorTest::dot() { + CORRADE_COMPARE(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}), 15.25f); +} + void VectorTest::dotSelf() { CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).dot(), 30.0f); } @@ -115,14 +204,6 @@ void VectorTest::normalized() { CORRADE_COMPARE(Vector4(1.0f, 1.0f, 1.0f, 1.0f).normalized(), Vector4(0.5f, 0.5f, 0.5f, 0.5f)); } -void VectorTest::projected() { - Vector3 line(1.0f, -1.0f, 0.5f); - Vector3 projected = Vector3(1.0f, 2.0f, 3.0f).projected(line); - - CORRADE_COMPARE(projected, Vector3(0.222222f, -0.222222f, 0.111111f)); - CORRADE_COMPARE(projected.normalized(), line.normalized()); -} - void VectorTest::sum() { CORRADE_COMPARE(Vector3(1.0f, 2.0f, 4.0f).sum(), 7.0f); } @@ -139,6 +220,14 @@ void VectorTest::max() { CORRADE_COMPARE(Vector3(1.0f, -2.0f, 3.0f).max(), 3.0f); } +void VectorTest::projected() { + Vector3 line(1.0f, -1.0f, 0.5f); + Vector3 projected = Vector3(1.0f, 2.0f, 3.0f).projected(line); + + CORRADE_COMPARE(projected, Vector3(0.222222f, -0.222222f, 0.111111f)); + CORRADE_COMPARE(projected.normalized(), line.normalized()); +} + void VectorTest::angle() { std::ostringstream o; Error::setOutput(&o); From 4c16a767db9449c64e7d341ac9a598b0bac135e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 21:26:26 +0100 Subject: [PATCH 268/567] Math: doc++, minor code cleanup. --- src/Math/RectangularMatrix.h | 14 +++++++------- src/Math/Vector.h | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index e9b7beded..0c5d91bb0 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -388,10 +388,10 @@ template class RectangularMatrix { Same as RectangularMatrix::operator*(U) const. */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number, const RectangularMatrix& matrix) { -#else +#ifdef DOXYGEN_GENERATING_OUTPUT template inline RectangularMatrix operator*(U number, const RectangularMatrix& matrix) { +#else +template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number, const RectangularMatrix& matrix) { #endif return matrix*number; } @@ -402,12 +402,12 @@ template inline Rectangula @f[ \boldsymbol B_{ji} = \frac a {\boldsymbol A_{ji}} @f] -@see RectangularMatrix::operator/() +@see RectangularMatrix::operator/(U) const */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template typename std::enable_if::value, RectangularMatrix>::type operator/(U number, const RectangularMatrix& matrix) { -#else +#ifdef DOXYGEN_GENERATING_OUTPUT template RectangularMatrix operator/(U number, const RectangularMatrix& matrix) { +#else +template typename std::enable_if::value, RectangularMatrix>::type operator/(U number, const RectangularMatrix& matrix) { #endif RectangularMatrix out; diff --git a/src/Math/Vector.h b/src/Math/Vector.h index d7b1b6d78..b2581d3f3 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -41,7 +41,7 @@ template class Vector: public RectangularMatrix<1, si * @brief Dot product * * @f[ - * a \cdot b = \sum_{i=0}^{n-1} a_ib_i + * \boldsymbol a \cdot \boldsymbol b = \sum_{i=0}^{n-1} \boldsymbol a_i \boldsymbol b_i * @f] * @see dot() const */ @@ -58,7 +58,7 @@ template class Vector: public RectangularMatrix<1, si * @brief Angle between normalized vectors (in radians) * * Expects that both vectors are normalized. @f[ - * \theta = acos \left( \frac{a \cdot b}{|a| \cdot |b|} \right) + * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| \cdot |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) * @f] */ inline static T angle(const Vector& normalizedA, const Vector& normalizedB) { @@ -74,7 +74,7 @@ template class Vector: public RectangularMatrix<1, si * @param t Interpolation phase (from range @f$ [0; 1] @f$) * * The interpolation is done as in following: @f[ - * v_{LERP} = (1 - t) \boldsymbol v_A + t \boldsymbol v_B + * \boldsymbol v_{LERP} = (1 - t) \boldsymbol v_A + t \boldsymbol v_B * @f] * @todo http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/ * (when SIMD is in place) @@ -83,22 +83,19 @@ template class Vector: public RectangularMatrix<1, si return (U(1) - t)*a + t*b; } - /** @brief Default constructor */ + /** @brief Construct zero-filled vector */ inline constexpr /*implicit*/ Vector() {} /** @todo Creating Vector from combination of vector and scalar types */ /** - * @brief Initializer-list constructor + * @brief Construct vector from values * @param first First value * @param next Next values */ template inline constexpr /*implicit*/ Vector(T first, U... next): RectangularMatrix<1, size, T>(first, next...) {} - /** - * @brief Constructor - * @param value Value for all fields - */ + /** @brief Construct vector with one value for all fields */ #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit Vector(T value) { #else @@ -183,7 +180,7 @@ template class Vector: public RectangularMatrix<1, si * @see operator*=(const Vector&) */ template inline Vector operator*(const Vector& other) const { - return Vector(*this)*=other; + return Vector(*this) *= other; } /** @@ -206,7 +203,7 @@ template class Vector: public RectangularMatrix<1, si * @see operator/=(const Vector&) */ template inline Vector operator/(const Vector& other) const { - return Vector(*this)/=other; + return Vector(*this) /= other; } /** @@ -214,7 +211,7 @@ template class Vector: public RectangularMatrix<1, si * * Should be used instead of length() for comparing vector length with * other values, because it doesn't compute the square root. @f[ - * a \cdot a = \sum_{i=0}^{n-1} a_i^2 + * \boldsymbol a \cdot \boldsymbol a = \sum_{i=0}^{n-1} \boldsymbol a_i^2 * @f] * @see dot(const Vector&, const Vector&) */ @@ -226,7 +223,7 @@ template class Vector: public RectangularMatrix<1, si * @brief %Vector length * * @f[ - * |a| = \sqrt{a \cdot a} + * |\boldsymbol a| = \sqrt{\boldsymbol a \cdot \boldsymbol a} * @f] * @see dot() const */ From baeadc96634981e5040ac0ea6f23dbd4041e7068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 26 Jan 2013 21:31:02 +0100 Subject: [PATCH 269/567] Math: matrix/vector rework, part 2: matrix as array of column vectors. Overall architecture is simplififed with this change and also it's not needed to use reinterpret_cast in matrix internals anymore, thus there is no need for operator() and [][] works now always as expected without any risk of GCC misoptimizations. On the other side, constructing matrix from list of elements is not possible anymore. You have to specify the elements as list of column vectors, which might be less convenient to write, but it helps to distinguish what is column and what is row: Matrix<2, int> a(1, 2, // before 3, 4); Matrix<2, int> a(Vector<2, int>(1, 2), // now Vector<2, int>(3, 4)); For some matrix specializations (i.e. Matrix3 and Matrix4) it is possible to use list-initialization instead of explicit type specification: Matrix<3, int>({1, 2, 3}, {4, 5, 6}, {7, 8, 9}); I didn't yet figure out how to properly implement the general (constexpr) constructor to also take lists, so it's a bit ugly for now. Matrix operations are now done column-wise, which should help with future SIMD implementations, documentation is also updated accordingly. I also removed forgotten remains of matrix/matrix operator*=(), which can be confusing, as the multiplication is not commutative. Why it is not present is explained in d9c900f076f2f87c7b7ba3f37a3179c0c0e4a02c. --- doc/matrix-vector.dox | 49 +-- src/Color.h | 7 +- src/Math/Algorithms/GaussJordan.h | 10 +- src/Math/Algorithms/Test/GaussJordanTest.cpp | 27 +- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 14 +- src/Math/Geometry/Distance.h | 8 +- src/Math/Matrix.h | 58 +-- src/Math/Matrix3.h | 60 ++- src/Math/Matrix4.h | 132 +++--- src/Math/Point2D.h | 3 +- src/Math/Point3D.h | 3 +- src/Math/Quaternion.h | 14 +- src/Math/RectangularMatrix.cpp | 30 -- src/Math/RectangularMatrix.h | 254 ++++-------- src/Math/Test/Matrix3Test.cpp | 120 +++--- src/Math/Test/Matrix4Test.cpp | 198 ++++----- src/Math/Test/MatrixTest.cpp | 125 +++--- src/Math/Test/RectangularMatrixTest.cpp | 178 ++++---- src/Math/Vector.cpp | 22 + src/Math/Vector.h | 407 ++++++++++++++++--- src/Math/Vector2.h | 3 +- src/Math/Vector3.h | 3 +- src/Math/Vector4.h | 3 +- src/Mesh.h | 2 + src/SceneGraph/Test/CameraTest.cpp | 32 +- 25 files changed, 920 insertions(+), 842 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 9faab0993..6c50d5b33 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -14,9 +14,9 @@ easier. %Magnum has three main matrix and vector classes: RectangularMatrix, (square) Matrix and Vector. To achieve greatest code reuse, %Matrix is internally -square %RectangularMatrix and %Vector is internally one-column -%RectangularMatrix. Both vectors and matrices can have arbitrary size (known -at compile time) and can store any meaningful type. +square %RectangularMatrix and %RectangularMatrix is internally array of one or +more %Vector instances. Both vectors and matrices can have arbitrary size +(known at compile time) and can store any arithmetic type. Each subclass brings some specialization to its superclass and for most common vector and matrix sizes there are specialized classes Matrix3 and Matrix4, @@ -50,14 +50,15 @@ Color4 black1; // {0.0f, 0.0f, 0.0f, 1.0f} Color4 black2; // {0, 0, 0, 255} @endcode -Most common and most efficient way to create matrix or vector is to pass -values of all components to the constructor. +Most common and most efficient way to create vector is to pass all values to +constructor, matrix is created by passing all column vectors to the +constructor. @code -Matrix3 mat(0, 1, 2, - 3, 4, 5, - 6, 7, 8); // column-major (see explanation why below) - Vector3 vec(0, 1, 2); + +Matrix3 mat({0, 1, 2}, + {3, 4, 5}, + {6, 7, 8}); @endcode All constructors check number of passed arguments and the errors are catched at compile time. @@ -83,8 +84,8 @@ same row count; vectors from vector and scalar: @code RectangularMatrix<2, 3, int> a; Vector3 b, c; -Matrix3 mat = Matrix3::from(b, a, c); -Vector<8, int> vec = Vector<8, int>::from(1, b, 2, c); +Matrix3 mat(a, b); +Vector<8, int> vec(1, b, 2, c); @endcode It is also possible to create them from an C-style array. The function does @@ -113,14 +114,10 @@ directly: RectangularMatrix<3, 2, int> a; a[2] /= 2; // third column (column major indexing, see explanation below) a[0][1] = 5; // first column, second element -a(0, 1) += 3; // first column, second element (preferred) Vector<3, int> b; b[1] = 1; // second element @endcode -For accessing matrix element prefer round bracket operator, as it is possibly -faster than the double square brackets (but never slower) and isn't prone to -compiler mis-optimizations. Fixed-size vector subclasses have functions for accessing named components and subparts: @@ -152,23 +149,19 @@ implications and it may differ from what is common in mathematics: @code RectangularMatrix<2, 3, int> mat; // two columns, three rows @endcode -- Order of components in matrix constructors is also column-major, so the - elements passed in constructor doesn't need to be reordered internally - before putting them into data array: +- Order of components in matrix constructors is also column-major, further + emphasized by requirement that you have to pass directly column vectors: @code -Matrix3 mat(0, 1, 2, - 3, 4, 5, - 6, 7, 8); // first column is {0, 1, 2} +Matrix3 mat({0, 1, 2}, + {3, 4, 5}, + {6, 7, 8}); // first column is {0, 1, 2} @endcode -- Element accessing order is also column-major. It costs virtually no time to - return reference to portion of data array as column vector, thus the bracket - operator is accessing columns. Returned vector has also its own bracket - operator, which is indexing rows. To avoid confusion, first parameter of - round bracket operator is thus also column index. +- Element accessing order is also column-major, thus the bracket operator is + accessing columns. Returned vector has also its own bracket operator, which + is then indexing rows. @code mat[0] *= 2; // first column -mat[2][0] = 5; // first element of first column vector -mat(2, 0) += 3; // first element of first column +mat[2][0] = 5; // first element of first column @endcode - Various algorithms which commonly operate on matrix rows (such as @ref Algorithms::GaussJordan "Gauss-Jordan elimination") have faster diff --git a/src/Color.h b/src/Color.h index 27e651984..483137267 100644 --- a/src/Color.h +++ b/src/Color.h @@ -22,7 +22,6 @@ #include #include "Math/Functions.h" -#include "Math/MathTypeTraits.h" #include "Math/Vector4.h" #include "Magnum.h" @@ -197,7 +196,7 @@ class Color3: public Math::Vector3 { inline constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3(r, g, b) {} /** @brief Copy constructor */ - inline constexpr Color3(const Math::RectangularMatrix<1, 3, T>& other): Math::Vector3(other) {} + inline constexpr Color3(const Math::Vector<3, T>& other): Math::Vector3(other) {} inline T& r() { return Math::Vector3::x(); } /**< @brief R component */ inline constexpr T r() const { return Math::Vector3::x(); } /**< @overload */ @@ -252,7 +251,6 @@ class Color3: public Math::Vector3 { } MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color3, 3) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Color3) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color3, 3) @@ -325,7 +323,7 @@ class Color4: public Math::Vector4 { inline constexpr /*implicit*/ Color4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} /** @brief Copy constructor */ - inline constexpr Color4(const Math::RectangularMatrix<1, 4, T>& other): Math::Vector4(other) {} + inline constexpr Color4(const Math::Vector<4, T>& other): Math::Vector4(other) {} inline T& r() { return Math::Vector4::x(); } /**< @brief R component */ inline constexpr T r() const { return Math::Vector4::x(); } /**< @overload */ @@ -366,7 +364,6 @@ class Color4: public Math::Vector4 { } MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color4, 4) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Color4) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4) diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index 30154fbab..dc1734346 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -76,7 +76,7 @@ template bool GaussJordan::inPlaceT /* Find max pivot */ std::size_t rowMax = row; for(std::size_t row2 = row+1; row2 != size; ++row2) - if(std::abs(a(row2, row)) > std::abs(a(rowMax, row))) + if(std::abs(a[row2][row]) > std::abs(a[rowMax][row])) rowMax = row2; /* Swap the rows */ @@ -84,12 +84,12 @@ template bool GaussJordan::inPlaceT std::swap(t[row], t[rowMax]); /* Singular */ - if(MathTypeTraits::equals(a(row, row), 0)) + if(MathTypeTraits::equals(a[row][row], T(0))) return false; /* Eliminate column */ for(std::size_t row2 = row+1; row2 != size; ++row2) { - T c = a(row2, row)/a(row, row); + T c = a[row2][row]/a[row][row]; a[row2] -= a[row]*c; t[row2] -= t[row]*c; @@ -98,10 +98,10 @@ template bool GaussJordan::inPlaceT /* Backsubstitute */ for(std::size_t row = size; row != 0; --row) { - T c = T(1)/a(row-1, row-1); + T c = T(1)/a[row-1][row-1]; for(std::size_t row2 = 0; row2 != row-1; ++row2) - t[row2] -= t[row-1]*a(row2, row-1)*c; + t[row2] -= t[row-1]*a[row2][row-1]*c; /* Normalize the row */ t[row-1] *= c; diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index aad48debd..7bf870708 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -29,6 +29,7 @@ class GaussJordanTest: public Corrade::TestSuite::Tester { }; typedef Matrix<4, float> Matrix4; +typedef Vector<4, float> Vector4; GaussJordanTest::GaussJordanTest() { addTests(&GaussJordanTest::singular, @@ -36,25 +37,25 @@ GaussJordanTest::GaussJordanTest() { } void GaussJordanTest::singular() { - Matrix4 a(1.0f, 2.0f, 3.0f, 4.0f, - 2.0f, 3.0f, -7.0f, 11.0f, - 2.0f, 4.0f, 6.0f, 8.0f, - 1.0f, 2.0f, 7.0f, 40.0f); + Matrix4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(2.0f, 3.0f, -7.0f, 11.0f), + Vector4(2.0f, 4.0f, 6.0f, 8.0f), + Vector4(1.0f, 2.0f, 7.0f, 40.0f)); RectangularMatrix<4, 1, float> t; CORRADE_VERIFY(!GaussJordan::inPlaceTransposed(a, t)); } void GaussJordanTest::invert() { - Matrix4 a(3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f); - - Matrix4 expectedInverse(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f, - -66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f, - 177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f, - 259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f); + Matrix4 a(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f), + Vector4(9.0f, 4.0f, 5.0f, 9.0f)); + + Matrix4 expectedInverse(Vector4(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f), + Vector4(-66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f), + Vector4(177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f), + Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f)); Matrix4 a2(a); Matrix4 inverse(Matrix4::Identity); diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 764616324..528c6b82f 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -34,11 +34,9 @@ GramSchmidtTest::GramSchmidtTest() { } void GramSchmidtTest::test() { - Matrix3 m( - 3.0f, 5.0f, 8.0f, - 4.0f, 4.0f, 7.0f, - 7.0f, -1.0f, 8.0f - ); + Matrix3 m(Vector3(3.0f, 5.0f, 8.0f), + Vector3(4.0f, 4.0f, 7.0f), + Vector3(7.0f, -1.0f, 8.0f)); Matrix3 normalized = Algorithms::gramSchmidt(m); @@ -56,9 +54,9 @@ void GramSchmidtTest::test() { CORRADE_COMPARE(Vector3::dot(normalized[1], normalized[2]), 0.0f); /* Just to be sure */ - Matrix3 expected( 0.303046f, 0.505076f, 0.808122f, - 0.928316f, -0.348119f, -0.130544f, - -0.215388f, -0.789754f, 0.574367f); + Matrix3 expected(Vector3( 0.303046f, 0.505076f, 0.808122f), + Vector3( 0.928316f, -0.348119f, -0.130544f), + Vector3(-0.215388f, -0.789754f, 0.574367f)); CORRADE_COMPARE(normalized, expected); } diff --git a/src/Math/Geometry/Distance.h b/src/Math/Geometry/Distance.h index 2268f1f95..0433887d4 100644 --- a/src/Math/Geometry/Distance.h +++ b/src/Math/Geometry/Distance.h @@ -44,7 +44,7 @@ class Distance { * @see linePointSquared(const Vector2&, const Vector2&, const Vector2&) */ template inline static T linePoint(const Vector2& a, const Vector2& b, const Vector2& point) { - return std::abs(Matrix<2, T>::from(b - a, a - point).determinant())/(b - a).length(); + return std::abs(Matrix<2, T>(b - a, a - point).determinant())/(b - a).length(); } /** @@ -59,7 +59,7 @@ class Distance { */ template inline static T linePointSquared(const Vector2& a, const Vector2& b, const Vector2& point) { Vector2 bMinusA = b - a; - return Math::pow<2>(Matrix<2, T>::from(bMinusA, a - point).determinant())/bMinusA.dot(); + return Math::pow<2>(Matrix<2, T>(bMinusA, a - point).determinant())/bMinusA.dot(); } /** @@ -134,7 +134,7 @@ class Distance { return std::sqrt(pointDistanceB); /* Between A and B */ - return std::abs(Matrix<2, T>::from(bMinusA, -pointMinusA).determinant())/std::sqrt(bDistanceA); + return std::abs(Matrix<2, T>(bMinusA, -pointMinusA).determinant())/std::sqrt(bDistanceA); } /** @@ -160,7 +160,7 @@ class Distance { return pointDistanceB; /* Between A and B */ - return Math::pow<2>(Matrix<2, T>::from(bMinusA, -pointMinusA).determinant())/bDistanceA; + return Math::pow<2>(Matrix<2, T>(bMinusA, -pointMinusA).determinant())/bDistanceA; } /** diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 1e17d95f4..e73930c58 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -64,27 +64,19 @@ template class Matrix: public RectangularMatrix inline constexpr /*implicit*/ Matrix(T first, U... next): RectangularMatrix(first, next...) {} + template inline constexpr /*implicit*/ Matrix(const Vector& first, const U&... next): RectangularMatrix(first, next...) {} /** @brief Copy constructor */ inline constexpr Matrix(const RectangularMatrix& other): RectangularMatrix(other) {} - /** @brief Multiply and assign matrix operator */ - inline Matrix& operator*=(const RectangularMatrix& other) { - return (*this = *this*other); - } - /** * @brief Trace of the matrix * @@ -96,7 +88,7 @@ template class Matrix: public RectangularMatrix class Matrix: public RectangularMatrix= skipCol), - row + (row >= skipRow)); + out[col][row] = (*this)[col + (col >= skipCol)] + [row + (row >= skipRow)]; return out; } @@ -143,7 +135,7 @@ template class Matrix: public RectangularMatrix class Matrix: public RectangularMatrix::operator*(other); } MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(size, size, Matrix) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(size, size, Matrix) #endif }; @@ -171,6 +162,9 @@ template inline typename std::enable_if inline typename std::enable_if::value, Matrix>::type operator/(U number, const Matrix& matrix) { return number/RectangularMatrix(matrix); } +template inline Matrix operator*(const Vector& vector, const RectangularMatrix& matrix) { + return RectangularMatrix<1, size, T>(vector)*matrix; +} #endif /** @debugoperator{Magnum::Math::Matrix} */ @@ -180,21 +174,6 @@ template inline Corrade::Utility::Debug operator<<(Co #ifndef DOXYGEN_GENERATING_OUTPUT #define MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Type, VectorType, size) \ - inline constexpr static Type& from(T* data) { \ - return *reinterpret_cast*>(data); \ - } \ - inline constexpr static const Type& from(const T* data) { \ - return *reinterpret_cast*>(data); \ - } \ - template inline constexpr static Type from(const Vector& first, const U&... next) { \ - return Matrix::from(first, next...); \ - } \ - \ - inline Type& operator=(const Type& other) { \ - Matrix::operator=(other); \ - return *this; \ - } \ - \ inline VectorType& operator[](std::size_t col) { \ return VectorType::from(Matrix::data()+col*size); \ } \ @@ -205,10 +184,6 @@ template inline Corrade::Utility::Debug operator<<(Co inline Type operator*(const Matrix& other) const { \ return Matrix::operator*(other); \ } \ - inline Type& operator*=(const Matrix& other) { \ - Matrix::operator*=(other); \ - return *this; \ - } \ template inline RectangularMatrix operator*(const RectangularMatrix& other) const { \ return Matrix::operator*(other); \ } \ @@ -225,6 +200,9 @@ template inline Corrade::Utility::Debug operator<<(Co } \ template inline typename std::enable_if::value, Type>::type operator/(U number, const Type& matrix) { \ return number/Matrix(matrix); \ + } \ + template inline Type operator*(const Vector& vector, const RectangularMatrix& matrix) { \ + return RectangularMatrix<1, size, T>(vector)*matrix; \ } namespace Implementation { @@ -235,7 +213,7 @@ template class MatrixDeterminant { T out(0); for(std::size_t col = 0; col != size; ++col) - out += ((col & 1) ? -1 : 1)*m(col, 0)*m.ij(col, 0).determinant(); + out += ((col & 1) ? -1 : 1)*m[col][0]*m.ij(col, 0).determinant(); return out; } @@ -244,14 +222,14 @@ template class MatrixDeterminant { template class MatrixDeterminant<2, T> { public: inline constexpr T operator()(const Matrix<2, T>& m) { - return m(0, 0)*m(1, 1) - m(1, 0)*m(0, 1); + return m[0][0]*m[1][1] - m[1][0]*m[0][1]; } }; template class MatrixDeterminant<1, T> { public: inline constexpr T operator()(const Matrix<1, T>& m) { - return m(0, 0); + return m[0][0]; } }; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 65014d7e7..832e02347 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -43,11 +43,9 @@ template class Matrix3: public Matrix<3, T> { * Vector2::xAxis(), Vector2::yAxis() */ inline constexpr static Matrix3 translation(const Vector2& vector) { - return Matrix3( /* Column-major! */ - T(1), T(0), T(0), - T(0), T(1), T(0), - vector.x(), vector.y(), T(1) - ); + return {{ T(1), T(0), T(0)}, + { T(0), T(1), T(0)}, + {vector.x(), vector.y(), T(1)}}; } /** @@ -58,11 +56,9 @@ template class Matrix3: public Matrix<3, T> { * Vector2::xScale(), Vector2::yScale() */ inline constexpr static Matrix3 scaling(const Vector2& vector) { - return Matrix3( /* Column-major! */ - vector.x(), T(0), T(0), - T(0), vector.y(), T(0), - T(0), T(0), T(1) - ); + return {{vector.x(), T(0), T(0)}, + { T(0), vector.y(), T(0)}, + { T(0), T(0), T(1)}}; } /** @@ -76,11 +72,9 @@ template class Matrix3: public Matrix<3, T> { T sine = std::sin(angle); T cosine = std::cos(angle); - return Matrix3( /* Column-major! */ - cosine, sine, T(0), - -sine, cosine, T(0), - T(0), T(0), T(1) - ); + return {{ cosine, sine, T(0)}, + { -sine, cosine, T(0)}, + { T(0), T(0), T(1)}}; } /** @@ -93,7 +87,7 @@ template class Matrix3: public Matrix<3, T> { static Matrix3 reflection(const Vector2& normal) { CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), "Math::Matrix3::reflection(): normal must be normalized", {}); - return from(Matrix<2, T>() - T(2)*normal*normal.transposed(), {}); + return from(Matrix<2, T>() - T(2)*normal*RectangularMatrix<1, 2, T>(normal).transposed(), {}); } /** @@ -116,11 +110,9 @@ template class Matrix3: public Matrix<3, T> { * @see rotationScaling() const, translation() const */ static Matrix3 from(const Matrix<2, T>& rotationScaling, const Vector2& translation) { - return from( - Vector3(rotationScaling[0], T(0)), - Vector3(rotationScaling[1], T(0)), - Vector3(translation, T(1)) - ); + return {{rotationScaling[0], T(0)}, + {rotationScaling[1], T(0)}, + { translation, T(1)}}; } /** @copydoc Matrix::Matrix(ZeroType) */ @@ -128,13 +120,13 @@ template class Matrix3: public Matrix<3, T> { /** @copydoc Matrix::Matrix(IdentityType, T) */ inline constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( - value, T(0), T(0), - T(0), value, T(0), - T(0), T(0), value + Vector<3, T>(value, T(0), T(0)), + Vector<3, T>( T(0), value, T(0)), + Vector<3, T>( T(0), T(0), value) ) {} - /** @copydoc Matrix::Matrix */ - template inline constexpr /*implicit*/ Matrix3(T first, U... next): Matrix<3, T>(first, next...) {} + /** @brief %Matrix from column vectors */ + inline constexpr /*implicit*/ Matrix3(const Vector3& first, const Vector3& second, const Vector3& third): Matrix<3, T>(first, second, third) {} /** @brief Copy constructor */ inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {} @@ -147,9 +139,8 @@ template class Matrix3: public Matrix<3, T> { * rotation(T), Matrix4::rotationScaling() const */ inline Matrix<2, T> rotationScaling() const { - return Matrix<2, T>::from( - (*this)[0].xy(), - (*this)[1].xy()); + return {(*this)[0].xy(), + (*this)[1].xy()}; } /** @@ -159,9 +150,8 @@ template class Matrix3: public Matrix<3, T> { * @see rotationScaling() const, rotation(T), Matrix4::rotation() const */ inline Matrix<2, T> rotation() const { - return Matrix<2, T>::from( - (*this)[0].xy().normalized(), - (*this)[1].xy().normalized()); + return {(*this)[0].xy().normalized(), + (*this)[1].xy().normalized()}; } /** @@ -202,7 +192,7 @@ template class Matrix3: public Matrix<3, T> { * @see rotationScaling() const, translation() const */ inline Matrix3 invertedEuclidean() const { - CORRADE_ASSERT((*this)(0, 2) == T(0) && (*this)(1, 2) == T(0) && (*this)(2, 2) == T(1), + CORRADE_ASSERT((*this)[0][2] == T(0) && (*this)[1][2] == T(0) && (*this)[2][2] == T(1), "Math::Matrix3::invertedEuclidean(): unexpected values on last row", {}); Matrix<2, T> inverseRotation = rotationScaling().transposed(); CORRADE_ASSERT((inverseRotation*rotationScaling() == Matrix<2, T>()), @@ -216,10 +206,12 @@ template class Matrix3: public Matrix<3, T> { } #endif + MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(3, 3, Matrix3) MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix3, Vector3, 3) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(3, 3, Matrix3) }; +MAGNUM_MATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(Matrix3, 3) + /** @debugoperator{Magnum::Math::Matrix3} */ template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix3& value) { return debug << static_cast&>(value); diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index dbbcaaf04..cbfa7ca4e 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -43,12 +43,10 @@ template class Matrix4: public Matrix<4, T> { * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() */ inline constexpr static Matrix4 translation(const Vector3& vector) { - return Matrix4( /* Column-major! */ - T(1), T(0), T(0), T(0), - T(0), T(1), T(0), T(0), - T(0), T(0), T(1), T(0), - vector.x(), vector.y(), vector.z(), T(1) - ); + return {{ T(1), T(0), T(0), T(0)}, + { T(0), T(1), T(0), T(0)}, + { T(0), T(0), T(1), T(0)}, + {vector.x(), vector.y(), vector.z(), T(1)}}; } /** @@ -59,12 +57,10 @@ template class Matrix4: public Matrix<4, T> { * Vector3::xScale(), Vector3::yScale(), Vector3::zScale() */ inline constexpr static Matrix4 scaling(const Vector3& vector) { - return Matrix4( /* Column-major! */ - vector.x(), T(0), T(0), T(0), - T(0), vector.y(), T(0), T(0), - T(0), T(0), vector.z(), T(0), - T(0), T(0), T(0), T(1) - ); + return {{vector.x(), T(0), T(0), T(0)}, + { T(0), vector.y(), T(0), T(0)}, + { T(0), T(0), vector.z(), T(0)}, + { T(0), T(0), T(0), T(1)}}; } /** @@ -92,21 +88,21 @@ template class Matrix4: public Matrix<4, T> { T yz = normalizedAxis.y()*normalizedAxis.z(); T zz = normalizedAxis.z()*normalizedAxis.z(); - return Matrix4( /* Column-major! */ - cosine + xx*oneMinusCosine, + return { + {cosine + xx*oneMinusCosine, xy*oneMinusCosine + normalizedAxis.z()*sine, xz*oneMinusCosine - normalizedAxis.y()*sine, - T(0), - xy*oneMinusCosine - normalizedAxis.z()*sine, + T(0)}, + {xy*oneMinusCosine - normalizedAxis.z()*sine, cosine + yy*oneMinusCosine, yz*oneMinusCosine + normalizedAxis.x()*sine, - T(0), - xz*oneMinusCosine + normalizedAxis.y()*sine, + T(0)}, + {xz*oneMinusCosine + normalizedAxis.y()*sine, yz*oneMinusCosine - normalizedAxis.x()*sine, cosine + zz*oneMinusCosine, - T(0), - T(0), T(0), T(0), T(1) - ); + T(0)}, + {T(0), T(0), T(0), T(1)} + }; } /** @@ -121,12 +117,10 @@ template class Matrix4: public Matrix<4, T> { T sine = std::sin(angle); T cosine = std::cos(angle); - return Matrix4( /* Column-major! */ - T(1), T(0), T(0), T(0), - T(0), cosine, sine, T(0), - T(0), -sine, cosine, T(0), - T(0), T(0), T(0), T(1) - ); + return {{T(1), T(0), T(0), T(0)}, + {T(0), cosine, sine, T(0)}, + {T(0), -sine, cosine, T(0)}, + {T(0), T(0), T(0), T(1)}}; } /** @@ -141,12 +135,10 @@ template class Matrix4: public Matrix<4, T> { T sine = std::sin(angle); T cosine = std::cos(angle); - return Matrix4( /* Column-major! */ - cosine, T(0), -sine, T(0), - T(0), T(1), T(0), T(0), - sine, T(0), cosine, T(0), - T(0), T(0), T(0), T(1) - ); + return {{cosine, T(0), -sine, T(0)}, + { T(0), T(1), T(0), T(0)}, + { sine, T(0), cosine, T(0)}, + { T(0), T(0), T(0), T(1)}}; } /** @@ -161,12 +153,10 @@ template class Matrix4: public Matrix<4, T> { T sine = std::sin(angle); T cosine = std::cos(angle); - return Matrix4( /* Column-major! */ - cosine, sine, T(0), T(0), - -sine, cosine, T(0), T(0), - T(0), T(0), T(1), T(0), - T(0), T(0), T(0), T(1) - ); + return {{cosine, sine, T(0), T(0)}, + { -sine, cosine, T(0), T(0)}, + { T(0), T(0), T(1), T(0)}, + { T(0), T(0), T(0), T(1)}}; } /** @@ -179,7 +169,7 @@ template class Matrix4: public Matrix<4, T> { static Matrix4 reflection(const Vector3& normal) { CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), "Math::Matrix4::reflection(): normal must be normalized", {}); - return from(Matrix<3, T>() - T(2)*normal*normal.transposed(), {}); + return from(Matrix<3, T>() - T(2)*normal*RectangularMatrix<1, 3, T>(normal).transposed(), {}); } /** @@ -194,12 +184,10 @@ template class Matrix4: public Matrix<4, T> { Vector2 xyScale = T(2.0)/size; T zScale = T(2.0)/(near-far); - return Matrix4( /* Column-major! */ - xyScale.x(), T(0.0), T(0.0), T(0.0), - T(0.0), xyScale.y(), T(0.0), T(0.0), - T(0.0), T(0.0), zScale, T(0.0), - T(0.0), T(0.0), near*zScale-1, T(1.0) - ); + return {{xyScale.x(), T(0), T(0), T(0)}, + { T(0), xyScale.y(), T(0), T(0)}, + { T(0), T(0), zScale, T(0)}, + { T(0), T(0), near*zScale-T(1), T(1)}}; } /** @@ -214,12 +202,10 @@ template class Matrix4: public Matrix<4, T> { Vector2 xyScale = 2*near/size; T zScale = T(1.0)/(near-far); - return Matrix4( /* Column-major! */ - xyScale.x(), T(0.0), T(0.0), T(0.0), - T(0.0), xyScale.y(), T(0.0), T(0.0), - T(0.0), T(0.0), (far+near)*zScale, T(-1.0), - T(0.0), T(0.0), (2*far*near)*zScale, T(0.0) - ); + return {{xyScale.x(), T(0), T(0), T(0)}, + { T(0), xyScale.y(), T(0), T(0)}, + { T(0), T(0), (far+near)*zScale, T(-1)}, + { T(0), T(0), T(2)*far*near*zScale, T(0)}}; } /** @@ -247,12 +233,10 @@ template class Matrix4: public Matrix<4, T> { * @see rotationScaling() const, translation() const */ static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation) { - return from( - Vector4(rotationScaling[0], T(0)), - Vector4(rotationScaling[1], T(0)), - Vector4(rotationScaling[2], T(0)), - Vector4(translation, T(1)) - ); + return {{rotationScaling[0], T(0)}, + {rotationScaling[1], T(0)}, + {rotationScaling[2], T(0)}, + { translation, T(1)}}; } /** @copydoc Matrix::Matrix(ZeroType) */ @@ -260,14 +244,14 @@ template class Matrix4: public Matrix<4, T> { /** @copydoc Matrix::Matrix(IdentityType, T) */ inline constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( - value, T(0), T(0), T(0), - T(0), value, T(0), T(0), - T(0), T(0), value, T(0), - T(0), T(0), T(0), value + Vector<4, T>(value, T(0), T(0), T(0)), + Vector<4, T>( T(0), value, T(0), T(0)), + Vector<4, T>( T(0), T(0), value, T(0)), + Vector<4, T>( T(0), T(0), T(0), value) ) {} - /** @copydoc Matrix::Matrix */ - template inline constexpr /*implicit*/ Matrix4(T first, U... next): Matrix<4, T>(first, next...) {} + /** @brief %Matrix from column vectors */ + inline constexpr /*implicit*/ Matrix4(const Vector4& first, const Vector4& second, const Vector4& third, const Vector4& fourth): Matrix<4, T>(first, second, third, fourth) {} /** @brief Copy constructor */ inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {} @@ -281,10 +265,9 @@ template class Matrix4: public Matrix<4, T> { */ inline Matrix<3, T> rotationScaling() const { /* Not Matrix3, because it is for affine 2D transformations */ - return Matrix<3, T>::from( - (*this)[0].xyz(), - (*this)[1].xyz(), - (*this)[2].xyz()); + return {(*this)[0].xyz(), + (*this)[1].xyz(), + (*this)[2].xyz()}; } /** @@ -296,10 +279,9 @@ template class Matrix4: public Matrix<4, T> { */ inline Matrix<3, T> rotation() const { /* Not Matrix3, because it is for affine 2D transformations */ - return Matrix<3, T>::from( - (*this)[0].xyz().normalized(), - (*this)[1].xyz().normalized(), - (*this)[2].xyz().normalized()); + return {(*this)[0].xyz().normalized(), + (*this)[1].xyz().normalized(), + (*this)[2].xyz().normalized()}; } /** @@ -349,7 +331,7 @@ template class Matrix4: public Matrix<4, T> { * @see rotationScaling() const, translation() const */ inline Matrix4 invertedEuclidean() const { - CORRADE_ASSERT((*this)(0, 3) == T(0) && (*this)(1, 3) == T(0) && (*this)(2, 3) == T(0) && (*this)(3, 3) == T(1), + CORRADE_ASSERT((*this)[0][3] == T(0) && (*this)[1][3] == T(0) && (*this)[2][3] == T(0) && (*this)[3][3] == T(1), "Math::Matrix4::invertedEuclidean(): unexpected values on last row", {}); Matrix<3, T> inverseRotation = rotationScaling().transposed(); CORRADE_ASSERT((inverseRotation*rotationScaling() == Matrix<3, T>()), @@ -363,10 +345,12 @@ template class Matrix4: public Matrix<4, T> { } #endif + MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(4, 4, Matrix4) MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(4, 4, Matrix4) }; +MAGNUM_MATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(Matrix4, 4) + /** @debugoperator{Magnum::Math::Matrix4} */ template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Matrix4& value) { return debug << static_cast&>(value); diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 93adf7d9f..53fbc9b21 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -57,7 +57,7 @@ template class Point2D: public Vector3 { inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z = T(1)): Vector3(xy, z) {} /** @brief Copy constructor */ - inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3(other) {} + inline constexpr Point2D(const Vector<3, T>& other): Vector3(other) {} /** * @brief Vector part of the point @@ -69,7 +69,6 @@ template class Point2D: public Vector3 { inline constexpr Vector2 vector() const { return Vector3::xy(); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point2D, 3) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Point2D) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3) diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 959b7e745..ca4588a8b 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -58,7 +58,7 @@ template class Point3D: public Vector4 { inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w = T(1)): Vector4(xyz, w) {} /** @brief Copy constructor */ - inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4(other) {} + inline constexpr Point3D(const Vector<4, T>& other): Vector4(other) {} /** * @brief Vector part of the point @@ -70,7 +70,6 @@ template class Point3D: public Vector4 { inline constexpr Vector3 vector() const { return Vector4::xyz(); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point3D, 4) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Point3D) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index d962a03ef..1615c4e41 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -174,16 +174,16 @@ template class Quaternion { * @see Matrix4::from(const Matrix<3, T>&, const Vector3&) */ Matrix<3, T> matrix() const { - return { /* Column-major! */ - T(1) - 2*pow<2>(_vector.y()) - 2*pow<2>(_vector.z()), + return { + Vector<3, T>(T(1) - 2*pow<2>(_vector.y()) - 2*pow<2>(_vector.z()), 2*_vector.x()*_vector.y() + 2*_vector.z()*_scalar, - 2*_vector.x()*_vector.z() - 2*_vector.y()*_scalar, - 2*_vector.x()*_vector.y() - 2*_vector.z()*_scalar, + 2*_vector.x()*_vector.z() - 2*_vector.y()*_scalar), + Vector<3, T>(2*_vector.x()*_vector.y() - 2*_vector.z()*_scalar, T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.z()), - 2*_vector.y()*_vector.z() + 2*_vector.x()*_scalar, - 2*_vector.x()*_vector.z() + 2*_vector.y()*_scalar, + 2*_vector.y()*_vector.z() + 2*_vector.x()*_scalar), + Vector<3, T>(2*_vector.x()*_vector.z() + 2*_vector.y()*_scalar, 2*_vector.y()*_vector.z() - 2*_vector.x()*_scalar, - T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.y()) + T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.y())) }; } diff --git a/src/Math/RectangularMatrix.cpp b/src/Math/RectangularMatrix.cpp index 73b56677d..1716c3a14 100644 --- a/src/Math/RectangularMatrix.cpp +++ b/src/Math/RectangularMatrix.cpp @@ -18,21 +18,6 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 2, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 3, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 4, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 2, int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 3, int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 4, int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 2, unsigned int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 3, unsigned int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 4, unsigned int>&); -#ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 2, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 3, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<1, 4, double>&); -#endif - template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 2, float>&); template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 3, float>&); template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 4, float>&); @@ -63,21 +48,6 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnu namespace Corrade { namespace Utility { #ifndef DOXYGEN_GENERATING_OUTPUT -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -#ifndef MAGNUM_TARGET_GLES -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -#endif - template struct ConfigurationValue>; template struct ConfigurationValue>; template struct ConfigurationValue>; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 0c5d91bb0..4667af89f 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -19,48 +19,12 @@ * @brief Class Magnum::Math::RectangularMatrix */ -#include -#include -#include -#include - -#include "MathTypeTraits.h" - -#include "magnumVisibility.h" +#include "Math/Vector.h" namespace Magnum { namespace Math { /** @todo Properly test all constexpr */ -/** @todoc Remove `ifndef` when Doxygen is sane again */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template class RectangularMatrix; -#endif - -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - template struct Sequence {}; - - /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ - template struct GenerateSequence: - GenerateSequence {}; - - template struct GenerateSequence<0, sequence...> { - typedef Sequence Type; - }; - - /* Implementation for RectangularMatrix::from(const RectangularMatrix&) */ - template inline constexpr Math::RectangularMatrix rectangularMatrixFrom(Sequence, const Math::RectangularMatrix& matrix) { - return {T(matrix.data()[sequence])...}; - } -} -#endif - -/** @todoc Remove `ifndef` when Doxygen is sane again */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template class Vector; -#endif - /** @brief Rectangular matrix @tparam cols Column count @@ -75,7 +39,7 @@ math formulas are in reverse order (i.e. @f$ \boldsymbol A_{ji} @f$ instead of @f$ \boldsymbol A_{ij} @f$). */ template class RectangularMatrix { - static_assert(cols != 0 && rows != 0, "Matrix cannot have zero elements"); + static_assert(cols != 0 && rows != 0, "RectangularMatrix cannot have zero elements"); public: typedef T Type; /**< @brief Data type */ @@ -98,18 +62,6 @@ template class RectangularMatrix { return *reinterpret_cast*>(data); } - /** - * @brief %Matrix from column vectors - * @param first First column vector - * @param next Next column vectors - * - * @todo Creating matrix from arbitrary combination of matrices with n rows - */ - template inline constexpr static RectangularMatrix from(const Vector& first, const U&... next) { - static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to Matrix from Vector constructor"); - return from(typename Implementation::GenerateSequence::Type(), first, next...); - } - /** * @brief %Matrix from another of different type * @@ -122,21 +74,21 @@ template class RectangularMatrix { * @endcode */ template inline constexpr static RectangularMatrix from(const RectangularMatrix& other) { - return Implementation::rectangularMatrixFrom(typename Implementation::GenerateSequence::Type(), other); + return from(typename Implementation::GenerateSequence::Type(), other); } - /** @brief Zero-filled matrix constructor */ - inline constexpr /*implicit*/ RectangularMatrix(): _data() {} + /** @brief Construct zero-filled matrix */ + inline constexpr /*implicit*/ RectangularMatrix() {} /** - * @brief Initializer-list constructor - * @param first First value - * @param next Next values + * @brief Construct matrix from column vectors + * @param first First column vector + * @param next Next column vectors * - * Note that the values are in column-major order. + * @todo Creating matrix from arbitrary combination of matrices with n rows */ - template inline constexpr /*implicit*/ RectangularMatrix(T first, U... next): _data{first, next...} { - static_assert(sizeof...(next)+1 == cols*rows, "Improper number of arguments passed to RectangularMatrix constructor"); + template inline constexpr /*implicit*/ RectangularMatrix(const Vector& first, const U&... next): _data{first, next...} { + static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to RectangularMatrix constructor"); } /** @brief Copy constructor */ @@ -149,47 +101,35 @@ template class RectangularMatrix { * @brief Raw data * @return One-dimensional array of `size*size` length in column-major * order. + * + * @see operator[] */ - inline T* data() { return _data; } - inline constexpr const T* data() const { return _data; } /**< @overload */ + inline T* data() { return reinterpret_cast(_data); } + inline constexpr const T* data() const { return reinterpret_cast(_data); } /**< @overload */ /** * @brief %Matrix column * - * For accessing individual elements prefer to use operator(), as it - * is guaranteed to not involve unnecessary conversions. + * Particular elements can be accessed using Vector::operator[], e.g.: + * @code + * RectangularMatrix<4, 3, float> m; + * float a = m[2][1]; + * @endcode + * + * @see data() */ inline Vector& operator[](std::size_t col) { - return Vector::from(_data+col*rows); + return _data[col]; } /** @overload */ inline constexpr const Vector& operator[](std::size_t col) const { - return Vector::from(_data+col*rows); - } - - /** - * @brief Element on given position - * - * Prefer this instead of using `[][]`. - * @see operator[] - */ - inline T& operator()(std::size_t col, std::size_t row) { - return _data[col*rows+row]; - } - /** @overload */ - inline constexpr const T& operator()(std::size_t col, std::size_t row) const { - return _data[col*rows+row]; + return _data[col]; } - /** - * @brief Equality operator - * - * @see Vector::operator<(), Vector::operator<=(), Vector::operator>=(), - * Vector::operator>() - */ + /** @brief Equality comparison */ inline bool operator==(const RectangularMatrix& other) const { - for(std::size_t i = 0; i != cols*rows; ++i) - if(!MathTypeTraits::equals(_data[i], other._data[i])) return false; + for(std::size_t i = 0; i != cols; ++i) + if(_data[i] != other._data[i]) return false; return true; } @@ -207,12 +147,12 @@ template class RectangularMatrix { /** * @brief Add and assign matrix * - * The computation is done in-place. @f[ - * \boldsymbol A_{ji} = \boldsymbol A_{ji} + \boldsymbol B_{ji} + * The computation is done column-wise in-place. @f[ + * \boldsymbol A_j = \boldsymbol A_j + \boldsymbol B_j * @f] */ RectangularMatrix& operator+=(const RectangularMatrix& other) { - for(std::size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols; ++i) _data[i] += other._data[i]; return *this; @@ -230,14 +170,14 @@ template class RectangularMatrix { /** * @brief Negated matrix * - * The computation is done in-place. @f[ - * \boldsymbol A_{ji} = -\boldsymbol A_{ji} + * The computation is done column-wise in-place. @f[ + * \boldsymbol A_j = -\boldsymbol A_j * @f] */ RectangularMatrix operator-() const { RectangularMatrix out; - for(std::size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols; ++i) out._data[i] = -_data[i]; return out; @@ -246,12 +186,12 @@ template class RectangularMatrix { /** * @brief Subtract and assign matrix * - * The computation is done in-place. @f[ - * \boldsymbol A_{ji} = \boldsymbol A_{ji} - \boldsymbol B_{ji} + * The computation is done column-wise in-place. @f[ + * \boldsymbol A_j = \boldsymbol A_j - \boldsymbol B_j * @f] */ RectangularMatrix& operator-=(const RectangularMatrix& other) { - for(std::size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols; ++i) _data[i] -= other._data[i]; return *this; @@ -282,8 +222,8 @@ template class RectangularMatrix { /** * @brief Multiply matrix with number and assign * - * The computation is done in-place. @f[ - * \boldsymbol A_{ji} = a \boldsymbol A_{ji} + * The computation is done column-wise in-place. @f[ + * \boldsymbol A_j = a \boldsymbol A_j * @f] */ #ifndef DOXYGEN_GENERATING_OUTPUT @@ -291,7 +231,7 @@ template class RectangularMatrix { #else template RectangularMatrix& operator*=(U number) { #endif - for(std::size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols; ++i) _data[i] *= number; return *this; @@ -313,8 +253,8 @@ template class RectangularMatrix { /** * @brief Divide matrix with number and assign * - * The computation is done in-place. @f[ - * \boldsymbol A_{ji} = \frac{\boldsymbol A_{ji}} a + * The computation is done column-wise in-place. @f[ + * \boldsymbol A_j = \frac{\boldsymbol A_j} a * @f] */ #ifndef DOXYGEN_GENERATING_OUTPUT @@ -322,7 +262,7 @@ template class RectangularMatrix { #else template RectangularMatrix& operator/=(U number) { #endif - for(std::size_t i = 0; i != cols*rows; ++i) + for(std::size_t i = 0; i != cols; ++i) _data[i] /= number; return *this; @@ -341,7 +281,7 @@ template class RectangularMatrix { for(std::size_t col = 0; col != size; ++col) for(std::size_t row = 0; row != rows; ++row) for(std::size_t pos = 0; pos != cols; ++pos) - out(col, row) += (*this)(pos, row)*other(col, pos); + out[col][row] += (*this)[pos][row]*other[col][pos]; return out; } @@ -355,7 +295,7 @@ template class RectangularMatrix { * @f] */ Vector operator*(const Vector& other) const { - return operator*(static_cast>(other)); + return operator*(RectangularMatrix<1, rows, T>(other))[0]; } /** @brief Transposed matrix */ @@ -364,23 +304,18 @@ template class RectangularMatrix { for(std::size_t col = 0; col != cols; ++col) for(std::size_t row = 0; row != rows; ++row) - out(row, col) = (*this)(col, row); + out[row][col] = (*this)[col][row]; return out; } - #ifndef DOXYGEN_GENERATING_OUTPUT - protected: - T _data[rows*cols]; - #endif - private: - template inline constexpr static RectangularMatrix from(Implementation::Sequence s, const Vector& first, U... next) { - return from(s, next..., first[sequence]...); - } - template inline constexpr static RectangularMatrix from(Implementation::Sequence, T first, U... next) { - return RectangularMatrix(first, next...); + /* Implementation for RectangularMatrix::from(const RectangularMatrix&) */ + template inline constexpr static Math::RectangularMatrix from(Implementation::Sequence, const Math::RectangularMatrix& matrix) { + return {Vector::from(matrix[sequence])...}; } + + Vector _data[cols]; }; /** @relates RectangularMatrix @@ -399,8 +334,8 @@ template inline typename s /** @relates RectangularMatrix @brief Divide matrix with number and invert -@f[ - \boldsymbol B_{ji} = \frac a {\boldsymbol A_{ji}} +The computation is done column-wise. @f[ + \boldsymbol B_j = \frac a {\boldsymbol A_j} @f] @see RectangularMatrix::operator/(U) const */ @@ -411,12 +346,24 @@ template typename std::ena #endif RectangularMatrix out; - for(std::size_t i = 0; i != cols*rows; ++i) - out.data()[i] = number/matrix.data()[i]; + for(std::size_t i = 0; i != cols; ++i) + out[i] = number/matrix[i]; return out; } +/** @relates RectangularMatrix +@brief Multiply vector with rectangular matrix + +Internally the same as multiplying one-column matrix with one-row matrix. @f[ + (\boldsymbol {aA})_{ji} = \boldsymbol a_i \boldsymbol A_j +@f] +@see RectangularMatrix::operator*(const RectangularMatrix&) const +*/ +template inline RectangularMatrix operator*(const Vector& vector, const RectangularMatrix& matrix) { + return RectangularMatrix<1, size, T>(vector)*matrix; +} + /** @debugoperator{Magnum::Math::RectangularMatrix} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::RectangularMatrix& value) { debug << "Matrix("; @@ -433,24 +380,8 @@ template Corrade::Utility::Debug op return debug; } -/* Explicit instantiation for types used in OpenGL */ #ifndef DOXYGEN_GENERATING_OUTPUT -/* Vectors */ -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 2, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 3, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 4, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 2, int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 3, int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 4, int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 2, unsigned int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 3, unsigned int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 4, unsigned int>&); -#ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 2, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 3, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<1, 4, double>&); -#endif - +/* Explicit instantiation for types used in OpenGL */ /* Square matrices */ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 2, float>&); extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 3, float>&); @@ -476,9 +407,7 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 4, double>&); extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 3, double>&); #endif -#endif -#ifndef DOXYGEN_GENERATING_OUTPUT #define MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(cols, rows, ...) \ inline constexpr static __VA_ARGS__& from(T* data) { \ return *reinterpret_cast<__VA_ARGS__*>(data); \ @@ -486,9 +415,6 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit inline constexpr static const __VA_ARGS__& from(const T* data) { \ return *reinterpret_cast(data); \ } \ - template inline constexpr static __VA_ARGS__ from(const Math::Vector& first, const U&... next) { \ - return Math::RectangularMatrix::from(first, next...); \ - } \ template inline constexpr static RectangularMatrix from(const Math::RectangularMatrix& other) { \ return Math::RectangularMatrix::from(other); \ } \ @@ -496,39 +422,38 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit inline __VA_ARGS__& operator=(const Math::RectangularMatrix& other) { \ Math::RectangularMatrix::operator=(other); \ return *this; \ - } - -#define MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(cols, rows, ...) \ + } \ + \ inline __VA_ARGS__ operator-() const { \ return Math::RectangularMatrix::operator-(); \ } \ - inline __VA_ARGS__ operator+(const Math::RectangularMatrix& other) const { \ - return Math::RectangularMatrix::operator+(other); \ - } \ inline __VA_ARGS__& operator+=(const Math::RectangularMatrix& other) { \ Math::RectangularMatrix::operator+=(other); \ return *this; \ } \ - inline __VA_ARGS__ operator-(const Math::RectangularMatrix& other) const { \ - return Math::RectangularMatrix::operator-(other); \ + inline __VA_ARGS__ operator+(const Math::RectangularMatrix& other) const { \ + return Math::RectangularMatrix::operator+(other); \ } \ inline __VA_ARGS__& operator-=(const Math::RectangularMatrix& other) { \ Math::RectangularMatrix::operator-=(other); \ return *this; \ } \ - template inline typename std::enable_if::value, __VA_ARGS__>::type operator*(U number) const { \ - return Math::RectangularMatrix::operator*(number); \ + inline __VA_ARGS__ operator-(const Math::RectangularMatrix& other) const { \ + return Math::RectangularMatrix::operator-(other); \ } \ template inline typename std::enable_if::value, __VA_ARGS__&>::type operator*=(U number) { \ Math::RectangularMatrix::operator*=(number); \ return *this; \ } \ - template inline typename std::enable_if::value, __VA_ARGS__>::type operator/(U number) const { \ - return Math::RectangularMatrix::operator/(number); \ + template inline typename std::enable_if::value, __VA_ARGS__>::type operator*(U number) const { \ + return Math::RectangularMatrix::operator*(number); \ } \ template inline typename std::enable_if::value, __VA_ARGS__&>::type operator/=(U number) { \ Math::RectangularMatrix::operator/=(number); \ return *this; \ + } \ + template inline typename std::enable_if::value, __VA_ARGS__>::type operator/(U number) const { \ + return Math::RectangularMatrix::operator/(number); \ } #endif @@ -547,7 +472,7 @@ template struct ConfigurationValue< for(std::size_t row = 0; row != rows; ++row) { for(std::size_t col = 0; col != cols; ++col) { if(!output.empty()) output += ' '; - output += ConfigurationValue::toString(value(col, row), flags); + output += ConfigurationValue::toString(value[col][row], flags); } } @@ -564,7 +489,7 @@ template struct ConfigurationValue< std::string part = stringValue.substr(oldpos, pos-oldpos); if(!part.empty()) { - result(i%cols, i/cols) = ConfigurationValue::fromString(part, flags); + result[i%cols][i/cols] = ConfigurationValue::fromString(part, flags); ++i; } @@ -576,22 +501,6 @@ template struct ConfigurationValue< }; #ifndef DOXYGEN_GENERATING_OUTPUT -/* Vectors */ -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -#ifndef MAGNUM_TARGET_GLES -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -#endif - /* Square matrices */ extern template struct MAGNUM_EXPORT ConfigurationValue>; extern template struct MAGNUM_EXPORT ConfigurationValue>; @@ -621,7 +530,4 @@ extern template struct MAGNUM_EXPORT ConfigurationValue::pi()/7), Vector3::xAxis()), matrix); CORRADE_COMPARE(Matrix4::rotationX(rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationY() { - Matrix4 matrix(0.90096887f, 0.0f, -0.43388374f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.43388374f, 0.0f, 0.90096887f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); + Matrix4 matrix({0.90096887f, 0.0f, -0.43388374f, 0.0f}, + { 0.0f, 1.0f, 0.0f, 0.0f}, + {0.43388374f, 0.0f, 0.90096887f, 0.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); CORRADE_COMPARE(Matrix4::rotationY(rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationZ() { - Matrix4 matrix( 0.90096887f, 0.43388374f, 0.0f, 0.0f, - -0.43388374f, 0.90096887f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); + Matrix4 matrix({ 0.90096887f, 0.43388374f, 0.0f, 0.0f}, + {-0.43388374f, 0.90096887f, 0.0f, 0.0f}, + { 0.0f, 0.0f, 1.0f, 0.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); CORRADE_COMPARE(Matrix4::rotationZ(rad(Math::Constants::pi()/7)), matrix); } @@ -174,12 +164,10 @@ void Matrix4Test::reflection() { CORRADE_COMPARE(o.str(), "Math::Matrix4::reflection(): normal must be normalized\n"); Matrix4 actual = Matrix4::reflection(normal.normalized()); - Matrix4 expected( - 0.777778f, 0.444444f, 0.444444f, 0.0f, - 0.444444f, 0.111111f, -0.888889f, 0.0f, - 0.444444f, -0.888889f, 0.111111f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); + Matrix4 expected({0.777778f, 0.444444f, 0.444444f, 0.0f}, + {0.444444f, 0.111111f, -0.888889f, 0.0f}, + {0.444444f, -0.888889f, 0.111111f, 0.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(actual*actual, Matrix4()); CORRADE_COMPARE(actual*normal, -normal); @@ -187,73 +175,59 @@ void Matrix4Test::reflection() { } void Matrix4Test::orthographicProjection() { - Matrix4 expected(0.4f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.5f, 0.0f, 0.0f, - 0.0f, 0.0f, -0.25f, 0.0f, - 0.0f, 0.0f, -1.25f, 1.0f); + Matrix4 expected({0.4f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.5f, 0.0f, 0.0f}, + {0.0f, 0.0f, -0.25f, 0.0f}, + {0.0f, 0.0f, -1.25f, 1.0f}); CORRADE_COMPARE(Matrix4::orthographicProjection({5.0f, 4.0f}, 1, 9), expected); } void Matrix4Test::perspectiveProjection() { - Matrix4 expected(4.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 7.111111f, 0.0f, 0.0f, - 0.0f, 0.0f, -1.9411764f, -1.0f, - 0.0f, 0.0f, -94.1176452f, 0.0f); - + Matrix4 expected({4.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 7.111111f, 0.0f, 0.0f}, + {0.0f, 0.0f, -1.9411764f, -1.0f}, + {0.0f, 0.0f, -94.1176452f, 0.0f}); CORRADE_COMPARE(Matrix4::perspectiveProjection({16.0f, 9.0f}, 32.0f, 100), expected); } void Matrix4Test::perspectiveProjectionFov() { - Matrix4 expected(4.1652994f, 0.0f, 0.0f, 0.0f, - 0.0f, 9.788454f, 0.0f, 0.0f, - 0.0f, 0.0f, -1.9411764f, -1.0f, - 0.0f, 0.0f, -94.1176452f, 0.0f); - + Matrix4 expected({4.1652994f, 0.0f, 0.0f, 0.0f}, + { 0.0f, 9.788454f, 0.0f, 0.0f}, + { 0.0f, 0.0f, -1.9411764f, -1.0f}, + { 0.0f, 0.0f, -94.1176452f, 0.0f}); CORRADE_COMPARE(Matrix4::perspectiveProjection(deg(27.0f), 2.35f, 32.0f, 100), expected); } void Matrix4Test::fromParts() { - Matrix3 rotationScaling( - 3.0f, 5.0f, 8.0f, - 4.0f, 4.0f, 7.0f, - 7.0f, -1.0f, 8.0f - ); + Matrix3 rotationScaling(Vector3(3.0f, 5.0f, 8.0f), + Vector3(4.0f, 4.0f, 7.0f), + Vector3(7.0f, -1.0f, 8.0f)); Vector3 translation(9.0f, 4.0f, 5.0f); - Matrix4 expected( - 3.0f, 5.0f, 8.0f, 0.0f, - 4.0f, 4.0f, 7.0f, 0.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 1.0f - ); - + Matrix4 expected({3.0f, 5.0f, 8.0f, 0.0f}, + {4.0f, 4.0f, 7.0f, 0.0f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 1.0f}); CORRADE_COMPARE(Matrix4::from(rotationScaling, translation), expected); } void Matrix4Test::rotationScalingPart() { - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - ); - - Matrix3 expected( - 3.0f, 5.0f, 8.0f, - 4.0f, 4.0f, 7.0f, - 7.0f, -1.0f, 8.0f - ); - + Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, + {4.0f, 4.0f, 7.0f, 3.0f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 9.0f}); + + Matrix3 expected(Vector3(3.0f, 5.0f, 8.0f), + Vector3(4.0f, 4.0f, 7.0f), + Vector3(7.0f, -1.0f, 8.0f)); CORRADE_COMPARE(m.rotationScaling(), expected); } void Matrix4Test::rotationPart() { - Matrix3 expectedRotationPart( - 0.35612214f, -0.80181062f, 0.47987163f, - 0.47987163f, 0.59757638f, 0.6423595f, - -0.80181062f, 0.0015183985f, 0.59757638f - ); + Matrix3 expectedRotationPart(Vector3( 0.35612214f, -0.80181062f, 0.47987163f), + Vector3( 0.47987163f, 0.59757638f, 0.6423595f), + Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)); Matrix4 rotation = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); CORRADE_COMPARE(rotation.rotation().determinant(), 1.0f); @@ -267,10 +241,10 @@ void Matrix4Test::rotationPart() { } void Matrix4Test::vectorParts() { - Matrix4 m(-1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 12.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 35.0f, 0.0f, - -5.0f, 12.0f, 0.5f, 1.0f); + Matrix4 m({-1.0f, 0.0f, 0.0f, 0.0f}, + { 0.0f, 12.0f, 0.0f, 0.0f}, + { 0.0f, 0.0f, 35.0f, 0.0f}, + {-5.0f, 12.0f, 0.5f, 1.0f}); CORRADE_COMPARE(m.right(), Vector3::xAxis(-1.0f)); CORRADE_COMPARE(m.up(), Vector3::yAxis(12.0f)); @@ -282,12 +256,10 @@ void Matrix4Test::invertedEuclidean() { std::ostringstream o; Error::setOutput(&o); - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - ); + Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, + {4.0f, 4.0f, 7.0f, 3.0f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 9.0f}); CORRADE_COMPARE(m.invertedEuclidean(), Matrix4()); CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): unexpected values on last row\n"); @@ -307,12 +279,10 @@ void Matrix4Test::invertedEuclidean() { } void Matrix4Test::debug() { - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - ); + Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, + {4.0f, 4.0f, 7.0f, 3.0f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 9.0f}); std::ostringstream o; Debug(&o) << m; @@ -325,12 +295,10 @@ void Matrix4Test::debug() { void Matrix4Test::configuration() { Configuration c; - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.125f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.55f - ); + Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, + {4.0f, 4.0f, 7.0f, 3.125f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 9.55f}); std::string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); c.setValue("matrix", m); diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index b004d6a3e..8b377e915 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -42,6 +42,7 @@ class MatrixTest: public Corrade::TestSuite::Tester { typedef Matrix<4, float> Matrix4; typedef Matrix<3, float> Matrix3; typedef Vector<4, float> Vector4; +typedef Vector<3, float> Vector3; MatrixTest::MatrixTest() { addTests(&MatrixTest::construct, @@ -57,18 +58,16 @@ MatrixTest::MatrixTest() { void MatrixTest::construct() { float m[] = { - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, + 3.0f, 5.0f, 8.0f, 4.0f, + 4.0f, 4.0f, 7.0f, 3.0f, 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f + 9.0f, 4.0f, 5.0f, 9.0f }; - Matrix4 expected( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - ); + Matrix4 expected(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f), + Vector4(9.0f, 4.0f, 5.0f, 9.0f)); CORRADE_COMPARE(Matrix4::from(m), expected); } @@ -78,19 +77,15 @@ void MatrixTest::constructIdentity() { Matrix4 identity2(Matrix4::Identity); Matrix4 identity3(Matrix4::Identity, 4.0f); - Matrix4 identityExpected( - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); + Matrix4 identityExpected(Vector4(1.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 1.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 1.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 1.0f)); - Matrix4 identity3Expected( - 4.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 4.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 4.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 4.0f - ); + Matrix4 identity3Expected(Vector4(4.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 4.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 4.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 4.0f)); CORRADE_COMPARE(identity, identityExpected); CORRADE_COMPARE(identity2, identityExpected); @@ -100,71 +95,61 @@ void MatrixTest::constructIdentity() { void MatrixTest::constructZero() { Matrix4 zero(Matrix4::Zero); - Matrix4 zeroExpected( - 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f - ); + Matrix4 zeroExpected(Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f)); CORRADE_COMPARE(zero, zeroExpected); } void MatrixTest::trace() { Matrix<5, std::int32_t> m( - 1, 2, 3, 0, 0, - 2, 3, 2, 1, -2, - 1, 1, -20, 1, 0, - 2, 0, 0, 10, 2, - 3, 1, 0, 1, -2 + Vector<5, std::int32_t>(1, 2, 3, 0, 0), + Vector<5, std::int32_t>(2, 3, 2, 1, -2), + Vector<5, std::int32_t>(1, 1, -20, 1, 0), + Vector<5, std::int32_t>(2, 0, 0, 10, 2), + Vector<5, std::int32_t>(3, 1, 0, 1, -2) ); CORRADE_COMPARE(m.trace(), -8); } void MatrixTest::ij() { - Matrix4 original( - 0.0f, 1.0f, 2.0f, 3.0f, - 4.0f, 5.0f, 6.0f, 7.0f, - 8.0f, 9.0f, 10.0f, 11.0f, - 12.0f, 13.0f, 14.0f, 15.0f - ); + Matrix4 original(Vector4( 0.0f, 1.0f, 2.0f, 3.0f), + Vector4( 4.0f, 5.0f, 6.0f, 7.0f), + Vector4( 8.0f, 9.0f, 10.0f, 11.0f), + Vector4(12.0f, 13.0f, 14.0f, 15.0f)); - Matrix3 skipped( - 0.0f, 1.0f, 3.0f, - 8.0f, 9.0f, 11.0f, - 12.0f, 13.0f, 15.0f - ); + Matrix3 skipped(Vector3( 0.0f, 1.0f, 3.0f), + Vector3( 8.0f, 9.0f, 11.0f), + Vector3(12.0f, 13.0f, 15.0f)); CORRADE_COMPARE(original.ij(1, 2), skipped); } void MatrixTest::determinant() { Matrix<5, std::int32_t> m( - 1, 2, 2, 1, 0, - 2, 3, 2, 1, -2, - 1, 1, 1, 1, 0, - 2, 0, 0, 1, 2, - 3, 1, 0, 1, -2 + Vector<5, std::int32_t>(1, 2, 2, 1, 0), + Vector<5, std::int32_t>(2, 3, 2, 1, -2), + Vector<5, std::int32_t>(1, 1, 1, 1, 0), + Vector<5, std::int32_t>(2, 0, 0, 1, 2), + Vector<5, std::int32_t>(3, 1, 0, 1, -2) ); CORRADE_COMPARE(m.determinant(), -2); } void MatrixTest::inverted() { - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - ); + Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f), + Vector4(9.0f, 4.0f, 5.0f, 9.0f)); - Matrix4 inverse( - -60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f, - -66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f, - 177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f, - 259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f - ); + Matrix4 inverse(Vector4(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f), + Vector4(-66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f), + Vector4(177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f), + Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f)); Matrix4 _inverse = m.inverted(); @@ -173,12 +158,10 @@ void MatrixTest::inverted() { } void MatrixTest::debug() { - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - ); + Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f), + Vector4(9.0f, 4.0f, 5.0f, 9.0f)); std::ostringstream o; Debug(&o) << m; @@ -201,12 +184,10 @@ void MatrixTest::debug() { void MatrixTest::configuration() { Configuration c; - Matrix4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.125f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.55f - ); + Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.125f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f), + Vector4(9.0f, 4.0f, 5.0f, 9.55f)); std::string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); c.setValue("matrix", m); diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 86bc8e61a..60f00e421 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -51,6 +51,9 @@ typedef RectangularMatrix<3, 4, float> Matrix3x4; typedef RectangularMatrix<2, 2, float> Matrix2; typedef RectangularMatrix<2, 2, std::int32_t> Matrix2i; typedef Vector<4, float> Vector4; +typedef Vector<3, float> Vector3; +typedef Vector<2, float> Vector2; +typedef Vector<2, std::int32_t> Vector2i; RectangularMatrixTest::RectangularMatrixTest() { addTests(&RectangularMatrixTest::constructFromData, @@ -79,11 +82,9 @@ void RectangularMatrixTest::constructFromData() { 7.0f, -1.0f, 8.0f, 0.0f }; - Matrix3x4 expected( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f - ); + Matrix3x4 expected(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f)); CORRADE_COMPARE(Matrix3x4::from(m), expected); } @@ -91,33 +92,34 @@ void RectangularMatrixTest::constructFromData() { void RectangularMatrixTest::constructDefault() { Matrix4x3 zero; - Matrix4x3 zeroExpected( - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f - ); + Matrix4x3 zeroExpected(Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f)); CORRADE_COMPARE(zero, zeroExpected); } void RectangularMatrixTest::constructConversion() { - Matrix2 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - Matrix2 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); - Matrix2i integral(1, 2, -15, 7); + Matrix2 floatingPoint(Vector2( 1.3f, 2.7f), + Vector2(-15.0f, 7.0f)); + Matrix2 floatingPointRounded(Vector2(1.0f, 2.0f), + Vector2(-15.0f, 7.0f)); + Matrix2i integral(Vector2i( 1, 2), + Vector2i(-15, 7)); CORRADE_COMPARE(Matrix2i::from(floatingPoint), integral); CORRADE_COMPARE(Matrix2::from(integral), floatingPointRounded); } void RectangularMatrixTest::constructFromVectors() { - Matrix3x4 actual = Matrix3x4::from(Vector4(1.0f, 2.0f, 3.0f, 4.0f), - Vector4(5.0f, 6.0f, 7.0f, 8.0f), - Vector4(9.0f, 10.0f, 11.0f, 12.0f)); + Matrix3x4 actual(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); - Matrix3x4 expected(1.0f, 2.0f, 3.0f, 4.0f, - 5.0f, 6.0f, 7.0f, 8.0f, - 9.0f, 10.0f, 11.0f, 12.0f); + Matrix3x4 expected(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); CORRADE_COMPARE(actual, expected); } @@ -128,54 +130,68 @@ void RectangularMatrixTest::data() { m[2] = vector; m[1][1] = 1.0f; - m(0, 2) = 1.5f; + m[0][2] = 1.5f; - CORRADE_COMPARE(m(1, 1), 1.0f); + CORRADE_COMPARE(m[1][1], 1.0f); CORRADE_COMPARE(m[0][2], 1.5f); CORRADE_COMPARE(m[2], vector); - Matrix3x4 expected( - 0.0f, 0.0f, 1.5f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 4.0f, 5.0f, 6.0f, 7.0f - ); + Matrix3x4 expected(Vector4(0.0f, 0.0f, 1.5f, 0.0f), + Vector4(0.0f, 1.0f, 0.0f, 0.0f), + Vector4(4.0f, 5.0f, 6.0f, 7.0f)); CORRADE_COMPARE(m, expected); } void RectangularMatrixTest::compare() { - CORRADE_VERIFY(Matrix2(1.0f, -3.0f, 5.0f, -10.0f) == Matrix2(1.0f + MathTypeTraits::epsilon()/2, -3.0f, 5.0f, -10.0f)); - CORRADE_VERIFY(Matrix2(1.0f, -1.0f, 5.0f, -10.0f) != Matrix2(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); - - CORRADE_VERIFY(Matrix2i(1, -3, 5, -10) == Matrix2i(1, -3, 5, -10)); - CORRADE_VERIFY(Matrix2i(1, -3, 5, -10) != Matrix2i(1, -2, 5, -10)); + Matrix2 a(Vector2(1.0f, -3.0f), + Vector2(5.0f, -10.0f)); + Matrix2 b(Vector2(1.0f + MathTypeTraits::epsilon()/2, -3.0f), + Vector2(5.0f, -10.0f)); + Matrix2 c(Vector2(1.0f, -1.0f + MathTypeTraits::epsilon()*2), + Vector2(5.0f, -10.0f)); + CORRADE_VERIFY(a == b); + CORRADE_VERIFY(a != c); + + Matrix2i ai(Vector2i(1, -3), + Vector2i(5, -10)); + Matrix2i bi(Vector2i(1, -2), + Vector2i(5, -10)); + CORRADE_VERIFY(ai == ai); + CORRADE_VERIFY(ai != bi); } void RectangularMatrixTest::negative() { - CORRADE_COMPARE(-Matrix2(1.0f, -3.0f, 5.0f, -10.0f), Matrix2(-1.0f, 3.0f, -5.0f, 10.0f)); + Matrix2 matrix(Vector2(1.0f, -3.0f), + Vector2(5.0f, -10.0f)); + Matrix2 negated(Vector2(-1.0f, 3.0f), + Vector2(-5.0f, 10.0f)); + CORRADE_COMPARE(-matrix, negated); } void RectangularMatrixTest::addSubtract() { - Matrix4x3 a(0.0f, 1.0f, 3.0f, - 4.0f, 5.0f, 7.0f, - 8.0f, 9.0f, 11.0f, - 12.0f, 13.0f, 15.0f); - Matrix4x3 b(-4.0f, 0.5f, 9.0f, - -9.0f, 11.0f, 0.25f, - 0.0f, -8.0f, 19.0f, - -3.0f, -5.0f, 2.0f); - Matrix4x3 c(-4.0f, 1.5f, 12.0f, - -5.0f, 16.0f, 7.25f, - 8.0f, 1.0f, 30.0f, - 9.0f, 8.0f, 17.0f); + Matrix4x3 a(Vector3(0.0f, 1.0f, 3.0f), + Vector3(4.0f, 5.0f, 7.0f), + Vector3(8.0f, 9.0f, 11.0f), + Vector3(12.0f, 13.0f, 15.0f)); + Matrix4x3 b(Vector3(-4.0f, 0.5f, 9.0f), + Vector3(-9.0f, 11.0f, 0.25f), + Vector3( 0.0f, -8.0f, 19.0f), + Vector3(-3.0f, -5.0f, 2.0f)); + Matrix4x3 c(Vector3(-4.0f, 1.5f, 12.0f), + Vector3(-5.0f, 16.0f, 7.25f), + Vector3( 8.0f, 1.0f, 30.0f), + Vector3( 9.0f, 8.0f, 17.0f)); CORRADE_COMPARE(a + b, c); CORRADE_COMPARE(c - b, a); } void RectangularMatrixTest::multiplyDivide() { - Matrix2 matrix(1.0f, 2.0f, 3.0f, 4.0f); - Matrix2 multiplied(-1.5f, -3.0f, -4.5f, -6.0f); + Matrix2 matrix(Vector2(1.0f, 2.0f), + Vector2(3.0f, 4.0f)); + Matrix2 multiplied(Vector2(-1.5f, -3.0f), + Vector2(-4.5f, -6.0f)); CORRADE_COMPARE(matrix*-1.5f, multiplied); CORRADE_COMPARE(-1.5f*matrix, multiplied); @@ -188,62 +204,58 @@ void RectangularMatrixTest::multiplyDivide() { CORRADE_COMPARE(-1.5f*matrixChar, multipliedChar); /* Divide vector with number and inverse */ - Matrix2 divisor(1.0f, 2.0f, -4.0f, 8.0f); - Matrix2 result(1.0f, 0.5f, -0.25f, 0.125f); + Matrix2 divisor(Vector2( 1.0f, 2.0f), + Vector2(-4.0f, 8.0f)); + Matrix2 result(Vector2( 1.0f, 0.5f), + Vector2(-0.25f, 0.125f)); CORRADE_COMPARE(1.0f/divisor, result); CORRADE_COMPARE(-1550.0f/multipliedChar, matrixChar); } void RectangularMatrixTest::multiply() { RectangularMatrix<4, 6, std::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 + Vector<6, std::int32_t>(-5, 27, 10, 33, 0, -15), + Vector<6, std::int32_t>( 7, 56, 66, 1, 0, -24), + Vector<6, std::int32_t>( 4, 41, 4, 0, 1, -4), + Vector<6, std::int32_t>( 9, -100, 19, -49, 1, 9) ); RectangularMatrix<5, 4, std::int32_t> right( - 1, -7, 0, 158, - 2, 24, -3, 40, - 3, -15, -2, -50, - 4, 17, -1, -284, - 5, 30, 4, 18 + Vector<4, std::int32_t>(1, -7, 0, 158), + Vector<4, std::int32_t>(2, 24, -3, 40), + Vector<4, std::int32_t>(3, -15, -2, -50), + Vector<4, std::int32_t>(4, 17, -1, -284), + Vector<4, std::int32_t>(5, 30, 4, 18) ); RectangularMatrix<5, 6, std::int32_t> expected( - 1368, -16165, 2550, -7716, 158, 1575, - 506, -2725, 2352, -1870, 37, -234, - -578, 4159, -1918, 2534, -52, -127, - -2461, 29419, -4238, 14065, -285, -3020, - 363, 179, 2388, -687, 22, -649 + Vector<6, std::int32_t>( 1368, -16165, 2550, -7716, 158, 1575), + Vector<6, std::int32_t>( 506, -2725, 2352, -1870, 37, -234), + Vector<6, std::int32_t>( -578, 4159, -1918, 2534, -52, -127), + Vector<6, std::int32_t>(-2461, 29419, -4238, 14065, -285, -3020), + Vector<6, std::int32_t>( 363, 179, 2388, -687, 22, -649) ); CORRADE_COMPARE(left*right, expected); } void RectangularMatrixTest::transposed() { - Matrix4x3 original( - 0.0f, 1.0f, 3.0f, - 4.0f, 5.0f, 7.0f, - 8.0f, 9.0f, 11.0f, - 12.0f, 13.0f, 15.0f - ); + Matrix4x3 original(Vector3( 0.0f, 1.0f, 3.0f), + Vector3( 4.0f, 5.0f, 7.0f), + Vector3( 8.0f, 9.0f, 11.0f), + Vector3(12.0f, 13.0f, 15.0f)); - Matrix3x4 transposed( - 0.0f, 4.0f, 8.0f, 12.0f, - 1.0f, 5.0f, 9.0f, 13.0f, - 3.0f, 7.0f, 11.0f, 15.0f - ); + Matrix3x4 transposed(Vector4(0.0f, 4.0f, 8.0f, 12.0f), + Vector4(1.0f, 5.0f, 9.0f, 13.0f), + Vector4(3.0f, 7.0f, 11.0f, 15.0f)); CORRADE_COMPARE(original.transposed(), transposed); } void RectangularMatrixTest::debug() { - Matrix3x4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f - ); + Matrix3x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.0f, 8.0f, 0.0f)); std::ostringstream o; Debug(&o) << m; @@ -263,11 +275,9 @@ void RectangularMatrixTest::debug() { } void RectangularMatrixTest::configuration() { - Matrix3x4 m( - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.125f, - 7.0f, -1.0f, 8.0f, 9.55f - ); + Matrix3x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.0f, 4.0f, 7.0f, 3.125f), + Vector4(7.0f, -1.0f, 8.0f, 9.55f)); std::string value("3 4 7 5 4 -1 8 7 8 4 3.125 9.55"); Configuration c; diff --git a/src/Math/Vector.cpp b/src/Math/Vector.cpp index 0004c854e..3e54dedd8 100644 --- a/src/Math/Vector.cpp +++ b/src/Math/Vector.cpp @@ -35,3 +35,25 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnu #endif }} + +namespace Corrade { namespace Utility { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +#ifndef MAGNUM_TARGET_GLES +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +#endif +#endif + +}} + diff --git a/src/Math/Vector.h b/src/Math/Vector.h index b2581d3f3..b85b65739 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -19,12 +19,32 @@ * @brief Class Magnum::Math::Vector */ +#include +#include #include +#include +#include -#include "RectangularMatrix.h" +#include "Math/MathTypeTraits.h" + +#include "magnumVisibility.h" namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct Sequence {}; + + /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ + template struct GenerateSequence: + GenerateSequence {}; + + template struct GenerateSequence<0, sequence...> { + typedef Sequence Type; + }; +} +#endif + /** @brief %Vector @tparam size %Vector size @@ -33,9 +53,45 @@ namespace Magnum { namespace Math { See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector} */ -template class Vector: public RectangularMatrix<1, size, T> { +template class Vector { + static_assert(size != 0, "Vector cannot have zero elements"); + + template friend class Vector; + public: - const static std::size_t Size = size; /**< @brief %Vector size */ + typedef T Type; /**< @brief Data type */ + const static std::size_t Size = size; /**< @brief %Vector size */ + + /** + * @brief %Vector from array + * @return Reference to the data as if it was Vector, thus doesn't + * perform any copying. + * + * @attention Use with caution, the function doesn't check whether the + * array is long enough. + */ + inline constexpr static Vector& from(T* data) { + return *reinterpret_cast*>(data); + } + /** @overload */ + inline constexpr static const Vector& from(const T* data) { + return *reinterpret_cast*>(data); + } + + /** + * @brief %Vector from another of different type + * + * Performs only default casting on the values, no rounding or + * anything else. Example usage: + * @code + * Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + * Vector<4, std::int8_t> integral(Vector<4, std::int8_t>::from(floatingPoint)); + * // integral == {1, 2, -15, 7} + * @endcode + */ + template inline constexpr static Vector from(const Vector& other) { + return from(typename Implementation::GenerateSequence::Type(), other); + } /** * @brief Dot product @@ -84,7 +140,7 @@ template class Vector: public RectangularMatrix<1, si } /** @brief Construct zero-filled vector */ - inline constexpr /*implicit*/ Vector() {} + inline constexpr /*implicit*/ Vector(): _data() {} /** @todo Creating Vector from combination of vector and scalar types */ @@ -93,7 +149,9 @@ template class Vector: public RectangularMatrix<1, si * @param first First value * @param next Next values */ - template inline constexpr /*implicit*/ Vector(T first, U... next): RectangularMatrix<1, size, T>(first, next...) {} + template inline constexpr /*implicit*/ Vector(T first, U... next): _data{first, next...} { + static_assert(sizeof...(next)+1 == size, "Improper number of arguments passed to Vector constructor"); + } /** @brief Construct vector with one value for all fields */ #ifdef DOXYGEN_GENERATING_OUTPUT @@ -102,15 +160,45 @@ template class Vector: public RectangularMatrix<1, si template inline explicit Vector(typename std::enable_if::value && size != 1, U>::type value) { #endif for(std::size_t i = 0; i != size; ++i) - (*this)[i] = value; + _data[i] = value; } /** @brief Copy constructor */ - inline constexpr Vector(const RectangularMatrix<1, size, T>& other): RectangularMatrix<1, size, T>(other) {} + inline constexpr Vector(const Vector&) = default; - /** @brief Value at given position */ - inline T& operator[](std::size_t pos) { return RectangularMatrix<1, size, T>::_data[pos]; } - inline constexpr T operator[](std::size_t pos) const { return RectangularMatrix<1, size, T>::_data[pos]; } /**< @overload */ + /** @brief Assignment operator */ + inline Vector& operator=(const Vector&) = default; + + /** + * @brief Raw data + * @return One-dimensional array of `size*size` length in column-major + * order. + * + * @see operator[] + */ + inline T* data() { return _data; } + inline constexpr const T* data() const { return _data; } /**< @overload */ + + /** + * @brief Value at given position + * + * @see data() + */ + inline T& operator[](std::size_t pos) { return _data[pos]; } + inline constexpr T operator[](std::size_t pos) const { return _data[pos]; } /**< @overload */ + + /** @brief Equality comparison */ + inline bool operator==(const Vector& other) const { + for(std::size_t i = 0; i != size; ++i) + if(!MathTypeTraits::equals(_data[i], other._data[i])) return false; + + return true; + } + + /** @brief Non-equality comparison */ + inline constexpr bool operator!=(const Vector& other) const { + return !operator==(other); + } /** * @brief Component-wise less than @@ -119,7 +207,7 @@ template class Vector: public RectangularMatrix<1, si */ inline bool operator<(const Vector& other) const { for(std::size_t i = 0; i != size; ++i) - if((*this)[i] >= other[i]) return false; + if(_data[i] >= other._data[i]) return false; return true; } @@ -131,7 +219,7 @@ template class Vector: public RectangularMatrix<1, si */ inline bool operator<=(const Vector& other) const { for(std::size_t i = 0; i != size; ++i) - if((*this)[i] > other[i]) return false; + if(_data[i] > other._data[i]) return false; return true; } @@ -143,7 +231,7 @@ template class Vector: public RectangularMatrix<1, si */ inline bool operator>=(const Vector& other) const { for(std::size_t i = 0; i != size; ++i) - if((*this)[i] < other[i]) return false; + if(_data[i] < other._data[i]) return false; return true; } @@ -155,11 +243,135 @@ template class Vector: public RectangularMatrix<1, si */ inline bool operator>(const Vector& other) const { for(std::size_t i = 0; i != size; ++i) - if((*this)[i] <= other[i]) return false; + if(_data[i] <= other._data[i]) return false; return true; } + /** + * @brief Negated vector + * + * The computation is done in-place. @f[ + * \boldsymbol a_i = -\boldsymbol a_i + * @f] + */ + Vector operator-() const { + Vector out; + + for(std::size_t i = 0; i != size; ++i) + out._data[i] = -_data[i]; + + return out; + } + + /** + * @brief Add and assign vector + * + * The computation is done in-place. @f[ + * \boldsymbol a_i = \boldsymbol a_i + \boldsymbol b_i + * @f] + */ + Vector& operator+=(const Vector& other) { + for(std::size_t i = 0; i != size; ++i) + _data[i] += other._data[i]; + + return *this; + } + + /** + * @brief Add vector + * + * @see operator+=() + */ + inline Vector operator+(const Vector& other) const { + return Vector(*this) += other; + } + + /** + * @brief Subtract and assign vector + * + * The computation is done in-place. @f[ + * \boldsymbol a_i = \boldsymbol a_i - \boldsymbol b_i + * @f] + */ + Vector& operator-=(const Vector& other) { + for(std::size_t i = 0; i != size; ++i) + _data[i] -= other._data[i]; + + return *this; + } + + /** + * @brief Subtract vector + * + * @see operator-=() + */ + inline Vector operator-(const Vector& other) const { + return Vector(*this) -= other; + } + + /** + * @brief Multiply vector with number and assign + * + * The computation is done in-place. @f[ + * \boldsymbol a_i = b \boldsymbol a_i + * @f] + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + template Vector& operator*=(U number) { + #else + template inline typename std::enable_if::value, Vector&>::type operator*=(U number) { + #endif + for(std::size_t i = 0; i != size; ++i) + _data[i] *= number; + + return *this; + } + + /** + * @brief Multiply vector with number + * + * @see operator*=(U), operator*(U, const Vector&) + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + template inline Vector operator*(U number) const { + #else + template inline typename std::enable_if::value, Vector>::type operator*(U number) const { + #endif + return Vector(*this) *= number; + } + + /** + * @brief Divide vector with number and assign + * + * The computation is done in-place. @f[ + * \boldsymbol a_i = \frac{\boldsymbol a_i} b + * @f] + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + template Vector& operator/=(U number) { + #else + template inline typename std::enable_if::value, Vector&>::type operator/=(U number) { + #endif + for(std::size_t i = 0; i != size; ++i) + _data[i] /= number; + + return *this; + } + + /** + * @brief Divide vector with number + * + * @see operator/=(), operator/(U, const Vector&) + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + template inline Vector operator/(U number) const { + #else + template inline typename std::enable_if::value, Vector>::type operator/(U number) const { + #endif + return Vector(*this) /= number; + } + /** * @brief Multiply vector component-wise and assign * @@ -169,7 +381,7 @@ template class Vector: public RectangularMatrix<1, si */ template Vector& operator*=(const Vector& other) { for(std::size_t i = 0; i != size; ++i) - (*this)[i] *= other[i]; + _data[i] *= other._data[i]; return *this; } @@ -192,7 +404,7 @@ template class Vector: public RectangularMatrix<1, si */ template Vector& operator/=(const Vector& other) { for(std::size_t i = 0; i != size; ++i) - (*this)[i] /= other[i]; + _data[i] /= other._data[i]; return *this; } @@ -252,66 +464,83 @@ template class Vector: public RectangularMatrix<1, si T out(0); for(std::size_t i = 0; i != size; ++i) - out += (*this)[i]; + out += _data[i]; return out; } /** @brief Product of values in the vector */ T product() const { - T out(1); + T out(_data[0]); - for(std::size_t i = 0; i != size; ++i) - out *= (*this)[i]; + for(std::size_t i = 1; i != size; ++i) + out *= _data[i]; return out; } /** @brief Minimal value in the vector */ T min() const { - T out((*this)[0]); + T out(_data[0]); for(std::size_t i = 1; i != size; ++i) - out = std::min(out, (*this)[i]); + out = std::min(out, _data[i]); return out; } /** @brief Maximal value in the vector */ T max() const { - T out((*this)[0]); + T out(_data[0]); for(std::size_t i = 1; i != size; ++i) - out = std::max(out, (*this)[i]); + out = std::max(out, _data[i]); return out; } - #ifndef DOXYGEN_GENERATING_OUTPUT - /* Reimplementation of functions to return correct type */ - template inline RectangularMatrix operator*(const RectangularMatrix& other) const { - return RectangularMatrix<1, size, T>::operator*(other); + private: + /* Implementation for from(const Vector&) */ + template inline constexpr static Vector from(Implementation::Sequence, const Vector& vector) { + return {T(vector.data()[sequence])...}; } - MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(1, size, Vector) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, size, Vector) - #endif - private: - /* Hiding unused things from RectangularMatrix */ - using RectangularMatrix<1, size, T>::Cols; - using RectangularMatrix<1, size, T>::Rows; - using RectangularMatrix<1, size, T>::operator[]; - using RectangularMatrix<1, size, T>::operator(); + T _data[size]; }; -#ifndef DOXYGEN_GENERATING_OUTPUT +/** @relates Vector +@brief Multiply number with vector + +Same as Vector::operator*(U) const. +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline Vector operator*(U number, const Vector& vector) { +#else template inline typename std::enable_if::value, Vector>::type operator*(U number, const Vector& vector) { - return number*RectangularMatrix<1, size, T>(vector); +#endif + return vector*number; } + +/** @relates Vector +@brief Divide vector with number and invert + +@f[ + \boldsymbol c_i = \frac b {\boldsymbol a_i} +@f] +@see Vector::operator/() +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline Vector operator/(U number, const Vector& vector) { +#else template inline typename std::enable_if::value, Vector>::type operator/(U number, const Vector& vector) { - return number/RectangularMatrix<1, size, T>(vector); -} #endif + Vector out; + + for(std::size_t i = 0; i != size; ++i) + out[i] = number/vector[i]; + + return out; +} /** @debugoperator{Magnum::Math::Vector} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Vector& value) { @@ -364,22 +593,50 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit return *this; \ } \ \ - template inline Math::RectangularMatrix operator*(const Math::RectangularMatrix& other) const { \ - return Math::Vector::operator*(other); \ + inline Type operator-() const { \ + return Math::Vector::operator-(); \ } \ - template inline Type operator*(const Math::Vector& other) const { \ - return Math::Vector::operator*(other); \ + inline Type& operator+=(const Math::Vector& other) { \ + Math::Vector::operator+=(other); \ + return *this; \ + } \ + inline Type operator+(const Math::Vector& other) const { \ + return Math::Vector::operator+(other); \ + } \ + inline Type& operator-=(const Math::Vector& other) { \ + Math::Vector::operator-=(other); \ + return *this; \ + } \ + inline Type operator-(const Math::Vector& other) const { \ + return Math::Vector::operator-(other); \ + } \ + template inline typename std::enable_if::value, Type&>::type operator*=(U number) { \ + Math::Vector::operator*=(number); \ + return *this; \ + } \ + template inline typename std::enable_if::value, Type>::type operator*(U number) const { \ + return Math::Vector::operator*(number); \ + } \ + template inline typename std::enable_if::value, Type&>::type operator/=(U number) { \ + Math::Vector::operator/=(number); \ + return *this; \ + } \ + template inline typename std::enable_if::value, Type>::type operator/(U number) const { \ + return Math::Vector::operator/(number); \ } \ template inline Type& operator*=(const Math::Vector& other) { \ Math::Vector::operator*=(other); \ return *this; \ } \ - template inline Type operator/(const Math::Vector& other) const { \ - return Math::Vector::operator/(other); \ + template inline Type operator*(const Math::Vector& other) const { \ + return Math::Vector::operator*(other); \ } \ template inline Type& operator/=(const Math::Vector& other) { \ Math::Vector::operator/=(other); \ return *this; \ + } \ + template inline Type operator/(const Math::Vector& other) const { \ + return Math::Vector::operator/(other); \ } \ \ inline Type normalized() const { return Math::Vector::normalized(); } \ @@ -400,8 +657,60 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit namespace Corrade { namespace Utility { -/** @configurationvalue{Magnum::Math::Vector} */ -template struct ConfigurationValue>: public ConfigurationValue> {}; +/** @configurationvalue{Magnum::Math::RectangularMatrix} */ +template struct ConfigurationValue> { + ConfigurationValue() = delete; + + /** @brief Writes elements separated with spaces */ + static std::string toString(const Magnum::Math::Vector& value, ConfigurationValueFlags flags) { + std::string output; + + for(std::size_t i = 0; i != size; ++i) { + if(!output.empty()) output += ' '; + output += ConfigurationValue::toString(value[i], flags); + } + + return output; + } + + /** @brief Reads elements separated with whitespace */ + static Magnum::Math::Vector fromString(const std::string& stringValue, ConfigurationValueFlags flags) { + Magnum::Math::Vector result; + + std::size_t oldpos = 0, pos = std::string::npos, i = 0; + do { + pos = stringValue.find(' ', oldpos); + std::string part = stringValue.substr(oldpos, pos-oldpos); + + if(!part.empty()) { + result[i] = ConfigurationValue::fromString(part, flags); + ++i; + } + + oldpos = pos+1; + } while(pos != std::string::npos); + + return result; + } +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +/* Vectors */ +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +#ifndef MAGNUM_TARGET_GLES +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +#endif +#endif }} diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index f27be7c48..ffd13751e 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -85,7 +85,7 @@ template class Vector2: public Vector<2, T> { inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} /** @brief Copy constructor */ - inline constexpr Vector2(const RectangularMatrix<1, 2, T>& other): Vector<2, T>(other) {} + inline constexpr Vector2(const Vector<2, T>& other): Vector<2, T>(other) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ @@ -93,7 +93,6 @@ template class Vector2: public Vector<2, T> { inline constexpr T y() const { return (*this)[1]; } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector2, 2) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 2, Vector2) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector2, 2) diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index ddec15a4a..3897a726e 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -126,7 +126,7 @@ template class Vector3: public Vector<3, T> { inline constexpr /*implicit*/ Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} /** @brief Copy constructor */ - inline constexpr Vector3(const RectangularMatrix<1, 3, T>& other): Vector<3, T>(other) {} + inline constexpr Vector3(const Vector<3, T>& other): Vector<3, T>(other) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ @@ -145,7 +145,6 @@ template class Vector3: public Vector<3, T> { inline constexpr Vector2 xy() const { return Vector2::from(Vector<3, T>::data()); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector3, 3) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Vector3) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector3, 3) diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 9bc2265b2..8d93a6609 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -57,7 +57,7 @@ template class Vector4: public Vector<4, T> { inline constexpr /*implicit*/ Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} /** @brief Copy constructor */ - inline constexpr Vector4(const RectangularMatrix<1, 4, T>& other): Vector<4, T>(other) {} + inline constexpr Vector4(const Vector<4, T>& other): Vector<4, T>(other) {} inline T& x() { return (*this)[0]; } /**< @brief X component */ inline constexpr T x() const { return (*this)[0]; } /**< @overload */ @@ -87,7 +87,6 @@ template class Vector4: public Vector<4, T> { inline constexpr Vector2 xy() const { return Vector2::from(Vector<4, T>::data()); } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector4, 4) - MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Vector4) }; MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Vector4, 4) diff --git a/src/Mesh.h b/src/Mesh.h index 40a6658a3..959a0f334 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -210,6 +210,8 @@ for more information. @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. +@todo test vertex specification & drawing +@todo How to glDrawElementsBaseVertex()/vertex offset -- in draw()? */ class MAGNUM_EXPORT Mesh { friend class Context; diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 2a3ba52f9..07d42dfc3 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -75,27 +75,27 @@ void CameraTest::fixAspectRatio() { CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::NotPreserved, projectionScale, size)), Matrix4()); /* Clip */ - Matrix4 expectedClip(1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 4.0f/3.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); + Matrix4 expectedClip({1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 4.0f/3.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, Vector2(0.5f), size)), expectedClip); - Matrix4 expectedClipRectangle(1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 2.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); + Matrix4 expectedClipRectangle({1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 2.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScale, size)), expectedClipRectangle); /* Extend */ - Matrix4 expectedExtend(3.0f/4.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); + Matrix4 expectedExtend({3.0f/4.0f, 0.0f, 0.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f, 0.0f}, + { 0.0f, 0.0f, 1.0f, 0.0f}, + { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, Vector2(0.5f), size)), expectedExtend); - Matrix4 expectedExtendRectangle(0.5f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); + Matrix4 expectedExtendRectangle({0.5f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, projectionScale, size)), expectedExtendRectangle); } From 5819dd4bd71a81ca363043770d4c12b7f144f1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 00:44:42 +0100 Subject: [PATCH 270/567] Math: matrix/vector rework, part 3: conversion as explicit constructor. Also updated all dependent classes to follow the change, such as Color and Rectangle. Backwards compatibility for GCC 4.6 (with lack of support for delegating constructors) will be done as non-constexpr constructor using operator=(). --- doc/matrix-vector.dox | 4 +-- src/Color.h | 6 ++++ src/Math/Functions.h | 6 ++-- src/Math/Geometry/Rectangle.h | 37 ++++++++++++------------ src/Math/Geometry/Test/RectangleTest.cpp | 3 +- src/Math/Matrix.h | 3 ++ src/Math/Matrix3.h | 3 ++ src/Math/Matrix4.h | 3 ++ src/Math/Point2D.h | 3 ++ src/Math/Point3D.h | 3 ++ src/Math/RectangularMatrix.h | 37 ++++++++++-------------- src/Math/Test/RectangularMatrixTest.cpp | 4 +-- src/Math/Test/VectorTest.cpp | 4 +-- src/Math/Vector.h | 37 ++++++++++-------------- src/Math/Vector2.h | 3 ++ src/Math/Vector3.h | 3 ++ src/Math/Vector4.h | 3 ++ src/SceneGraph/AbstractCamera.hpp | 2 +- src/Text/Font.cpp | 6 ++-- 19 files changed, 93 insertions(+), 77 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 6c50d5b33..81ecf0cf6 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -99,10 +99,10 @@ RectangularMatrix<2, 3, int>::from(mat) *= 2; // mat == { 4, 8, 12, 2, 6, 10 } Note that unlike constructors, this function has no way to check whether the array is long enough to contain all elements, so use with caution. -You can also convert between data types: +You can also *explicitly* convert between data types: @code Vector4 floating(1.3f, 2.7f, -15.0f, 7.0f); -Vector4 integral(Vector4::from(floating)); // {1, 2, -15, 7} +Vector4 integral(floating); // {1, 2, -15, 7} @endcode @section matrix-vector-component-access Accessing matrix and vector components diff --git a/src/Color.h b/src/Color.h index 483137267..145a6c5bc 100644 --- a/src/Color.h +++ b/src/Color.h @@ -195,6 +195,9 @@ class Color3: public Math::Vector3 { */ inline constexpr /*implicit*/ Color3(T r, T g, T b): Math::Vector3(r, g, b) {} + /** @copydoc Math::Vector::Vector(const Vector&) */ + template inline constexpr explicit Color3(const Math::Vector<3, U>& other): Math::Vector3(other) {} + /** @brief Copy constructor */ inline constexpr Color3(const Math::Vector<3, T>& other): Math::Vector3(other) {} @@ -322,6 +325,9 @@ class Color4: public Math::Vector4 { is fairly common, nearly always with A set to 1 */ inline constexpr /*implicit*/ Color4(const Math::Vector3& rgb, T a = Implementation::defaultAlpha()): Math::Vector4(rgb[0], rgb[1], rgb[2], a) {} + /** @copydoc Math::Vector::Vector(const Vector&) */ + template inline constexpr explicit Color4(const Math::Vector<4, U>& other): Math::Vector4(other) {} + /** @brief Copy constructor */ inline constexpr Color4(const Math::Vector<4, T>& other): Math::Vector4(other) {} diff --git a/src/Math/Functions.h b/src/Math/Functions.h index e4416e90d..fe767f915 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -177,12 +177,12 @@ template inline typename std::enable_if inline typename std::enable_if::value, FloatingPoint>::type normalize(const Integral& value) { static_assert(std::is_floating_point::value && std::is_integral::value, "Math::normalize(): normalization must be done from integral to floating-point type"); - return FloatingPoint::from(value)/typename FloatingPoint::Type(std::numeric_limits::max()); + return FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()); } template inline typename std::enable_if::value, FloatingPoint>::type normalize(const Integral& value) { static_assert(std::is_floating_point::value && std::is_integral::value, "Math::normalize(): normalization must be done from integral to floating-point type"); - return Math::max(FloatingPoint::from(value)/typename FloatingPoint::Type(std::numeric_limits::max()), FloatingPoint(-1)); + return Math::max(FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()), FloatingPoint(-1)); } #endif @@ -213,7 +213,7 @@ template inline typename std::enable_if inline typename std::enable_if::value, Integral>::type denormalize(const FloatingPoint& value) { static_assert(std::is_floating_point::value && std::is_integral::value, "Math::denormalize(): denormalization must be done from floating-point to integral type"); - return Integral::from(value*std::numeric_limits::max()); + return Integral(value*std::numeric_limits::max()); } #endif diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 66bf161f4..1ca5275e7 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -32,6 +32,8 @@ are inclusive, while top/right positions are exclusive. @see Magnum::Rectangle, Magnum::Rectanglei */ template class Rectangle { + template friend class Rectangle; + public: /** * Create rectangle from position and size @@ -43,33 +45,32 @@ template class Rectangle { } /** - * @brief %Rectangle from another of different type + * @brief Construct zero rectangle + * + * Construct zero-area rectangle positioned at origin. + */ + inline constexpr Rectangle() = default; + + /** @brief Construct rectangle from two corners */ + inline constexpr Rectangle(const Vector2& bottomLeft, const Vector2& topRight): _bottomLeft(bottomLeft), _topRight(topRight) {} + + /** + * @brief Construct rectangle from another of different type * * Performs only default casting on the values, no rounding or * anything else. Example usage: * @code * Rectangle floatingPoint({1.3f, 2.7f}, {-15.0f, 7.0f}); - * auto integral = Rectangle::from(floatingPoint); - * // integral == {{1, 2}, {-15, 7}} + * Rectangle integral(floatingPoint); // {{1, 2}, {-15, 7}} * @endcode */ - template inline constexpr static Rectangle from(const Rectangle& other) { - return {Vector2::from(other.bottomLeft()), Vector2::from(other.topRight())}; - } + template inline constexpr explicit Rectangle(const Rectangle& other): _bottomLeft(other._bottomLeft), _topRight(other._topRight) {} - /** - * @brief Default constructor - * - * Construct zero-area rectangle positioned at origin. - */ - inline constexpr Rectangle() = default; + /** @brief Copy constructor */ + inline constexpr Rectangle(const Rectangle&) = default; - /** - * @brief Constructor - * @param bottomLeft Bottom left rectangle corner - * @param topRight Top right rectangle corner - */ - inline constexpr Rectangle(const Vector2& bottomLeft, const Vector2& topRight): _bottomLeft(bottomLeft), _topRight(topRight) {} + /** @brief Assignment operator */ + inline Rectangle& operator=(const Rectangle&) = default; /** @brief Equality operator */ inline constexpr bool operator==(const Rectangle& other) const { diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 20562c860..267dc724b 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -74,8 +74,7 @@ void RectangleTest::compare() { void RectangleTest::construct() { CORRADE_COMPARE(Rectanglei(), Rectanglei({0, 0}, {0, 0})); CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83})); - CORRADE_COMPARE(Rectanglei::from(Rectangle({1.3f, 2.7f}, {-15.0f, 7.0f})), - Rectanglei({1, 2}, {-15, 7})); + CORRADE_COMPARE(Rectanglei(Rectangle({1.3f, 2.7f}, {-15.0f, 7.0f})), Rectanglei({1, 2}, {-15, 7})); } void RectangleTest::size() { diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index e73930c58..c0687e0a0 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -74,6 +74,9 @@ template class Matrix: public RectangularMatrix inline constexpr /*implicit*/ Matrix(const Vector& first, const U&... next): RectangularMatrix(first, next...) {} + /** @copydoc RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ + template inline constexpr explicit Matrix(const RectangularMatrix& other): RectangularMatrix(other) {} + /** @brief Copy constructor */ inline constexpr Matrix(const RectangularMatrix& other): RectangularMatrix(other) {} diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 832e02347..5a648fe7d 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -128,6 +128,9 @@ template class Matrix3: public Matrix<3, T> { /** @brief %Matrix from column vectors */ inline constexpr /*implicit*/ Matrix3(const Vector3& first, const Vector3& second, const Vector3& third): Matrix<3, T>(first, second, third) {} + /** @copydoc Matrix::Matrix(const RectangularMatrix&) */ + template inline constexpr explicit Matrix3(const RectangularMatrix<3, 3, U>& other): Matrix<3, T>(other) {} + /** @brief Copy constructor */ inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {} diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index cbfa7ca4e..5ac26b89b 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -253,6 +253,9 @@ template class Matrix4: public Matrix<4, T> { /** @brief %Matrix from column vectors */ inline constexpr /*implicit*/ Matrix4(const Vector4& first, const Vector4& second, const Vector4& third, const Vector4& fourth): Matrix<4, T>(first, second, third, fourth) {} + /** @copydoc Matrix::Matrix(const RectangularMatrix&) */ + template inline constexpr explicit Matrix4(const RectangularMatrix<4, 4, U>& other): Matrix<4, T>(other) {} + /** @brief Copy constructor */ inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {} diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 53fbc9b21..702eea7e3 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -56,6 +56,9 @@ template class Point2D: public Vector3 { */ inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z = T(1)): Vector3(xy, z) {} + /** @copydoc Vector::Vector(const Vector&) */ + template inline constexpr explicit Point2D(const Vector<3, U>& other): Vector3(other) {} + /** @brief Copy constructor */ inline constexpr Point2D(const Vector<3, T>& other): Vector3(other) {} diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index ca4588a8b..13ff4c473 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -57,6 +57,9 @@ template class Point3D: public Vector4 { */ inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w = T(1)): Vector4(xyz, w) {} + /** @copydoc Vector::Vector(const Vector&) */ + template inline constexpr explicit Point3D(const Vector<4, U>& other): Vector4(other) {} + /** @brief Copy constructor */ inline constexpr Point3D(const Vector<4, T>& other): Vector4(other) {} diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 4667af89f..176c6c742 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -62,21 +62,6 @@ template class RectangularMatrix { return *reinterpret_cast*>(data); } - /** - * @brief %Matrix from another of different type - * - * Performs only default casting on the values, no rounding or - * anything else. Example usage: - * @code - * RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * RectangularMatrix<4, 1, std::int8_t> integral(RectangularMatrix<4, 1, std::int8_t>::from(floatingPoint)); - * // integral == {1, 2, -15, 7} - * @endcode - */ - template inline constexpr static RectangularMatrix from(const RectangularMatrix& other) { - return from(typename Implementation::GenerateSequence::Type(), other); - } - /** @brief Construct zero-filled matrix */ inline constexpr /*implicit*/ RectangularMatrix() {} @@ -91,6 +76,19 @@ template class RectangularMatrix { static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to RectangularMatrix constructor"); } + /** + * @brief Construct matrix from another of different type + * + * Performs only default casting on the values, no rounding or + * anything else. Example usage: + * @code + * RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + * RectangularMatrix<4, 1, std::int8_t> integral(floatingPoint); + * // integral == {1, 2, -15, 7} + * @endcode + */ + template inline constexpr explicit RectangularMatrix(const RectangularMatrix& other): RectangularMatrix(typename Implementation::GenerateSequence::Type(), other) {} + /** @brief Copy constructor */ inline constexpr RectangularMatrix(const RectangularMatrix&) = default; @@ -310,10 +308,8 @@ template class RectangularMatrix { } private: - /* Implementation for RectangularMatrix::from(const RectangularMatrix&) */ - template inline constexpr static Math::RectangularMatrix from(Implementation::Sequence, const Math::RectangularMatrix& matrix) { - return {Vector::from(matrix[sequence])...}; - } + /* Implementation for RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ + template inline constexpr explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix): _data{Vector(matrix[sequence])...} {} Vector _data[cols]; }; @@ -414,9 +410,6 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit } \ inline constexpr static const __VA_ARGS__& from(const T* data) { \ return *reinterpret_cast(data); \ - } \ - template inline constexpr static RectangularMatrix from(const Math::RectangularMatrix& other) { \ - return Math::RectangularMatrix::from(other); \ } \ \ inline __VA_ARGS__& operator=(const Math::RectangularMatrix& other) { \ diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 60f00e421..730b2c3e8 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -108,8 +108,8 @@ void RectangularMatrixTest::constructConversion() { Matrix2i integral(Vector2i( 1, 2), Vector2i(-15, 7)); - CORRADE_COMPARE(Matrix2i::from(floatingPoint), integral); - CORRADE_COMPARE(Matrix2::from(integral), floatingPointRounded); + CORRADE_COMPARE(Matrix2i(floatingPoint), integral); + CORRADE_COMPARE(Matrix2(integral), floatingPointRounded); } void RectangularMatrixTest::constructFromVectors() { diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 03fead6d7..bf42ef228 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -109,8 +109,8 @@ void VectorTest::constructConversion() { Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); Vector4i integral(1, 2, -15, 7); - CORRADE_COMPARE(Vector4i::from(floatingPoint), integral); - CORRADE_COMPARE(Vector4::from(integral), floatingPointRounded); + CORRADE_COMPARE(Vector4i(floatingPoint), integral); + CORRADE_COMPARE(Vector4(integral), floatingPointRounded); } void VectorTest::data() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index b85b65739..a8f912ca3 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -78,21 +78,6 @@ template class Vector { return *reinterpret_cast*>(data); } - /** - * @brief %Vector from another of different type - * - * Performs only default casting on the values, no rounding or - * anything else. Example usage: - * @code - * Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * Vector<4, std::int8_t> integral(Vector<4, std::int8_t>::from(floatingPoint)); - * // integral == {1, 2, -15, 7} - * @endcode - */ - template inline constexpr static Vector from(const Vector& other) { - return from(typename Implementation::GenerateSequence::Type(), other); - } - /** * @brief Dot product * @@ -163,6 +148,19 @@ template class Vector { _data[i] = value; } + /** + * @brief Construct vector from another of different type + * + * Performs only default casting on the values, no rounding or + * anything else. Example usage: + * @code + * Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + * Vector<4, std::int8_t> integral(floatingPoint); + * // integral == {1, 2, -15, 7} + * @endcode + */ + template inline constexpr explicit Vector(const Vector& other): Vector(typename Implementation::GenerateSequence::Type(), other) {} + /** @brief Copy constructor */ inline constexpr Vector(const Vector&) = default; @@ -500,10 +498,8 @@ template class Vector { } private: - /* Implementation for from(const Vector&) */ - template inline constexpr static Vector from(Implementation::Sequence, const Vector& vector) { - return {T(vector.data()[sequence])...}; - } + /* Implementation for Vector::Vector(const Vector&) */ + template inline constexpr explicit Vector(Implementation::Sequence, const Vector& vector): _data{T(vector.data()[sequence])...} {} T _data[size]; }; @@ -581,9 +577,6 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit inline constexpr static const Type& from(const T* data) { \ return *reinterpret_cast*>(data); \ } \ - template inline constexpr static Type from(const Math::Vector& other) { \ - return Math::Vector::from(other); \ - } \ template inline static const Type lerp(const Math::Vector& a, const Math::Vector& b, U t) { \ return Math::Vector::lerp(a, b, t); \ } \ diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index ffd13751e..0cf539a8c 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -84,6 +84,9 @@ template class Vector2: public Vector<2, T> { */ inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} + /** @copydoc Vector::Vector(const Vector&) */ + template inline constexpr explicit Vector2(const Vector<2, U>& other): Vector<2, T>(other) {} + /** @brief Copy constructor */ inline constexpr Vector2(const Vector<2, T>& other): Vector<2, T>(other) {} diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 3897a726e..5a7a2354d 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -125,6 +125,9 @@ template class Vector3: public Vector<3, T> { */ inline constexpr /*implicit*/ Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} + /** @copydoc Vector::Vector(const Vector&) */ + template inline constexpr explicit Vector3(const Vector<3, U>& other): Vector<3, T>(other) {} + /** @brief Copy constructor */ inline constexpr Vector3(const Vector<3, T>& other): Vector<3, T>(other) {} diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 8d93a6609..1c0963f5f 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -56,6 +56,9 @@ template class Vector4: public Vector<4, T> { */ inline constexpr /*implicit*/ Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} + /** @copydoc Vector::Vector(const Vector&) */ + template inline constexpr explicit Vector4(const Vector<4, U>& other): Vector<4, T>(other) {} + /** @brief Copy constructor */ inline constexpr Vector4(const Vector<4, T>& other): Vector<4, T>(other) {} diff --git a/src/SceneGraph/AbstractCamera.hpp b/src/SceneGraph/AbstractCamera.hpp index 934dad4a3..a39f85ab9 100644 --- a/src/SceneGraph/AbstractCamera.hpp +++ b/src/SceneGraph/AbstractCamera.hpp @@ -50,7 +50,7 @@ template typename DimensionTraits relativeAspectRatio = Math::Vector2::from(viewport)*projectionScale; + Math::Vector2 relativeAspectRatio = Math::Vector2(viewport)*projectionScale; /* Extend on larger side = scale larger side down Clip on smaller side = scale smaller side up */ diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index c294641ee..8a6130fcd 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -80,9 +80,9 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co /* Save character texture position and texture coordinates for given character index */ glyphs.insert({charIndices[i], std::make_tuple( Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/size, - Vector2::from(charPositions[i].size())/size), - Rectangle(Vector2::from(charPositions[i].bottomLeft())/atlasSize, - Vector2::from(charPositions[i].topRight())/atlasSize) + Vector2(charPositions[i].size())/size), + Rectangle(Vector2(charPositions[i].bottomLeft())/atlasSize, + Vector2(charPositions[i].topRight())/atlasSize) )}); } From 9bbc656da5f21dc34752e9e45d48122c75849d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 00:47:34 +0100 Subject: [PATCH 271/567] Math: creating Vector from one value is broken. Added "expect fail" test, it is not the priority now (and it is handled correctly in subclasses). --- src/Math/Test/VectorTest.cpp | 8 ++++++++ src/Math/Vector.h | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index bf42ef228..d5130414f 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -30,6 +30,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void constructFromData(); void constructDefault(); + void constructOneValue(); void constructConversion(); void data(); @@ -66,6 +67,7 @@ typedef Vector<4, std::int32_t> Vector4i; VectorTest::VectorTest() { addTests(&VectorTest::constructFromData, &VectorTest::constructDefault, + &VectorTest::constructOneValue, &VectorTest::constructConversion, &VectorTest::data, @@ -104,6 +106,12 @@ void VectorTest::constructDefault() { CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); } +void VectorTest::constructOneValue() { + CORRADE_EXPECT_FAIL("Constructing Vector from one value is broken."); + CORRADE_VERIFY(false); +// CORRADE_COMPARE(Vector4(7.25f), Vector4(7.25f, 7.25f, 7.25f, 7.25f)); +} + void VectorTest::constructConversion() { Vector4 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index a8f912ca3..6758d19de 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -138,7 +138,10 @@ template class Vector { static_assert(sizeof...(next)+1 == size, "Improper number of arguments passed to Vector constructor"); } - /** @brief Construct vector with one value for all fields */ + /** + * @brief Construct vector with one value for all fields + * @todo Fix this to be actually usable (not only in subclasses) + */ #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit Vector(T value) { #else From dcb4595e6e6f7ce1fc709dc0f772c5ba1bbb040f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 00:49:16 +0100 Subject: [PATCH 272/567] Math: new class BoolVector. Will handle output from various comparison operators in Vector. --- src/Math/BoolVector.h | 232 +++++++++++++++++++++++++++++++ src/Math/CMakeLists.txt | 1 + src/Math/Test/BoolVectorTest.cpp | 166 ++++++++++++++++++++++ src/Math/Test/CMakeLists.txt | 1 + 4 files changed, 400 insertions(+) create mode 100644 src/Math/BoolVector.h create mode 100644 src/Math/Test/BoolVectorTest.cpp diff --git a/src/Math/BoolVector.h b/src/Math/BoolVector.h new file mode 100644 index 000000000..eb472a64f --- /dev/null +++ b/src/Math/BoolVector.h @@ -0,0 +1,232 @@ +#ifndef Magnum_Math_BoolVector_h +#define Magnum_Math_BoolVector_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::BoolVector + */ + +#include +#include + +namespace Magnum { namespace Math { + +/** +@brief %Vector storing boolean values +@tparam size Bit count + +Result of component-wise comparison from Vector. The boolean values are stored +as bits in array of unsigned bytes, unused bits have undefined value which +doesn't affect comparison or all() / none() / any() functions. See also +@ref matrix-vector for brief introduction. +*/ +template class BoolVector { + static_assert(size != 0, "BoolVector cannot have zero elements"); + + public: + static const std::size_t Size = size; /**< @brief %Vector size */ + static const std::size_t DataSize = (size-1)/8+1; /**< @brief %Vector storage size */ + + /** @brief Construct boolean with one value for all elements */ + inline static BoolVector from(bool value) { + BoolVector out; + + for(std::size_t i = 0; i != size; ++i) + out._data[i] = (value ? FullSegmentMask : 0); + + return out; + } + + /** @brief Construct zero-filled boolean vector */ + inline constexpr BoolVector(): _data() {} + + /** @brief Construct boolean vector from given values */ + template inline constexpr BoolVector(std::uint8_t first, U... next): _data{first, std::uint8_t(next)...} { + static_assert(sizeof...(next)+1 == DataSize, "Improper number of arguments passed to BoolVector constructor"); + } + + /** @brief Copy constructor */ + inline constexpr BoolVector(const BoolVector&) = default; + + /** @brief Copy assignment */ + inline BoolVector& operator=(const BoolVector&) = default; + + /** + * @brief Raw data + * @return %Array of DataSize length + * + * @see operator[](), set() + */ + inline std::uint8_t* data() { return _data; } + inline constexpr const std::uint8_t* data() const { return _data; } /**< @overload */ + + /** @brief Bit at given position */ + inline constexpr bool operator[](std::size_t i) const { + return (_data[i/8] >> i%8) & 0x01; + } + + /** @brief Set bit at given position */ + inline BoolVector& set(std::size_t i, bool value) { + _data[i/8] |= ((value & 0x01) << i%8); + return *this; + } + + /** @brief Equality comparison */ + inline bool operator==(const BoolVector& other) const { + for(std::size_t i = 0; i != size/8; ++i) + if(_data[i] != other._data[i]) return false; + + /* Check last segment */ + if(size%8 && (_data[DataSize-1] & LastSegmentMask) != (other._data[DataSize-1] & LastSegmentMask)) + return false; + + return true; + } + + /** @brief Non-equality comparison */ + inline bool operator!=(const BoolVector& other) const { + return !operator==(other); + } + + /** @brief Whether all bits are set */ + bool all() const { + /* Check all full segments */ + for(std::size_t i = 0; i != size/8; ++i) + if(_data[i] != FullSegmentMask) return false; + + /* Check last segment */ + if(size%8 && (_data[DataSize-1] & LastSegmentMask) != LastSegmentMask) + return false; + + return true; + } + + /** @brief Whether no bits are set */ + bool none() const { + /* Check all full segments */ + for(std::size_t i = 0; i != size/8; ++i) + if(_data[i]) return false; + + /* Check last segment */ + if(size%8 && (_data[DataSize-1] & LastSegmentMask)) + return false; + + return true; + } + + /** @brief Whether any bit is set */ + inline bool any() const { + return !none(); + } + + /** @brief Bitwise inversion */ + inline BoolVector operator~() const { + BoolVector out; + + for(std::size_t i = 0; i != DataSize; ++i) + out._data[i] = ~_data[i]; + + return out; + } + + /** + * @brief Bitwise AND and assign + * + * The computation is done in-place. + */ + inline BoolVector& operator&=(const BoolVector& other) { + for(std::size_t i = 0; i != DataSize; ++i) + _data[i] &= other._data[i]; + + return *this; + } + + /** + * @brief Bitwise AND + * + * @see operator&=() + */ + inline BoolVector operator&(const BoolVector& other) const { + return BoolVector(*this) &= other; + } + + /** + * @brief Bitwise OR and assign + * + * The computation is done in-place. + */ + inline BoolVector& operator|=(const BoolVector& other) { + for(std::size_t i = 0; i != DataSize; ++i) + _data[i] |= other._data[i]; + + return *this; + } + + /** + * @brief Bitwise OR + * + * @see operator|=() + */ + inline BoolVector operator|(const BoolVector& other) const { + return BoolVector(*this) |= other; + } + + /** + * @brief Bitwise XOR and assign + * + * The computation is done in-place. + */ + inline BoolVector& operator^=(const BoolVector& other) { + for(std::size_t i = 0; i != DataSize; ++i) + _data[i] ^= other._data[i]; + + return *this; + } + + /** + * @brief Bitwise XOR + * + * @see operator^=() + */ + inline BoolVector operator^(const BoolVector& other) const { + return BoolVector(*this) ^= other; + } + + private: + enum: std::uint8_t { + FullSegmentMask = 0xFF, + LastSegmentMask = (1 << size%8) - 1 + }; + + std::uint8_t _data[(size-1)/8+1]; +}; + +/** @debugoperator{Magnum::Math::BoolVector} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const BoolVector& value) { + debug << "BoolVector("; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + for(std::size_t i = 0; i != size; ++i) { + if(i && !(i%8)) debug << " "; + debug << (value[i] ? "1" : "0"); + } + debug << ")"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +}} + +#endif diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 1d347f4d0..284415193 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,4 +1,5 @@ set(MagnumMath_HEADERS + BoolVector.h Constants.h Functions.h Math.h diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp new file mode 100644 index 000000000..b430f6d02 --- /dev/null +++ b/src/Math/Test/BoolVectorTest.cpp @@ -0,0 +1,166 @@ +/* + Copyright © 1910, 1911, 1912 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/BoolVector.h" + +namespace Magnum { namespace Math { namespace Test { + +class BoolVectorTest: public Corrade::TestSuite::Tester { + public: + explicit BoolVectorTest(); + + void constructDefault(); + void constructOneValue(); + void data(); + + void compare(); + void compareUndefined(); + void all(); + void none(); + void any(); + + void bitInverse(); + void bitAndOrXor(); + + void debug(); +}; + +static_assert(BoolVector<15>::DataSize == 2, "Improper DataSize"); +static_assert(BoolVector<16>::DataSize == 2, "Improper DataSize"); +static_assert(BoolVector<17>::DataSize == 3, "Improper DataSize"); + +typedef Math::BoolVector<19> BoolVector19; + +BoolVectorTest::BoolVectorTest() { + addTests(&BoolVectorTest::constructDefault, + &BoolVectorTest::constructOneValue, + &BoolVectorTest::data, + + &BoolVectorTest::compare, + &BoolVectorTest::compareUndefined, + &BoolVectorTest::all, + &BoolVectorTest::none, + &BoolVectorTest::any, + + &BoolVectorTest::bitInverse, + &BoolVectorTest::bitAndOrXor, + + &BoolVectorTest::debug); +} + +void BoolVectorTest::constructDefault() { + CORRADE_COMPARE(BoolVector19(), BoolVector19(0x00, 0x00, 0x00)); +} + +void BoolVectorTest::constructOneValue() { + CORRADE_COMPARE(BoolVector19::from(false), BoolVector19(0x00, 0x00, 0x00)); + CORRADE_COMPARE(BoolVector19::from(true), BoolVector19(0xff, 0xff, 0x07)); +} + +void BoolVectorTest::data() { + BoolVector19 a(0x08, 0x03, 0x04); + + CORRADE_VERIFY(!a[0] && !a[1] && !a[2]); + CORRADE_VERIFY(a[3]); + CORRADE_VERIFY(!a[4] && !a[5] && !a[6] && !a[7]); + CORRADE_VERIFY(a[8]); + CORRADE_VERIFY(a[9]); + CORRADE_VERIFY(!a[10] && !a[11] && !a[12] && !a[13] && !a[14] && !a[15] && !a[16] && !a[17]); + CORRADE_VERIFY(a[18]); + + a.set(15, true); + CORRADE_VERIFY(a[15]); + + CORRADE_COMPARE(a, BoolVector19(0x08, 0x83, 0x04)); +} + +void BoolVectorTest::compare() { + BoolVector19 a(0xa5, 0x5f, 0x07); + CORRADE_VERIFY(a == a); + + /* Change in full segments */ + BoolVector19 b(0xa3, 0x5f, 0x07); + BoolVector19 c(0xa5, 0x98, 0x07); + CORRADE_VERIFY(a != b); + CORRADE_VERIFY(a != c); + + /* Change in last bit */ + BoolVector19 d(0xa5, 0x5f, 0x06); + CORRADE_VERIFY(a != d); +} + +void BoolVectorTest::compareUndefined() { + BoolVector19 a(0xa5, 0x5f, 0x07); + + /* Change in unused part of last segment */ + BoolVector19 b(0xa5, 0x5f, 0x0f); + CORRADE_VERIFY(a == b); + + /* Change in used part of last segment */ + BoolVector19 c(0xa5, 0x5f, 0x03); + CORRADE_VERIFY(a != c); +} + +void BoolVectorTest::all() { + CORRADE_VERIFY(BoolVector19(0xff, 0xff, 0x07).all()); + + /* Last segment - bit in used and unused part */ + CORRADE_VERIFY(BoolVector19(0xff, 0xff, 0x0f).all()); + CORRADE_VERIFY(!BoolVector19(0xff, 0xff, 0x04).all()); +} + +void BoolVectorTest::none() { + CORRADE_VERIFY(BoolVector19(0x00, 0x00, 0x00).none()); + + /* Last segment - bit in used and unused part */ + CORRADE_VERIFY(BoolVector19(0x00, 0x00, 0x08).none()); + CORRADE_VERIFY(!BoolVector19(0x00, 0x00, 0x04).none()); +} + +void BoolVectorTest::any() { + CORRADE_VERIFY(BoolVector19(0x00, 0x01, 0x00).any()); + + /* Last segment - bit in used and unused part */ + CORRADE_VERIFY(BoolVector19(0x00, 0x00, 0x04).any()); + CORRADE_VERIFY(!BoolVector19(0x00, 0x00, 0x08).any()); +} + +void BoolVectorTest::bitInverse() { + CORRADE_COMPARE(~BoolVector19(0xa5, 0x5f, 0x03), BoolVector19(0x5a, 0xa0, 0x04)); +} + +void BoolVectorTest::bitAndOrXor() { + BoolVector19 a(0xa5, 0x5f, 0x03); + BoolVector19 b(0x37, 0xf3, 0x06); + + CORRADE_COMPARE(a & b, BoolVector19(0x25, 0x53, 0x02)); + CORRADE_COMPARE(a | b, BoolVector19(0xb7, 0xff, 0x07)); + CORRADE_COMPARE(a ^ b, BoolVector19(0x92, 0xac, 0x05)); +} + +void BoolVectorTest::debug() { + std::ostringstream o; + + Corrade::Utility::Debug(&o) << BoolVector19(0x25, 0x53, 0x02); + + CORRADE_COMPARE(o.str(), "BoolVector(10100100 11001010 010)\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::BoolVectorTest) diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 185946510..1d413def9 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -1,3 +1,4 @@ +corrade_add_test(MathBoolVectorTest BoolVectorTest.cpp) corrade_add_test(MathConstantsTest ConstantsTest.cpp) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) From 799bc629eb717cb80cb9e3497e5183f4175b38ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 01:36:48 +0100 Subject: [PATCH 273/567] Math: matrix/vector rework, part 4: using BoolVector for comparisons. The comparisons have also SIMD instructions returning bool vector, this future-proofs them. Also it isn't confusing anymore (a < b is true when all are less or just one?). --- src/Math/Test/VectorTest.cpp | 16 ++++------ src/Math/Vector.h | 57 ++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index d5130414f..4f66d1342 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -140,17 +140,11 @@ void VectorTest::compare() { } void VectorTest::compareComponentWise() { - CORRADE_VERIFY(Vector4(1.0f, -2.0f, -5.0f, 7.0f) < Vector4(1.1f, -1.0f, 3.0f, 8.0f)); - CORRADE_VERIFY(!(Vector4(1.0f, -2.0f, -5.0f, 7.0f) < Vector4(1.1f, -1.0f, 3.0f, 7.0f))); - - CORRADE_VERIFY(Vector4(1.0f, -2.0f, -5.0f, 7.0f) <= Vector4(1.1f, -1.0f, 3.0f, 7.0f)); - CORRADE_VERIFY(!(Vector4(1.0f, -2.0f, -5.0f, 7.0f) <= Vector4(1.0f, -2.0f, -5.0f, 6.0f))); - - CORRADE_VERIFY(Vector4(1.1f, -1.0f, 3.0f, 7.0f) >= Vector4(1.0f, -2.0f, -5.0f, 7.0f)); - CORRADE_VERIFY(!(Vector4(1.0f, -2.0f, -5.0f, 6.0f) >= Vector4(1.0f, -2.0f, -5.0f, 7.0f))); - - CORRADE_VERIFY(Vector4(1.1f, -1.0f, 3.0f, 8.0f) > Vector4(1.0f, -2.0f, -5.0f, 7.0f)); - CORRADE_VERIFY(!(Vector4(1.1f, -1.0f, 3.0f, 7.0f) > Vector4(1.0f, -2.0f, -5.0f, 7.0f))); + typedef BoolVector<3> BoolVector3; + CORRADE_COMPARE(Vector3(1.0f, -1.0f, 5.0f) < Vector3(1.1f, -1.0f, 3.0f), BoolVector3(0x1)); + CORRADE_COMPARE(Vector3(1.0f, -1.0f, 5.0f) <= Vector3(1.1f, -1.0f, 3.0f), BoolVector3(0x3)); + CORRADE_COMPARE(Vector3(1.0f, -1.0f, 5.0f) >= Vector3(1.1f, -1.0f, 3.0f), BoolVector3(0x6)); + CORRADE_COMPARE(Vector3(1.0f, -1.0f, 5.0f) > Vector3(1.1f, -1.0f, 3.0f), BoolVector3(0x4)); } void VectorTest::negative() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 6758d19de..45c3f2af0 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -25,6 +25,7 @@ #include #include +#include "Math/BoolVector.h" #include "Math/MathTypeTraits.h" #include "magnumVisibility.h" @@ -201,52 +202,44 @@ template class Vector { return !operator==(other); } - /** - * @brief Component-wise less than - * @return `True` if all components are smaller than their - * counterparts in @p other, `false` otherwise - */ - inline bool operator<(const Vector& other) const { + /** @brief Component-wise less than */ + inline BoolVector operator<(const Vector& other) const { + BoolVector out; + for(std::size_t i = 0; i != size; ++i) - if(_data[i] >= other._data[i]) return false; + out.set(i, _data[i] < other._data[i]); - return true; + return out; } - /** - * @brief Component-wise less than or equal - * @return `True` if all components are smaller than or equal to their - * counterparts in @p other, `false` otherwise - */ - inline bool operator<=(const Vector& other) const { + /** @brief Component-wise less than or equal */ + inline BoolVector operator<=(const Vector& other) const { + BoolVector out; + for(std::size_t i = 0; i != size; ++i) - if(_data[i] > other._data[i]) return false; + out.set(i, _data[i] <= other._data[i]); - return true; + return out; } - /** - * @brief Component-wise greater than or equal - * @return `True` if all components are larger than or equal to their - * counterparts in @p other, `false` otherwise - */ - inline bool operator>=(const Vector& other) const { + /** @brief Component-wise greater than or equal */ + inline BoolVector operator>=(const Vector& other) const { + BoolVector out; + for(std::size_t i = 0; i != size; ++i) - if(_data[i] < other._data[i]) return false; + out.set(i, _data[i] >= other._data[i]); - return true; + return out; } - /** - * @brief Component-wise greater than - * @return `True` if all components are larger than their - * counterparts in @p other, `false` otherwise - */ - inline bool operator>(const Vector& other) const { + /** @brief Component-wise greater than */ + inline BoolVector operator>(const Vector& other) const { + BoolVector out; + for(std::size_t i = 0; i != size; ++i) - if(_data[i] <= other._data[i]) return false; + out.set(i, _data[i] > other._data[i]); - return true; + return out; } /** From 16571a884bebd0b6bd30d01a990fb342324024b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 12:59:55 +0100 Subject: [PATCH 274/567] Text: prerender font using dedicated function, not in constructor. The number of possible combinations would explode for no reason when opening font from different locations will be implemented. --- src/Text/Font.cpp | 48 +++++++++++++++++++++-------------------------- src/Text/Font.h | 16 ++++++++-------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 8a6130fcd..de8627bee 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -26,13 +26,27 @@ namespace Magnum { namespace Text { Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size): _size(size) { - /** @todo Use delegating constructor when GCC 4.6 support is dropped */ - create(renderer, fontFile); + #ifndef MAGNUM_TARGET_GLES + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); + #else + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); + #endif + + /* Create FreeType font */ + CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); + CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); + + /* Create Harfbuzz font */ + _hbFont = hb_ft_font_create(_ftFont, nullptr); + + /* Set up the texture */ + _texture.setWrapping(Texture2D::Wrapping::ClampToEdge) + ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) + ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); } -Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, const std::string& characters, const Vector2i& atlasSize): _size(size) { - /** @todo Use delegating constructor when GCC 4.6 support is dropped */ - create(renderer, fontFile); +void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { + glyphs.clear(); /** @bug Crash when atlas is too small */ /** @todo Get rid of duplicate characters */ @@ -79,8 +93,8 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co /* Save character texture position and texture coordinates for given character index */ glyphs.insert({charIndices[i], std::make_tuple( - Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/size, - Vector2(charPositions[i].size())/size), + Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/_size, + Vector2(charPositions[i].size())/_size), Rectangle(Vector2(charPositions[i].bottomLeft())/atlasSize, Vector2(charPositions[i].topRight())/atlasSize) )}); @@ -94,26 +108,6 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, co #endif } -void Font::create(FontRenderer& renderer, const std::string& fontFile) { - #ifndef MAGNUM_TARGET_GLES - MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); - #else - MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); - #endif - - /* Create FreeType font */ - CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); - CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); - - /* Create Harfbuzz font */ - _hbFont = hb_ft_font_create(_ftFont, nullptr); - - /* Set up the texture */ - _texture.setWrapping(Texture2D::Wrapping::ClampToEdge) - ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) - ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); -} - void Font::destroy() { if(!_ftFont) return; diff --git a/src/Text/Font.h b/src/Text/Font.h index 326a58ca6..30e697163 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -46,24 +46,25 @@ class MAGNUM_TEXT_EXPORT Font { public: /** - * @brief Empty font constructor + * @brief Create font from file * @param renderer %Font renderer * @param fontFile %Font file * @param size %Font size * - * Creates font with no prerendered characters. + * Creates font with no prerendered characters. See prerender() for + * more information. */ Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); /** - * @brief Create font for given character set - * @param renderer %Font renderer - * @param fontFile %Font file - * @param size %Font size + * @brief Prerender given character set * @param characters Characters to render * @param atlasSize Size of resulting atlas + * + * Creates new atlas with prerendered characters, replacing the + * previous one (if any). */ - Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size, const std::string& characters, const Vector2i& atlasSize); + void prerender(const std::string& characters, const Vector2i& atlasSize); ~Font(); @@ -95,7 +96,6 @@ class MAGNUM_TEXT_EXPORT Font { inline hb_font_t* font() { return _hbFont; } private: - void MAGNUM_TEXT_LOCAL create(FontRenderer& renderer, const std::string& fontFile); void MAGNUM_TEXT_LOCAL destroy(); void MAGNUM_TEXT_LOCAL move(); From 19e0302b6f867a902c8c6eaf8332fe6fd55975bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 13:09:27 +0100 Subject: [PATCH 275/567] Don't render bloated and scary inheritance graphs in documentation. Just pretend that everything is shiny and following KISS principle. --- Doxyfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doxyfile b/Doxyfile index 8d1694bd6..88735c3e1 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1671,7 +1671,7 @@ DOT_FONTPATH = # indirect inheritance relations. Setting this tag to YES will force the # CLASS_DIAGRAMS tag to NO. -CLASS_GRAPH = YES +CLASS_GRAPH = NO # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and @@ -1738,7 +1738,7 @@ CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will generate a graphical hierarchy of all classes instead of a textual one. -GRAPHICAL_HIERARCHY = YES +GRAPHICAL_HIERARCHY = NO # If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories From e24207f62019a46ff0a601a5f1dbb639af4a9bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 13:24:23 +0100 Subject: [PATCH 276/567] Doc++ --- doc/matrix-vector.dox | 11 +++++++++++ src/Math/Matrix.h | 13 ++++++++++++- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 81ecf0cf6..bb2162a0c 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -131,6 +131,17 @@ xyz.xy() *= 5; @endcode Color3 and Color4 name their components `rgba` instead of `xyzw`. +Matrix3 and Matrix4 have functions for accessing properties of given 2D/3D +transformation: +@code +Matrix4 a = Matrix4::translation(Vector3::yAxis(4.0f)); +Vector3 translation = a.translation(); + +Matrix3 b = Matrix3::rotation(deg(15.f)); +Matrix<2, float> rotationScaling = b.rotationScaling(); +Vector2 up = b.up(); +@endcode + For more involved operations with components there is the swizzle() function: @code Vector4 original(-1, 2, 3, 4); diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index c0687e0a0..cfe96ca3e 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -74,7 +74,18 @@ template class Matrix: public RectangularMatrix inline constexpr /*implicit*/ Matrix(const Vector& first, const U&... next): RectangularMatrix(first, next...) {} - /** @copydoc RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ + /** + * @brief Construct matrix from another of different type + * + * Performs only default casting on the values, no rounding or + * anything else. Example usage: + * @code + * Matrix<2, float> floatingPoint({1.3f, 2.7f}, + * {-15.0f, 7.0f}); + * Matrix<2, std::int8_t> integral(floatingPoint); + * // integral == {{1, 2}, {-15, 7}} + * @endcode + */ template inline constexpr explicit Matrix(const RectangularMatrix& other): RectangularMatrix(other) {} /** @brief Copy constructor */ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 5a648fe7d..e7dd8ce9d 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -128,7 +128,7 @@ template class Matrix3: public Matrix<3, T> { /** @brief %Matrix from column vectors */ inline constexpr /*implicit*/ Matrix3(const Vector3& first, const Vector3& second, const Vector3& third): Matrix<3, T>(first, second, third) {} - /** @copydoc Matrix::Matrix(const RectangularMatrix&) */ + /** @copydoc Matrix::Matrix(const RectangularMatrix&) */ template inline constexpr explicit Matrix3(const RectangularMatrix<3, 3, U>& other): Matrix<3, T>(other) {} /** @brief Copy constructor */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 5ac26b89b..55f6a58ce 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -253,7 +253,7 @@ template class Matrix4: public Matrix<4, T> { /** @brief %Matrix from column vectors */ inline constexpr /*implicit*/ Matrix4(const Vector4& first, const Vector4& second, const Vector4& third, const Vector4& fourth): Matrix<4, T>(first, second, third, fourth) {} - /** @copydoc Matrix::Matrix(const RectangularMatrix&) */ + /** @copydoc Matrix::Matrix(const RectangularMatrix&) */ template inline constexpr explicit Matrix4(const RectangularMatrix<4, 4, U>& other): Matrix<4, T>(other) {} /** @brief Copy constructor */ From cc2eac41bc091b685d1c5a76d41ec3c2893f314d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 13:25:41 +0100 Subject: [PATCH 277/567] Text: removing duplicate glyphs in Font::prerender(). --- src/Text/Font.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index de8627bee..2bdfce706 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -15,6 +15,7 @@ #include "Font.h" +#include #include #include FT_FREETYPE_H #include @@ -49,7 +50,6 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { glyphs.clear(); /** @bug Crash when atlas is too small */ - /** @todo Get rid of duplicate characters */ /* Get character codes from string */ /** @todo proper UTF-8 decoding */ @@ -61,6 +61,10 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { for(std::uint32_t charCode: charCodes) charIndices.push_back(FT_Get_Char_Index(_ftFont, charCode)); + /* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */ + std::sort(charIndices.begin(), charIndices.end()); + charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end()); + /* Sizes of all characters */ std::vector charSizes; charSizes.reserve(charIndices.size()); From 58aefb3fa0f0741d70b94fe51573274e58063e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 15:00:51 +0100 Subject: [PATCH 278/567] Text: explicit Font constructor. --- src/Text/Font.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/Font.h b/src/Text/Font.h index 30e697163..06866d1a9 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -54,7 +54,7 @@ class MAGNUM_TEXT_EXPORT Font { * Creates font with no prerendered characters. See prerender() for * more information. */ - Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); + explicit Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); /** * @brief Prerender given character set From a45454ca73cb95f615bf28632b4419a268ceaafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 15:04:25 +0100 Subject: [PATCH 279/567] Using CORRADE_INTERNAL_ASSERT_OUTPUT() where appropriate. --- src/Buffer.h | 4 ++-- src/Text/Font.cpp | 14 +++++++------- src/Text/FontRenderer.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index a02d20088..0f2b30b08 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -75,7 +75,7 @@ buffer again. Vector3* data = static_cast(buffer.map(0, 200*sizeof(Vector3), Buffer::MapFlag::Write|Buffer::MapFlag::InvalidateBuffer)); for(std::size_t i = 0; i != 200; ++i) data[i] = ...; -CORRADE_INTERNAL_ASSERT(buffer.unmap()); +CORRADE_INTERNAL_ASSERT_OUTPUT(buffer.unmap()); @endcode If you are updating only a few discrete portions of the buffer, you can use @ref MapFlag "MapFlag::FlushExplicit" and flushMappedRange() to reduce number @@ -86,7 +86,7 @@ for(std::size_t i: {7, 27, 56, 128}) { data[i] = ...; buffer.flushMappedRange(i*sizeof(Vector3), sizeof(Vector3)); } -CORRADE_INTERNAL_ASSERT(buffer.unmap()); +CORRADE_INTERNAL_ASSERT_OUTPUT(buffer.unmap()); @endcode @section Buffer-performance-optimization Performance optimizations diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 2bdfce706..249ac0b22 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -34,8 +34,8 @@ Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size): _ #endif /* Create FreeType font */ - CORRADE_INTERNAL_ASSERT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); - CORRADE_INTERNAL_ASSERT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); /* Create Harfbuzz font */ _hbFont = hb_ft_font_create(_ftFont, nullptr); @@ -69,7 +69,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { std::vector charSizes; charSizes.reserve(charIndices.size()); for(FT_UInt c: charIndices) { - CORRADE_INTERNAL_ASSERT(FT_Load_Glyph(_ftFont, c, FT_LOAD_DEFAULT) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(_ftFont, c, FT_LOAD_DEFAULT) == 0); charSizes.push_back((Vector2i(_ftFont->glyph->metrics.width, _ftFont->glyph->metrics.height))/64); } @@ -84,8 +84,8 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { /* Load and render glyph */ /** @todo B&W only */ FT_GlyphSlot glyph = _ftFont->glyph; - CORRADE_INTERNAL_ASSERT(FT_Load_Glyph(_ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0); - CORRADE_INTERNAL_ASSERT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(_ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0); /* Copy rendered bitmap to texture image */ const FT_Bitmap& bitmap = glyph->bitmap; @@ -96,12 +96,12 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { pixmap[yout*atlasSize.x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin]; /* Save character texture position and texture coordinates for given character index */ - glyphs.insert({charIndices[i], std::make_tuple( + CORRADE_INTERNAL_ASSERT_OUTPUT(glyphs.insert({charIndices[i], std::make_tuple( Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/_size, Vector2(charPositions[i].size())/_size), Rectangle(Vector2(charPositions[i].bottomLeft())/atlasSize, Vector2(charPositions[i].topRight())/atlasSize) - )}); + )}).second); } /* Set texture data */ diff --git a/src/Text/FontRenderer.cpp b/src/Text/FontRenderer.cpp index 94c5fde25..8b1f540f9 100644 --- a/src/Text/FontRenderer.cpp +++ b/src/Text/FontRenderer.cpp @@ -22,7 +22,7 @@ namespace Magnum { namespace Text { FontRenderer::FontRenderer() { - CORRADE_INTERNAL_ASSERT(FT_Init_FreeType(&_library) == 0); + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Init_FreeType(&_library) == 0); } FontRenderer::~FontRenderer() { From c59404bece4ea199ea446cf1876f5126f2234407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 15:22:11 +0100 Subject: [PATCH 280/567] Doc++ --- doc/matrix-vector.dox | 14 +++++++------- src/Text/Font.h | 3 --- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index bb2162a0c..44be0fff9 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -131,6 +131,13 @@ xyz.xy() *= 5; @endcode Color3 and Color4 name their components `rgba` instead of `xyzw`. +For more involved operations with components there is the swizzle() function: +@code +Vector4 original(-1, 2, 3, 4); +Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } +Vector<6, int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } +@endcode + Matrix3 and Matrix4 have functions for accessing properties of given 2D/3D transformation: @code @@ -142,13 +149,6 @@ Matrix<2, float> rotationScaling = b.rotationScaling(); Vector2 up = b.up(); @endcode -For more involved operations with components there is the swizzle() function: -@code -Vector4 original(-1, 2, 3, 4); -Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } -Vector<6, int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } -@endcode - @section matrix-vector-column-major Matrices are column-major and vectors are columns OpenGL matrices are column-major, thus it is reasonable to have matrices in diff --git a/src/Text/Font.h b/src/Text/Font.h index 06866d1a9..1bc84f567 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -50,9 +50,6 @@ class MAGNUM_TEXT_EXPORT Font { * @param renderer %Font renderer * @param fontFile %Font file * @param size %Font size - * - * Creates font with no prerendered characters. See prerender() for - * more information. */ explicit Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); From 6458b03a7689d1886e1e1367c97874e1ee2ef84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 15:22:36 +0100 Subject: [PATCH 281/567] Text: ability to create Font from memory instead of file. --- src/Text/Font.cpp | 24 +++++++++++++++++------- src/Text/Font.h | 10 ++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 249ac0b22..a2d02e97a 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -27,19 +27,29 @@ namespace Magnum { namespace Text { Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size): _size(size) { - #ifndef MAGNUM_TARGET_GLES - MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); - #else - MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); - #endif - - /* Create FreeType font */ CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); + + finishConstruction(); +} + +Font::Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, GLfloat size): _size(size) { + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Memory_Face(renderer.library(), data, dataSize, 0, &_ftFont) == 0); + + finishConstruction(); +} + +void Font::finishConstruction() { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); /* Create Harfbuzz font */ _hbFont = hb_ft_font_create(_ftFont, nullptr); + #ifndef MAGNUM_TARGET_GLES + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); + #else + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); + #endif + /* Set up the texture */ _texture.setWrapping(Texture2D::Wrapping::ClampToEdge) ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) diff --git a/src/Text/Font.h b/src/Text/Font.h index 1bc84f567..0a59f6975 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -53,6 +53,15 @@ class MAGNUM_TEXT_EXPORT Font { */ explicit Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); + /** + * @brief Create font from memory + * @param renderer %Font renderer + * @param data %Font data + * @param size %Font data size + * @param size %Font size + */ + explicit Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, GLfloat size); + /** * @brief Prerender given character set * @param characters Characters to render @@ -93,6 +102,7 @@ class MAGNUM_TEXT_EXPORT Font { inline hb_font_t* font() { return _hbFont; } private: + void MAGNUM_TEXT_LOCAL finishConstruction(); void MAGNUM_TEXT_LOCAL destroy(); void MAGNUM_TEXT_LOCAL move(); From 0274ad7d5601c3cc36ce54bd610de0c66edb356f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 16:02:13 +0100 Subject: [PATCH 282/567] Math: explicit one-parameter Point*D constructor. Was causing improper implicit conversions, such as here (example directly from unit tests, where it was unintentionally used): Vector3 normal; Matrix4 transformation; auto transformedNormal = transformation*normal; Not only that it was possible to multiply 4x4 matrix with 3-component vector, but the resulting type was Point3D which was absolutely confusing. Currently it must be explicitly converted: transformedNormal = transformation*Point3D(normal); --- src/Math/Point2D.h | 9 ++++++++- src/Math/Point3D.h | 9 ++++++++- src/Math/Test/Matrix3Test.cpp | 3 ++- src/Math/Test/Matrix4Test.cpp | 3 ++- src/Primitives/Icosphere.cpp | 3 ++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 702eea7e3..6172707ba 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -54,7 +54,14 @@ template class Point2D: public Vector3 { * @param xy Two-component vector * @param z Z component */ - inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z = T(1)): Vector3(xy, z) {} + inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z): Vector3(xy, z) {} + + /** + * @brief Construct 2D point from 2D vector + * + * Z component is set to `1`. + */ + inline constexpr explicit Point2D(const Vector2& xy): Vector3(xy, T(1)) {} /** @copydoc Vector::Vector(const Vector&) */ template inline constexpr explicit Point2D(const Vector<3, U>& other): Vector3(other) {} diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index 13ff4c473..a30e9c8ff 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -55,7 +55,14 @@ template class Point3D: public Vector4 { * @param xyz Three-component vector * @param w W component */ - inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w = T(1)): Vector4(xyz, w) {} + inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w): Vector4(xyz, w) {} + + /** + * @brief Construct 3D point from 3D vector + * + * W component is set to `1`. + */ + inline constexpr explicit Point3D(const Vector3& xyz): Vector4(xyz, T(1)) {} /** @copydoc Vector::Vector(const Vector&) */ template inline constexpr explicit Point3D(const Vector<4, U>& other): Vector4(other) {} diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 744c4cace..aae9352a2 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -48,6 +48,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { typedef Math::Matrix3 Matrix3; typedef Math::Matrix<2, float> Matrix2; typedef Math::Vector2 Vector2; +typedef Math::Point2D Point2D; Matrix3Test::Matrix3Test() { addTests(&Matrix3Test::constructIdentity, @@ -122,7 +123,7 @@ void Matrix3Test::reflection() { {0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(actual*actual, Matrix3()); - CORRADE_COMPARE(actual*normal, -normal); + CORRADE_COMPARE((actual*Point2D(normal)).vector(), -normal); CORRADE_COMPARE(actual, expected); } diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 53e9f6d96..e3734870e 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -53,6 +53,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { typedef Math::Matrix4 Matrix4; typedef Math::Matrix<3, float> Matrix3; typedef Math::Vector3 Vector3; +typedef Math::Point3D Point3D; Matrix4Test::Matrix4Test() { addTests(&Matrix4Test::constructIdentity, @@ -170,7 +171,7 @@ void Matrix4Test::reflection() { { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(actual*actual, Matrix4()); - CORRADE_COMPARE(actual*normal, -normal); + CORRADE_COMPARE((actual*Point3D(normal)).vector(), -normal); CORRADE_COMPARE(actual, expected); } diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index d5e79bbf8..0be978c15 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -54,7 +54,8 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vecto {0.0f, 0.525731f, -0.850651f}, {0.0f, 0.525731f, 0.850651f} }}, {}) { - positions(0)->assign(normals(0)->begin(), normals(0)->end()); + positions(0)->reserve(normals(0)->size()); + for(auto i: *normals(0)) positions(0)->push_back(Point3D(i)); } }} From fa6494f21eed744ef22c530379d1a106ec9e6280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 27 Jan 2013 16:28:44 +0100 Subject: [PATCH 283/567] SceneGraph: forgot to initialize variables. Really need them to be computed from the matrix. --- src/SceneGraph/Camera3D.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index 42e2f5d9d..7bfe41db8 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -24,7 +24,7 @@ namespace Magnum { namespace SceneGraph { -template Camera3D::Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object) {} +template Camera3D::Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(T(0)), _far(T(0)) {} template Camera3D* Camera3D::setOrthographic(const Math::Vector2& size, T near, T far) { /** @todo Get near/far from the matrix */ From 08312ae3353bc7caf6b479a617916f713a35e013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 Jan 2013 17:54:09 +0100 Subject: [PATCH 284/567] Math: minor code reorganization. Place "alias" methods after "implementation" methods. --- src/Math/RectangularMatrix.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 176c6c742..ffc8248b1 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -204,19 +204,6 @@ template class RectangularMatrix { return RectangularMatrix(*this)-=other; } - /** - * @brief Multiply matrix with number - * - * @see operator*=(U), operator*(U, const RectangularMatrix&) - */ - #ifndef DOXYGEN_GENERATING_OUTPUT - template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number) const { - #else - template inline RectangularMatrix operator*(U number) const { - #endif - return RectangularMatrix(*this)*=number; - } - /** * @brief Multiply matrix with number and assign * @@ -236,16 +223,16 @@ template class RectangularMatrix { } /** - * @brief Divide matrix with number + * @brief Multiply matrix with number * - * @see operator/=(), operator/(U, const RectangularMatrix&) + * @see operator*=(U), operator*(U, const RectangularMatrix&) */ #ifndef DOXYGEN_GENERATING_OUTPUT - template inline typename std::enable_if::value, RectangularMatrix>::type operator/(U number) const { + template inline typename std::enable_if::value, RectangularMatrix>::type operator*(U number) const { #else - template inline RectangularMatrix operator/(U number) const { + template inline RectangularMatrix operator*(U number) const { #endif - return RectangularMatrix(*this)/=number; + return RectangularMatrix(*this)*=number; } /** @@ -266,6 +253,19 @@ template class RectangularMatrix { return *this; } + /** + * @brief Divide matrix with number + * + * @see operator/=(), operator/(U, const RectangularMatrix&) + */ + #ifndef DOXYGEN_GENERATING_OUTPUT + template inline typename std::enable_if::value, RectangularMatrix>::type operator/(U number) const { + #else + template inline RectangularMatrix operator/(U number) const { + #endif + return RectangularMatrix(*this)/=number; + } + /** * @brief Multiply matrix * From ac9dca07818b4c27d396fe7265de0abeccc3cc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 Jan 2013 17:56:11 +0100 Subject: [PATCH 285/567] Math: access RectangularMatrix's own data directly. --- src/Math/RectangularMatrix.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index ffc8248b1..84a7eca5e 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -41,6 +41,8 @@ of @f$ \boldsymbol A_{ij} @f$). template class RectangularMatrix { static_assert(cols != 0 && rows != 0, "RectangularMatrix cannot have zero elements"); + template friend class RectangularMatrix; + public: typedef T Type; /**< @brief Data type */ const static std::size_t Cols = cols; /**< @brief %Matrix column count */ @@ -279,7 +281,7 @@ template class RectangularMatrix { for(std::size_t col = 0; col != size; ++col) for(std::size_t row = 0; row != rows; ++row) for(std::size_t pos = 0; pos != cols; ++pos) - out[col][row] += (*this)[pos][row]*other[col][pos]; + out[col][row] += _data[pos][row]*other._data[col][pos]; return out; } @@ -302,7 +304,7 @@ template class RectangularMatrix { for(std::size_t col = 0; col != cols; ++col) for(std::size_t row = 0; row != rows; ++row) - out[row][col] = (*this)[col][row]; + out[row][col] = _data[col][row]; return out; } From 37955c468fc3be8411bc557ec16ccde471c97769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 Jan 2013 17:58:59 +0100 Subject: [PATCH 286/567] Math: creating matrix from diagonal, retrieving values on diagonal. --- src/Math/RectangularMatrix.h | 35 +++++++++++++++++++++++++ src/Math/Test/RectangularMatrixTest.cpp | 34 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 84a7eca5e..7a0f45101 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -48,6 +48,13 @@ template class RectangularMatrix { const static std::size_t Cols = cols; /**< @brief %Matrix column count */ const static std::size_t Rows = rows; /**< @brief %Matrix row count */ + /** + * @brief Size of matrix diagonal + * + * @see fromDiagonal(), diagonal() + */ + const static std::size_t DiagonalSize = (cols < rows ? cols : rows); + /** * @brief %Matrix from array * @return Reference to the data as if it was Matrix, thus doesn't @@ -64,6 +71,20 @@ template class RectangularMatrix { return *reinterpret_cast*>(data); } + /** + * @brief Construct diagonal matrix + * + * @see diagonal() + */ + inline static RectangularMatrix fromDiagonal(const Vector& diagonal) { + RectangularMatrix out; + + for(std::size_t i = 0; i != DiagonalSize; ++i) + out[i][i] = diagonal[i]; + + return out; + } + /** @brief Construct zero-filled matrix */ inline constexpr /*implicit*/ RectangularMatrix() {} @@ -309,6 +330,20 @@ template class RectangularMatrix { return out; } + /** + * @brief Values on diagonal + * + * @see fromDiagonal() + */ + Vector diagonal() const { + Vector out; + + for(std::size_t i = 0; i != DiagonalSize; ++i) + out[i] = _data[i][i]; + + return out; + } + private: /* Implementation for RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ template inline constexpr explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix): _data{Vector(matrix[sequence])...} {} diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 730b2c3e8..78d867199 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -31,6 +31,7 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void constructDefault(); void constructConversion(); void constructFromVectors(); + void constructFromDiagonal(); void data(); void compare(); @@ -41,6 +42,7 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void multiply(); void transposed(); + void diagonal(); void debug(); void configuration(); @@ -60,6 +62,7 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::constructDefault, &RectangularMatrixTest::constructConversion, &RectangularMatrixTest::constructFromVectors, + &RectangularMatrixTest::constructFromDiagonal, &RectangularMatrixTest::data, &RectangularMatrixTest::compare, @@ -70,6 +73,7 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::multiply, &RectangularMatrixTest::transposed, + &RectangularMatrixTest::diagonal, &RectangularMatrixTest::debug, &RectangularMatrixTest::configuration); @@ -124,6 +128,21 @@ void RectangularMatrixTest::constructFromVectors() { CORRADE_COMPARE(actual, expected); } +void RectangularMatrixTest::constructFromDiagonal() { + Vector3 diagonal(-1.0f, 5.0f, 11.0f); + + Matrix3x4 expectedA(Vector4(-1.0f, 0.0f, 0.0f, 0.0f), + Vector4( 0.0f, 5.0f, 0.0f, 0.0f), + Vector4( 0.0f, 0.0f, 11.0f, 0.0f)); + CORRADE_COMPARE(Matrix3x4::fromDiagonal(diagonal), expectedA); + + Matrix4x3 expectedB(Vector3(-1.0f, 0.0f, 0.0f), + Vector3( 0.0f, 5.0f, 0.0f), + Vector3( 0.0f, 0.0f, 11.0f), + Vector3( 0.0f, 0.0f, 0.0f)); + CORRADE_COMPARE(Matrix4x3::fromDiagonal(diagonal), expectedB); +} + void RectangularMatrixTest::data() { Matrix3x4 m; Vector4 vector(4.0f, 5.0f, 6.0f, 7.0f); @@ -252,6 +271,21 @@ void RectangularMatrixTest::transposed() { CORRADE_COMPARE(original.transposed(), transposed); } +void RectangularMatrixTest::diagonal() { + Vector3 diagonal(-1.0f, 5.0f, 11.0f); + + Matrix4x3 a(Vector3(-1.0f, 1.0f, 3.0f), + Vector3( 4.0f, 5.0f, 7.0f), + Vector3( 8.0f, 9.0f, 11.0f), + Vector3(12.0f, 13.0f, 15.0f)); + CORRADE_COMPARE(a.diagonal(), diagonal); + + Matrix3x4 b(Vector4(-1.0f, 4.0f, 8.0f, 12.0f), + Vector4( 1.0f, 5.0f, 9.0f, 13.0f), + Vector4( 3.0f, 7.0f, 11.0f, 15.0f)); + CORRADE_COMPARE(b.diagonal(), diagonal); +} + void RectangularMatrixTest::debug() { Matrix3x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Vector4(4.0f, 4.0f, 7.0f, 3.0f), From e58962dc43fc5486f3deabfd6b1b2dceeeb7a646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 Jan 2013 22:28:50 +0100 Subject: [PATCH 287/567] Don't use fully qualified Corrade::Utility::Debug when not needed. --- src/Array.h | 14 ++++++++------ src/Color.h | 4 ++-- src/Math/Geometry/Test/RectangleTest.cpp | 2 +- src/Math/Test/BoolVectorTest.cpp | 2 +- src/Math/Test/Matrix3Test.cpp | 4 +--- src/Math/Test/Matrix4Test.cpp | 4 +--- src/Math/Test/MatrixTest.cpp | 4 +--- src/Math/Test/Point2DTest.cpp | 4 +--- src/Math/Test/Point3DTest.cpp | 4 +--- src/Math/Test/QuaternionTest.cpp | 2 +- src/Math/Test/RectangularMatrixTest.cpp | 4 +--- src/Math/Test/Vector2Test.cpp | 4 +--- src/Math/Test/Vector3Test.cpp | 4 +--- src/Math/Test/Vector4Test.cpp | 4 +--- src/Math/Test/VectorTest.cpp | 4 +--- src/Resource.h | 2 +- src/Test/ColorTest.cpp | 4 +--- src/Test/MeshTest.cpp | 6 ++---- src/Test/ResourceManagerTest.cpp | 2 -- src/Trade/AbstractImporter.cpp | 2 +- 20 files changed, 28 insertions(+), 52 deletions(-) diff --git a/src/Array.h b/src/Array.h index 22b8288a5..2788fcfc3 100644 --- a/src/Array.h +++ b/src/Array.h @@ -23,6 +23,8 @@ #include #include +#include "Magnum.h" + namespace Magnum { /** @@ -179,30 +181,30 @@ template class Array3D: public Array<3, T> { }; /** @debugoperator{Magnum::Array} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array& value) { +template Debug operator<<(Debug debug, const Array& value) { debug << "Array("; - debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug.setFlag(Debug::SpaceAfterEachValue, false); for(std::uint8_t i = 0; i != dimensions; ++i) { if(i != 0) debug << ", "; debug << value[i]; } debug << ")"; - debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + debug.setFlag(Debug::SpaceAfterEachValue, true); return debug; } /** @debugoperator{Magnum::Array1D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array1D& value) { +template inline Debug operator<<(Debug debug, const Array1D& value) { return debug << static_cast&>(value); } /** @debugoperator{Magnum::Array2D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array2D& value) { +template inline Debug operator<<(Debug debug, const Array2D& value) { return debug << static_cast&>(value); } /** @debugoperator{Magnum::Array3D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Array3D& value) { +template inline Debug operator<<(Debug debug, const Array3D& value) { return debug << static_cast&>(value); } diff --git a/src/Color.h b/src/Color.h index 145a6c5bc..cd5ac19ee 100644 --- a/src/Color.h +++ b/src/Color.h @@ -375,12 +375,12 @@ class Color4: public Math::Vector4 { MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4) /** @debugoperator{Magnum::Color3} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Color3& value) { +template inline Debug operator<<(Debug debug, const Color3& value) { return debug << static_cast&>(value); } /** @debugoperator{Magnum::Color4} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Color4& value) { +template inline Debug operator<<(Debug debug, const Color4& value) { return debug << static_cast&>(value); } diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 267dc724b..84c8b2567 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -87,7 +87,7 @@ void RectangleTest::size() { void RectangleTest::debug() { std::ostringstream o; - Corrade::Utility::Debug(&o) << Rectanglei({34, 23}, {47, 30}); + Debug(&o) << Rectanglei({34, 23}, {47, 30}); CORRADE_COMPARE(o.str(), "Rectangle({34, 23}, {47, 30})\n"); } diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp index b430f6d02..f2b1c4e75 100644 --- a/src/Math/Test/BoolVectorTest.cpp +++ b/src/Math/Test/BoolVectorTest.cpp @@ -156,7 +156,7 @@ void BoolVectorTest::bitAndOrXor() { void BoolVectorTest::debug() { std::ostringstream o; - Corrade::Utility::Debug(&o) << BoolVector19(0x25, 0x53, 0x02); + Debug(&o) << BoolVector19(0x25, 0x53, 0x02); CORRADE_COMPARE(o.str(), "BoolVector(10100100 11001010 010)\n"); } diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index aae9352a2..e5e57e11c 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -20,8 +20,6 @@ #include "Math/Constants.h" #include "Math/Matrix3.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Matrix3Test: public Corrade::TestSuite::Tester { @@ -218,7 +216,7 @@ void Matrix3Test::debug() { } void Matrix3Test::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Matrix3 m({5.0f, 8.0f, 4.0f}, {4.0f, 7.0f, 3.125f}, diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index e3734870e..24c0debd2 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -20,8 +20,6 @@ #include "Math/Constants.h" #include "Math/Matrix4.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Matrix4Test: public Corrade::TestSuite::Tester { @@ -294,7 +292,7 @@ void Matrix4Test::debug() { } void Matrix4Test::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, {4.0f, 4.0f, 7.0f, 3.125f}, diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 8b377e915..330a86b04 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -19,8 +19,6 @@ #include "Math/Matrix.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class MatrixTest: public Corrade::TestSuite::Tester { @@ -182,7 +180,7 @@ void MatrixTest::debug() { } void MatrixTest::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Vector4(4.0f, 4.0f, 7.0f, 3.125f), diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp index f69179c37..e3e29e9c3 100644 --- a/src/Math/Test/Point2DTest.cpp +++ b/src/Math/Test/Point2DTest.cpp @@ -19,8 +19,6 @@ #include "Math/Point2D.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Point2DTest: public Corrade::TestSuite::Tester { @@ -53,7 +51,7 @@ void Point2DTest::debug() { } void Point2DTest::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Point2D vec(3.0f, 3.125f, 9.55f); std::string value("3 3.125 9.55"); diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp index 4617b6fbc..9ac4f30c0 100644 --- a/src/Math/Test/Point3DTest.cpp +++ b/src/Math/Test/Point3DTest.cpp @@ -19,8 +19,6 @@ #include "Math/Point3D.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Point3DTest: public Corrade::TestSuite::Tester { @@ -53,7 +51,7 @@ void Point3DTest::debug() { } void Point3DTest::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Point3D vec(3.0f, 3.125f, 9.0f, 9.55f); std::string value("3 3.125 9 9.55"); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 40176ec9f..078efc9db 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -250,7 +250,7 @@ void QuaternionTest::slerp() { void QuaternionTest::debug() { std::ostringstream o; - Corrade::Utility::Debug(&o) << Quaternion({1.0f, 2.0f, 3.0f}, -4.0f); + Debug(&o) << Quaternion({1.0f, 2.0f, 3.0f}, -4.0f); CORRADE_COMPARE(o.str(), "Quaternion({1, 2, 3}, -4)\n"); } diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 78d867199..53d74418c 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -19,8 +19,6 @@ #include "Math/RectangularMatrix.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class RectangularMatrixTest: public Corrade::TestSuite::Tester { @@ -314,7 +312,7 @@ void RectangularMatrixTest::configuration() { Vector4(7.0f, -1.0f, 8.0f, 9.55f)); std::string value("3 4 7 5 4 -1 8 7 8 4 3.125 9.55"); - Configuration c; + Corrade::Utility::Configuration c; c.setValue("matrix", m); CORRADE_COMPARE(c.value("matrix"), value); diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 729281509..4314ee219 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -19,8 +19,6 @@ #include "Math/Vector2.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Vector2Test: public Corrade::TestSuite::Tester { @@ -78,7 +76,7 @@ void Vector2Test::debug() { } void Vector2Test::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Vector2 vec(3.125f, 9.0f); std::string value("3.125 9"); diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index c4a7a2c03..36204c764 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -19,8 +19,6 @@ #include "Math/Vector3.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Vector3Test: public Corrade::TestSuite::Tester { @@ -100,7 +98,7 @@ void Vector3Test::debug() { } void Vector3Test::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Vector3 vec(3.0f, 3.125f, 9.55f); std::string value("3 3.125 9.55"); diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index b1606c230..a5d5953ae 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -19,8 +19,6 @@ #include "Math/Vector4.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class Vector4Test: public Corrade::TestSuite::Tester { @@ -84,7 +82,7 @@ void Vector4Test::debug() { } void Vector4Test::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Vector4 vec(3.0f, 3.125f, 9.0f, 9.55f); std::string value("3 3.125 9 9.55"); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 4f66d1342..2e8a2561f 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -20,8 +20,6 @@ #include "Math/Constants.h" #include "Math/Vector.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Math { namespace Test { class VectorTest: public Corrade::TestSuite::Tester { @@ -269,7 +267,7 @@ void VectorTest::debug() { } void VectorTest::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Vector4 vec(3.0f, 3.125f, 9.0f, 9.55f); std::string value("3 3.125 9 9.55"); diff --git a/src/Resource.h b/src/Resource.h index 7b94a491e..88dbb415b 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -90,7 +90,7 @@ class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { }; /** @debugoperator{Magnum::ResourceKey} */ -inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { +inline Debug operator<<(Debug debug, const ResourceKey& value) { return debug << static_cast&>(value); } diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 959bc7144..d2dfb0526 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -19,8 +19,6 @@ #include "Color.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Test { class ColorTest: public Corrade::TestSuite::Tester { @@ -170,7 +168,7 @@ void ColorTest::debug() { } void ColorTest::configuration() { - Configuration c; + Corrade::Utility::Configuration c; Color3f color3(0.5f, 0.75f, 1.0f); std::string value3("0.5 0.75 1"); diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index 5850c68b5..f436c305c 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -19,8 +19,6 @@ #include "Mesh.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Test { class MeshTest: public Corrade::TestSuite::Tester { @@ -53,7 +51,7 @@ void MeshTest::debugIndexType() { } void MeshTest::configurationPrimitive() { - Configuration c; + Corrade::Utility::Configuration c; c.setValue("primitive", Mesh::Primitive::LineStrip); CORRADE_COMPARE(c.value("primitive"), "LineStrip"); @@ -61,7 +59,7 @@ void MeshTest::configurationPrimitive() { } void MeshTest::configurationIndexType() { - Configuration c; + Corrade::Utility::Configuration c; c.setValue("type", Mesh::IndexType::UnsignedByte); CORRADE_COMPARE(c.value("type"), "UnsignedByte"); diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index fb676037d..25ec60ac4 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -21,8 +21,6 @@ #include "corradeCompatibility.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Test { class ResourceManagerTest: public Corrade::TestSuite::Tester { diff --git a/src/Trade/AbstractImporter.cpp b/src/Trade/AbstractImporter.cpp index 1ccf4da86..9c0419253 100644 --- a/src/Trade/AbstractImporter.cpp +++ b/src/Trade/AbstractImporter.cpp @@ -17,7 +17,7 @@ #include -using namespace Corrade::Utility; +#include "Magnum.h" namespace Magnum { namespace Trade { From 794b94f4fec5cb3e58db934a75243b4c58db1eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 Jan 2013 22:34:41 +0100 Subject: [PATCH 288/567] Doc++ --- src/Text/Font.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/Font.h b/src/Text/Font.h index 0a59f6975..743685649 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -57,7 +57,7 @@ class MAGNUM_TEXT_EXPORT Font { * @brief Create font from memory * @param renderer %Font renderer * @param data %Font data - * @param size %Font data size + * @param dataSize %Font data size * @param size %Font size */ explicit Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, GLfloat size); From 5b3e1a0ea014a0ae1352df3b99b9aca16f0223fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 14:35:12 +0100 Subject: [PATCH 289/567] Math: save one unneeded initialization in Vector::sum(). --- src/Math/Vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 45c3f2af0..58d9e6d1d 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -455,9 +455,9 @@ template class Vector { /** @brief Sum of values in the vector */ T sum() const { - T out(0); + T out(_data[0]); - for(std::size_t i = 0; i != size; ++i) + for(std::size_t i = 1; i != size; ++i) out += _data[i]; return out; From 7b507d0485fd3d7a1eebd882a3360ed06a80c50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 14:36:13 +0100 Subject: [PATCH 290/567] Math: improve Vector::min()/max() tests. --- src/Math/Test/VectorTest.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 2e8a2561f..adaa4f166 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -213,11 +213,13 @@ void VectorTest::product() { } void VectorTest::min() { + /* Check also that initial value isn't initialized to 0 */ CORRADE_COMPARE(Vector3(1.0f, -2.0f, 3.0f).min(), -2.0f); } void VectorTest::max() { - CORRADE_COMPARE(Vector3(1.0f, -2.0f, 3.0f).max(), 3.0f); + /* Check also that initial value isn't initialized to 0 */ + CORRADE_COMPARE(Vector3(-1.0f, -2.0f, -3.0f).max(), -1.0f); } void VectorTest::projected() { From 60f86b8ea0c2bfe1c7015bd68ae84cd29388798c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 14:36:45 +0100 Subject: [PATCH 291/567] Math: added Vector::{min,max}Abs(). --- src/Math/Test/VectorTest.cpp | 16 ++++++++++++++++ src/Math/Vector.h | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index adaa4f166..ba53288cc 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -48,7 +48,9 @@ class VectorTest: public Corrade::TestSuite::Tester { void sum(); void product(); void min(); + void minAbs(); void max(); + void maxAbs(); void projected(); void angle(); @@ -85,7 +87,9 @@ VectorTest::VectorTest() { &VectorTest::sum, &VectorTest::product, &VectorTest::min, + &VectorTest::minAbs, &VectorTest::max, + &VectorTest::maxAbs, &VectorTest::projected, &VectorTest::angle, @@ -217,11 +221,23 @@ void VectorTest::min() { CORRADE_COMPARE(Vector3(1.0f, -2.0f, 3.0f).min(), -2.0f); } +void VectorTest::minAbs() { + /* Check that initial value is absolute and also all others */ + CORRADE_COMPARE(Vector3(-2.0f, 1.0f, 3.0f).minAbs(), 1.0f); + CORRADE_COMPARE(Vector3(1.0f, -2.0f, 3.0f).minAbs(), 1.0f); +} + void VectorTest::max() { /* Check also that initial value isn't initialized to 0 */ CORRADE_COMPARE(Vector3(-1.0f, -2.0f, -3.0f).max(), -1.0f); } +void VectorTest::maxAbs() { + /* Check that initial value is absolute and also all others */ + CORRADE_COMPARE(Vector3(-5.0f, 1.0f, 3.0f).maxAbs(), 5.0f); + CORRADE_COMPARE(Vector3(1.0f, -5.0f, 3.0f).maxAbs(), 5.0f); +} + void VectorTest::projected() { Vector3 line(1.0f, -1.0f, 0.5f); Vector3 projected = Vector3(1.0f, 2.0f, 3.0f).projected(line); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 58d9e6d1d..f05b2ff6f 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -483,6 +483,16 @@ template class Vector { return out; } + /** @brief Minimal absolute value in the vector */ + T minAbs() const { + T out(std::abs(_data[0])); + + for(std::size_t i = 1; i != size; ++i) + out = std::min(out, std::abs(_data[i])); + + return out; + } + /** @brief Maximal value in the vector */ T max() const { T out(_data[0]); @@ -493,6 +503,16 @@ template class Vector { return out; } + /** @brief Maximal absolute value in the vector */ + T maxAbs() const { + T out(std::abs(_data[0])); + + for(std::size_t i = 1; i != size; ++i) + out = std::max(out, std::abs(_data[i])); + + return out; + } + private: /* Implementation for Vector::Vector(const Vector&) */ template inline constexpr explicit Vector(Implementation::Sequence, const Vector& vector): _data{T(vector.data()[sequence])...} {} From 0f547d7e8ed830460349abb4e8e302eaab04f8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 14:37:18 +0100 Subject: [PATCH 292/567] Math: added RectangularMatrix::sum(),product(),{min,max}(),{min,max}Abs(). --- src/Math/RectangularMatrix.h | 60 +++++++++++++++++++++++++ src/Math/Test/RectangularMatrixTest.cpp | 60 +++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 7a0f45101..56c65e66d 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -344,6 +344,66 @@ template class RectangularMatrix { return out; } + /** @brief Sum of values in the matrix */ + T sum() const { + T out(_data[0].sum()); + + for(std::size_t i = 1; i != cols; ++i) + out += _data[i].sum(); + + return out; + } + + /** @brief Product of values in the matrix */ + T product() const { + T out(_data[0].product()); + + for(std::size_t i = 1; i != cols; ++i) + out *= _data[i].product(); + + return out; + } + + /** @brief Minimal value in the matrix */ + T min() const { + T out(_data[0].min()); + + for(std::size_t i = 1; i != cols; ++i) + out = std::min(out, _data[i].min()); + + return out; + } + + /** @brief Minimal absolute value in the matrix */ + T minAbs() const { + T out(_data[0].minAbs()); + + for(std::size_t i = 1; i != cols; ++i) + out = std::min(out, _data[i].minAbs()); + + return out; + } + + /** @brief Maximal value in the matrix */ + T max() const { + T out(_data[0].max()); + + for(std::size_t i = 1; i != cols; ++i) + out = std::max(out, _data[i].max()); + + return out; + } + + /** @brief Maximal absolute value in the matrix */ + T maxAbs() const { + T out(_data[0].maxAbs()); + + for(std::size_t i = 1; i != cols; ++i) + out = std::max(out, _data[i].maxAbs()); + + return out; + } + private: /* Implementation for RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ template inline constexpr explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix): _data{Vector(matrix[sequence])...} {} diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 53d74418c..d8b9adf19 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -42,6 +42,13 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void transposed(); void diagonal(); + void sum(); + void product(); + void min(); + void minAbs(); + void max(); + void maxAbs(); + void debug(); void configuration(); }; @@ -73,6 +80,13 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::transposed, &RectangularMatrixTest::diagonal, + &RectangularMatrixTest::sum, + &RectangularMatrixTest::product, + &RectangularMatrixTest::min, + &RectangularMatrixTest::minAbs, + &RectangularMatrixTest::max, + &RectangularMatrixTest::maxAbs, + &RectangularMatrixTest::debug, &RectangularMatrixTest::configuration); } @@ -284,6 +298,52 @@ void RectangularMatrixTest::diagonal() { CORRADE_COMPARE(b.diagonal(), diagonal); } +void RectangularMatrixTest::sum() { + Matrix2 matrix(Vector2(1.0f, 2.0f), + Vector2(3.0f, 4.0f)); + CORRADE_COMPARE(matrix.sum(), 10.0f); +} + +void RectangularMatrixTest::product() { + Matrix2 matrix(Vector2(1.0f, 2.0f), + Vector2(3.0f, 4.0f)); + CORRADE_COMPARE(matrix.product(), 24.0f); +} + +void RectangularMatrixTest::min() { + /* Check also that initial value isn't initialized to 0 */ + Matrix2 matrix(Vector2(-2.0f, 1.0f), + Vector2(3.0f, 4.0f)); + CORRADE_COMPARE(matrix.min(), -2.0f); +} + +void RectangularMatrixTest::minAbs() { + /* Check that initial value is absolute and also all others */ + Matrix2 a(Vector2(-2.0f, 1.0f), + Vector2(3.0f, 4.0f)); + Matrix2 b(Vector2(3.0f, 4.0f), + Vector2(-2.0f, 1.0f)); + CORRADE_COMPARE(a.minAbs(), 1.0f); + CORRADE_COMPARE(a.minAbs(), 1.0f); +} + +void RectangularMatrixTest::max() { + /* Check also that initial value isn't initialized to 0 */ + Matrix2 matrix(Vector2(-2.0f, -1.0f), + Vector2(-3.0f, -4.0f)); + CORRADE_COMPARE(matrix.max(), -1.0f); +} + +void RectangularMatrixTest::maxAbs() { + /* Check that initial value is absolute and also all others */ + Matrix2 a(Vector2(2.0f, 1.0f), + Vector2(3.0f, -4.0f)); + Matrix2 b(Vector2(3.0f, -4.0f), + Vector2(2.0f, 1.0f)); + CORRADE_COMPARE(a.maxAbs(), 4.0f); + CORRADE_COMPARE(b.maxAbs(), 4.0f); +} + void RectangularMatrixTest::debug() { Matrix3x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Vector4(4.0f, 4.0f, 7.0f, 3.0f), From 2d0aad34b2980c84647ac247bbd74ddca652b9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 14:51:25 +0100 Subject: [PATCH 293/567] Math: SVD algorithm implementation. --- src/Math/Algorithms/CMakeLists.txt | 3 +- src/Math/Algorithms/Svd.h | 328 ++++++++++++++++++++++++ src/Math/Algorithms/Test/CMakeLists.txt | 1 + src/Math/Algorithms/Test/SvdTest.cpp | 97 +++++++ 4 files changed, 428 insertions(+), 1 deletion(-) create mode 100644 src/Math/Algorithms/Svd.h create mode 100644 src/Math/Algorithms/Test/SvdTest.cpp diff --git a/src/Math/Algorithms/CMakeLists.txt b/src/Math/Algorithms/CMakeLists.txt index 0a54d2d3c..66cf6c7e9 100644 --- a/src/Math/Algorithms/CMakeLists.txt +++ b/src/Math/Algorithms/CMakeLists.txt @@ -1,6 +1,7 @@ set(MagnumMathAlgorithms_HEADERS GaussJordan.h - GramSchmidt.h) + GramSchmidt.h + Svd.h) install(FILES ${MagnumMathAlgorithms_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Algorithms) if(BUILD_TESTS) diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h new file mode 100644 index 000000000..7320c513c --- /dev/null +++ b/src/Math/Algorithms/Svd.h @@ -0,0 +1,328 @@ +#ifndef Magnum_Math_Algorithms_Svd_h +#define Magnum_Math_Algorithms_Svd_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::Math::Algorithms::svd() + */ + +#include + +#include "Math/Functions.h" +#include "Math/Matrix.h" + +namespace Magnum { namespace Math { namespace Algorithms { + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +template T pythagoras(T a, T b) { + T absa = std::abs(a); + T absb = std::abs(b); + if(absa > absb) + return absa*std::sqrt(T(1) + Math::pow<2>(absb/absa)); + else if(absb == T(0)) /** @todo epsilon comparison? */ + return T(0); + else + return absb*std::sqrt(T(1) + Math::pow<2>(absa/absb)); +} + +template T smallestDelta(); +template<> inline constexpr float smallestDelta() { return 1.0e-32; } +template<> inline constexpr double smallestDelta() { return 1.0e-64; } + +} +#endif + +/** +@brief Singular Value Decomposition + +Performs Thin SVD on given matrix where @p rows >= @p cols: +@f[ + M = U \Sigma V^* +@f] +Returns first @p cols column vectors of @f$ U @f$, diagonal of @f$ \Sigma @f$ +and non-transposed @f$ V @f$. If the solution doesn't converge, returns +zero matrices. + +Full @f$ U @f$, @f$ \Sigma @f$ matrices and original @f$ M @f$ matrix can be +reconstructed from the values as following: +@code +RectangularMatrix m; + +RectangularMatrix uPart; +Vector wDiagonal; +Matrix v; + +std::tie(uPart, wDiagonal, v) = Math::Algorithms::svd(m); + +// Extend U +Matrix u(Matrix::Zero); +for(std::size_t i = 0; i != rows; ++i) + u[i] = uPart[i]; + +// Diagonal W +RectangularMatrix w = + RectangularMatrix::fromDiagonal(wDiagonal); + +// u*w*v.transposed() == m +@endcode + +Implementation based on *Golub, G. H.; Reinsch, C. (1970). "Singular value +decomposition and least squares solutions"*. +*/ +/* The matrix is passed by value because it is changed inside */ +template std::tuple, Vector, Matrix> svd(RectangularMatrix m) { + static_assert(rows >= cols, "Unsupported matrix aspect ratio"); + static_assert(T(1)+MathTypeTraits::epsilon() > T(1), "Epsilon too small"); + constexpr T tol = Implementation::smallestDelta()/MathTypeTraits::epsilon(); + static_assert(tol > T(0), "Tol too small"); + constexpr std::size_t maxIterations = 50; + + Matrix v(Matrix::Zero); + Vector e, q; + + /* Householder's reduction to bidiagonal form */ + T g = T(0); + T epsilonX = T(0); + for(std::size_t i = 0; i != cols; ++i) { + const std::size_t l = i+1; + + e[i] = g; + T s1 = T(0); + for(std::size_t j = i; j != rows; ++j) + s1 += Math::pow<2>(m[i][j]); + if(s1 > tol) { + const T f = m[i][i]; + g = (f < T(0) ? std::sqrt(s1) : -std::sqrt(s1)); + const T h = f*g - s1; + m[i][i] = f - g; + + for(std::size_t j = l; j != cols; ++j) { + T s = T(0); + for(std::size_t k = i; k != rows; ++k) + s += m[i][k]*m[j][k]; + const T f = s/h; + for(std::size_t k = i; k != rows; ++k) + m[j][k] += f*m[i][k]; + } + } else g = T(0); + + q[i] = g; + T s2 = T(0); + for(std::size_t j = l; j != cols; ++j) + s2 += Math::pow<2>(m[j][i]); + if(s2 > tol) { + const T f = m[i+1][i]; + g = (f < T(0) ? std::sqrt(s2) : -std::sqrt(s2)); + const T h = f*g - s2; + m[i+1][i] = f - g; + + for(std::size_t j = l; j != cols; ++j) + e[j] = m[j][i]/h; + + for(std::size_t j = l; j != rows; ++j) { + T s = T(0); + for(std::size_t k = l; k != cols; ++k) + s += m[k][j]*m[k][i]; + for(std::size_t k = l; k != cols; ++k) + m[k][j] += s*e[k]; + } + + } else g = T(0); + + const T y = std::abs(q[i]) + std::abs(e[i]); + if(y > epsilonX) epsilonX = y; + } + + /* Accumulation of right hand transformations */ + for(std::size_t l = cols; l != 0; --l) { + const std::size_t i = l-1; + + if(g != T(0)) { /** @todo epsilon check? */ + const T h = g*m[i+1][i]; + + for(std::size_t j = l; j != cols; ++j) + v[i][j] = m[j][i]/h; + + for(std::size_t j = l; j != cols; ++j) { + T s = T(0); + for(std::size_t k = l; k != cols; ++k) + s += m[k][i]*v[j][k]; + for(std::size_t k = l; k != cols; ++k) + v[j][k] += s*v[i][k]; + } + } + + for(std::size_t j = l; j != cols; ++j) + v[j][i] = v[i][j] = T(0); + + v[i][i] = T(1); + g = e[i]; + } + + /* Accumulation of left hand transformations */ + for(std::size_t l = cols; l != 0; --l) { + const std::size_t i = l-1; + + for(std::size_t j = l; j != cols; ++j) + m[j][i] = T(0); + + const T d = q[i]; + if(d != T(0)) { /** @todo epsilon check? */ + const T h = m[i][i]*d; + for(std::size_t j = l; j != cols; ++j) { + T s = T(0); + for(std::size_t k = l; k != rows; ++k) + s += m[i][k]*m[j][k]; + const T f = s/h; + for(std::size_t k = i; k != rows; ++k) + m[j][k] += f*m[i][k]; + } + + for(std::size_t j = i; j != rows; ++j) + m[i][j] /= d; + + } else for(std::size_t j = i; j != rows; ++j) + m[i][j] = T(0); + + m[i][i] += T(1); + } + + /* Diagonalization of the bidiagonal form */ + const T epsilon = MathTypeTraits::epsilon()*epsilonX; + for(std::size_t k2 = cols; k2 != 0; --k2) { + const std::size_t k = k2 - 1; + + for(std::size_t iteration = 0; iteration != maxIterations; ++iteration) { + /* Test for splitting */ + bool doCancellation = true; + std::size_t l = 0; + for(std::size_t l2 = k2; l2 != 0; --l2) { + l = l2 - 1; + if(std::abs(e[l]) <= epsilon) { + doCancellation = false; + break; + } else if(std::abs(q[l-1]) <= epsilon) { + break; + } + } + + /* Cancellation */ + if(doCancellation) { + const std::size_t l1 = l - 1; + T c = T(0); + T s = T(1); + for(std::size_t i = l; i != k+1; ++i) { + CORRADE_INTERNAL_ASSERT(i <= k+1); + + const T f = s*e[i]; + e[i] = c*e[i]; + if(std::abs(f) <= epsilon) break; + + const T g = q[i]; + const T h = Implementation::pythagoras(f, g); + q[i] = h; + c = g/h; + s = -f/h; + + const Vector a = m[l1]; + const Vector b = m[i]; + m[l1] = a*c+b*s; + m[i] = -a*s+b*c; + } + } + + /* Test for convergence */ + const T z = q[k]; + if(l == k) { + /* Invert to non-negative */ + if(z < T(0)) { + q[k] = -z; + v[k] = -v[k]; + } + + break; + + /* Exceeded iteration count, done */ + } else if(iteration >= maxIterations-1) { + Corrade::Utility::Error() << "Magnum::Math::Algorithms::svd(): no convergence"; + return std::make_tuple(RectangularMatrix(), Vector(), Matrix(Matrix::Zero)); + } + + /* Shift from bottom 2x2 minor */ + const T y = q[k-1]; + const T h = e[k]; + const T d = e[k-1]; + T x = q[l]; + T f = ((y - z)*(y + z) + (d - h)*(d + h))/(T(2)*h*y); + const T b = Implementation::pythagoras(f, T(1)); + if(f < T(0)) + f = ((x - z)*(x + z) + h*(y/(f - b) - h))/x; + else + f = ((x - z)*(x + z) + h*(y/(f + b) - h))/x; + + /* Next QR transformation */ + /** @todo isn't this extractable elsewhere? */ + T c = T(1); + T s = T(1); + for(std::size_t i = l+1; i != k+1; ++i) { + CORRADE_INTERNAL_ASSERT(i <= k+1); + + const T g1 = c*e[i]; + const T h1 = s*e[i]; + const T y1 = q[i]; + + const T z1 = Implementation::pythagoras(f, h1); + e[i-1] = z1; + c = f/z1; + s = h1/z1; + f = x*c + g1*s; + + const T g2 = -x*s + g1*c; + const T h2 = y1*s; + const T y2 = y1*c; + + const Vector a1 = v[i-1]; + const Vector b1 = v[i]; + v[i-1] = a1*c+b1*s; + v[i] = -a1*s+b1*c; + + const T z2 = Implementation::pythagoras(f, h2); + q[i-1] = z2; + c = f/z2; + s = h2/z2; + f = c*g2 + s*y2; + x = -s*g2 + c*y2; + + const Vector a2 = m[i-1]; + const Vector b2 = m[i]; + m[i-1] = a2*c+b2*s; + m[i] = -a2*s+b2*c; + } + + e[l] = T(0); + e[k] = f; + q[k] = x; + } + } + + return std::make_tuple(m, q, v); +} + +}}} + +#endif diff --git a/src/Math/Algorithms/Test/CMakeLists.txt b/src/Math/Algorithms/Test/CMakeLists.txt index e7e6975e0..15166b9b7 100644 --- a/src/Math/Algorithms/Test/CMakeLists.txt +++ b/src/Math/Algorithms/Test/CMakeLists.txt @@ -1,2 +1,3 @@ corrade_add_test(MathAlgorithmsGaussJordanTest GaussJordanTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathAlgorithmsGramSchmidtTest GramSchmidtTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathAlgorithmsSvdTest SvdTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Algorithms/Test/SvdTest.cpp b/src/Math/Algorithms/Test/SvdTest.cpp new file mode 100644 index 000000000..9c0a55560 --- /dev/null +++ b/src/Math/Algorithms/Test/SvdTest.cpp @@ -0,0 +1,97 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Algorithms/Svd.h" + +namespace Magnum { namespace Math { namespace Algorithms { namespace Test { + +class SvdTest: public Corrade::TestSuite::Tester { + public: + explicit SvdTest(); + + void testDouble(); + void testFloat(); +}; + +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; + +typedef RectangularMatrix<5, 8, float> Matrix5x8f; +typedef Matrix<8, float> Matrix8f; +typedef Matrix<5, float> Matrix5f; +typedef Vector<8, float> Vector8f; +typedef Vector<5, float> Vector5f; + +constexpr static Matrix5x8d a( + 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); + +SvdTest::SvdTest() { + addTests(&SvdTest::testDouble, + &SvdTest::testFloat); +} + +void SvdTest::testDouble() { + Matrix5x8d u; + Vector5d w; + Matrix5d v; + std::tie(u, w, v) = Algorithms::svd(a); + + /* 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); + + /* 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); +} + +void SvdTest::testFloat() { + Matrix5x8f u; + Vector5f w; + Matrix5f v; + std::tie(u, w, v) = Algorithms::svd(Matrix5x8f(a)); + + /* 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); + + /* 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_TEST_MAIN(Magnum::Math::Algorithms::Test::SvdTest) From f7a86410819eda61449666e200d24e21666681ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 16:20:23 +0100 Subject: [PATCH 294/567] Math: fixed one-argument Vector constructors. It is now possible to implicitly create one-element Vector and also explicitly fill more-element Vector with one value without any ambiguous overload conflicts: Vector<1, int> a1 = 1; // calls implicit constructor //Vector<3, int> a3 = 1; // error! Vector<1, int> b1(1); // still calls the implicit constructor, the // explicit is disabled for one-element vector Vector<3, int> b3(1); // calls the explicit "filling" constructor, // the implicit is disabled for only one argument The downside of this is that now specifying improper element count in constructor doesn't lead to static_assert with human readable error, but rather cryptic "no match" error. --- src/Math/Test/VectorTest.cpp | 14 +++++++++++--- src/Math/Vector.h | 17 ++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index ba53288cc..66ade42a7 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -29,6 +29,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void constructFromData(); void constructDefault(); void constructOneValue(); + void constructOneComponent(); void constructConversion(); void data(); @@ -68,6 +69,7 @@ VectorTest::VectorTest() { addTests(&VectorTest::constructFromData, &VectorTest::constructDefault, &VectorTest::constructOneValue, + &VectorTest::constructOneComponent, &VectorTest::constructConversion, &VectorTest::data, @@ -109,9 +111,15 @@ void VectorTest::constructDefault() { } void VectorTest::constructOneValue() { - CORRADE_EXPECT_FAIL("Constructing Vector from one value is broken."); - CORRADE_VERIFY(false); -// CORRADE_COMPARE(Vector4(7.25f), Vector4(7.25f, 7.25f, 7.25f, 7.25f)); + CORRADE_COMPARE(Vector4(7.25f), Vector4(7.25f, 7.25f, 7.25f, 7.25f)); +} + +void VectorTest::constructOneComponent() { + typedef Vector<1, float> Vector1; + + /* Implicit constructor must work */ + Vector1 vec = 1; + CORRADE_COMPARE(vec, Vector1(1)); } void VectorTest::constructConversion() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index f05b2ff6f..97568a4cf 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -135,18 +135,17 @@ template class Vector { * @param first First value * @param next Next values */ - template inline constexpr /*implicit*/ Vector(T first, U... next): _data{first, next...} { - static_assert(sizeof...(next)+1 == size, "Improper number of arguments passed to Vector constructor"); - } + #ifdef DOXYGEN_GENERATING_OUTPUT + template inline constexpr /*implicit*/ Vector(T first, U... next); + #else + template::type> inline constexpr /*implicit*/ Vector(T first, U... next): _data{first, next...} {} + #endif - /** - * @brief Construct vector with one value for all fields - * @todo Fix this to be actually usable (not only in subclasses) - */ + /** @brief Construct vector with one value for all fields */ #ifdef DOXYGEN_GENERATING_OUTPUT - inline explicit Vector(T value) { + inline explicit Vector(T value); #else - template inline explicit Vector(typename std::enable_if::value && size != 1, U>::type value) { + template::value && size != 1, T>::type> inline explicit Vector(U value) { #endif for(std::size_t i = 0; i != size; ++i) _data[i] = value; From a39fa198c8c3fcce8f4d1e57be1dfe50a755f7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 17:03:41 +0100 Subject: [PATCH 295/567] Math: removed inappropriate `constexpr` from operator!=() Method calling another method that will possibly be done via SIMD in the future cannot be constexpr. --- src/Math/RectangularMatrix.h | 2 +- src/Math/Vector.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 56c65e66d..b7a2b846e 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -161,7 +161,7 @@ template class RectangularMatrix { * @see Vector::operator<(), Vector::operator<=(), Vector::operator>=(), * Vector::operator>() */ - inline constexpr bool operator!=(const RectangularMatrix& other) const { + inline bool operator!=(const RectangularMatrix& other) const { return !operator==(other); } diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 97568a4cf..4be582d1f 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -197,7 +197,7 @@ template class Vector { } /** @brief Non-equality comparison */ - inline constexpr bool operator!=(const Vector& other) const { + inline bool operator!=(const Vector& other) const { return !operator==(other); } From 0f938003df2ca8398e6b4c43ba3b8dd535ca0c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 17:06:02 +0100 Subject: [PATCH 296/567] Math: constexpr implementation for "filling" Vector constructor. Also removed constexpr alternatives to it in Vector2, Vector3 and Vector4 as they are now not needed. --- src/Math/Vector.h | 10 ++++++---- src/Math/Vector2.h | 2 +- src/Math/Vector3.h | 2 +- src/Math/Vector4.h | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 4be582d1f..ee5b1c30b 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -43,6 +43,8 @@ namespace Implementation { template struct GenerateSequence<0, sequence...> { typedef Sequence Type; }; + + template inline constexpr T repeat(T value, std::size_t) { return value; } } #endif @@ -145,11 +147,8 @@ template class Vector { #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit Vector(T value); #else - template::value && size != 1, T>::type> inline explicit Vector(U value) { + template::value && size != 1, T>::type> inline constexpr explicit Vector(U value): Vector(typename Implementation::GenerateSequence::Type(), value) {} #endif - for(std::size_t i = 0; i != size; ++i) - _data[i] = value; - } /** * @brief Construct vector from another of different type @@ -516,6 +515,9 @@ template class Vector { /* Implementation for Vector::Vector(const Vector&) */ template inline constexpr explicit Vector(Implementation::Sequence, const Vector& vector): _data{T(vector.data()[sequence])...} {} + /* Implementation for Vector::Vector(U) */ + template inline constexpr explicit Vector(Implementation::Sequence, T value): _data{Implementation::repeat(value, sequence)...} {} + T _data[size]; }; diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 0cf539a8c..2fa7116c2 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -75,7 +75,7 @@ template class Vector2: public Vector<2, T> { inline constexpr /*implicit*/ Vector2() {} /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector2(T value): Vector<2, T>(value, value) {} + inline constexpr explicit Vector2(T value): Vector<2, T>(value) {} /** * @brief Constructor diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 5a7a2354d..a2ad90872 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -108,7 +108,7 @@ template class Vector3: public Vector<3, T> { inline constexpr /*implicit*/ Vector3() {} /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector3(T value): Vector<3, T>(value, value, value) {} + inline constexpr explicit Vector3(T value): Vector<3, T>(value) {} /** * @brief Constructor diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 1c0963f5f..329a96d94 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -38,7 +38,7 @@ template class Vector4: public Vector<4, T> { inline constexpr /*implicit*/ Vector4() {} /** @copydoc Vector::Vector(T) */ - inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {} + inline constexpr explicit Vector4(T value): Vector<4, T>(value) {} /** * @brief Constructor From bbc98746e44bf6badc010a24a7cbaae5984fab25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 17:07:54 +0100 Subject: [PATCH 297/567] Math: properly testing all constexpr methods in Vector. Fixed conversion constructor, as pointer chasings are not allowed in constexpr functions. --- src/Math/Test/VectorTest.cpp | 32 ++++++++++++++++++++++++++++++++ src/Math/Vector.h | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 66ade42a7..a07b3d345 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -33,6 +33,8 @@ class VectorTest: public Corrade::TestSuite::Tester { void constructConversion(); void data(); + void constExpressions(); + void negative(); void addSubtract(); void multiplyDivide(); @@ -73,6 +75,8 @@ VectorTest::VectorTest() { &VectorTest::constructConversion, &VectorTest::data, + &VectorTest::constExpressions, + &VectorTest::negative, &VectorTest::addSubtract, &VectorTest::multiplyDivide, @@ -141,6 +145,34 @@ void VectorTest::data() { CORRADE_COMPARE(vector, Vector4(4.0f, 5.0f, 1.0f, 1.5f)); } +void VectorTest::constExpressions() { + /* Default constructor */ + constexpr Vector4 a; + CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); + + /* Value constructor */ + constexpr Vector4 b(1.0f, 3.5f, 4.0f, -2.7f); + CORRADE_COMPARE(b, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); + + /* One-value constructor */ + constexpr Vector4 c(7.0f); + CORRADE_COMPARE(c, Vector4(7.0f, 7.0f, 7.0f, 7.0f)); + + /* Conversion constructor */ + constexpr Vector4i d(b); + CORRADE_COMPARE(d, Vector4i(1, 3, 4, -2)); + + /* Copy constructor */ + constexpr Vector4 e(b); + CORRADE_COMPARE(e, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); + + /* Data access, pointer chasings, i.e. *(b.data()[3]), are not possible */ + constexpr float f = b[3]; + constexpr float g = *b.data(); + CORRADE_COMPARE(f, -2.7f); + CORRADE_COMPARE(g, 1.0f); +} + void VectorTest::compare() { CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + MathTypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index ee5b1c30b..11f2a0b54 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -513,7 +513,7 @@ template class Vector { private: /* Implementation for Vector::Vector(const Vector&) */ - template inline constexpr explicit Vector(Implementation::Sequence, const Vector& vector): _data{T(vector.data()[sequence])...} {} + template inline constexpr explicit Vector(Implementation::Sequence, const Vector& vector): _data{T(vector._data[sequence])...} {} /* Implementation for Vector::Vector(U) */ template inline constexpr explicit Vector(Implementation::Sequence, T value): _data{Implementation::repeat(value, sequence)...} {} From bbea562a6c4bb43d8ee13f9d7509ee6a273be55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 17:36:18 +0100 Subject: [PATCH 298/567] Math: properly testing all constexpr methods in RectangularMatrix. Fixed data() method, it doesn't need to use reinterpret_cast. --- src/Math/RectangularMatrix.h | 6 ++-- src/Math/Test/RectangularMatrixTest.cpp | 42 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index b7a2b846e..56a6acc6b 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -23,8 +23,6 @@ namespace Magnum { namespace Math { -/** @todo Properly test all constexpr */ - /** @brief Rectangular matrix @tparam cols Column count @@ -125,8 +123,8 @@ template class RectangularMatrix { * * @see operator[] */ - inline T* data() { return reinterpret_cast(_data); } - inline constexpr const T* data() const { return reinterpret_cast(_data); } /**< @overload */ + inline T* data() { return _data[0].data(); } + inline constexpr const T* data() const { return _data[0].data(); } /**< @overload */ /** * @brief %Matrix column diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index d8b9adf19..95aefcc8b 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -32,6 +32,8 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void constructFromDiagonal(); void data(); + void constExpressions(); + void compare(); void negative(); @@ -70,6 +72,8 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::constructFromDiagonal, &RectangularMatrixTest::data, + &RectangularMatrixTest::constExpressions, + &RectangularMatrixTest::compare, &RectangularMatrixTest::negative, @@ -174,6 +178,44 @@ void RectangularMatrixTest::data() { CORRADE_COMPARE(m, expected); } +void RectangularMatrixTest::constExpressions() { + /* Default constructor */ + constexpr Matrix3x4 a; + CORRADE_COMPARE(a, Matrix3x4(Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f))); + + /* Value constructor */ + constexpr Matrix3x4 b(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.5f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.7f, 8.0f, 0.0f)); + CORRADE_COMPARE(b, Matrix3x4(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.5f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.7f, 8.0f, 0.0f))); + + /* Conversion constructor */ + typedef RectangularMatrix<3, 4, std::int32_t> Matrix3x4i; + typedef Vector<4, std::int32_t> Vector4i; + constexpr Matrix3x4i c(b); + CORRADE_COMPARE(c, Matrix3x4i(Vector4i(3, 5, 8, 4), + Vector4i(4, 4, 7, 3), + Vector4i(7, -1, 8, 0))); + + /* Copy constructor */ + constexpr Matrix3x4 d(b); + CORRADE_COMPARE(d, Matrix3x4(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + Vector4(4.5f, 4.0f, 7.0f, 3.0f), + Vector4(7.0f, -1.7f, 8.0f, 0.0f))); + + /* Data access, pointer chasings, i.e. *(b.data()[1]), are not possible */ + constexpr Vector4 e = b[2]; + constexpr float f = b[1][2]; + constexpr float g = *b.data(); + CORRADE_COMPARE(e, Vector4(7.0f, -1.7f, 8.0f, 0.0f)); + CORRADE_COMPARE(f, 7.0f); + CORRADE_COMPARE(g, 3.0f); +} + void RectangularMatrixTest::compare() { Matrix2 a(Vector2(1.0f, -3.0f), Vector2(5.0f, -10.0f)); From f517a000edd8c965c735e26f49d2859d29269efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 17:16:07 +0100 Subject: [PATCH 299/567] Math: follow Vector changes in BoolVector. Added constexpr "filling" constructor, updated tests, added constexpr test. --- src/Math/BoolVector.h | 50 +++++++++++++++++++++++--------- src/Math/Test/BoolVectorTest.cpp | 41 ++++++++++++++++++++++++-- src/Math/Vector.h | 16 ---------- 3 files changed, 75 insertions(+), 32 deletions(-) diff --git a/src/Math/BoolVector.h b/src/Math/BoolVector.h index eb472a64f..a5ac589d4 100644 --- a/src/Math/BoolVector.h +++ b/src/Math/BoolVector.h @@ -24,6 +24,22 @@ namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct Sequence {}; + + /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ + template struct GenerateSequence: + GenerateSequence {}; + + template struct GenerateSequence<0, sequence...> { + typedef Sequence Type; + }; + + template inline constexpr T repeat(T value, std::size_t) { return value; } +} +#endif + /** @brief %Vector storing boolean values @tparam size Bit count @@ -40,23 +56,26 @@ template class BoolVector { static const std::size_t Size = size; /**< @brief %Vector size */ static const std::size_t DataSize = (size-1)/8+1; /**< @brief %Vector storage size */ - /** @brief Construct boolean with one value for all elements */ - inline static BoolVector from(bool value) { - BoolVector out; - - for(std::size_t i = 0; i != size; ++i) - out._data[i] = (value ? FullSegmentMask : 0); - - return out; - } - /** @brief Construct zero-filled boolean vector */ inline constexpr BoolVector(): _data() {} - /** @brief Construct boolean vector from given values */ - template inline constexpr BoolVector(std::uint8_t first, U... next): _data{first, std::uint8_t(next)...} { - static_assert(sizeof...(next)+1 == DataSize, "Improper number of arguments passed to BoolVector constructor"); - } + /** + * @brief Construct boolean vector from segment values + * @param first Value for first 8bit segment + * @param next Values for next Bbit segments + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + template inline constexpr /*implicit*/ BoolVector(std::uint8_t first, T... next); + #else + template::type> inline constexpr /*implicit*/ BoolVector(std::uint8_t first, T... next): _data{first, std::uint8_t(next)...} {} + #endif + + /** @brief Construct boolean vector with one value for all fields */ + #ifdef DOXYGEN_GENERATING_OUTPUT + inline explicit BoolVector(T value); + #else + template::value && size != 1, bool>::type> inline constexpr explicit BoolVector(T value): BoolVector(typename Implementation::GenerateSequence::Type(), value ? FullSegmentMask : 0) {} + #endif /** @brief Copy constructor */ inline constexpr BoolVector(const BoolVector&) = default; @@ -211,6 +230,9 @@ template class BoolVector { LastSegmentMask = (1 << size%8) - 1 }; + /* Implementation for Vector::Vector(U) */ + template inline constexpr explicit BoolVector(Implementation::Sequence, std::uint8_t value): _data{Implementation::repeat(value, sequence)...} {} + std::uint8_t _data[(size-1)/8+1]; }; diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp index f2b1c4e75..5729c9415 100644 --- a/src/Math/Test/BoolVectorTest.cpp +++ b/src/Math/Test/BoolVectorTest.cpp @@ -26,8 +26,11 @@ class BoolVectorTest: public Corrade::TestSuite::Tester { void constructDefault(); void constructOneValue(); + void constructOneElement(); void data(); + void constExpressions(); + void compare(); void compareUndefined(); void all(); @@ -49,8 +52,11 @@ typedef Math::BoolVector<19> BoolVector19; BoolVectorTest::BoolVectorTest() { addTests(&BoolVectorTest::constructDefault, &BoolVectorTest::constructOneValue, + &BoolVectorTest::constructOneElement, &BoolVectorTest::data, + &BoolVectorTest::constExpressions, + &BoolVectorTest::compare, &BoolVectorTest::compareUndefined, &BoolVectorTest::all, @@ -68,8 +74,15 @@ void BoolVectorTest::constructDefault() { } void BoolVectorTest::constructOneValue() { - CORRADE_COMPARE(BoolVector19::from(false), BoolVector19(0x00, 0x00, 0x00)); - CORRADE_COMPARE(BoolVector19::from(true), BoolVector19(0xff, 0xff, 0x07)); + CORRADE_COMPARE(BoolVector19(false), BoolVector19(0x00, 0x00, 0x00)); + CORRADE_COMPARE(BoolVector19(true), BoolVector19(0xff, 0xff, 0x07)); +} + +void BoolVectorTest::constructOneElement() { + typedef BoolVector<1> BoolVector1; + + BoolVector1 a = 0x01; + CORRADE_COMPARE(a, BoolVector1(0x01)); } void BoolVectorTest::data() { @@ -89,6 +102,30 @@ void BoolVectorTest::data() { CORRADE_COMPARE(a, BoolVector19(0x08, 0x83, 0x04)); } +void BoolVectorTest::constExpressions() { + /* Default constructor */ + constexpr BoolVector19 a; + CORRADE_COMPARE(a, BoolVector19(0x00, 0x00, 0x00)); + + /* Value constructor */ + constexpr BoolVector19 b(0xa5, 0x5f, 0x07); + CORRADE_COMPARE(b, BoolVector19(0xa5, 0x5f, 0x07)); + + /* One-value constructor */ + constexpr BoolVector19 c(true); + CORRADE_COMPARE(c, BoolVector19(0xff, 0xff, 0x07)); + + /* Copy constructor */ + constexpr BoolVector19 d(b); + CORRADE_COMPARE(d, BoolVector19(0xa5, 0x5f, 0x07)); + + /* Data access, pointer chasings, i.e. *(b.data()[3]), are not possible */ + constexpr bool e = b[2]; + constexpr std::uint8_t f = *b.data(); + CORRADE_COMPARE(e, true); + CORRADE_COMPARE(f, 0xa5); +} + void BoolVectorTest::compare() { BoolVector19 a(0xa5, 0x5f, 0x07); CORRADE_VERIFY(a == a); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 11f2a0b54..6bf8eadb4 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -32,22 +32,6 @@ namespace Magnum { namespace Math { -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - template struct Sequence {}; - - /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ - template struct GenerateSequence: - GenerateSequence {}; - - template struct GenerateSequence<0, sequence...> { - typedef Sequence Type; - }; - - template inline constexpr T repeat(T value, std::size_t) { return value; } -} -#endif - /** @brief %Vector @tparam size %Vector size From f2599778f3767a985076c538cc4cf17f2095aa4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Jan 2013 17:44:38 +0100 Subject: [PATCH 300/567] Primitives: fixed compilation error. Caused by recent change of Point*D constructor to explicit. --- src/Primitives/Icosphere.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 79f5583e3..9377eb68e 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -64,7 +64,8 @@ template class Icosphere { }); MeshTools::clean(*indices(), *normals(0)); - positions(0)->assign(normals(0)->begin(), normals(0)->end()); + positions(0)->reserve(normals(0)->size()); + for(auto i: *normals(0)) positions(0)->push_back(Point3D(i)); } }; From 0885320603fb3139fbfd8f8094ed7895980d4d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 31 Jan 2013 19:18:34 +0100 Subject: [PATCH 301/567] Math: vector dot product in terms of component-wise multiply and sum. Less SIMD alternatives to implement in the future. --- src/Math/Vector.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 6bf8eadb4..6744acb13 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -73,13 +73,8 @@ template class Vector { * @f] * @see dot() const */ - static T dot(const Vector& a, const Vector& b) { - T out(0); - - for(std::size_t i = 0; i != size; ++i) - out += a[i]*b[i]; - - return out; + inline static T dot(const Vector& a, const Vector& b) { + return (a*b).sum(); } /** From 2269919a9915e3d5fdfe65b2e4ae21483fdfd73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Feb 2013 21:22:13 +0100 Subject: [PATCH 302/567] Physics: specify AABB by its minimal and maximal dimensions. Center + size was confusing for entering and also with bad performance for computing collisions. --- .../Implementation/AxisAlignedBoxRenderer.cpp | 4 +- src/Physics/AxisAlignedBox.cpp | 4 +- src/Physics/AxisAlignedBox.h | 40 +++++++++---------- src/Physics/Test/AxisAlignedBoxTest.cpp | 10 ++--- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 09d4af8b7..87b7ab1b6 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -27,8 +27,8 @@ template AxisAlignedBoxRenderer::AxisAligne template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the box is 2x2(x2) */ typename DimensionTraits::MatrixType transformation = - DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* - DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()/2); + DimensionTraits::MatrixType::translation((axisAlignedBox.transformedMin()+axisAlignedBox.transformedMax())/2)* + DimensionTraits::MatrixType::scaling((axisAlignedBox.transformedMax()-axisAlignedBox.transformedMin())/2); this->shader->setTransformationProjectionMatrix(projectionMatrix*transformation) ->setColor(options->color()) ->use(); diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 9c2f004cf..026dd62c5 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -21,8 +21,8 @@ namespace Magnum { namespace Physics { template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { - _transformedPosition = (matrix*typename DimensionTraits::PointType(_position)).vector(); - _transformedSize = matrix.rotationScaling()*_size; + _transformedMin = (matrix*typename DimensionTraits::PointType(_min)).vector(); + _transformedMax = (matrix*typename DimensionTraits::PointType(_max)).vector(); } template class AxisAlignedBox<2>; diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index ed642b966..1f92ecf36 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Physics { template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ - inline explicit AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} + inline explicit AxisAlignedBox(const typename DimensionTraits::VectorType& min, const typename DimensionTraits::VectorType& max): _min(min), _max(max), _transformedMin(min), _transformedMax(max) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::AxisAlignedBox; @@ -42,37 +42,37 @@ template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: pu void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; - /** @brief Position */ - inline typename DimensionTraits::VectorType position() const { - return _position; + /** @brief Minimal coordinates */ + inline typename DimensionTraits::VectorType min() const { + return _min; } - /** @brief Set position */ - inline void setPosition(const typename DimensionTraits::VectorType& position) { - _position = position; + /** @brief Set minimal coordinates */ + inline void setMin(const typename DimensionTraits::VectorType& min) { + _min = min; } - /** @brief Size */ - inline typename DimensionTraits::VectorType size() const { return _size; } + /** @brief Maximal coordinates */ + inline typename DimensionTraits::VectorType max() const { return _max; } - /** @brief Set size */ - inline void setSize(const typename DimensionTraits::VectorType& size) { - _size = size; + /** @brief Set maximal coordinates */ + inline void setMax(const typename DimensionTraits::VectorType& max) { + _max = max; } - /** @brief Transformed position */ - inline typename DimensionTraits::VectorType transformedPosition() const { - return _transformedPosition; + /** @brief Transformed minimal coordinates */ + inline typename DimensionTraits::VectorType transformedMin() const { + return _transformedMin; } - /** @brief Transformed size */ - inline typename DimensionTraits::VectorType transformedSize() const { - return _transformedSize; + /** @brief Transformed maximal coordinates */ + inline typename DimensionTraits::VectorType transformedMax() const { + return _transformedMax; } private: - typename DimensionTraits::VectorType _position, _transformedPosition, - _size, _transformedSize; + typename DimensionTraits::VectorType _min, _max, + _transformedMin, _transformedMax; }; /** @brief Two-dimensional axis-aligned box */ diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index a9554d30d..3ef7f3827 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -35,13 +35,9 @@ AxisAlignedBoxTest::AxisAlignedBoxTest() { void AxisAlignedBoxTest::applyTransformation() { Physics::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); - box.applyTransformationMatrix(Matrix4::scaling({2.0f, -1.0f, 1.5f})); - CORRADE_COMPARE(box.transformedPosition(), Vector3(-2.0f, 2.0f, -4.5f)); - CORRADE_COMPARE(box.transformedSize(), Vector3(2.0f, -2.0f, 4.5f)); - - box.applyTransformationMatrix(Matrix4::translation(Vector3(1.0f))*Matrix4::rotation(deg(90.0f), Vector3::xAxis())); - CORRADE_COMPARE(box.transformedPosition(), Vector3(0.0f, 4.0f, -1.0f)); - CORRADE_COMPARE(box.transformedSize(), Vector3(1.0f, -3.0f, 2.0f)); + box.applyTransformationMatrix(Matrix4::translation(Vector3(1.0f))*Matrix4::scaling({2.0f, -1.0f, 1.5f})); + CORRADE_COMPARE(box.transformedMin(), Vector3(-1.0f, 3.0f, -3.5f)); + CORRADE_COMPARE(box.transformedMax(), Vector3(3.0f, -1.0f, 5.5f)); } }}} From 792892bbeddd05537c0eb44d0e3ede0d900e666e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Feb 2013 21:23:35 +0100 Subject: [PATCH 303/567] Physics: AxisAlignedBox / Point collision. --- src/Physics/AxisAlignedBox.cpp | 13 +++++++++++++ src/Physics/AxisAlignedBox.h | 11 ++++++++++- src/Physics/Test/AxisAlignedBoxTest.cpp | 22 ++++++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 026dd62c5..abce0aa3e 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -17,6 +17,7 @@ #include "Math/Matrix3.h" #include "Math/Matrix4.h" +#include "Physics/Point.h" namespace Magnum { namespace Physics { @@ -25,6 +26,18 @@ template void AxisAlignedBox::applyTransfor _transformedMax = (matrix*typename DimensionTraits::PointType(_max)).vector(); } +template bool AxisAlignedBox::collides(const AbstractShape* other) const { + if(other->type() == AbstractShape::Type::Point) + return *this % *static_cast*>(other); + + return AbstractShape::collides(other); +} + +template bool AxisAlignedBox::operator%(const Point& other) const { + return (other.transformedPosition() >= _transformedMin).all() && + (other.transformedPosition() < _transformedMax).all(); +} + template class AxisAlignedBox<2>; template class AxisAlignedBox<3>; diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 1f92ecf36..2b6eb7f4a 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -20,7 +20,8 @@ */ #include "Math/Vector3.h" -#include "AbstractShape.h" +#include "Physics/AbstractShape.h" +#include "Physics/Physics.h" #include "corradeCompatibility.h" @@ -42,6 +43,8 @@ template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: pu void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; + bool collides(const AbstractShape* other) const override; + /** @brief Minimal coordinates */ inline typename DimensionTraits::VectorType min() const { return _min; @@ -70,6 +73,9 @@ template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: pu return _transformedMax; } + /** @brief Collision with point */ + bool operator%(const Point& other) const; + private: typename DimensionTraits::VectorType _min, _max, _transformedMin, _transformedMax; @@ -81,6 +87,9 @@ typedef AxisAlignedBox<2> AxisAlignedBox2D; /** @brief Three-dimensional axis-aligned box */ typedef AxisAlignedBox<3> AxisAlignedBox3D; +/** @collisionoperator{Point,AxisAlignedBox} */ +template inline bool operator%(const Point& a, const AxisAlignedBox& b) { return b % a; } + }} #endif diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index 3ef7f3827..700822895 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -18,18 +18,23 @@ #include "Math/Constants.h" #include "Math/Matrix4.h" #include "Physics/AxisAlignedBox.h" +#include "Physics/Point.h" + +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { -class AxisAlignedBoxTest: public Corrade::TestSuite::Tester { +class AxisAlignedBoxTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: AxisAlignedBoxTest(); void applyTransformation(); + void collisionPoint(); }; AxisAlignedBoxTest::AxisAlignedBoxTest() { - addTests(&AxisAlignedBoxTest::applyTransformation); + addTests(&AxisAlignedBoxTest::applyTransformation, + &AxisAlignedBoxTest::collisionPoint); } void AxisAlignedBoxTest::applyTransformation() { @@ -40,6 +45,19 @@ void AxisAlignedBoxTest::applyTransformation() { CORRADE_COMPARE(box.transformedMax(), Vector3(3.0f, -1.0f, 5.5f)); } +void AxisAlignedBoxTest::collisionPoint() { + Physics::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); + Physics::Point3D point1({-1.5f, -1.0f, 2.0f}); + Physics::Point3D point2({0.5f, 1.0f, -2.5f}); + + randomTransformation(box); + randomTransformation(point1); + randomTransformation(point2); + + VERIFY_NOT_COLLIDES(box, point1); + VERIFY_COLLIDES(box, point2); +} + }}} CORRADE_TEST_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest) From 38f6ddcbef0e3e41080066100de219eccbacc659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Feb 2013 23:45:58 +0100 Subject: [PATCH 304/567] Physics: function for detecting first collision with shape in the group. --- src/Physics/ObjectShapeGroup.cpp | 13 +++++++++ src/Physics/ObjectShapeGroup.h | 9 +++++++ src/Physics/Test/ObjectShapeTest.cpp | 40 +++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index 013bf4d78..f6d7cb30c 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -15,6 +15,7 @@ #include "ObjectShapeGroup.h" +#include "Physics/AbstractShape.h" #include "ObjectShape.h" namespace Magnum { namespace Physics { @@ -32,6 +33,18 @@ template void ObjectShapeGroup::setClean() dirty = false; } +template ObjectShape* ObjectShapeGroup::firstCollision(const ObjectShape* shape) { + /* Nothing to test with, done */ + if(!shape->shape()) return nullptr; + + setClean(); + for(std::size_t i = 0; i != this->size(); ++i) + if((*this)[i] != shape && (*this)[i]->shape() && (*this)[i]->shape()->collides(shape->shape())) + return (*this)[i]; + + return nullptr; +} + template class ObjectShapeGroup<2>; template class ObjectShapeGroup<3>; diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 0c864cbb7..46db09721 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -71,6 +71,15 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: */ void setClean(); + /** + * @brief First collision of given shape with other shapes in the group + * + * Returns first shape colliding with given one. If there aren't any + * collisions, returns `nullptr`. Calls setClean() before the + * operation. + */ + ObjectShape* firstCollision(const ObjectShape* shape); + private: bool dirty; }; diff --git a/src/Physics/Test/ObjectShapeTest.cpp b/src/Physics/Test/ObjectShapeTest.cpp index 256e453d0..a6b8c17b5 100644 --- a/src/Physics/Test/ObjectShapeTest.cpp +++ b/src/Physics/Test/ObjectShapeTest.cpp @@ -18,6 +18,7 @@ #include "Physics/ObjectShapeGroup.h" #include "Physics/ObjectShape.h" #include "Physics/Point.h" +#include "Physics/Sphere.h" #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" @@ -28,13 +29,15 @@ class ObjectShapeTest: public Corrade::TestSuite::Tester { ObjectShapeTest(); void clean(); + void firstCollision(); }; typedef SceneGraph::Scene> Scene3D; typedef SceneGraph::Object> Object3D; ObjectShapeTest::ObjectShapeTest() { - addTests(&ObjectShapeTest::clean); + addTests(&ObjectShapeTest::clean, + &ObjectShapeTest::firstCollision); } void ObjectShapeTest::clean() { @@ -78,6 +81,41 @@ void ObjectShapeTest::clean() { CORRADE_VERIFY(b.isDirty()); } +void ObjectShapeTest::firstCollision() { + Scene3D scene; + ObjectShapeGroup3D group; + + Object3D a(&scene); + ObjectShape3D* aShape = new ObjectShape3D(&a, &group); + aShape->setShape(Physics::Sphere3D({1.0f, -2.0f, 3.0f}, 1.5f)); + + Object3D b(&scene); + ObjectShape3D* bShape = new ObjectShape3D(&b, &group); + bShape->setShape(Physics::Point3D({3.0f, -2.0f, 3.0f})); + + Object3D c(&scene); + ObjectShape3D* cShape = new ObjectShape3D(&c, &group); + + /* No-op if the object has no shape */ + CORRADE_VERIFY(group.isDirty()); + CORRADE_VERIFY(!group.firstCollision(cShape)); + CORRADE_VERIFY(group.isDirty()); + + /* No collisions initially */ + CORRADE_VERIFY(!group.firstCollision(aShape)); + CORRADE_VERIFY(!group.firstCollision(bShape)); + CORRADE_VERIFY(!group.isDirty()); + + /* Move point into sphere */ + b.translate(Vector3::xAxis(-1.0f)); + + /* Collision */ + CORRADE_VERIFY(group.isDirty()); + CORRADE_VERIFY(group.firstCollision(aShape) == bShape); + CORRADE_VERIFY(group.firstCollision(bShape) == aShape); + CORRADE_VERIFY(!group.isDirty()); +} + }}} CORRADE_TEST_MAIN(Magnum::Physics::Test::ObjectShapeTest) From 49b5c3c5614da4c5b8a16406be4ef59f658f45cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Feb 2013 23:46:54 +0100 Subject: [PATCH 305/567] Minor code cleanup. --- src/Physics/ObjectShapeGroup.cpp | 2 +- src/Physics/Test/ObjectShapeTest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index f6d7cb30c..b24d65a35 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -16,7 +16,7 @@ #include "ObjectShapeGroup.h" #include "Physics/AbstractShape.h" -#include "ObjectShape.h" +#include "Physics/ObjectShape.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Test/ObjectShapeTest.cpp b/src/Physics/Test/ObjectShapeTest.cpp index a6b8c17b5..132dc48f4 100644 --- a/src/Physics/Test/ObjectShapeTest.cpp +++ b/src/Physics/Test/ObjectShapeTest.cpp @@ -46,7 +46,7 @@ void ObjectShapeTest::clean() { Object3D a(&scene); ObjectShape3D* shape = new ObjectShape3D(&a, &group); - shape->setShape(new Physics::Point3D({1.0f, -2.0f, 3.0f})); + shape->setShape(Physics::Point3D({1.0f, -2.0f, 3.0f})); a.scale(Vector3(-2.0f)); Object3D b(&scene); From 0dea0d8aff6e29ecb1d7863a5c2839c5997e084a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Feb 2013 23:13:20 +0100 Subject: [PATCH 306/567] Platform: cleaned-up AbstractXApplication header. --- src/Platform/AbstractXApplication.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index b8f999ff1..9f0b3f3fa 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -80,9 +80,9 @@ class AbstractXApplication { /** @brief Exit application main loop */ inline void exit() { flags |= Flag::Exit; } + protected: /** @{ @name Drawing functions */ - protected: /** @copydoc GlutApplication::viewportEvent() */ virtual void viewportEvent(const Vector2i& size) = 0; @@ -99,7 +99,6 @@ class AbstractXApplication { /** @{ @name Keyboard handling */ - protected: /** @copydoc Sdl2Application::keyPressEvent() */ virtual void keyPressEvent(KeyEvent& event); @@ -110,7 +109,6 @@ class AbstractXApplication { /** @{ @name Mouse handling */ - protected: /** @copydoc Sdl2Application::mousePressEvent() */ virtual void mousePressEvent(MouseEvent& event); @@ -145,6 +143,8 @@ class AbstractXApplication { Flags flags; }; +CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags) + /** @brief Base for input events @@ -206,6 +206,8 @@ class AbstractXApplication::InputEvent { bool _accepted; }; +CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Modifiers) + /** @brief Key event @@ -389,9 +391,6 @@ When no other application header is included this macro is also aliased to #endif #endif -CORRADE_ENUMSET_OPERATORS(AbstractXApplication::InputEvent::Modifiers) -CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags) - /* Implementations for inline functions with unused parameters */ inline void AbstractXApplication::keyPressEvent(KeyEvent&) {} inline void AbstractXApplication::keyReleaseEvent(KeyEvent&) {} From c1135988451f373d097333b692e02ba1cdb3a142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Feb 2013 23:27:45 +0100 Subject: [PATCH 307/567] Platform: added Sdl2Application::exit(). --- src/Platform/Sdl2Application.cpp | 12 ++++++------ src/Platform/Sdl2Application.h | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index b423b5519..41a1b3876 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -40,7 +40,7 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { } -Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vector2i& size): _redraw(true) { +Sdl2Application::Sdl2Application(int, char**, const std::string& name, const Vector2i& size): flags(Flag::Redraw) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; std::exit(1); @@ -83,7 +83,7 @@ Sdl2Application::~Sdl2Application() { } int Sdl2Application::exec() { - for(;;) { + while(!(flags & Flag::Exit)) { SDL_Event event; while(SDL_PollEvent(&event)) { @@ -92,10 +92,10 @@ int Sdl2Application::exec() { switch(event.window.event) { case SDL_WINDOWEVENT_RESIZED: viewportEvent({event.window.data1, event.window.data2}); - _redraw = true; + flags |= Flag::Redraw; break; case SDL_WINDOWEVENT_EXPOSED: - _redraw = true; + flags |= Flag::Redraw; break; } break; @@ -127,8 +127,8 @@ int Sdl2Application::exec() { } } - if(_redraw) { - _redraw = false; + if(flags & Flag::Redraw) { + flags &= ~Flag::Redraw; drawEvent(); } else Corrade::Utility::sleep(5); } diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 00aad8e99..281f00231 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -80,6 +80,9 @@ class Sdl2Application { */ int exec(); + /** @brief Exit application main loop */ + inline void exit() { flags |= Flag::Exit; } + protected: /** @{ @name Drawing functions */ @@ -94,7 +97,7 @@ class Sdl2Application { inline void swapBuffers() { SDL_GL_SwapWindow(window); } /** @copydoc GlutApplication::redraw() */ - inline void redraw() { _redraw = true; } + inline void redraw() { flags |= Flag::Redraw; } /*@}*/ @@ -146,14 +149,24 @@ class Sdl2Application { /*@}*/ private: + enum class Flag: std::uint8_t { + Redraw = 1 << 0, + Exit = 1 << 1 + }; + + typedef Corrade::Containers::EnumSet Flags; + CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) + SDL_Window* window; SDL_GLContext context; Context* c; - bool _redraw; + Flags flags; }; +CORRADE_ENUMSET_OPERATORS(Sdl2Application::Flags) + /** @brief Base for input events From 3eef49ae8b365ab11d62450831018e3ed0729055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Feb 2013 10:28:42 +0100 Subject: [PATCH 308/567] Text: cleaned up TextRenderer header. --- src/Text/TextRenderer.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 629dce858..920e8ce58 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -66,14 +66,6 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * subclasses and rectangle spanning the rendered text. */ static std::tuple render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); - - private: - #ifndef DOXYGEN_GENERATING_OUTPUT - struct Vertex { - typename DimensionTraits::PointType position; - Vector2 textureCoordinates; - }; - #endif }; /** @brief Two-dimensional text renderer */ From a2e21020aa52326162074fb13c5bc5316f946ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Feb 2013 14:35:48 +0100 Subject: [PATCH 309/567] Text: reworked TextRenderer internals. * Common layouting code in separate non-templated class. * Direct creation of interleaved vertex array and compressed index buffer, saves some memory operations and removes MeshTools dependency. * Preparation for mutable TextRenderer implementation. --- src/Text/CMakeLists.txt | 2 +- src/Text/TextRenderer.cpp | 238 +++++++++++++++++++++++++------------- 2 files changed, 160 insertions(+), 80 deletions(-) diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index 2bdebfb92..26f254e3f 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -17,7 +17,7 @@ set(MagnumText_HEADERS add_library(MagnumText SHARED ${MagnumText_SRCS}) -target_link_libraries(MagnumText Magnum MagnumMeshTools MagnumTextureTools ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES}) +target_link_libraries(MagnumText Magnum MagnumTextureTools ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES}) install(TARGETS MagnumText DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumText_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Text) diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index b81a0c6c8..e31d4fe44 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -20,9 +20,8 @@ #include "Math/Point2D.h" #include "Math/Point3D.h" +#include "Mesh.h" #include "Swizzle.h" -#include "MeshTools/CompressIndices.h" -#include "MeshTools/Interleave.h" #include "Shaders/AbstractTextShader.h" #include "Text/Font.h" @@ -30,9 +29,28 @@ namespace Magnum { namespace Text { namespace { -std::tuple, std::vector, std::vector, Rectangle> renderInternal(Font& font, GLfloat size, const std::string& text) { +class TextLayouter { + public: + TextLayouter(Font& font, const GLfloat size, const std::string& text); + + ~TextLayouter(); + + inline std::uint32_t glyphCount() { return _glyphCount; } + + std::tuple renderGlyph(const Vector2& cursorPosition, const std::uint32_t i); + + private: + const Font& font; + const GLfloat size; + hb_buffer_t* buffer; + hb_glyph_info_t* glyphInfo; + hb_glyph_position_t* glyphPositions; + std::uint32_t _glyphCount; +}; + +TextLayouter::TextLayouter(Font& font, const GLfloat size, const std::string& text): font(font), size(size) { /* Prepare HarfBuzz buffer */ - hb_buffer_t *buffer = hb_buffer_create(); + buffer = hb_buffer_create(); hb_buffer_set_unicode_funcs(buffer, hb_icu_get_unicode_funcs()); hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); @@ -42,58 +60,96 @@ std::tuple, std::vector, std::vector positions, texcoords; - std::vector indices; - positions.reserve(glyphCount*4); - texcoords.reserve(glyphCount*4); - indices.reserve(glyphCount*6); +TextLayouter::~TextLayouter() { + /* Destroy HarfBuzz buffer */ + hb_buffer_destroy(buffer); +} - /* Starting cursor position */ - Vector2 cursorPosition; +std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const std::uint32_t i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle texturePosition, textureCoordinates; + std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; - /* Create quads for all glyphs */ - for(std::uint32_t i = 0; i != glyphCount; ++i) { - /* Position of the texture in the resulting glyph, texture coordinates */ - Rectangle texturePosition, textureCoordinates; - std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; + /* Glyph offset and advance to next glyph in normalized coordinates */ + Vector2 offset = Vector2(glyphPositions[i].x_offset, + glyphPositions[i].y_offset)/(64*font.size()); + Vector2 advance = Vector2(glyphPositions[i].x_advance, + glyphPositions[i].y_advance)/(64*font.size()); - /* Glyph offset and advance to next glyph in normalized coordinates */ - Vector2 offset = Vector2(glyphPositions[i].x_offset, - glyphPositions[i].y_offset)/(64*font.size()); - Vector2 advance = Vector2(glyphPositions[i].x_advance, - glyphPositions[i].y_advance)/(64*font.size()); + /* Absolute quad position, composed from cursor position, glyph offset + and texture position, denormalized to requested text size */ + Rectangle quadPosition = Rectangle::fromSize( + (cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, + texturePosition.size()*size); - /* Absolute quad position, composed from cursor position, glyph offset - and texture position, denormalized to requested text size */ - Rectangle quadPosition = Rectangle::fromSize( - (cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, - texturePosition.size()*size); + return std::make_tuple(quadPosition, textureCoordinates, advance); +} +template void createIndices(void* output, const std::uint32_t glyphCount) { + T* const out = reinterpret_cast(output); + for(std::uint32_t i = 0; i != glyphCount; ++i) { /* 0---2 2 | / /| | / / | |/ / | 1 1---3 */ - /* Quad with texture coordinates */ - indices.insert(indices.end(), { - std::uint32_t(positions.size()), - std::uint32_t(positions.size()+1), - std::uint32_t(positions.size()+2), - std::uint32_t(positions.size()+1), - std::uint32_t(positions.size()+3), - std::uint32_t(positions.size()+2) - }); + const T vertex = i*4; + const T pos = i*6; + out[pos] = vertex; + out[pos+1] = vertex+1; + out[pos+2] = vertex+2; + out[pos+3] = vertex+1; + out[pos+4] = vertex+3; + out[pos+5] = vertex+2; + } +} + +template typename DimensionTraits::PointType point(const Vector2& vec); + +template<> inline Point2D point<2>(const Vector2& vec) { + return swizzle<'x', 'y', '1'>(vec); +} + +template<> inline Point3D point<3>(const Vector2& vec) { + return swizzle<'x', 'y', '0', '1'>(vec); +} + +template struct Vertex { + typename DimensionTraits::PointType position; + Vector2 texcoords; +}; + +} + +template std::tuple::PointType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { + TextLayouter layouter(font, size, text); + + const std::uint32_t vertexCount = layouter.glyphCount()*4; + + /* Output data */ + std::vector::PointType> positions; + std::vector texcoords; + positions.reserve(vertexCount); + texcoords.reserve(vertexCount); + + /* Render all glyphs */ + Vector2 cursorPosition; + for(std::uint32_t i = 0; i != layouter.glyphCount(); ++i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle quadPosition, textureCoordinates; + Vector2 advance; + std::tie(quadPosition, textureCoordinates, advance) = layouter.renderGlyph(cursorPosition, i); + positions.insert(positions.end(), { - quadPosition.topLeft(), - quadPosition.bottomLeft(), - quadPosition.topRight(), - quadPosition.bottomRight(), + point(quadPosition.topLeft()), + point(quadPosition.bottomLeft()), + point(quadPosition.topRight()), + point(quadPosition.bottomRight()), }); texcoords.insert(texcoords.end(), { textureCoordinates.topLeft(), @@ -106,58 +162,82 @@ std::tuple, std::vector, std::vector indices(layouter.glyphCount()*6); + createIndices(indices.data(), layouter.glyphCount()); + /* Rendered rectangle */ Rectangle rectangle; - if(glyphCount) rectangle = {positions[1], positions[positions.size()-2]}; - - /* Destroy HarfBuzz buffer */ - hb_buffer_destroy(buffer); + if(layouter.glyphCount()) rectangle = {positions[1].xy(), positions[positions.size()-2].xy()}; return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle); } -template typename DimensionTraits::PointType point(const Vector2& vec); - -template<> inline Point2D point<2>(const Vector2& vec) { - return swizzle<'x', 'y', '1'>(vec); -} - -template<> inline Point3D point<3>(const Vector2& vec) { - return swizzle<'x', 'y', '0', '1'>(vec); -} - -} +template std::tuple TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { + TextLayouter layouter(font, size, text); -template std::tuple::PointType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { - std::vector positions, textureCoordinates; - std::vector indices; - Rectangle rectangle; - std::tie(positions, textureCoordinates, indices, rectangle) = renderInternal(font, size, text); + const std::uint32_t vertexCount = layouter.glyphCount()*4; + const std::uint32_t indexCount = layouter.glyphCount()*6; - /* Create PointXD from Vector2 */ - std::vector::PointType> positionsXD; - positionsXD.reserve(positions.size()); - for(const Vector2& position: positions) - positionsXD.push_back(point(position)); + /* Vertex buffer */ + std::vector> vertices; + vertices.reserve(vertexCount); - return std::make_tuple(std::move(positionsXD), std::move(textureCoordinates), std::move(indices), rectangle); -} + /* Render all glyphs */ + Vector2 cursorPosition; + for(std::uint32_t i = 0; i != layouter.glyphCount(); ++i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle quadPosition, textureCoordinates; + Vector2 advance; + std::tie(quadPosition, textureCoordinates, advance) = layouter.renderGlyph(cursorPosition, i); + + vertices.insert(vertices.end(), { + {point(quadPosition.topLeft()), textureCoordinates.topLeft()}, + {point(quadPosition.bottomLeft()), textureCoordinates.bottomLeft()}, + {point(quadPosition.topRight()), textureCoordinates.topRight()}, + {point(quadPosition.bottomRight()), textureCoordinates.bottomRight()} + }); -template std::tuple TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { - Mesh mesh; + /* Advance cursor position to next character */ + cursorPosition += advance; + } + vertexBuffer->setData(vertices, usage); + + /* Fill index buffer */ + Mesh::IndexType indexType; + std::size_t indicesSize; + char* indices; + if(vertexCount < 255) { + indexType = Mesh::IndexType::UnsignedByte; + indicesSize = indexCount*sizeof(GLushort); + indices = new char[indicesSize]; + createIndices(indices, layouter.glyphCount()); + } else if(vertexCount < 65535) { + indexType = Mesh::IndexType::UnsignedShort; + indicesSize = indexCount*sizeof(GLushort); + indices = new char[indicesSize]; + createIndices(indices, layouter.glyphCount()); + } else { + indexType = Mesh::IndexType::UnsignedInt; + indicesSize = indexCount*sizeof(GLuint); + indices = new char[indicesSize]; + createIndices(indices, layouter.glyphCount()); + } + indexBuffer->setData(indicesSize, indices, usage); + delete indices; - std::vector::PointType> positions; - std::vector textureCoordinates; - std::vector indices; + /* Rendered rectangle */ Rectangle rectangle; - std::tie(positions, textureCoordinates, indices, rectangle) = render(font, size, text); + if(layouter.glyphCount()) rectangle = {vertices[1].position.xy(), vertices[vertices.size()-2].position.xy()}; - MeshTools::interleave(&mesh, vertexBuffer, usage, positions, textureCoordinates); - MeshTools::compressIndices(&mesh, indexBuffer, usage, indices); + /* Configure mesh */ + Mesh mesh; mesh.setPrimitive(Mesh::Primitive::Triangles) + ->setIndexCount(indexCount) ->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::AbstractTextShader::Position(), - typename Shaders::AbstractTextShader::TextureCoordinates()); + typename Shaders::AbstractTextShader::TextureCoordinates()) + ->setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); return std::make_tuple(std::move(mesh), rectangle); } From e67142db1d8fca6b0f407bd435fd665d52036cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Feb 2013 14:38:33 +0100 Subject: [PATCH 310/567] Properly check (and document) dependencies for Text library. --- CMakeLists.txt | 2 +- modules/FindMagnum.cmake | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba6c5a807..b24e7f526 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_ cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_TEXT "Build Text library" OFF "NOT WITH_EVERYTHING" ON) -cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" OFF "NOT WITH_EVERYTHING" ON) +cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_TEXT" ON) cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 8a5ed0983..0774bc391 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -22,7 +22,8 @@ # Primitives - Library with stock geometric primitives (static) # SceneGraph - Scene graph library # Shaders - Library with stock shaders -# Text - Text rendering library +# Text - Text rendering library (depends on TextureTools component, +# HarfBuzz and FreeType library) # TextureTools - TextureTools library # GlxApplication - GLX application (depends on X11 libraries) # XEglApplication - X/EGL application (depends on EGL and X11 libraries) @@ -208,6 +209,13 @@ foreach(component ${Magnum_FIND_COMPONENTS}) # Text library if(${component} STREQUAL Text) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Font.h) + + # Dependencies + find_package(FreeType) + find_package(HarfBuzz) + if(NOT FREETYPE_FOUND OR NOT HARFBUZZ_FOUND) + unset(MAGNUM_${_COMPONENT}_LIBRARY) + endif() endif() # TextureTools library From 8a639391348cd7f995433a191fd9646195f59e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Feb 2013 17:00:31 +0100 Subject: [PATCH 311/567] Math: added vector/scalar abs() function. --- src/Math/Functions.h | 15 +++++++++++++++ src/Math/Test/FunctionsTest.cpp | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index fe767f915..76bff57b4 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -117,6 +117,21 @@ template Vector max(const Vector& a } #endif +/** @brief Absolute value */ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T abs(const T& a); +#else +template inline typename std::enable_if::value, T>::type abs(T a) { + return std::abs(a); +} +template Vector abs(const Vector& a) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::abs(a[i]); + return out; +} +#endif + /** @brief Clamp value diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index f71362c65..dd88b08cc 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -26,6 +26,7 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void min(); void max(); + void abs(); void clamp(); void normalizeUnsigned(); void normalizeSigned(); @@ -47,6 +48,7 @@ typedef Math::Vector3 Vector3i; FunctionsTest::FunctionsTest() { addTests(&FunctionsTest::min, &FunctionsTest::max, + &FunctionsTest::abs, &FunctionsTest::clamp, &FunctionsTest::normalizeUnsigned, &FunctionsTest::normalizeSigned, @@ -69,6 +71,12 @@ void FunctionsTest::max() { CORRADE_COMPARE(Math::max(Vector3i(5, -3, 2), Vector3i(9, -5, 18)), Vector3i(9, -3, 18)); } +void FunctionsTest::abs() { + CORRADE_COMPARE(Math::abs(-5), 5); + CORRADE_COMPARE(Math::abs(5), 5); + CORRADE_COMPARE(Math::abs(Vector3i(5, -3, 2)), Vector3i(5, 3, 2)); +} + void FunctionsTest::clamp() { CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); From 780228d0b8074b21f4ef51f2af551d74fd218aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Feb 2013 17:58:08 +0100 Subject: [PATCH 312/567] SceneGraph: restarting animation should allow the same repeat count. Updated test to check that. --- src/SceneGraph/Animable.hpp | 4 +++- src/SceneGraph/Test/AnimableTest.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp index c1a3f11f5..619e556c2 100644 --- a/src/SceneGraph/Animable.hpp +++ b/src/SceneGraph/Animable.hpp @@ -80,10 +80,12 @@ template void AnimableGroup::st CORRADE_INTERNAL_ASSERT(animable->previousState == animable->currentState); continue; - /* The animation was started recently, set start time to previous frame time */ + /* The animation was started recently, set start time to previous frame + time, reset repeat count */ } else if(animable->previousState == AnimationState::Stopped) { animable->previousState = AnimationState::Running; animable->startTime = time; + animable->repeats = 0; ++_runningCount; animable->animationStarted(); diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index 1c4840fb1..1be3a1fd4 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -266,6 +266,21 @@ void AnimableTest::repeat() { group.step(33.0f, 0.5f); CORRADE_COMPARE(animable.state(), AnimationState::Stopped); CORRADE_COMPARE(animable.time, 4.5f); + + /* Starting the animation again, should be repeatable again */ + animable.setState(AnimationState::Running); + + /* Three animation repeats */ + group.step(1.0f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + group.step(11.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + group.step(25.5f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Running); + + /* Should be stopped now */ + group.step(33.0f, 0.5f); + CORRADE_COMPARE(animable.state(), AnimationState::Stopped); } void AnimableTest::stop() { From 9a1f1e1a16b23e793730958a11eb33e26ca7e9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Feb 2013 15:15:04 +0100 Subject: [PATCH 313/567] Text: mutable TextRenderer implementation. Allows fast text updates (using buffer mapping). Also fully documented the workflow. --- src/Text/Font.h | 24 ++++++++ src/Text/FontRenderer.h | 5 +- src/Text/Text.h | 5 +- src/Text/TextRenderer.cpp | 90 ++++++++++++++++++++++++++++ src/Text/TextRenderer.h | 119 +++++++++++++++++++++++++++++++++++++- 5 files changed, 237 insertions(+), 6 deletions(-) diff --git a/src/Text/Font.h b/src/Text/Font.h index 743685649..07cc72761 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -39,6 +39,28 @@ namespace Magnum { namespace Text { @brief %Font Contains font with characters prerendered into texture atlas. + +@section Font-usage Usage + +You need to maintain instance of FontRenderer during the lifetime of all Font +instances. The font can be created either from file or from memory location of +format supported by [FreeType](http://www.freetype.org/) library. Next step is +to prerender all the glyphs which will be used in text rendering later. +@code +Text::FontRenderer fontRenderer; + +Text::Font font(fontRenderer, "MyFont.ttf", 48.0f); +font.prerender("abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789 ", Vector2i(512)); +@endcode +See TextRenderer for information about text rendering. + +@section Font-extensions Required OpenGL functionality + +%Font texture uses one-component internal format, which requires +@extension{ARB,texture_rg} (also part of OpenGL ES 3.0 or available as +@es_extension{EXT,texture_rg} in ES 2.0). */ class MAGNUM_TEXT_EXPORT Font { Font(const Font&) = delete; @@ -69,6 +91,8 @@ class MAGNUM_TEXT_EXPORT Font { * * Creates new atlas with prerendered characters, replacing the * previous one (if any). + * @attention @p atlasSize must be large enough to contain all + * rendered glyphs. */ void prerender(const std::string& characters, const Vector2i& atlasSize); diff --git a/src/Text/FontRenderer.h b/src/Text/FontRenderer.h index 0164edf32..6fd72ec57 100644 --- a/src/Text/FontRenderer.h +++ b/src/Text/FontRenderer.h @@ -29,9 +29,10 @@ typedef FT_LibraryRec_* FT_Library; namespace Magnum { namespace Text { /** -@brief Font renderer +@brief %Font renderer -Contains global instance of font renderer used by Font class. +Contains global instance of font renderer. See Font class documentation for +more information. */ class MAGNUM_TEXT_EXPORT FontRenderer { public: diff --git a/src/Text/Text.h b/src/Text/Text.h index 982b73d75..56cef3e75 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -25,7 +25,10 @@ namespace Magnum { namespace Text { class Font; class FontRenderer; -/* TextRenderer used only statically */ + +template class TextRenderer; +typedef TextRenderer<2> TextRenderer2D; +typedef TextRenderer<3> TextRenderer3D; }} diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index e31d4fe44..8af91b16e 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -20,6 +20,8 @@ #include "Math/Point2D.h" #include "Math/Point3D.h" +#include "Context.h" +#include "Extensions.h" #include "Mesh.h" #include "Swizzle.h" #include "Shaders/AbstractTextShader.h" @@ -242,6 +244,94 @@ template std::tuple TextRenderer TextRenderer::TextRenderer(Font& font, const GLfloat size): font(font), size(size), _capacity(0), vertexBuffer(Buffer::Target::Array), indexBuffer(Buffer::Target::ElementArray) { + #ifndef MAGNUM_TARGET_GLES + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::map_buffer_range); + #else + #ifdef MAGNUM_TARGET_GLES2 + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::map_buffer_range); + #endif + #endif + + _mesh.setPrimitive(Mesh::Primitive::Triangles) + ->addInterleavedVertexBuffer(&vertexBuffer, 0, + typename Shaders::AbstractTextShader::Position(), + typename Shaders::AbstractTextShader::TextureCoordinates()); +} + +template void TextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) { + _capacity = glyphCount; + + const std::uint32_t vertexCount = glyphCount*4; + const std::uint32_t indexCount = glyphCount*6; + + /* Allocate vertex buffer, reset vertex count */ + vertexBuffer.setData(vertexCount*sizeof(Vertex), nullptr, vertexBufferUsage); + _mesh.setVertexCount(0); + + /* Allocate index buffer, reset index count and reconfigure buffer binding */ + Mesh::IndexType indexType; + std::size_t indicesSize; + if(vertexCount < 255) { + indexType = Mesh::IndexType::UnsignedByte; + indicesSize = indexCount*sizeof(GLushort); + } else if(vertexCount < 65535) { + indexType = Mesh::IndexType::UnsignedShort; + indicesSize = indexCount*sizeof(GLushort); + } else { + indexType = Mesh::IndexType::UnsignedInt; + indicesSize = indexCount*sizeof(GLuint); + } + indexBuffer.setData(indicesSize, nullptr, indexBufferUsage); + _mesh.setIndexCount(0) + ->setIndexBuffer(&indexBuffer, 0, indexType, 0, vertexCount); + + /* Prefill index buffer */ + void* indices = indexBuffer.map(0, indicesSize, Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write); + if(vertexCount < 255) + createIndices(indices, glyphCount); + else if(vertexCount < 65535) + createIndices(indices, glyphCount); + else + createIndices(indices, glyphCount); + CORRADE_INTERNAL_ASSERT_OUTPUT(indexBuffer.unmap()); +} + +template void TextRenderer::render(const std::string& text) { + TextLayouter layouter(font, size, text); + + CORRADE_ASSERT(layouter.glyphCount() <= _capacity, "Text::TextRenderer::render(): capacity" << _capacity << "too small to render" << layouter.glyphCount() << "glyphs", ); + + /* Render all glyphs */ + Vertex* const vertices = static_cast*>(vertexBuffer.map(0, layouter.glyphCount()*4*sizeof(Vertex), + Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write)); + Vector2 cursorPosition; + for(std::uint32_t i = 0; i != layouter.glyphCount(); ++i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle quadPosition, textureCoordinates; + Vector2 advance; + std::tie(quadPosition, textureCoordinates, advance) = layouter.renderGlyph(cursorPosition, i); + + if(i == 0) + _rectangle.bottomLeft() = quadPosition.bottomLeft(); + else if(i == layouter.glyphCount()-1) + _rectangle.topRight() = quadPosition.topRight(); + + const std::size_t vertex = i*4; + vertices[vertex] = {point(quadPosition.topLeft()), textureCoordinates.topLeft()}; + vertices[vertex+1] = {point(quadPosition.bottomLeft()), textureCoordinates.bottomLeft()}; + vertices[vertex+2] = {point(quadPosition.topRight()), textureCoordinates.topRight()}; + vertices[vertex+3] = {point(quadPosition.bottomRight()), textureCoordinates.bottomRight()}; + + /* Advance cursor position to next character */ + cursorPosition += advance; + } + CORRADE_INTERNAL_ASSERT_OUTPUT(vertexBuffer.unmap()); + + /* Update index count */ + _mesh.setIndexCount(layouter.glyphCount()*6); +} + template class TextRenderer<2>; template class TextRenderer<3>; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 920e8ce58..89328520c 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -19,9 +19,10 @@ * @brief Class Magnum::Text::TextRenderer */ -#include "Math/Vector2.h" +#include "Math/Geometry/Rectangle.h" #include "Buffer.h" #include "DimensionTraits.h" +#include "Mesh.h" #include "Text/Text.h" #include "magnumTextVisibility.h" @@ -36,8 +37,65 @@ namespace Magnum { namespace Text { @brief %Text renderer Lays out the text into mesh using [HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz) -library. Use of ligatures, kerning etc. depends on features supported by the -particular font. +library. Use of ligatures, kerning etc. depends on features supported by +particular font. See also Font. + +@section TextRenderer-usage Usage + +Immutable text (e.g. menu items, credits) can be simply rendered using static +methods, returning result either as data arrays or as fully configured mesh. +The text can be then drawn by configuring text shader, binding font texture +and drawing the mesh: +@code +Text::Font font; +Shaders::TextShader2D shader; +Buffer vertexBuffer, indexBuffer; +Mesh mesh; + +// Render the text +Rectangle rectangle; +std::tie(mesh, rectangle) = Text::TextRenderer2D::render(font, 0.15f, + "Hello World!", &vertexBuffer, &indexBuffer, Buffer::Usage::StaticDraw); + +// Draw white text centered on the screen +shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-rectangle.width()/2.0f)) + ->setColor(Color3<>(1.0f)); + ->use(); +font.texture()->bind(Shaders::TextShader2D::FontTextureLayer); +mesh.draw(); +@endcode +See render(Font&, GLfloat, const std::string&) and +render(Font&, GLfloat, const std::string&, Buffer*, Buffer*, Buffer::Usage) +for more information. + +While this method is sufficient for one-shot rendering of static texts, for +mutable texts (e.g. FPS counters, chat messages) there is another approach +that doesn't recreate everything on each text change: +@code +Text::Font font; +Shaders::TextShader2D shader; + +// Initialize renderer and reserve memory for enough glyphs +Text::TextRenderer2D renderer(font, 0.15f); +renderer.reserve(32, Buffer::Usage::DynamicDraw, Buffer::Usage::StaticDraw); + +// Update the text occasionally +renderer.render("Hello World Countdown: 10"); + +// Draw the text centered on the screen +shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-renderer.rectangle().width()/2.0f)) + ->setColor(Color3<>(1.0f)); + ->use(); +font.texture()->bind(Shaders::TextShader2D::FontTextureLayer); +renderer.mesh().draw(); +@endcode + +@section TextRenderer-extensions Required OpenGL functionality + +Mutable text rendering requires @extension{ARB,map_buffer_range} (also part of +OpenGL ES 3.0 or available as @es_extension{EXT,map_buffer_range} in ES 2.0) +for asynchronous buffer updates. + @see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractTextShader */ template class MAGNUM_TEXT_EXPORT TextRenderer { @@ -66,6 +124,61 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * subclasses and rectangle spanning the rendered text. */ static std::tuple render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + + /** + * @brief Constructor + * @param font %Font to use + * @param size %Font size + */ + TextRenderer(Font& font, GLfloat size); + + /** + * @brief Capacity for rendered glyphs + * + * @see reserve() + */ + inline std::uint32_t capacity() const { return _capacity; } + + /** @brief Rectangle spanning the rendered text */ + inline Rectangle rectangle() const { return _rectangle; } + + /** @brief Text mesh */ + inline Mesh* mesh() { return &_mesh; } + + /** + * @brief Reserve capacity for rendered glyphs + * + * Reallocates memory in buffers to hold @p glyphCount glyphs and + * prefills index buffer. Consider using appropriate @p vertexBufferUsage + * if the text will be changed frequently. Index buffer is changed + * only by calling this function, thus @p indexBufferUsage generally + * doesn't need to be so dynamic if the capacity won't be changed much. + * + * Initially zero capacity is reserved. + * @see capacity() + */ + void reserve(const std::uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage); + + /** + * @brief Render text + * + * Renders the text to vertex buffer, reusing index buffer already + * filled with reserve(). Rectangle spanning the rendered text is + * available through rectangle(). + * + * Initially no text is rendered. + * @attention The capacity must be large enough to contain all glyphs, + * see reserve() for more information. + */ + void render(const std::string& text); + + private: + Font& font; + GLfloat size; + std::uint32_t _capacity; + Rectangle _rectangle; + Buffer vertexBuffer, indexBuffer; + Mesh _mesh; }; /** @brief Two-dimensional text renderer */ From ede0d9b503d826eb3683783cb1b1a587ee540110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Feb 2013 18:41:56 +0100 Subject: [PATCH 314/567] Math: generalize Gram-Schmidt algorithm for non-square matrices. --- src/Math/Algorithms/GramSchmidt.h | 15 ++++++++------- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h index cbaa3d04c..c6f60e2f5 100644 --- a/src/Math/Algorithms/GramSchmidt.h +++ b/src/Math/Algorithms/GramSchmidt.h @@ -19,29 +19,30 @@ * @brief Function Magnum::Math::Algorithms::gramSchmidtInPlace(), Magnum::Math::Algorithms::gramSchmidt() */ -#include "Math/Matrix.h" +#include "Math/RectangularMatrix.h" namespace Magnum { namespace Math { namespace Algorithms { /** -@brief Gram-schmidt matrix orthonormalization +@brief Gram-Schmidt matrix orthonormalization @param[in,out] matrix Matrix to perform orthonormalization on */ -template void gramSchmidtInPlace(Matrix& matrix) { - for(std::size_t i = 0; i != size; ++i) { +template void gramSchmidtInPlace(RectangularMatrix& matrix) { + static_assert(cols <= rows, "Unsupported matrix aspect ratio"); + for(std::size_t i = 0; i != cols; ++i) { matrix[i] = matrix[i].normalized(); - for(std::size_t j = i+1; j != size; ++j) + for(std::size_t j = i+1; j != cols; ++j) matrix[j] -= matrix[j].projected(matrix[i]); } } /** -@brief Gram-schmidt matrix orthonormalization +@brief Gram-Schmidt matrix orthonormalization Unlike gramSchmidtInPlace() returns the modified matrix instead of performing the orthonormalization in-place. */ -template Matrix gramSchmidt(Matrix matrix) { +template RectangularMatrix gramSchmidt(RectangularMatrix matrix) { gramSchmidtInPlace(matrix); return matrix; } diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 528c6b82f..3313c3ac8 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -26,7 +26,7 @@ class GramSchmidtTest: public Corrade::TestSuite::Tester { void test(); }; -typedef Matrix<3, float> Matrix3; +typedef RectangularMatrix<3, 3, float> Matrix3; typedef Vector<3, float> Vector3; GramSchmidtTest::GramSchmidtTest() { From 11544813a20acec33d7fef3e8a77364c2f600f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Feb 2013 18:44:47 +0100 Subject: [PATCH 315/567] Math: don't needlessly include Matrix in GaussJordanTest. Should save another bit of recompilation time in addition to previous commit. --- src/Math/Algorithms/Test/GaussJordanTest.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index 7bf870708..1825769df 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Matrix.h" #include "Math/Algorithms/GaussJordan.h" namespace Magnum { namespace Math { namespace Algorithms { namespace Test { @@ -28,7 +27,7 @@ class GaussJordanTest: public Corrade::TestSuite::Tester { void invert(); }; -typedef Matrix<4, float> Matrix4; +typedef RectangularMatrix<4, 4, float> Matrix4; typedef Vector<4, float> Vector4; GaussJordanTest::GaussJordanTest() { @@ -58,11 +57,11 @@ void GaussJordanTest::invert() { Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f)); Matrix4 a2(a); - Matrix4 inverse(Matrix4::Identity); + Matrix4 inverse = Matrix4::fromDiagonal(Vector4(1.0f)); CORRADE_VERIFY(GaussJordan::inPlace(a2, inverse)); CORRADE_COMPARE(inverse, expectedInverse); - CORRADE_COMPARE(a*inverse, Matrix4()); + CORRADE_COMPARE(a*inverse, Matrix4::fromDiagonal(Vector4(1.0f))); } }}}} From 019c9c0c5fc1f61dee93442b2c82926e7676ba21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Feb 2013 18:46:37 +0100 Subject: [PATCH 316/567] Math: Gauss-Jordan algorithm as pure functions. No need to wrap this in a class. --- src/Math/Algorithms/GaussJordan.h | 79 +++++++++----------- src/Math/Algorithms/Test/GaussJordanTest.cpp | 4 +- 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index dc1734346..130403216 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Math::Algorithms::GaussJordan + * @brief Function Magnum::Math::Algorithms::gaussJordanInPlaceTransposed(), Magnum::Math::Algorithms::gaussJordanInPlace() */ #include "Math/RectangularMatrix.h" @@ -24,54 +24,25 @@ namespace Magnum { namespace Math { namespace Algorithms { /** -@brief Gauss-Jordan elimination +@brief In-place Gauss-Jordan elimination on transposed matrices +@param a Transposed left side of augmented matrix +@param t Transposed right side of augmented matrix +@return True if @p a is regular, false if @p a is singular (and thus the + system cannot be solved). + +As Gauss-Jordan elimination works on rows and matrices in OpenGL are +column-major, it is more efficient to operate on transposed matrices and treat +columns as rows. See also gaussJordanInPlace() which works with non-transposed matrices. + +The function eliminates matrix @p a and solves @p t in place. For efficiency +reasons, only pure Gaussian elimination is done on @p a and the final +backsubstitution is done only on @p t, as @p a would always end with identity +matrix anyway. Based on ultra-compact Python code by Jarno Elonen, http://elonen.iki.fi/code/misc-notes/python-gaussj/index.html. */ -class GaussJordan { - public: - GaussJordan() = delete; - - /** - * @brief Eliminate transposed matrices in place - * @param a Transposed left side of augmented matrix - * @param t Transposed right side of augmented matrix - * @return True if @p a is regular, false if @p a is singular (and - * thus the system cannot be solved). - * - * As Gauss-Jordan elimination works on rows and matrices in OpenGL - * are column-major, it is more efficient to operate on transposed - * matrices and treat columns as rows. See also inPlace() which works - * with non-transposed matrices. - * - * The function eliminates matrix @p a and solves @p t in place. For - * efficiency reasons, only pure Gaussian elimination is done on @p a - * and the final backsubstitution is done only on @p t, as @p a would - * always end with identity matrix anyway. - */ - template static bool inPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t); - - /** - * @brief Eliminate in place - * - * Transposes the matrices, calls inPlaceTransposed() on them and then - * transposes them back. - */ - template static bool inPlace(RectangularMatrix& a, RectangularMatrix& t) { - a = a.transposed(); - RectangularMatrix tTransposed = t.transposed(); - - bool ret = inPlaceTransposed(a, tTransposed); - - a = a.transposed(); - t = tTransposed.transposed(); - - return ret; - } -}; - -template bool GaussJordan::inPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t) { +template bool gaussJordanInPlaceTransposed(RectangularMatrix& a, RectangularMatrix& t) { for(std::size_t row = 0; row != size; ++row) { /* Find max pivot */ std::size_t rowMax = row; @@ -110,6 +81,24 @@ template bool GaussJordan::inPlaceT return true; } +/** +@brief In-place Gauss-Jordan elimination + +Transposes the matrices, calls gaussJordanInPlaceTransposed() on them and then +transposes them back. +*/ +template bool gaussJordanInPlace(RectangularMatrix& a, RectangularMatrix& t) { + a = a.transposed(); + RectangularMatrix tTransposed = t.transposed(); + + bool ret = gaussJordanInPlaceTransposed(a, tTransposed); + + a = a.transposed(); + t = tTransposed.transposed(); + + return ret; +} + }}} #endif diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index 1825769df..155144f84 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -42,7 +42,7 @@ void GaussJordanTest::singular() { Vector4(1.0f, 2.0f, 7.0f, 40.0f)); RectangularMatrix<4, 1, float> t; - CORRADE_VERIFY(!GaussJordan::inPlaceTransposed(a, t)); + CORRADE_VERIFY(!gaussJordanInPlaceTransposed(a, t)); } void GaussJordanTest::invert() { @@ -58,7 +58,7 @@ void GaussJordanTest::invert() { Matrix4 a2(a); Matrix4 inverse = Matrix4::fromDiagonal(Vector4(1.0f)); - CORRADE_VERIFY(GaussJordan::inPlace(a2, inverse)); + CORRADE_VERIFY(gaussJordanInPlace(a2, inverse)); CORRADE_COMPARE(inverse, expectedInverse); CORRADE_COMPARE(a*inverse, Matrix4::fromDiagonal(Vector4(1.0f))); From ce2a07a09ae89c5738cdbaffd5507743d6d0630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 11:23:45 +0100 Subject: [PATCH 317/567] Math: slightly faster Vector::projectedOntoNormalized(). The assertion will still compute the dot product (but not in release builds). --- src/Math/Test/VectorTest.cpp | 18 ++++++++++++++++++ src/Math/Vector.h | 23 +++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index a07b3d345..d274b5af5 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -56,6 +56,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void maxAbs(); void projected(); + void projectedOntoNormalized(); void angle(); void lerp(); @@ -98,6 +99,7 @@ VectorTest::VectorTest() { &VectorTest::maxAbs, &VectorTest::projected, + &VectorTest::projectedOntoNormalized, &VectorTest::angle, &VectorTest::lerp, @@ -286,6 +288,22 @@ void VectorTest::projected() { CORRADE_COMPARE(projected.normalized(), line.normalized()); } +void VectorTest::projectedOntoNormalized() { + std::ostringstream o; + Error::setOutput(&o); + + Vector3 vector(1.0f, 2.0f, 3.0f); + Vector3 line(1.0f, -1.0f, 0.5f); + Vector3 projected = vector.projectedOntoNormalized(line); + CORRADE_VERIFY(projected != projected); + CORRADE_COMPARE(o.str(), "Math::Vector::projectedOntoNormalized(): line must be normalized\n"); + + projected = vector.projectedOntoNormalized(line.normalized()); + CORRADE_COMPARE(projected, Vector3(0.222222f, -0.222222f, 0.111111f)); + CORRADE_COMPARE(projected.normalized(), line.normalized()); + CORRADE_COMPARE(projected, vector.projected(line)); +} + void VectorTest::angle() { std::ostringstream o; Error::setOutput(&o); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 6744acb13..977ed935b 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -420,14 +420,29 @@ template class Vector { } /** - * @brief %Vector projected onto another + * @brief %Vector projected onto line * - * Returns vector projected onto line defined by @p other. @f[ + * Returns vector projected onto @p line. @f[ * \boldsymbol a_1 = \frac{\boldsymbol a \cdot \boldsymbol b}{\boldsymbol b \cdot \boldsymbol b} \boldsymbol b * @f] + * @see projectedOntoNormalized() */ - inline Vector projected(const Vector& other) const { - return other*dot(*this, other)/other.dot(); + inline Vector projected(const Vector& line) const { + return line*dot(*this, line)/line.dot(); + } + + /** + * @brief %Vector projected onto normalized line + * + * Slightly faster alternative to projected(), expects @p line to be + * normalized. @f[ + * \boldsymbol a_1 = \frac{\boldsymbol a \cdot \boldsymbol b}{\boldsymbol b \cdot \boldsymbol b} \boldsymbol b = + * (\boldsymbol a \cdot \boldsymbol b) \boldsymbol b + * @f] + */ + inline Vector projectedOntoNormalized(const Vector& line) const { + CORRADE_ASSERT(MathTypeTraits::equals(line.dot(), T(1)), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); + return line*dot(*this, line); } /** @brief Sum of values in the vector */ From 1967179a40cdca5ec23ec531876c46530b26610f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 11:29:28 +0100 Subject: [PATCH 318/567] Math: slight improvement of Gram-Schmidt orthonormalization algorithm. Using Vector::projectOntoNormalized(), as it is slightly faster, renamed the functions to properly mention that this is orthonormalization. --- src/Math/Algorithms/GramSchmidt.h | 16 ++++++++-------- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 8 ++++---- src/SceneGraph/EuclideanMatrixTransformation2D.h | 2 +- src/SceneGraph/EuclideanMatrixTransformation3D.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h index c6f60e2f5..905641766 100644 --- a/src/Math/Algorithms/GramSchmidt.h +++ b/src/Math/Algorithms/GramSchmidt.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Function Magnum::Math::Algorithms::gramSchmidtInPlace(), Magnum::Math::Algorithms::gramSchmidt() + * @brief Function Magnum::Math::Algorithms::gramSchmidtOrthonormalizeInPlace(), Magnum::Math::Algorithms::gramSchmidtOrthonormalize() */ #include "Math/RectangularMatrix.h" @@ -24,26 +24,26 @@ namespace Magnum { namespace Math { namespace Algorithms { /** -@brief Gram-Schmidt matrix orthonormalization +@brief In-place Gram-Schmidt matrix orthonormalization @param[in,out] matrix Matrix to perform orthonormalization on */ -template void gramSchmidtInPlace(RectangularMatrix& matrix) { +template void gramSchmidtOrthonormalizeInPlace(RectangularMatrix& matrix) { static_assert(cols <= rows, "Unsupported matrix aspect ratio"); for(std::size_t i = 0; i != cols; ++i) { matrix[i] = matrix[i].normalized(); for(std::size_t j = i+1; j != cols; ++j) - matrix[j] -= matrix[j].projected(matrix[i]); + matrix[j] -= matrix[j].projectedOntoNormalized(matrix[i]); } } /** @brief Gram-Schmidt matrix orthonormalization -Unlike gramSchmidtInPlace() returns the modified matrix instead of performing -the orthonormalization in-place. +Unlike gramSchmidtOrthonormalizeInPlace() returns the modified matrix instead +of performing the orthonormalization in-place. */ -template RectangularMatrix gramSchmidt(RectangularMatrix matrix) { - gramSchmidtInPlace(matrix); +template RectangularMatrix gramSchmidtOrthonormalize(RectangularMatrix matrix) { + gramSchmidtOrthonormalizeInPlace(matrix); return matrix; } diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 3313c3ac8..85700deaa 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -23,22 +23,22 @@ class GramSchmidtTest: public Corrade::TestSuite::Tester { public: GramSchmidtTest(); - void test(); + void orthonormalize(); }; typedef RectangularMatrix<3, 3, float> Matrix3; typedef Vector<3, float> Vector3; GramSchmidtTest::GramSchmidtTest() { - addTests(&GramSchmidtTest::test); + addTests(&GramSchmidtTest::orthonormalize); } -void GramSchmidtTest::test() { +void GramSchmidtTest::orthonormalize() { Matrix3 m(Vector3(3.0f, 5.0f, 8.0f), Vector3(4.0f, 4.0f, 7.0f), Vector3(7.0f, -1.0f, 8.0f)); - Matrix3 normalized = Algorithms::gramSchmidt(m); + Matrix3 normalized = Algorithms::gramSchmidtOrthonormalize(m); /* Verify the first vector is in direction of first original */ CORRADE_COMPARE(normalized[0], m[0].normalized()); diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index cb4a59081..fa80ed2a6 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -85,7 +85,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { */ EuclideanMatrixTransformation2D* normalizeRotation() { setTransformation(Math::Matrix3::from( - Math::Algorithms::gramSchmidt(_transformation.rotationScaling()), + Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); return this; } diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index d39dac91a..693b2b6c1 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -85,7 +85,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { */ EuclideanMatrixTransformation3D* normalizeRotation() { setTransformation(Math::Matrix4::from( - Math::Algorithms::gramSchmidt(_transformation.rotationScaling()), + Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); return this; } From b63adf24042c620fa1dfedd48860d3b5cce7e0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 11:56:03 +0100 Subject: [PATCH 319/567] Math: added Gram-Schmidt orthogonalization algorithm. --- src/Math/Algorithms/GramSchmidt.h | 25 ++++++++++- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 46 +++++++++++++++----- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h index 905641766..b27f51b3c 100644 --- a/src/Math/Algorithms/GramSchmidt.h +++ b/src/Math/Algorithms/GramSchmidt.h @@ -16,13 +16,36 @@ */ /** @file - * @brief Function Magnum::Math::Algorithms::gramSchmidtOrthonormalizeInPlace(), Magnum::Math::Algorithms::gramSchmidtOrthonormalize() + * @brief Function Magnum::Math::Algorithms::gramSchmidtOrthogonalizeInPlace(), Magnum::Math::Algorithms::gramSchmidtOrthogonalize(), Magnum::Math::Algorithms::gramSchmidtOrthonormalizeInPlace(), Magnum::Math::Algorithms::gramSchmidtOrthonormalize() */ #include "Math/RectangularMatrix.h" namespace Magnum { namespace Math { namespace Algorithms { +/** +@brief In-place Gram-Schmidt matrix orthogonalization +@param[in,out] matrix Matrix to perform orthogonalization on +*/ +template void gramSchmidtOrthogonalizeInPlace(RectangularMatrix& matrix) { + static_assert(cols <= rows, "Unsupported matrix aspect ratio"); + for(std::size_t i = 0; i != cols; ++i) { + for(std::size_t j = i+1; j != cols; ++j) + matrix[j] -= matrix[j].projected(matrix[i]); + } +} + +/** +@brief Gram-Schmidt matrix orthogonalization + +Unlike gramSchmidtOrthogonalizeInPlace() returns the modified matrix instead +of performing the orthogonalization in-place. +*/ +template RectangularMatrix gramSchmidtOrthogonalize(RectangularMatrix matrix) { + gramSchmidtOrthogonalizeInPlace(matrix); + return matrix; +} + /** @brief In-place Gram-Schmidt matrix orthonormalization @param[in,out] matrix Matrix to perform orthonormalization on diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 85700deaa..67e1e7595 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -23,6 +23,7 @@ class GramSchmidtTest: public Corrade::TestSuite::Tester { public: GramSchmidtTest(); + void orthogonalize(); void orthonormalize(); }; @@ -30,7 +31,32 @@ typedef RectangularMatrix<3, 3, float> Matrix3; typedef Vector<3, float> Vector3; GramSchmidtTest::GramSchmidtTest() { - addTests(&GramSchmidtTest::orthonormalize); + addTests(&GramSchmidtTest::orthogonalize, + &GramSchmidtTest::orthonormalize); +} + +void GramSchmidtTest::orthogonalize() { + Matrix3 m(Vector3(3.0f, 5.0f, 1.0f), + Vector3(4.0f, 4.0f, 7.0f), + Vector3(7.0f, -1.0f, -3.0f)); + + Matrix3 orthogonalized = Algorithms::gramSchmidtOrthogonalize(m); + + /* Verify the first vector is in direction of first original */ + CORRADE_COMPARE(orthogonalized[0], m[0]); + + /* (The vectors don't need to unit length) */ + + /* Verify the vectors are orthogonal */ + CORRADE_COMPARE(Vector3::dot(orthogonalized[0], orthogonalized[1]), 0.0f); + CORRADE_COMPARE(Vector3::dot(orthogonalized[0], orthogonalized[2]), 0.0f); + CORRADE_COMPARE(Vector3::dot(orthogonalized[1], orthogonalized[2]), 0.0f); + + /* Just to be sure */ + Matrix3 expected(Vector3( 3.0f, 5.0f, 1.0f), + Vector3(0.657143f, -1.571429f, 5.885714f), + Vector3(6.086759f, -3.3379f, -1.570777f)); + CORRADE_COMPARE(orthogonalized, expected); } void GramSchmidtTest::orthonormalize() { @@ -38,26 +64,26 @@ void GramSchmidtTest::orthonormalize() { Vector3(4.0f, 4.0f, 7.0f), Vector3(7.0f, -1.0f, 8.0f)); - Matrix3 normalized = Algorithms::gramSchmidtOrthonormalize(m); + Matrix3 orthonormalized = Algorithms::gramSchmidtOrthonormalize(m); /* Verify the first vector is in direction of first original */ - CORRADE_COMPARE(normalized[0], m[0].normalized()); + CORRADE_COMPARE(orthonormalized[0], m[0].normalized()); /* Verify the vectors have unit length */ - CORRADE_COMPARE(normalized[0].length(), 1.0f); - CORRADE_COMPARE(normalized[1].length(), 1.0f); - CORRADE_COMPARE(normalized[2].length(), 1.0f); + CORRADE_COMPARE(orthonormalized[0].length(), 1.0f); + CORRADE_COMPARE(orthonormalized[1].length(), 1.0f); + CORRADE_COMPARE(orthonormalized[2].length(), 1.0f); /* Verify the vectors are orthogonal */ - CORRADE_COMPARE(Vector3::dot(normalized[0], normalized[1]), 0.0f); - CORRADE_COMPARE(Vector3::dot(normalized[0], normalized[2]), 0.0f); - CORRADE_COMPARE(Vector3::dot(normalized[1], normalized[2]), 0.0f); + CORRADE_COMPARE(Vector3::dot(orthonormalized[0], orthonormalized[1]), 0.0f); + CORRADE_COMPARE(Vector3::dot(orthonormalized[0], orthonormalized[2]), 0.0f); + CORRADE_COMPARE(Vector3::dot(orthonormalized[1], orthonormalized[2]), 0.0f); /* Just to be sure */ Matrix3 expected(Vector3( 0.303046f, 0.505076f, 0.808122f), Vector3( 0.928316f, -0.348119f, -0.130544f), Vector3(-0.215388f, -0.789754f, 0.574367f)); - CORRADE_COMPARE(normalized, expected); + CORRADE_COMPARE(orthonormalized, expected); } }}}} From 0144c38a54908747537fec9a64b05cd82cf50c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 12:17:04 +0100 Subject: [PATCH 320/567] Math: moved lerp() from Vector to Functions.h. It does nothing special for vectors (unlike e.g. quaternion LERP) and scalar overload is useful too. --- src/Math/Functions.h | 24 ++++++++++++++++++++++++ src/Math/Quaternion.h | 2 ++ src/Math/Test/FunctionsTest.cpp | 19 +++++++++++++++++++ src/Math/Test/VectorTest.cpp | 14 -------------- src/Math/Vector.h | 19 ------------------- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index 76bff57b4..b313780b0 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -153,6 +153,30 @@ template Vector clamp(const Vector& } #endif +/** +@brief Linear interpolation of two values +@param a First value +@param b Second value +@param t Interpolation phase (from range @f$ [0; 1] @f$) + +The interpolation for vectors is done as in following, similarly for scalars: @f[ + \boldsymbol v_{LERP} = (1 - t) \boldsymbol v_A + t \boldsymbol v_B +@f] +@see Quaternion::lerp() +@todo http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/ + (when SIMD is in place) +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T lerp(const T& a, const T& b, U t); +#else +template inline T lerp(T a, T b, U t) { + return (U(1) - t)*a + t*b; +} +template inline Vector lerp(const Vector& a, const Vector& b, U t) { + return (U(1) - t)*a + t*b; +} +#endif + /** @brief Normalize integral value diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 1615c4e41..1d513f8bc 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -72,6 +72,7 @@ template class Quaternion { * Expects that both quaternions are normalized. @f[ * q_{LERP} = \frac{(1 - t) q_A + t q_B}{|(1 - t) q_A + t q_B|} * @f] + * @see slerp(), Math::lerp() */ inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), @@ -91,6 +92,7 @@ template class Quaternion { * ~~~~~~~~~~ * \theta = acos \left( \frac{q_A \cdot q_B}{|q_A| \cdot |q_B|} \right) * @f] + * @see lerp() */ inline static Quaternion slerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index dd88b08cc..049c9be67 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -28,6 +28,7 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void max(); void abs(); void clamp(); + void lerp(); void normalizeUnsigned(); void normalizeSigned(); void denormalizeUnsigned(); @@ -50,6 +51,7 @@ FunctionsTest::FunctionsTest() { &FunctionsTest::max, &FunctionsTest::abs, &FunctionsTest::clamp, + &FunctionsTest::lerp, &FunctionsTest::normalizeUnsigned, &FunctionsTest::normalizeSigned, &FunctionsTest::denormalizeUnsigned, @@ -85,6 +87,23 @@ void FunctionsTest::clamp() { CORRADE_COMPARE(Math::clamp(Vector3(0.5f, -1.6f, 9.5f), -1.0f, 5.0f), Vector3(0.5f, -1.0f, 5.0f)); } +void FunctionsTest::lerp() { + /* Floating-point / integral scalar */ + CORRADE_COMPARE(Math::lerp(2.0f, 5.0f, 0.5f), 3.5f); + CORRADE_COMPARE(Math::lerp(2, 5, 0.5f), 3); + + /* Floating-point vector */ + Vector3 a(-1.0f, 2.0f, 3.0f); + Vector3 b(3.0f, -2.0f, 11.0f); + CORRADE_COMPARE(Math::lerp(a, b, 0.25f), Vector3(0.0f, 1.0f, 5.0f)); + + /* Integer vector */ + typedef Math::Vector<3, std::int32_t> Vector3ub; + Vector3ub c(0, 128, 64); + Vector3ub d(16, 0, 32); + CORRADE_COMPARE(Math::lerp(c, d, 0.25f), Vector3ub(4, 96, 56)); +} + void FunctionsTest::normalizeUnsigned() { CORRADE_COMPARE((Math::normalize(0)), 0.0f); CORRADE_COMPARE((Math::normalize(255)), 1.0f); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index d274b5af5..9035fdaeb 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -58,7 +58,6 @@ class VectorTest: public Corrade::TestSuite::Tester { void projected(); void projectedOntoNormalized(); void angle(); - void lerp(); void debug(); void configuration(); @@ -101,7 +100,6 @@ VectorTest::VectorTest() { &VectorTest::projected, &VectorTest::projectedOntoNormalized, &VectorTest::angle, - &VectorTest::lerp, &VectorTest::debug, &VectorTest::configuration); @@ -320,18 +318,6 @@ void VectorTest::angle() { rad(1.162514f)); } -void VectorTest::lerp() { - Vector3 a(-1.0f, 2.0f, 3.0f); - Vector3 b(3.0f, -2.0f, 11.0f); - - CORRADE_COMPARE(Vector3::lerp(a, b, 0.25f), Vector3(0.0f, 1.0f, 5.0f)); - - typedef Math::Vector<3, std::int32_t> Vector3ub; - Vector3ub c(0, 128, 64); - Vector3ub d(16, 0, 32); - CORRADE_COMPARE(Vector3ub::lerp(c, d, 0.25f), Vector3ub(4, 96, 56)); -} - void VectorTest::debug() { std::ostringstream o; Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 977ed935b..edc480ec2 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -90,22 +90,6 @@ template class Vector { return std::acos(dot(normalizedA, normalizedB)); } - /** - * @brief Linear interpolation of two vectors - * @param a First vector - * @param b Second vector - * @param t Interpolation phase (from range @f$ [0; 1] @f$) - * - * The interpolation is done as in following: @f[ - * \boldsymbol v_{LERP} = (1 - t) \boldsymbol v_A + t \boldsymbol v_B - * @f] - * @todo http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/ - * (when SIMD is in place) - */ - template inline static Vector lerp(const Vector& a, const Vector& b, U t) { - return (U(1) - t)*a + t*b; - } - /** @brief Construct zero-filled vector */ inline constexpr /*implicit*/ Vector(): _data() {} @@ -587,9 +571,6 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit } \ inline constexpr static const Type& from(const T* data) { \ return *reinterpret_cast*>(data); \ - } \ - template inline static const Type lerp(const Math::Vector& a, const Math::Vector& b, U t) { \ - return Math::Vector::lerp(a, b, t); \ } \ \ inline Type& operator=(const Type& other) { \ From 99e2bd4c6433eee67b820aa9420f55c9dbeca713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 12:18:35 +0100 Subject: [PATCH 321/567] Doc++ --- doc/matrix-vector.dox | 2 +- src/Math/Algorithms/GramSchmidt.h | 4 ++-- src/Math/Matrix.h | 1 + src/Math/Matrix3.h | 1 + src/Math/Matrix4.h | 1 + src/Math/RectangularMatrix.h | 1 + 6 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 44be0fff9..5f5afec45 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -175,7 +175,7 @@ mat[0] *= 2; // first column mat[2][0] = 5; // first element of first column @endcode - Various algorithms which commonly operate on matrix rows (such as - @ref Algorithms::GaussJordan "Gauss-Jordan elimination") have faster + @ref Algorithms::gaussJordanInPlace() "Gauss-Jordan elimination") have faster alternatives which operate on columns. It's then up to user decision to operate with transposed matrices or use the slower non-transposed alternative of the algorithm. diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h index b27f51b3c..189fd3de6 100644 --- a/src/Math/Algorithms/GramSchmidt.h +++ b/src/Math/Algorithms/GramSchmidt.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Math { namespace Algorithms { /** @brief In-place Gram-Schmidt matrix orthogonalization -@param[in,out] matrix Matrix to perform orthogonalization on +@param[in,out] matrix %Matrix to perform orthogonalization on */ template void gramSchmidtOrthogonalizeInPlace(RectangularMatrix& matrix) { static_assert(cols <= rows, "Unsupported matrix aspect ratio"); @@ -48,7 +48,7 @@ template RectangularMatrix void gramSchmidtOrthonormalizeInPlace(RectangularMatrix& matrix) { static_assert(cols <= rows, "Unsupported matrix aspect ratio"); diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index cfe96ca3e..b4f482391 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -61,6 +61,7 @@ template class Matrix: public RectangularMatrix class Matrix3: public Matrix<3, T> { inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {} /** @copydoc Matrix::Matrix(IdentityType, T) */ + /** @todo Use constexpr implementation in Matrix, when done */ inline constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( Vector<3, T>(value, T(0), T(0)), Vector<3, T>( T(0), value, T(0)), diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 55f6a58ce..e919c75f3 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -243,6 +243,7 @@ template class Matrix4: public Matrix<4, T> { inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} /** @copydoc Matrix::Matrix(IdentityType, T) */ + /** @todo Use constexpr implementation in Matrix, when done */ inline constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( Vector<4, T>(value, T(0), T(0), T(0)), Vector<4, T>( T(0), value, T(0), T(0)), diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 56a6acc6b..f9df7752b 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -73,6 +73,7 @@ template class RectangularMatrix { * @brief Construct diagonal matrix * * @see diagonal() + * @todo make this constexpr */ inline static RectangularMatrix fromDiagonal(const Vector& diagonal) { RectangularMatrix out; From bc48107d5a370c49da17508d49d76d68ecb3f7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 17:38:58 +0100 Subject: [PATCH 322/567] magnum-info: indent with 4, not 3 spaces. --- src/Platform/magnum-info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 2ad9c5b53..8418c8283 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -95,7 +95,7 @@ MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, a for(const auto& extension: Extension::extensions(versions[i])) { std::string extensionName = extension.string(); Debug d; - d << " " << extensionName << std::string(60-extensionName.size(), ' '); + d << " " << extensionName << std::string(60-extensionName.size(), ' '); if(c->isExtensionSupported(extension)) d << "SUPPORTED"; else if(c->isVersionSupported(extension.requiredVersion())) From 18ad4307aa561ad934fad91f00c2fcce2f39c0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 18:31:03 +0100 Subject: [PATCH 323/567] Implementation for texture level parameter query. --- src/AbstractTexture.cpp | 18 ++++++++++++++++++ src/AbstractTexture.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 6693f37da..5f9492970 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -32,6 +32,10 @@ AbstractTexture::ParameterfImplementation AbstractTexture::parameterfImplementat &AbstractTexture::parameterImplementationDefault; AbstractTexture::ParameterfvImplementation AbstractTexture::parameterfvImplementation = &AbstractTexture::parameterImplementationDefault; +#ifndef MAGNUM_TARGET_GLES +AbstractTexture::GetLevelParameterivImplementation AbstractTexture::getLevelParameterivImplementation = + &AbstractTexture::getLevelParameterImplementationDefault; +#endif AbstractTexture::MipmapImplementation AbstractTexture::mipmapImplementation = &AbstractTexture::mipmapImplementationDefault; #ifndef MAGNUM_TARGET_GLES @@ -218,6 +222,7 @@ void AbstractTexture::initializeContextBasedFunctionality(Context* context) { parameteriImplementation = &AbstractTexture::parameterImplementationDSA; parameterfImplementation = &AbstractTexture::parameterImplementationDSA; parameterfvImplementation = &AbstractTexture::parameterImplementationDSA; + getLevelParameterivImplementation = &AbstractTexture::getLevelParameterImplementationDSA; mipmapImplementation = &AbstractTexture::mipmapImplementationDSA; storage1DImplementation = &AbstractTexture::storageImplementationDSA; storage2DImplementation = &AbstractTexture::storageImplementationDSA; @@ -270,7 +275,20 @@ void AbstractTexture::parameterImplementationDefault(GLenum parameter, const GLf void AbstractTexture::parameterImplementationDSA(GLenum parameter, const GLfloat* values) { glTextureParameterfvEXT(_id, _target, parameter, values); } +#endif +#ifndef MAGNUM_TARGET_GLES +void AbstractTexture::getLevelParameterImplementationDefault(GLenum target, GLint level, GLenum parameter, GLint* values) { + bindInternal(); + glGetTexLevelParameteriv(target, level, parameter, values); +} + +void AbstractTexture::getLevelParameterImplementationDSA(GLenum target, GLint level, GLenum parameter, GLint* values) { + glGetTextureLevelParameterivEXT(_id, target, level, parameter, values); +} +#endif + +#ifndef MAGNUM_TARGET_GLES void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels, AbstractTexture::InternalFormat internalFormat, const Math::Vector< 1, GLsizei >& size) { bindInternal(); /** @todo Re-enable when extension wrangler is available for ES2 */ diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 9d7c8a118..328d75a15 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1185,6 +1185,13 @@ class MAGNUM_EXPORT AbstractTexture { #endif static ParameterfvImplementation parameterfvImplementation; + #ifndef MAGNUM_TARGET_GLES + typedef void(AbstractTexture::*GetLevelParameterivImplementation)(GLenum, GLint, GLenum, GLint*); + void MAGNUM_LOCAL getLevelParameterImplementationDefault(GLenum target, GLint level, GLenum parameter, GLint* values); + void MAGNUM_LOCAL getLevelParameterImplementationDSA(GLenum target, GLint level, GLenum parameter, GLint* values); + static MAGNUM_LOCAL GetLevelParameterivImplementation getLevelParameterivImplementation; + #endif + typedef void(AbstractTexture::*MipmapImplementation)(); void MAGNUM_LOCAL mipmapImplementationDefault(); #ifndef MAGNUM_TARGET_GLES From dd9fcd83f01d1e71a1813eed85462468d50cf2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 22:58:23 +0100 Subject: [PATCH 324/567] Fixed name clash in internal implementation. Clang didn't like that. --- src/AbstractShaderProgram.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 07fd6fa4f..3fd055743 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1207,12 +1207,12 @@ template<> struct Attribute { } }; -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size; } +template struct Attribute>: public Attribute { + inline constexpr static GLint components() { return size_; } }; -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size; } +template struct Attribute>: public Attribute { + inline constexpr static GLint components() { return size_; } }; #ifndef MAGNUM_TARGET_GLES @@ -1237,14 +1237,14 @@ template struct Attribute struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size; } - inline constexpr static std::size_t vectorCount() { return size; } +template struct Attribute>: public Attribute { + inline constexpr static GLint components() { return size_; } + inline constexpr static std::size_t vectorCount() { return size_; } }; -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size; } - inline constexpr static std::size_t vectorCount() { return size; } +template struct Attribute>: public Attribute { + inline constexpr static GLint components() { return size_; } + inline constexpr static std::size_t vectorCount() { return size_; } }; #endif From c339063566d0f55395695d7506afb460d4a53f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 22:59:41 +0100 Subject: [PATCH 325/567] Don't instanitate/declare structs as classes. Clang warned about that. --- src/AbstractTexture.cpp | 6 +++--- src/Context.h | 2 +- src/Magnum.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 5f9492970..33d5f534a 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -458,9 +458,9 @@ namespace Implementation { return nullptr; } - template class ImageHelper; - template class ImageHelper; - template class ImageHelper; + template struct ImageHelper; + template struct ImageHelper; + template struct ImageHelper; } #endif diff --git a/src/Context.h b/src/Context.h index e072a2826..f0153c75e 100644 --- a/src/Context.h +++ b/src/Context.h @@ -30,7 +30,7 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - class State; + struct State; } #endif diff --git a/src/Magnum.h b/src/Magnum.h index 017261599..440d57a67 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -53,7 +53,7 @@ namespace Magnum { namespace Math { template constexpr T deg(T value); template constexpr T rad(T value); - template class Constants; + template struct Constants; } /* Bring debugging facility from Corrade::Utility namespace */ From 55fecaff5abc82ca8f47dbc487fbf1ab7b362e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 23:27:42 +0100 Subject: [PATCH 326/567] Template aliases also can't have "conflicting" default arguments. Clang didn't like that (and I thought these workarounds aren't needed with C++11's alias template anymore). --- src/SceneGraph/AbstractCamera.h | 14 ++++++++-- src/SceneGraph/AbstractFeature.h | 14 ++++++++-- src/SceneGraph/AbstractGroupedFeature.h | 14 ++++++++-- src/SceneGraph/AbstractObject.h | 14 ++++++++-- src/SceneGraph/AbstractTransformation.h | 14 ++++++++-- src/SceneGraph/Animable.h | 14 ++++++++-- src/SceneGraph/AnimableGroup.h | 14 ++++++++-- src/SceneGraph/Drawable.h | 37 +++++++++++++++++++++---- src/SceneGraph/FeatureGroup.h | 14 ++++++++-- 9 files changed, 127 insertions(+), 22 deletions(-) diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index e15793dde..4f2c24076 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -169,7 +169,12 @@ for more information. @note Not available on GCC < 4.7. Use %AbstractCamera<2, T> instead. @see AbstractCamera3D */ -template using AbstractCamera2D = AbstractCamera<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractCamera2D = AbstractCamera<2, T>; /** @brief Base for three-dimensional cameras @@ -179,7 +184,12 @@ for more information. @note Not available on GCC < 4.7. Use %AbstractCamera<3, T> instead. @see AbstractCamera2D */ -template using AbstractCamera3D = AbstractCamera<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractCamera3D = AbstractCamera<3, T>; #endif }} diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 749e620b2..38b76eb3a 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -293,7 +293,12 @@ for more information. @note Not available on GCC < 4.7. Use %AbstractFeature<2, T> instead. @see AbstractFeature3D */ -template using AbstractFeature2D = AbstractFeature<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractFeature2D = AbstractFeature<2, T>; /** @brief Base for three-dimensional features @@ -303,7 +308,12 @@ for more information. @note Not available on GCC < 4.7. Use %AbstractFeature<3, T> instead. @see AbstractFeature2D */ -template using AbstractFeature3D = AbstractFeature<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractFeature3D = AbstractFeature<3, T>; #endif }} diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index 7d7326e8a..e1dbfd58b 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -102,7 +102,12 @@ AbstractGroupedFeature for more information. instead. @see AbstractGroupedFeature3D */ -template using AbstractGroupedFeature2D = AbstractGroupedFeature<2, Derived, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractGroupedFeature2D = AbstractGroupedFeature<2, Derived, T>; /** @brief Base for three-dimensional grouped features @@ -113,7 +118,12 @@ AbstractGroupedFeature for more information. instead. @see AbstractGroupedFeature2D */ -template using AbstractGroupedFeature3D = AbstractGroupedFeature<3, Derived, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractGroupedFeature3D = AbstractGroupedFeature<3, Derived, T>; #endif }} diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 7f3d711da..5714c9a92 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -197,7 +197,12 @@ for more information. @note Not available on GCC < 4.7. Use %AbstractObject<2, T> instead. @see AbstractObject3D */ -template using AbstractObject2D = AbstractObject<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractObject2D = AbstractObject<2, T>; /** @brief Base for three-dimensional objects @@ -207,7 +212,12 @@ for more information. @note Not available on GCC < 4.7. Use %AbstractObject<3, T> instead. @see AbstractObject2D */ -template using AbstractObject3D = AbstractObject<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractObject3D = AbstractObject<3, T>; #endif }} diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index d3eab7d49..92c2ea62d 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -149,7 +149,12 @@ AbstractTransformation for more information. instead. @see AbstractTransformation3D */ -template using AbstractTransformation2D = AbstractTransformation<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractTransformation2D = AbstractTransformation<2, T>; /** @brief Base for three-dimensional transformations @@ -160,7 +165,12 @@ AbstractTransformation for more information. instead. @see AbstractTransformation2D */ -template using AbstractTransformation3D = AbstractTransformation<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractTransformation3D = AbstractTransformation<3, T>; #endif }} diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 959dbf32a..3b21555e6 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -331,7 +331,12 @@ information. @note Not available on GCC < 4.7. Use %Animable<2, T> instead. @see Animable3D */ -template using Animable2D = Animable<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using Animable2D = Animable<2, T>; /** @brief Three-dimensional animable @@ -341,7 +346,12 @@ information. @note Not available on GCC < 4.7. Use %Animable<3, T> instead. @see Animable2D */ -template using Animable3D = Animable<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using Animable3D = Animable<3, T>; #endif }} diff --git a/src/SceneGraph/AnimableGroup.h b/src/SceneGraph/AnimableGroup.h index 814c214cd..5b6a1780b 100644 --- a/src/SceneGraph/AnimableGroup.h +++ b/src/SceneGraph/AnimableGroup.h @@ -76,7 +76,12 @@ more information. @note Not available on GCC < 4.7. Use %AnimableGroup<2, T> instead. @see AnimableGroup3D */ -template using AnimableGroup2D = AnimableGroup<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AnimableGroup2D = AnimableGroup<2, T>; /** @brief Three-dimensional animable @@ -86,7 +91,12 @@ more information. @note Not available on GCC < 4.7. Use %AnimableGroup<3, T> instead. @see AnimableGroup2D */ -template using AnimableGroup3D = AnimableGroup<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AnimableGroup3D = AnimableGroup<3, T>; #endif }} diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 416efd140..702d3d60c 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -144,7 +144,12 @@ information. @note Not available on GCC < 4.7. Use %Drawable<2, T> instead. @see Drawable3D */ -template using Drawable2D = Drawable<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using Drawable2D = Drawable<2, T>; /** @brief Three-dimensional drawable @@ -154,7 +159,12 @@ information. @note Not available on GCC < 4.7. Use %Drawable<3, T> instead. @see Drawable2D */ -template using Drawable3D = Drawable<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using Drawable3D = Drawable<3, T>; #endif /** @@ -164,12 +174,17 @@ See Drawable for more information. @see @ref scenegraph, DrawableGroup2D, DrawableGroup3D */ #ifndef CORRADE_GCC46_COMPATIBILITY -template using DrawableGroup = FeatureGroup, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template #else -#ifndef DOXYGEN_GENERATING_OUTPUT template +#endif +using DrawableGroup = FeatureGroup, T>; #else +#ifdef DOXYGEN_GENERATING_OUTPUT template +#else +template #endif class DrawableGroup: public FeatureGroup, T> {}; #endif @@ -183,7 +198,12 @@ more information. @note Not available on GCC < 4.7. Use %Drawable<2, T> instead. @see DrawableGroup3D */ -template using DrawableGroup2D = DrawableGroup<2, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using DrawableGroup2D = DrawableGroup<2, T>; /** @brief Group of three-dimensional drawables @@ -193,7 +213,12 @@ more information. @note Not available on GCC < 4.7. Use %Drawable<3, T> instead. @see DrawableGroup2D */ -template using DrawableGroup3D = DrawableGroup<3, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using DrawableGroup3D = DrawableGroup<3, T>; #endif }} diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index ad1a94bbb..229f719c9 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -118,7 +118,12 @@ AbstractGroupedFeature for more information. instead. @see FeatureGroup3D */ -template using FeatureGroup2D = FeatureGroup<2, Feature, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using FeatureGroup2D = FeatureGroup<2, Feature, T>; /** @brief Base for three-dimensional object features @@ -129,7 +134,12 @@ AbstractGroupedFeature for more information. instead. @see FeatureGroup2D */ -template using FeatureGroup3D = FeatureGroup<3, Feature, T>; +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using FeatureGroup3D = FeatureGroup<3, Feature, T>; #endif }} From 28c15aeb93593cbf64f35ec19f70d1e8e59d1e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Feb 2013 12:35:06 +0100 Subject: [PATCH 327/567] Clang fixes for friend declarations. Friending only constructor apparently doesn't help, specifying full-scope name for Resource. --- src/ResourceManager.h | 2 +- src/SceneGraph/AbstractObject.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 380b2af7a..1c0128e85 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -89,7 +89,7 @@ namespace Implementation { }; template class ResourceManagerData { - template friend class Resource; + template friend class Magnum::Resource; friend class AbstractResourceLoader; ResourceManagerData(const ResourceManagerData&) = delete; diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 5714c9a92..233c9a878 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -55,7 +55,7 @@ template class AbstractObject { friend class Corrade::Containers::LinkedList>; friend class Corrade::Containers::LinkedListItem, AbstractObject>; - friend AbstractFeature::AbstractFeature(AbstractObject*); + friend class AbstractFeature; public: /** @brief Feature object type */ From 3610a80dfd931d468662cb3516c9ab5c00be6624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Feb 2013 12:37:16 +0100 Subject: [PATCH 328/567] Clang fixes for templated base classes. Unlike GCC it does need the `template` keyword on weird places. --- src/SceneGraph/AbstractFeature.h | 2 +- src/SceneGraph/EuclideanMatrixTransformation2D.h | 2 +- src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/Object.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 38b76eb3a..3b8d344dc 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -133,7 +133,7 @@ template class AbstractFeature * @param object %Object holding this feature */ inline explicit AbstractFeature(AbstractObject* object) { - object->Corrade::Containers::LinkedList>::insert(this); + object->Corrade::Containers::template LinkedList>::insert(this); } virtual ~AbstractFeature() = 0; diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index fa80ed2a6..3b497cf40 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -128,7 +128,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * @return Pointer to self (for method chaining) */ inline EuclideanMatrixTransformation2D* move(Object>* under) { - static_cast*>(this)->Corrade::Containers::LinkedList>>::move(this, under); + static_cast*>(this)->Corrade::Containers::template LinkedList>>::move(this, under); return this; } diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index fa469bc42..08f1fdbd0 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -139,7 +139,7 @@ class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { * @return Pointer to self (for method chaining) */ inline MatrixTransformation2D* move(Object>* under) { - static_cast*>(this)->Corrade::Containers::LinkedList>>::move(this, under); + static_cast*>(this)->Corrade::Containers::template LinkedList>>::move(this, under); return this; } diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index 72c45dfec..708384def 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -69,7 +69,7 @@ template Object* Object::s } /* Remove the object from old parent children list */ - if(this->parent()) this->parent()->Corrade::Containers::LinkedList>::cut(this); + if(this->parent()) this->parent()->Corrade::Containers::template LinkedList>::cut(this); /* Add the object to list of new parent */ if(parent) parent->Corrade::Containers::LinkedList>::insert(this); From 8d2485c331fb6b01cfc79dc819acf1b5b4ac12a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Feb 2013 12:38:14 +0100 Subject: [PATCH 329/567] Clang also needs parentheses around default templated arguments. --- src/SceneGraph/AbstractObject.h | 2 +- src/SceneGraph/Object.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 233c9a878..3278ed29c 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -127,7 +127,7 @@ template class AbstractObject * Object type, use typesafe Object::transformations() when * possible. */ - virtual std::vector::MatrixType> transformationMatrices(const std::vector*>& objects, const typename DimensionTraits::MatrixType& initialTransformationMatrix = typename DimensionTraits::MatrixType()) const = 0; + virtual std::vector::MatrixType> transformationMatrices(const std::vector*>& objects, const typename DimensionTraits::MatrixType& initialTransformationMatrix = (typename DimensionTraits::MatrixType())) const = 0; /*@}*/ diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index e3975ef8b..0b6fb50be 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -239,7 +239,7 @@ template class MAGNUM_SCENEGRAPH_EXPORT Object: public Abs Object* sceneObject() override; const Object* sceneObject() const override; - std::vector::MatrixType> transformationMatrices(const std::vector*>& objects, const typename DimensionTraits::MatrixType& initialTransformationMatrix = typename DimensionTraits::MatrixType()) const override; + std::vector::MatrixType> transformationMatrices(const std::vector*>& objects, const typename DimensionTraits::MatrixType& initialTransformationMatrix = (typename DimensionTraits::MatrixType())) const override; typename Transformation::DataType MAGNUM_SCENEGRAPH_LOCAL computeJointTransformation(const std::vector*>& jointObjects, std::vector& jointTransformations, const std::size_t joint, const typename Transformation::DataType& initialTransformation) const; From f23827bd87ac9b51333593febd003dad5dbe5c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Feb 2013 12:39:22 +0100 Subject: [PATCH 330/567] Clang linker fixes. --- src/Physics/AxisAlignedBox.cpp | 4 ++-- src/Physics/Capsule.cpp | 4 ++-- src/Physics/ObjectShape.cpp | 4 ++-- src/Physics/ObjectShapeGroup.cpp | 4 ++-- src/Physics/Sphere.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index abce0aa3e..786003a40 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -38,7 +38,7 @@ template bool AxisAlignedBox::operator%(con (other.transformedPosition() < _transformedMax).all(); } -template class AxisAlignedBox<2>; -template class AxisAlignedBox<3>; +template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox<2>; +template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox<3>; }} diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 59b54f653..784b016d9 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -53,7 +53,7 @@ template bool Capsule::operator%(const Sphe Math::pow<2>(transformedRadius()+other.transformedRadius()); } -template class Capsule<2>; -template class Capsule<3>; +template class MAGNUM_PHYSICS_EXPORT Capsule<2>; +template class MAGNUM_PHYSICS_EXPORT Capsule<3>; }} diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index fb1a800fc..220655125 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -46,7 +46,7 @@ template void ObjectShape::clean(const type if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); } -template class ObjectShape<2>; -template class ObjectShape<3>; +template class MAGNUM_PHYSICS_EXPORT ObjectShape<2>; +template class MAGNUM_PHYSICS_EXPORT ObjectShape<3>; }} diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index b24d65a35..39766effd 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -45,7 +45,7 @@ template ObjectShape* ObjectShapeGroup; -template class ObjectShapeGroup<3>; +template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup<2>; +template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup<3>; }} diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 7096ff0cb..c0cf2aa33 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -78,7 +78,7 @@ template bool Sphere::operator%(const Spher Math::pow<2>(transformedRadius()+other.transformedRadius()); } -template class Sphere<2>; -template class Sphere<3>; +template class MAGNUM_PHYSICS_EXPORT Sphere<2>; +template class MAGNUM_PHYSICS_EXPORT Sphere<3>; }} From 692f4854a7f9fff0325a2245fac121fdd95fcdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Feb 2013 12:40:14 +0100 Subject: [PATCH 331/567] Ability to retrieve texture image size in given mip level. --- src/AbstractTexture.cpp | 23 +++++++++++++++++++++++ src/AbstractTexture.h | 10 ++++++++++ src/CubeMapTexture.h | 14 ++++++++++++++ src/CubeMapTextureArray.h | 11 +++++++++++ src/Texture.h | 17 +++++++++++++++++ 5 files changed, 75 insertions(+) diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 33d5f534a..7fe72dca1 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -464,6 +464,29 @@ namespace Implementation { } #endif +#ifndef MAGNUM_TARGET_GLES +Math::Vector<1, GLint> AbstractTexture::DataHelper<1>::imageSize(AbstractTexture* texture, GLenum target, GLint level) { + Math::Vector<1, GLint> value; + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_WIDTH, &value[0]); + return value; +} + +Vector2i AbstractTexture::DataHelper<2>::imageSize(AbstractTexture* texture, GLenum target, GLint level) { + Vector2i value; + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_WIDTH, &value[0]); + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_HEIGHT, &value[1]); + return value; +} + +Vector3i AbstractTexture::DataHelper<3>::imageSize(AbstractTexture* texture, GLenum target, GLint level) { + Vector3i value; + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_WIDTH, &value[0]); + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_HEIGHT, &value[1]); + (texture->*getLevelParameterivImplementation)(target, level, GL_TEXTURE_DEPTH, &value[2]); + return value; +} +#endif + void AbstractTexture::DataHelper<2>::setWrapping(AbstractTexture* texture, const Array2D& wrapping) { #ifndef MAGNUM_TARGET_GLES CORRADE_ASSERT(texture->_target != GL_TEXTURE_RECTANGLE || ((wrapping.x() == Wrapping::ClampToEdge || wrapping.x() == Wrapping::ClampToBorder) && (wrapping.y() == Wrapping::ClampToEdge || wrapping.y() == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", ); diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 328d75a15..3d190e76c 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1308,6 +1308,8 @@ template<> struct AbstractTexture::DataHelper<1> { inline constexpr static Target target() { return Target::Texture1D; } + static Math::Vector<1, GLint> imageSize(AbstractTexture* texture, GLenum target, GLint level); + inline static void setWrapping(AbstractTexture* texture, const Array1D& wrapping) { (texture->*parameteriImplementation)(GL_TEXTURE_WRAP_S, static_cast(wrapping.x())); } @@ -1341,6 +1343,10 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> { inline constexpr static Target target() { return Target::Texture2D; } + #ifndef MAGNUM_TARGET_GLES + static Vector2i imageSize(AbstractTexture* texture, GLenum target, GLint level); + #endif + static void setWrapping(AbstractTexture* texture, const Array2D& wrapping); inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector2i& size) { @@ -1375,6 +1381,10 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> { inline constexpr static Target target() { return Target::Texture3D; } + #ifndef MAGNUM_TARGET_GLES + static Vector3i imageSize(AbstractTexture* texture, GLenum target, GLint level); + #endif + static void setWrapping(AbstractTexture* texture, const Array3D& wrapping); inline static void setStorage(AbstractTexture* texture, GLenum target, GLsizei levels, InternalFormat internalFormat, const Vector3i& size) { diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 61dcd3b77..ed3a2c9d3 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -110,6 +110,20 @@ class CubeMapTexture: public AbstractTexture { return this; } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief %Image size in given mip level + * @param coordinate Coordinate + * @param level Mip level + * + * See Texture::imageSize() for more information. + * @requires_gl %Texture image queries are not available in OpenGL ES. + */ + inline Vector2i imageSize(Coordinate coordinate, GLint level) { + return DataHelper<2>::imageSize(this, static_cast(coordinate), level); + } + #endif + /** * @brief Set storage * diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 28c2feea5..d6b25f3af 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -99,6 +99,17 @@ class CubeMapTextureArray: public AbstractTexture { return this; } + /** + * @brief %Image size in given mip level + * @param coordinate Coordinate + * @param level Mip level + * + * See Texture::imageSize() for more information. + */ + inline Vector3i imageSize(Coordinate coordinate, GLint level) { + return DataHelper<3>::imageSize(this, GL_TEXTURE_CUBE_MAP_POSITIVE_X + static_cast(coordinate), level); + } + /** * @brief Set storage * diff --git a/src/Texture.h b/src/Texture.h index 0913bd083..80cf12063 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -174,6 +174,23 @@ template class Texture: public AbstractTexture { /** @brief %Texture target */ inline constexpr Target target() const { return static_cast(_target); } + #ifndef MAGNUM_TARGET_GLES + /** + * @brief %Image size in given mip level + * + * The result is not cached in any way. If + * @extension{EXT,direct_state_access} is not available, the texture + * is bound to some layer before the operation. + * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{GetTexLevelParameter} or @fn_gl_extension{GetTextureLevelParameter,EXT,direct_state_access} + * with @def_gl{TEXTURE_WIDTH}, @def_gl{TEXTURE_HEIGHT} or @def_gl{TEXTURE_DEPTH}. + * @requires_gl %Texture image queries are not available in OpenGL ES. + */ + inline typename DimensionTraits::VectorType imageSize(GLint level) { + return DataHelper::imageSize(this, _target, level); + } + #endif + /** * @brief Set wrapping * @param wrapping Wrapping type for all texture dimensions From afea4f34dbd0bf5a6f2bc692186d046afcf87b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Feb 2013 16:48:22 +0100 Subject: [PATCH 332/567] Text: proper UTF-8 support in Font::prerender(). --- src/Text/Font.cpp | 10 ++++++++-- src/Text/Font.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index a2d02e97a..cffabf54b 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -19,6 +19,7 @@ #include #include FT_FREETYPE_H #include +#include #include "Extensions.h" #include "Image.h" @@ -62,8 +63,13 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { /** @bug Crash when atlas is too small */ /* Get character codes from string */ - /** @todo proper UTF-8 decoding */ - std::vector charCodes(characters.begin(), characters.end()); + std::vector charCodes; + charCodes.reserve(characters.size()); + for(std::size_t i = 0; i != characters.size(); ) { + std::uint32_t codepoint; + std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(characters, i); + charCodes.push_back(codepoint); + } /* Get character indices */ std::vector charIndices; diff --git a/src/Text/Font.h b/src/Text/Font.h index 07cc72761..1c12d55f2 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -86,7 +86,7 @@ class MAGNUM_TEXT_EXPORT Font { /** * @brief Prerender given character set - * @param characters Characters to render + * @param characters UTF-8 characters to render * @param atlasSize Size of resulting atlas * * Creates new atlas with prerendered characters, replacing the From 5af9e3abc6d9fce609101ee87e53bf6e2ca6bf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Feb 2013 00:25:35 +0100 Subject: [PATCH 333/567] TextureTools: use Math::max() instead of doing it by hand. --- src/TextureTools/Atlas.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/TextureTools/Atlas.cpp b/src/TextureTools/Atlas.cpp index 336777880..2963515e6 100644 --- a/src/TextureTools/Atlas.cpp +++ b/src/TextureTools/Atlas.cpp @@ -15,6 +15,7 @@ #include "Atlas.h" +#include "Math/Functions.h" #include "Math/Geometry/Rectangle.h" namespace Magnum { namespace TextureTools { @@ -24,11 +25,8 @@ std::vector atlas(const Vector2i& atlasSize, const std::vector maxSize.x()) maxSize.x() = size.x(); - if(size.y() > maxSize.y()) maxSize.y() = size.y(); - } + for(const Vector2i& size: sizes) + maxSize = Math::max(maxSize, size); std::vector atlas; From ff06d88a2477b704ee6faa7b6cb2fecb0ab99e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Feb 2013 00:54:46 +0100 Subject: [PATCH 334/567] Extension header for OpenGL ES is available now. ES3 will need to be handled differently, not bothering with that for now. --- src/AbstractTexture.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 3d190e76c..d1f468953 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1108,12 +1108,7 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { - /** @todo Remove `ifndef` when extension header is available */ - #ifndef MAGNUM_TARGET_GLES (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); - #else - static_cast(anisotropy); - #endif return this; } From 35c4b5bd23f12a8c528442e1b53d906dd193ab86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Feb 2013 00:58:17 +0100 Subject: [PATCH 335/567] Doc++ --- src/Context.h | 2 +- src/Extensions.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Context.h b/src/Context.h index f0153c75e..d0cb02b45 100644 --- a/src/Context.h +++ b/src/Context.h @@ -184,7 +184,7 @@ class MAGNUM_EXPORT Context { } /** - * @brief Renderer string + * @brief %Renderer string * * @see vendorString(), @fn_gl{GetString} with @def_gl{RENDERER} */ diff --git a/src/Extensions.h b/src/Extensions.h index 3458a3e3b..d0d7f2fc4 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -32,12 +32,8 @@ the same public methods as Extension class (requiredVersion(), coreVersion() and string(), but these structs are better suited for compile-time decisions rather than %Extension instances. See Context::isExtensionSupported() for example usage. - @see MAGNUM_ASSERT_EXTENSION_SUPPORTED() - @todo Manual indices for extensions, this has gaps -@todo Unhide ES2_compatibility, ES3_compatibility on ES -@todo Add ES and GL 4.3 extensions */ namespace Extensions { From 7c81755152e24c14f4af67855970270d3c9ecb22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Feb 2013 20:16:02 +0100 Subject: [PATCH 336/567] Math: slightly reorganize Quaternion test. --- src/Math/Test/QuaternionTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 078efc9db..a254336bb 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -27,6 +27,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { explicit QuaternionTest(); void construct(); + void constructDefault(); void addSubtract(); void negated(); void multiplyDivideScalar(); @@ -52,6 +53,7 @@ typedef Math::Vector3 Vector3; QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, + &QuaternionTest::constructDefault, &QuaternionTest::addSubtract, &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, @@ -75,7 +77,9 @@ void QuaternionTest::construct() { Quaternion q({1.0f, 2.0f, 3.0f}, -4.0f); CORRADE_COMPARE(q.vector(), Vector3(1.0f, 2.0f, 3.0f)); CORRADE_COMPARE(q.scalar(), -4.0f); +} +void QuaternionTest::constructDefault() { CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f})); } From 730c09567d731697af9093218ea9a29ab7264382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Feb 2013 20:18:04 +0100 Subject: [PATCH 337/567] Math: ability to explicitly create Quaternion for given vector. --- src/Math/Quaternion.h | 7 +++++++ src/Math/Test/QuaternionTest.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 1d513f8bc..5b3bb6aa4 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -124,6 +124,13 @@ template class Quaternion { /** @brief Create quaternion from vector and scalar */ inline constexpr /*implicit*/ Quaternion(const Vector3& vector, T scalar): _vector(vector), _scalar(scalar) {} + /** + * @brief Create quaternion from vector + * + * Scalar is set to `0`. + */ + inline constexpr explicit Quaternion(const Vector3& vector): _vector(vector), _scalar(T(0)) {} + /** @brief Equality comparison */ inline bool operator==(const Quaternion& other) const { return _vector == other._vector && MathTypeTraits::equals(_scalar, other._scalar); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index a254336bb..1503152dc 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -28,6 +28,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); + void constructFromVector(); void addSubtract(); void negated(); void multiplyDivideScalar(); @@ -54,6 +55,7 @@ typedef Math::Vector3 Vector3; QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, &QuaternionTest::constructDefault, + &QuaternionTest::constructFromVector, &QuaternionTest::addSubtract, &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, @@ -83,6 +85,10 @@ void QuaternionTest::constructDefault() { CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f})); } +void QuaternionTest::constructFromVector() { + CORRADE_COMPARE(Quaternion({1.0f, 2.0f, 3.0f}), Quaternion({1.0f, 2.0f, 3.0f}, 0.0f)); +} + void QuaternionTest::addSubtract() { Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); From 93ac7f0d3ca2e5160087538ac83a4d828b63abfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Feb 2013 20:21:05 +0100 Subject: [PATCH 338/567] Math: rotating vectors with Quaternion. --- src/Math/Quaternion.h | 29 ++++++++++++++++++++++++++++- src/Math/Test/QuaternionTest.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 5b3bb6aa4..0280732e8 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -366,7 +366,7 @@ template class Quaternion { * * Equivalent to conjugated(). Expects that the quaternion is * normalized. @f[ - * q^{-1} = q^* = [-\boldsymbol q_V, q_S] ~~~~~ |q| = 1 + * q^{-1} = q^* = [-\boldsymbol q_V, q_S] * @f] */ inline Quaternion invertedNormalized() const { @@ -376,6 +376,33 @@ template class Quaternion { return conjugated(); } + /** + * @brief Rotate vector with quaternion + * + * @f[ + * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} + * @f] + * @see rotateVectorNormalized() + */ + inline Vector3 rotateVector(const Vector3& vector) const { + return ((*this)*Quaternion(vector)*inverted()).vector(); + } + + /** + * @brief Rotate vector with normalized quaternion + * + * Faster alternative to rotateVector(), expects that the quaternion is + * normalized. @f[ + * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* + * @f] + */ + inline Vector3 rotateVectorNormalized(const Vector3& vector) const { + CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + "Math::Quaternion::rotateVectorNormalized(): quaternion must be normalized", + Vector3(std::numeric_limits::quiet_NaN())); + return ((*this)*Quaternion(vector)*conjugated()).vector(); + } + private: /* Used in angle() and slerp() (no assertions) */ inline static T angleInternal(const Quaternion& normalizedA, const Quaternion& normalizedB) { diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 1503152dc..2954c0c58 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -45,6 +45,8 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void matrix(); void lerp(); void slerp(); + void rotateVector(); + void rotateVectorNormalized(); void debug(); }; @@ -72,6 +74,8 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::matrix, &QuaternionTest::lerp, &QuaternionTest::slerp, + &QuaternionTest::rotateVector, + &QuaternionTest::rotateVectorNormalized, &QuaternionTest::debug); } @@ -257,6 +261,32 @@ void QuaternionTest::slerp() { CORRADE_COMPARE(slerp, Quaternion({0.119165f, 0.0491109f, 0.0491109f}, 0.990442f)); } +void QuaternionTest::rotateVector() { + Quaternion a = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + Vector3 v(0.0f, -3.6f, 0.7f); + + Vector3 rotated = a.rotateVector(v); + CORRADE_COMPARE(Vector3::angle(v.normalized(), rotated.normalized()), deg(23.0f)); + CORRADE_COMPARE(Vector3::cross(v, rotated).normalized(), Vector3::xAxis()); + CORRADE_COMPARE(rotated.length(), v.length()); +} + +void QuaternionTest::rotateVectorNormalized() { + Quaternion a = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + Vector3 v(0.0f, -3.6f, 0.7f); + + std::ostringstream o; + Corrade::Utility::Error::setOutput(&o); + Vector3 notRotated = (a*2).rotateVectorNormalized(v); + CORRADE_VERIFY(notRotated != notRotated); + CORRADE_COMPARE(o.str(), "Math::Quaternion::rotateVectorNormalized(): quaternion must be normalized\n"); + + Vector3 rotated = a.rotateVector(v); + CORRADE_COMPARE(Vector3::angle(v.normalized(), rotated.normalized()), deg(23.0f)); + CORRADE_COMPARE(Vector3::cross(v, rotated).normalized(), Vector3::xAxis()); + CORRADE_COMPARE(rotated.length(), v.length()); +} + void QuaternionTest::debug() { std::ostringstream o; From a0b8dcc067d70954b8dfe643a04b566bf95bb7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 14 Feb 2013 00:54:45 +0100 Subject: [PATCH 339/567] Math: rename Quaternion::fromRotation() to rotation(). Now it is similar in usage to Matrix4 functions and is now also crossreferenced in documentation. Also updated the test to also check assertion. --- src/Math/Matrix4.h | 13 ++++++++----- src/Math/Quaternion.h | 9 +++++---- src/Math/Test/QuaternionTest.cpp | 25 ++++++++++++++++--------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index e919c75f3..810493644 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -70,8 +70,8 @@ template class Matrix4: public Matrix<4, T> { * * Expects that the rotation axis is normalized. If possible, use * faster alternatives like rotationX(), rotationY() and rotationZ(). - * @see rotation() const, Matrix3::rotation(T), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() + * @see rotation() const, Quaternion::rotation(), Matrix3::rotation(T), + * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), deg(), rad() */ static Matrix4 rotation(T angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), @@ -111,7 +111,8 @@ template class Matrix4: public Matrix<4, T> { * * Faster than calling `Matrix4::rotation(angle, Vector3::xAxis())`. * @see rotation(T, const Vector3&), rotationY(), rotationZ(), - * rotation() const, Matrix3::rotation(T), deg(), rad() + * rotation() const, Quaternion::rotation(), Matrix3::rotation(T), + * deg(), rad() */ static Matrix4 rotationX(T angle) { T sine = std::sin(angle); @@ -129,7 +130,8 @@ template class Matrix4: public Matrix<4, T> { * * Faster than calling `Matrix4::rotation(angle, Vector3::yAxis())`. * @see rotation(T, const Vector3&), rotationX(), rotationZ(), - * rotation() const, Matrix3::rotation(T), deg(), rad() + * rotation() const, Quaternion::rotation(), Matrix3::rotation(T), + * deg(), rad() */ static Matrix4 rotationY(T angle) { T sine = std::sin(angle); @@ -147,7 +149,8 @@ template class Matrix4: public Matrix<4, T> { * * Faster than calling `Matrix4::rotation(angle, Vector3::zAxis())`. * @see rotation(T, const Vector3&), rotationX(), rotationY(), - * rotation() const, Matrix3::rotation(T), deg(), rad() + * rotation() const, Quaternion::rotation(), Matrix3::rotation(T), + * deg(), rad() */ static Matrix4 rotationZ(T angle) { T sine = std::sin(angle); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 0280732e8..8caeb01a6 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -110,10 +110,11 @@ template class Quaternion { * Expects that the rotation axis is normalized. @f[ * q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] * @f] + * @see Matrix4::rotation() */ - inline static Quaternion fromRotation(T angle, const Vector3& normalizedAxis) { + inline static Quaternion rotation(T angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), - "Math::Quaternion::fromRotation(): axis must be normalized", {}); + "Math::Quaternion::rotation(): axis must be normalized", {}); return {normalizedAxis*std::sin(angle/2), std::cos(angle/2)}; } @@ -153,7 +154,7 @@ template class Quaternion { * Expects that the quaternion is normalized. @f[ * \theta = 2 \cdot acos q_S * @f] - * @see rotationAxis(), fromRotation() + * @see rotationAxis(), rotation() */ inline T rotationAngle() const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), @@ -168,7 +169,7 @@ template class Quaternion { * Expects that the quaternion is normalized. @f[ * \boldsymbol a = \frac{\boldsymbol q_V}{\sqrt{1 - q_S^2}} * @f] - * @see rotationAngle(), fromRotation() + * @see rotationAngle(), rotation() */ inline Vector3 rotationAxis() const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 2954c0c58..b73b223d8 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -175,16 +175,23 @@ void QuaternionTest::invertedNormalized() { } void QuaternionTest::rotation() { + std::ostringstream o; + Error::setOutput(&o); + float angle = deg(120.0f); Vector3 axis(1.0f/Constants::sqrt3()); - Quaternion q = Quaternion::fromRotation(angle, axis); + + CORRADE_COMPARE(Quaternion::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); + + Quaternion q = Quaternion::rotation(angle, axis); CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f)); CORRADE_COMPARE(q.rotationAngle(), angle); CORRADE_COMPARE(q.rotationAxis(), axis); CORRADE_COMPARE(q.rotationAxis().length(), 1.0f); /* Verify negative angle */ - Quaternion q2 = Quaternion::fromRotation(deg(-120.0f), axis); + Quaternion q2 = Quaternion::rotation(deg(-120.0f), axis); CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f)); CORRADE_COMPARE(q2.rotationAngle(), deg(120.0f)); CORRADE_COMPARE(q2.rotationAxis(), -axis); @@ -209,7 +216,7 @@ void QuaternionTest::angle() { void QuaternionTest::matrix() { float angle = deg(37.0f); Vector3 axis(1.0f/Constants::sqrt3()); - Quaternion q = Quaternion::fromRotation(angle, axis); + Quaternion q = Quaternion::rotation(angle, axis); Matrix<3, float> expected = Matrix4::rotation(angle, axis).rotationScaling(); CORRADE_COMPARE(q.matrix(), expected); @@ -218,8 +225,8 @@ void QuaternionTest::matrix() { } void QuaternionTest::lerp() { - Quaternion a = Quaternion::fromRotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); - Quaternion b = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + Quaternion a = Quaternion::rotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); std::ostringstream o; Corrade::Utility::Error::setOutput(&o); @@ -240,8 +247,8 @@ void QuaternionTest::lerp() { } void QuaternionTest::slerp() { - Quaternion a = Quaternion::fromRotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); - Quaternion b = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + Quaternion a = Quaternion::rotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); std::ostringstream o; Corrade::Utility::Error::setOutput(&o); @@ -262,7 +269,7 @@ void QuaternionTest::slerp() { } void QuaternionTest::rotateVector() { - Quaternion a = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); Vector3 v(0.0f, -3.6f, 0.7f); Vector3 rotated = a.rotateVector(v); @@ -272,7 +279,7 @@ void QuaternionTest::rotateVector() { } void QuaternionTest::rotateVectorNormalized() { - Quaternion a = Quaternion::fromRotation(deg(23.0f), Vector3::xAxis()); + Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); Vector3 v(0.0f, -3.6f, 0.7f); std::ostringstream o; From 95982e5176ea48d5b071495fd601aa009d290d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Feb 2013 12:14:56 +0100 Subject: [PATCH 340/567] Math: various code cleanup. --- src/Math/Quaternion.cpp | 4 ++-- src/Math/Quaternion.h | 8 ++++++-- src/Math/Test/CMakeLists.txt | 4 +--- src/Math/Test/QuaternionTest.cpp | 33 ++++++++++++++++++++------------ 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/Math/Quaternion.cpp b/src/Math/Quaternion.cpp index 80d01c33b..c736cbfbf 100644 --- a/src/Math/Quaternion.cpp +++ b/src/Math/Quaternion.cpp @@ -18,9 +18,9 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Quaternion&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Quaternion&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); #endif #endif diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 8caeb01a6..c1b12c700 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -119,7 +119,11 @@ template class Quaternion { return {normalizedAxis*std::sin(angle/2), std::cos(angle/2)}; } - /** @brief Default constructor */ + /** + * @brief Default constructor + * + * %Vector part is set to zero, scalar part to `1`. + */ inline constexpr /*implicit*/ Quaternion(): _scalar(T(1)) {} /** @brief Create quaternion from vector and scalar */ @@ -435,7 +439,7 @@ template inline Quaternion operator/(T scalar, const Quaternion& return {scalar/quaternion.vector(), scalar/quaternion.scalar()}; } -/** @debugoperator{Magnum::Math::Geometry::Rectangle} */ +/** @debugoperator{Magnum::Math::Quaternion} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Quaternion& value) { debug << "Quaternion({"; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 1d413def9..5bcc56daa 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -3,16 +3,14 @@ corrade_add_test(MathConstantsTest ConstantsTest.cpp) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) -corrade_add_test(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib) - corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector3Test Vector3Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector4Test Vector4Test.cpp LIBRARIES MagnumMathTestLib) - corrade_add_test(MathPoint2DTest Point2DTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathPoint3DTest Point3DTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrixTest MatrixTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrix3Test Matrix3Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index b73b223d8..b2c25688e 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -29,17 +29,21 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void addSubtract(); void negated(); void multiplyDivideScalar(); void multiply(); + void dot(); void dotSelf(); void length(); void normalized(); + void conjugated(); void inverted(); void invertedNormalized(); + void rotation(); void angle(); void matrix(); @@ -58,17 +62,21 @@ QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, &QuaternionTest::constructDefault, &QuaternionTest::constructFromVector, + &QuaternionTest::addSubtract, &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, &QuaternionTest::multiply, + &QuaternionTest::dot, &QuaternionTest::dotSelf, &QuaternionTest::length, &QuaternionTest::normalized, + &QuaternionTest::conjugated, &QuaternionTest::inverted, &QuaternionTest::invertedNormalized, + &QuaternionTest::rotation, &QuaternionTest::angle, &QuaternionTest::matrix, @@ -76,6 +84,7 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::slerp, &QuaternionTest::rotateVector, &QuaternionTest::rotateVectorNormalized, + &QuaternionTest::debug); } @@ -86,7 +95,7 @@ void QuaternionTest::construct() { } void QuaternionTest::constructDefault() { - CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, {1.0f})); + CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); } void QuaternionTest::constructFromVector() { @@ -94,12 +103,12 @@ void QuaternionTest::constructFromVector() { } void QuaternionTest::addSubtract() { - Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); - Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); - Quaternion c({0.5f, 4.4f, 1.0f}, 8.0f); + Quaternion a({ 1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); + Quaternion c({ 0.5f, 4.4f, 1.0f}, 8.0f); - CORRADE_COMPARE(a+b, c); - CORRADE_COMPARE(c-b, a); + CORRADE_COMPARE(a + b, c); + CORRADE_COMPARE(c - b, a); } void QuaternionTest::negated() { @@ -107,8 +116,8 @@ void QuaternionTest::negated() { } void QuaternionTest::multiplyDivideScalar() { - Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); - Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f); + Quaternion a({ 1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion b({-1.5f, -4.5f, 3.0f}, 6.0f); CORRADE_COMPARE(a*-1.5f, b); CORRADE_COMPARE(-1.5f*a, b); @@ -123,8 +132,8 @@ void QuaternionTest::multiply() { } void QuaternionTest::dot() { - Quaternion a({1.0f, 3.0f, -2.0f}, -4.0f); - Quaternion b({-0.5f, 1.5f, 3.0f}, 12.0f); + Quaternion a({ 1.0f, 3.0f, -2.0f}, -4.0f); + Quaternion b({-0.5f, 1.5f, 3.0f}, 12.0f); CORRADE_COMPARE(Quaternion::dot(a, b), -50.0f); } @@ -144,8 +153,8 @@ void QuaternionTest::normalized() { } void QuaternionTest::conjugated() { - CORRADE_COMPARE(Quaternion({1.0f, 3.0f, -2.0f}, -4.0f).conjugated(), - Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)); + CORRADE_COMPARE(Quaternion({ 1.0f, 3.0f, -2.0f}, -4.0f).conjugated(), + Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)); } void QuaternionTest::inverted() { From 5d6b2b4ecdfcf056cd1e346c4befe617b0ca1b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Feb 2013 12:15:28 +0100 Subject: [PATCH 341/567] Math: properly test Quaternion comparison. --- src/Math/Test/QuaternionTest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index b2c25688e..cfd6686eb 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -29,6 +29,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void compare(); void addSubtract(); void negated(); @@ -62,6 +63,7 @@ QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, &QuaternionTest::constructDefault, &QuaternionTest::constructFromVector, + &QuaternionTest::compare, &QuaternionTest::addSubtract, &QuaternionTest::negated, @@ -102,6 +104,13 @@ void QuaternionTest::constructFromVector() { CORRADE_COMPARE(Quaternion({1.0f, 2.0f, 3.0f}), Quaternion({1.0f, 2.0f, 3.0f}, 0.0f)); } +void QuaternionTest::compare() { + CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); +} + void QuaternionTest::addSubtract() { Quaternion a({ 1.0f, 3.0f, -2.0f}, -4.0f); Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); From 3f6a2d5ae86a29e3ba76c24293792db44877c50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Feb 2013 12:18:40 +0100 Subject: [PATCH 342/567] Math: dual number implementation. --- src/Math/CMakeLists.txt | 1 + src/Math/Dual.h | 167 +++++++++++++++++++++++++++++++++++ src/Math/Math.h | 2 + src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/DualTest.cpp | 116 ++++++++++++++++++++++++ 5 files changed, 287 insertions(+) create mode 100644 src/Math/Dual.h create mode 100644 src/Math/Test/DualTest.cpp diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 284415193..b8155147e 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,6 +1,7 @@ set(MagnumMath_HEADERS BoolVector.h Constants.h + Dual.h Functions.h Math.h MathTypeTraits.h diff --git a/src/Math/Dual.h b/src/Math/Dual.h new file mode 100644 index 000000000..43e3e1eca --- /dev/null +++ b/src/Math/Dual.h @@ -0,0 +1,167 @@ +#ifndef Magnum_Math_Dual_h +#define Magnum_Math_Dual_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Dual + */ + +#include + +#include "Math/MathTypeTraits.h" + +namespace Magnum { namespace Math { + +/** @brief %Dual number */ +template class Dual { + public: + /** + * @brief Default constructor + * + * Both parts are default-constructed. + */ + inline constexpr /*implicit*/ Dual(): _real(), _dual() {} + + /** + * @brief Construct dual number from real and dual part + * + * @f[ + * \hat a = a_0 + \epsilon a_\epsilon + * @f] + */ + inline constexpr /*implicit*/ Dual(const T& real, const T& dual = T()): _real(real), _dual(dual) {} + + /** @brief Equality comparison */ + inline bool operator==(const Dual& other) const { + return MathTypeTraits::equals(_real, other._real) && + MathTypeTraits::equals(_dual, other._dual); + } + + /** @brief Non-equality comparison */ + inline bool operator!=(const Dual& other) const { + return !operator==(other); + } + + /** @brief Real part */ + inline constexpr T real() const { return _real; } + + /** @brief %Dual part */ + inline constexpr T dual() const { return _dual; } + + /** + * @brief Add and assign dual number + * + * The computation is done in-place. @f[ + * \hat a + \hat b = a_0 + b_0 + \epsilon (a_\epsilon + b_\epsilon) + * @f] + */ + inline Dual& operator+=(const Dual& other) { + _real += other._real; + _dual += other._dual; + return *this; + } + + /** + * @brief Add dual number + * + * @see operator+=() + */ + inline Dual operator+(const Dual& other) const { + return Dual(*this)+=other; + } + + /** + * @brief Negated dual number + * + * @f[ + * -\hat a = -a_0 - \epsilon a_\epsilon + * @f] + */ + inline Dual operator-() const { + return {-_real, -_dual}; + } + + /** + * @brief Subtract and assign dual number + * + * The computation is done in-place. @f[ + * \hat a - \hat b = a_0 - b_0 + \epsilon (a_\epsilon - b_\epsilon) + * @f] + */ + inline Dual& operator-=(const Dual& other) { + _real -= other._real; + _dual -= other._dual; + return *this; + } + + /** + * @brief Subtract dual number + * + * @see operator-=() + */ + inline Dual operator-(const Dual& other) const { + return Dual(*this)-=other; + } + + /** + * @brief Multiply by dual number + * + * @f[ + * \hat a \hat b = a_0 b_0 + \epsilon (a_0 b_\epsilon + a_\epsilon b_0) + * @f] + */ + inline Dual operator*(const Dual& other) const { + return {_real*other._real, _real*other._dual + _dual*other._real}; + } + + /** + * @brief Divide by dual number + * + * @f[ + * \frac{\hat a}{\hat b} = \frac{a_0}{b_0} + \epsilon \frac{a_\epsilon b_0 - a_0 b_\epsilon}{b_0^2} + * @f] + */ + inline Dual operator/(const Dual& other) const { + return {_real/other._real, (_dual*other._real - _real*other._dual)/(other._real*other._real)}; + } + + /** + * @brief Conjugated dual number + * + * @f[ + * \overline{\hat a} = a_0 - \epsilon a_\epsilon + * @f] + */ + inline Dual conjugated() const { + return {_real, -_dual}; + } + + private: + T _real, _dual; +}; + +/** @debugoperator{Magnum::Math::Dual} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Dual& value) { + debug << "Dual("; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << value.real() << ", " << value.dual() << ")"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +}} + +#endif diff --git a/src/Math/Math.h b/src/Math/Math.h index b62f82fe6..38e2a047f 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -27,6 +27,8 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT /* Class Constants used only statically */ +template class Dual; + template class Matrix; template class Matrix3; template class Matrix4; diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 5bcc56daa..e7a739288 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -17,6 +17,7 @@ corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathDualTest DualTest.cpp) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test MathQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp new file mode 100644 index 000000000..527b9c85d --- /dev/null +++ b/src/Math/Test/DualTest.cpp @@ -0,0 +1,116 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/Dual.h" + +namespace Magnum { namespace Math { namespace Test { + +class DualTest: public Corrade::TestSuite::Tester { + public: + explicit DualTest(); + + void construct(); + void constructDefault(); + void compare(); + + void addSubtract(); + void negated(); + void multiplyDivide(); + + void conjugated(); + + void debug(); +}; + +typedef Math::Dual Dual; + +DualTest::DualTest() { + addTests(&DualTest::construct, + &DualTest::constructDefault, + &DualTest::compare, + + &DualTest::addSubtract, + &DualTest::negated, + &DualTest::multiplyDivide, + + &DualTest::conjugated, + + &DualTest::debug); +} + +void DualTest::construct() { + Dual a(2.0f, -7.5f); + CORRADE_COMPARE(a.real(), 2.0f); + CORRADE_COMPARE(a.dual(), -7.5f); + + Dual b(3.0f); + CORRADE_COMPARE(b.real(), 3.0f); + CORRADE_COMPARE(b.dual(), 0.0f); +} + +void DualTest::constructDefault() { + CORRADE_COMPARE(Dual(), Dual(0.0f, 0.0f)); +} + +void DualTest::compare() { + CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); + + /* Compare to real part only */ + CORRADE_VERIFY(Dual(1.0f, 0.0f) == 1.0f); + CORRADE_VERIFY(Dual(1.0f, 3.0f) != 1.0f); +} + +void DualTest::addSubtract() { + Dual a(2.0f, -7.5f); + Dual b(-3.3f, 0.2f); + Dual c(-1.3f, -7.3f); + + CORRADE_COMPARE(a + b, c); + CORRADE_COMPARE(c - b, a); +} + +void DualTest::negated() { + CORRADE_COMPARE(-Dual(1.0f, -6.5f), Dual(-1.0f, 6.5f)); +} + +void DualTest::multiplyDivide() { + Dual a(1.5f, -4.0f); + Dual b(-2.0f, 0.5f); + Dual c(-3.0f, 8.75f); + + CORRADE_COMPARE(a*b, c); + CORRADE_COMPARE(c/b, a); +} + +void DualTest::conjugated() { + CORRADE_COMPARE(Dual(1.0f, -6.5f).conjugated(), Dual(1.0f, 6.5f)); +} + +void DualTest::debug() { + std::ostringstream o; + + Debug(&o) << Dual(2.5f, -0.3f); + CORRADE_COMPARE(o.str(), "Dual(2.5, -0.3)\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::DualTest) From b8df58a5e79b3fa4273ce9ac25c33455519fedbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 19:03:04 +0100 Subject: [PATCH 343/567] Math: Allow division of Dual with Dual of another type. Will allow dividing Dual> with Dual. --- src/Math/Dual.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 43e3e1eca..5e3b6f884 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -27,6 +27,8 @@ namespace Magnum { namespace Math { /** @brief %Dual number */ template class Dual { + template friend class Dual; + public: /** * @brief Default constructor @@ -134,7 +136,7 @@ template class Dual { * \frac{\hat a}{\hat b} = \frac{a_0}{b_0} + \epsilon \frac{a_\epsilon b_0 - a_0 b_\epsilon}{b_0^2} * @f] */ - inline Dual operator/(const Dual& other) const { + template inline Dual operator/(const Dual& other) const { return {_real/other._real, (_dual*other._real - _real*other._dual)/(other._real*other._real)}; } From 2a25c6eafd66278447e9d640f5fea58a34c0f758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 19:03:52 +0100 Subject: [PATCH 344/567] Math: return proper type from Dual operators in subclasses. --- src/Math/Dual.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 5e3b6f884..45cc4f344 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -155,6 +155,33 @@ template class Dual { T _real, _dual; }; +#ifndef DOXYGEN_GENERATING_OUTPUT +#define MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(Type, Underlying) \ + inline Type operator-() const { \ + return Dual>::operator-(); \ + } \ + inline Type& operator+=(const Dual>& other) { \ + Dual>::operator+=(other); \ + return *this; \ + } \ + inline Type operator+(const Dual>& other) const { \ + return Dual>::operator+(other); \ + } \ + inline Type& operator-=(const Dual>& other) { \ + Dual>::operator-=(other); \ + return *this; \ + } \ + inline Type operator-(const Dual>& other) const { \ + return Dual>::operator-(other); \ + } \ + inline Type operator*(const Dual>& other) const { \ + return Dual>::operator*(other); \ + } \ + template inline Type operator/(const Dual& other) const { \ + return Dual>::operator/(other); \ + } +#endif + /** @debugoperator{Magnum::Math::Dual} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Dual& value) { debug << "Dual("; From 6eeac71290303e2ae00d07e991c3105b04333605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 19:28:17 +0100 Subject: [PATCH 345/567] Math: Use default pure equality comparison for arbitrary types. --- src/Math/MathTypeTraits.h | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 29ca45e00..d60a1eb80 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -42,20 +42,26 @@ namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct MathTypeTraitsDefault { + MathTypeTraitsDefault() = delete; + + inline constexpr static bool equals(T a, T b) { + return a == b; + } + }; +} +#endif + /** @brief Traits class for numeric types Traits classes are usable for detecting type features at compile time without the need for repeated code such as method overloading or template specialization for given types. - -This class and class methods are specialized only for types where it makes -sense, it has empty implementation for unknown types or types which don't -support given feature, thus forcing the compilation stop with an error. */ -template struct MathTypeTraits { - MathTypeTraits() = delete; - +template struct MathTypeTraits: Implementation::MathTypeTraitsDefault { /* * The following values are implemented as inline functions, not as * static const variables, because the compiler will inline the return @@ -77,15 +83,15 @@ template struct MathTypeTraits { * * Returns minimal difference between numbers to be considered * inequal. Returns 1 for integer types and reasonably small value for - * floating-point types. + * floating-point types. Not implemented for arbitrary types. */ inline constexpr static T epsilon(); /** * @brief Fuzzy compare * - * Uses equality for integer types and fuzzy compare for floating-point - * types (using @ref epsilon value). + * Uses fuzzy compare for floating-point types (using epsilon() value), + * pure equality comparison everywhere else. */ static bool equals(T a, T b); #endif @@ -100,17 +106,10 @@ template struct MathTypeTraits { */ #ifndef DOXYGEN_GENERATING_OUTPUT - /* Integral scalar types */ namespace Implementation { - template struct MathTypeTraitsIntegral { - MathTypeTraitsIntegral() = delete; - - inline constexpr static T epsilon() { return 1; } - - inline constexpr static bool equals(T a, T b) { - return a == b; - } + template struct MathTypeTraitsIntegral: MathTypeTraitsDefault { + inline constexpr static T epsilon() { return T(1); } }; } From 5615a4c7f6f8e3629885465d6eaa98686483a4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 19:32:13 +0100 Subject: [PATCH 346/567] Math: initial implementation of DualQuaternion class. Currently practically unusable. --- src/CMakeLists.txt | 1 + src/Math/CMakeLists.txt | 1 + src/Math/DualQuaternion.cpp | 27 +++++ src/Math/DualQuaternion.h | 159 +++++++++++++++++++++++++++ src/Math/Math.h | 1 + src/Math/Quaternion.h | 2 +- src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/DualQuaternionTest.cpp | 114 +++++++++++++++++++ 8 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 src/Math/DualQuaternion.cpp create mode 100644 src/Math/DualQuaternion.h create mode 100644 src/Math/Test/DualQuaternionTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f20f218e..b446f4e95 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,6 +98,7 @@ add_library(MagnumObjects OBJECT ${Magnum_SRCS}) # Files shared between main library and math unit test library set(MagnumMath_SRCS + Math/DualQuaternion.cpp Math/Functions.cpp Math/Quaternion.cpp Math/RectangularMatrix.cpp diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index b8155147e..4bcbf5743 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -2,6 +2,7 @@ set(MagnumMath_HEADERS BoolVector.h Constants.h Dual.h + DualQuaternion.h Functions.h Math.h MathTypeTraits.h diff --git a/src/Math/DualQuaternion.cpp b/src/Math/DualQuaternion.cpp new file mode 100644 index 000000000..7a5d2448c --- /dev/null +++ b/src/Math/DualQuaternion.cpp @@ -0,0 +1,27 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "DualQuaternion.h" + +namespace Magnum { namespace Math { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualQuaternion&); +#ifndef MAGNUM_TARGET_GLES +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualQuaternion&); +#endif +#endif + +}} diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h new file mode 100644 index 000000000..51aed4e36 --- /dev/null +++ b/src/Math/DualQuaternion.h @@ -0,0 +1,159 @@ +#ifndef Magnum_Math_DualQuaternion_h +#define Magnum_Math_DualQuaternion_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::DualQuaternion + */ + +#include "Math/Dual.h" +#include "Math/Quaternion.h" + +namespace Magnum { namespace Math { + +/** +@brief %Dual quaternion + +@see Dual, Quaternion +*/ +template class DualQuaternion: public Dual> { + public: + /** + * @brief Default constructor + * + * All components set to zero except real scalar part, which is `1`. + * @todoc Remove workaround when Doxygen is predictable + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + inline constexpr /*implicit*/ DualQuaternion(); + #else + inline constexpr /*implicit*/ DualQuaternion(): Dual>({}, {{}, T(0)}) {} + #endif + + /** + * @brief Construct dual quaternion from real and dual part + * + * @f[ + * \hat q = q_0 + \epsilon q_\epsilon + * @f] + */ + inline constexpr /*implicit*/ DualQuaternion(const Quaternion& real, const Quaternion& dual): Dual>(real, dual) {} + + /** + * @brief Quaternion-conjugated dual quaternion + * + * @f[ + * \hat q^* = q_0^* + q_\epsilon^* + * @f] + * @see dualConjugated(), conjugated(), Quaternion::conjugated() + */ + inline DualQuaternion quaternionConjugated() const { + return {this->real().conjugated(), this->dual().conjugated()}; + } + + /** + * @brief Dual-conjugated dual quaternion + * + * @f[ + * \overline{\hat q} = q_0 - \epsilon q_\epsilon + * @f] + * @see quaternionConjugated(), conjugated(), Dual::conjugated() + */ + inline DualQuaternion dualConjugated() const { + return Dual>::conjugated(); + } + + /** + * @brief Conjugated dual quaternion + * + * Both quaternion and dual conjugation. @f[ + * \overline{\hat q^*} = q_0^* - \epsilon q_\epsilon^* = q_0^* + \epsilon [\boldsymbol q_{\epsilon V}, -q_S] + * @f] + * @see quaternionConjugated(), dualConjugated(), Quaternion::conjugated(), + * Dual::conjugated() + */ + inline DualQuaternion conjugated() const { + return {this->real().conjugated(), {this->dual().vector(), -this->dual().scalar()}}; + } + + /** + * @brief %Dual quaternion norm + * + * @f[ + * ||\hat q|| = \sqrt{\hat q^* \hat q} = ||q_0|| + \epsilon \frac{q_0 \cdot q_\epsilon}{||q_0||} + * @f] + */ + inline Dual norm() const { + T norm = this->real().length(); + return {norm, Quaternion::dot(this->real(), this->dual())/norm}; + } + + /** + * @brief Inverted dual quaternion + * + * See invertedNormalized() which is faster for normalized + * dual quaternions. @f[ + * \hat q^{-1} = \frac{\hat q^*}{||\hat q||^2} + * @f] + */ + inline DualQuaternion inverted() const { + return quaternionConjugated()/Math::pow<2>(norm()); + } + + /** + * @brief Inverted normalized dual quaternion + * + * Equivalent to quaternionConjugated(). Expects that the quaternion is + * normalized. @f[ + * \hat q^{-1} = \frac{\hat q^*}{||\hat q||^2} = \hat q^* + * @f] + */ + inline DualQuaternion invertedNormalized() const { + CORRADE_ASSERT(MathTypeTraits::equals(norm(), T(1)), + "Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized", {}); + return quaternionConjugated(); + } + + MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualQuaternion, Quaternion) + + private: + /* Used by Dual operators and dualConjugated() */ + DualQuaternion(const Dual>& other): Dual>(other) {} +}; + +/** @debugoperator{Magnum::Math::DualQuaternion} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const DualQuaternion& value) { + debug << "DualQuaternion({{"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << value.real().vector().x() << ", " << value.real().vector().y() << ", " << value.real().vector().z() + << "}, " << value.real().scalar() << "}, {{" + << value.dual().vector().x() << ", " << value.dual().vector().y() << ", " << value.dual().vector().z() + << "}, " << value.dual().scalar() << "})"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/* Explicit instantiation for commonly used types */ +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualQuaternion&); +#ifndef MAGNUM_TARGET_GLES +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualQuaternion&); +#endif +#endif + +}} + +#endif diff --git a/src/Math/Math.h b/src/Math/Math.h index 38e2a047f..6259f89c2 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -28,6 +28,7 @@ namespace Magnum { namespace Math { /* Class Constants used only statically */ template class Dual; +template class DualQuaternion; template class Matrix; template class Matrix3; diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index c1b12c700..47c4f3991 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Math { /** @brief %Quaternion -@see Magnum::Quaternion +@see DualQuaternion, Magnum::Quaternion */ template class Quaternion { public: diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index e7a739288..84cb4cbfb 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -19,5 +19,6 @@ corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualTest DualTest.cpp) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib) set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test MathQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp new file mode 100644 index 000000000..18d51109d --- /dev/null +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -0,0 +1,114 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/DualQuaternion.h" + +namespace Magnum { namespace Math { namespace Test { + +class DualQuaternionTest: public Corrade::TestSuite::Tester { + public: + explicit DualQuaternionTest(); + + void construct(); + void constructDefault(); + + void norm(); + + void quaternionConjugated(); + void dualConjugated(); + void conjugated(); + void inverted(); + + void debug(); +}; + +typedef Math::Dual Dual; +typedef Math::DualQuaternion DualQuaternion; +typedef Math::Quaternion Quaternion; +typedef Math::Vector3 Vector3; + +DualQuaternionTest::DualQuaternionTest() { + addTests(&DualQuaternionTest::construct, + &DualQuaternionTest::constructDefault, + + &DualQuaternionTest::norm, + + &DualQuaternionTest::quaternionConjugated, + &DualQuaternionTest::dualConjugated, + &DualQuaternionTest::conjugated, + &DualQuaternionTest::inverted, + + &DualQuaternionTest::debug); +} + +void DualQuaternionTest::construct() { + DualQuaternion q({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.1f, 3.3f}, 2.0f}); + CORRADE_COMPARE(q.real(), Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_COMPARE(q.dual(), Quaternion({0.5f, -3.1f, 3.3f}, 2.0f)); +} + +void DualQuaternionTest::constructDefault() { + CORRADE_COMPARE(DualQuaternion(), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); +} + +void DualQuaternionTest::norm() { + CORRADE_COMPARE(DualQuaternion().norm(), 1.0f); + + DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 0.5f, -3.0f, 3.0f}, 2.0f}); + CORRADE_COMPARE(a.norm(), Dual(5.477226f, -0.821584f)); +} + +void DualQuaternionTest::quaternionConjugated() { + DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 0.5f, -3.1f, 3.3f}, 2.0f}); + DualQuaternion b({{-1.0f, -2.0f, -3.0f}, -4.0f}, {{-0.5f, 3.1f, -3.3f}, 2.0f}); + + CORRADE_COMPARE(a.quaternionConjugated(), b); +} + +void DualQuaternionTest::dualConjugated() { + DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{ 0.5f, -3.1f, 3.3f}, 2.0f}); + DualQuaternion b({{1.0f, 2.0f, 3.0f}, -4.0f}, {{-0.5f, 3.1f, -3.3f}, -2.0f}); + + CORRADE_COMPARE(a.dualConjugated(), b); +} + +void DualQuaternionTest::conjugated() { + DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 0.5f, -3.1f, 3.3f}, 2.0f}); + DualQuaternion b({{-1.0f, -2.0f, -3.0f}, -4.0f}, {{ 0.5f, -3.1f, 3.3f}, -2.0f}); + + CORRADE_COMPARE(a.conjugated(), b); +} + +void DualQuaternionTest::inverted() { + DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 2.5f, -3.1f, 3.3f}, 2.0f}); + DualQuaternion b({{-0.033333f, -0.066667f, -0.1f}, -0.133333f}, {{-0.087333f, 0.095333f, -0.122f}, 0.050667f}); + + CORRADE_COMPARE(a*a.inverted(), DualQuaternion()); + CORRADE_COMPARE(a.inverted(), b); +} + +void DualQuaternionTest::debug() { + std::ostringstream o; + + Debug(&o) << DualQuaternion({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.1f, 3.3f}, 2.0f}); + CORRADE_COMPARE(o.str(), "DualQuaternion({{1, 2, 3}, -4}, {{0.5, -3.1, 3.3}, 2})\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::DualQuaternionTest) From 4c1608378a79d62d239cb9c6270832720bde57c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 20:12:35 +0100 Subject: [PATCH 347/567] Math: document that Quaternion::rotationAxis() might return NaN vector. --- src/Math/Quaternion.h | 4 +++- src/Math/Test/QuaternionTest.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 47c4f3991..be49ec335 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -170,7 +170,9 @@ template class Quaternion { /** * @brief Rotation axis of unit quaternion * - * Expects that the quaternion is normalized. @f[ + * Expects that the quaternion is normalized. Returns either unit-length + * vector for valid rotation quaternion or NaN vector for + * default-constructed quaternion. @f[ * \boldsymbol a = \frac{\boldsymbol q_V}{\sqrt{1 - q_S^2}} * @f] * @see rotationAngle(), rotation() diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index cfd6686eb..079c0b755 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -213,6 +213,10 @@ void QuaternionTest::rotation() { CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f)); CORRADE_COMPARE(q2.rotationAngle(), deg(120.0f)); CORRADE_COMPARE(q2.rotationAxis(), -axis); + + /* Default-constructed quaternion has zero angle and NaN axis */ + CORRADE_COMPARE(Quaternion().rotationAngle(), deg(0.0f)); + CORRADE_VERIFY(Quaternion().rotationAxis() != Quaternion().rotationAxis()); } void QuaternionTest::angle() { From 3ad264893ea0808acf9e11d05a63b78e5bd7ea5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 20:13:36 +0100 Subject: [PATCH 348/567] Math: creating rotation and translation DualQuaternion. --- src/Math/DualQuaternion.h | 68 ++++++++++++++++++++++++++++ src/Math/Matrix4.h | 10 ++-- src/Math/Quaternion.h | 6 ++- src/Math/Test/CMakeLists.txt | 8 +++- src/Math/Test/DualQuaternionTest.cpp | 30 ++++++++++++ 5 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 51aed4e36..0b399b4f3 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -31,6 +31,36 @@ namespace Magnum { namespace Math { */ template class DualQuaternion: public Dual> { public: + /** + * @brief Rotation dual quaternion + * @param angle Rotation angle (counterclockwise, in radians) + * @param normalizedAxis Normalized rotation axis + * + * Expects that the rotation axis is normalized. @f[ + * \hat q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] + \epsilon [\boldsymbol 0, 0] + * @f] + * @see rotationAngle(), rotationAxis(), Quaternion::rotation(), + * Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis(), deg(), rad() + */ + inline static DualQuaternion rotation(T angle, const Vector3& normalizedAxis) { + return {Quaternion::rotation(angle, normalizedAxis), {{}, T(0)}}; + } + + /** + * @brief Translation dual quaternion + * @param vector Translation vector + * + * @f[ + * \hat q = [\boldsymbol 0, 1] + \epsilon [\frac{\boldsymbol v}{2}, 0] + * @f] + * @see translation() const, Matrix3::translation(const Vector2&), + * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() + */ + inline static DualQuaternion translation(const Vector3& vector) { + return {{}, {vector/T(2), T(0)}}; + } + /** * @brief Default constructor * @@ -52,6 +82,44 @@ template class DualQuaternion: public Dual> { */ inline constexpr /*implicit*/ DualQuaternion(const Quaternion& real, const Quaternion& dual): Dual>(real, dual) {} + /** + * @brief Rotation angle of unit dual quaternion + * + * Expects that the real part of the quaternion is normalized. @f[ + * \theta = 2 \cdot acos q_{S 0} + * @f] + * @see rotationAxis(), rotation(), Quaternion::rotationAngle() + */ + inline T rotationAngle() const { + return this->real().rotationAngle(); + } + + /** + * @brief Rotation axis of unit dual quaternion + * + * Expects that the quaternion is normalized. Returns either unit-length + * vector for valid rotation quaternion or NaN vector for + * default-constructed quaternion. @f[ + * \boldsymbol a = \frac{\boldsymbol q_{V 0}}{\sqrt{1 - q_{S 0}^2}} + * @f] + * @see rotationAngle(), rotation(), Quaternion::rotationAxis() + */ + inline Vector3 rotationAxis() const { + return this->real().rotationAxis(); + } + + /** + * @brief Translation part of unit dual quaternion + * + * @f[ + * \boldsymbol a = 2 (q_\epsilon q_0^*)_V + * @f] + * @see translation(const Vector3&) + */ + inline Vector3 translation() const { + return (this->dual()*this->real().conjugated()).vector()*T(2); + } + /** * @brief Quaternion-conjugated dual quaternion * diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 810493644..4b5c85ce1 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -39,8 +39,9 @@ template class Matrix4: public Matrix<4, T> { * @brief 3D translation * @param vector Translation vector * - * @see translation(), Matrix3::translation(const Vector2&), - * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() + * @see translation(), DualQuaternion::translation(), + * Matrix3::translation(const Vector2&), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis() */ inline constexpr static Matrix4 translation(const Vector3& vector) { return {{ T(1), T(0), T(0), T(0)}, @@ -70,8 +71,9 @@ template class Matrix4: public Matrix<4, T> { * * Expects that the rotation axis is normalized. If possible, use * faster alternatives like rotationX(), rotationY() and rotationZ(). - * @see rotation() const, Quaternion::rotation(), Matrix3::rotation(T), - * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), deg(), rad() + * @see rotation() const, DualQuaternion::rotation(), + * Quaternion::rotation(), Matrix3::rotation(T), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() */ static Matrix4 rotation(T angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index be49ec335..a25049370 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -103,14 +103,16 @@ template class Quaternion { } /** - * @brief Create quaternion from rotation + * @brief Rotation quaternion * @param angle Rotation angle (counterclockwise, in radians) * @param normalizedAxis Normalized rotation axis * * Expects that the rotation axis is normalized. @f[ * q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] * @f] - * @see Matrix4::rotation() + * @see rotationAngle(), rotationAxis(), DualQuaternion::rotation(), + * Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis(), deg(), rad() */ inline static Quaternion rotation(T angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 84cb4cbfb..1f70c8dcb 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -21,4 +21,10 @@ corrade_add_test(MathDualTest DualTest.cpp) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib) -set_target_properties(MathVectorTest MathMatrix3Test MathMatrix4Test MathQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) +set_target_properties( + MathVectorTest + MathMatrix3Test + MathMatrix4Test + MathDualQuaternionTest + MathQuaternionTest + PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 18d51109d..dfc41fcf9 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -16,6 +16,7 @@ #include #include +#include "Math/Constants.h" #include "Math/DualQuaternion.h" namespace Magnum { namespace Math { namespace Test { @@ -34,6 +35,9 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void conjugated(); void inverted(); + void rotation(); + void translation(); + void debug(); }; @@ -53,6 +57,9 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::conjugated, &DualQuaternionTest::inverted, + &DualQuaternionTest::rotation, + &DualQuaternionTest::translation, + &DualQuaternionTest::debug); } @@ -102,6 +109,29 @@ void DualQuaternionTest::inverted() { CORRADE_COMPARE(a.inverted(), b); } +void DualQuaternionTest::rotation() { + std::ostringstream o; + Error::setOutput(&o); + + float angle = deg(120.0f); + Vector3 axis(1.0f/Constants::sqrt3()); + + CORRADE_COMPARE(DualQuaternion::rotation(angle, axis*2.0f), DualQuaternion()); + CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); + + DualQuaternion q = DualQuaternion::rotation(angle, axis); + CORRADE_COMPARE(q, DualQuaternion({Vector3(0.5f, 0.5f, 0.5f), 0.5f}, {{}, 0.0f})); + CORRADE_COMPARE(q.rotationAngle(), angle); + CORRADE_COMPARE(q.rotationAxis(), axis); +} + +void DualQuaternionTest::translation() { + Vector3 vec(1.0f, -3.5f, 0.5f); + DualQuaternion q = DualQuaternion::translation(vec); + CORRADE_COMPARE(q, DualQuaternion({}, {{0.5f, -1.75f, 0.25f}, 0.0f})); + CORRADE_COMPARE(q.translation(), vec); +} + void DualQuaternionTest::debug() { std::ostringstream o; From 5673cf26568673e9c246b7c9d38e101f8cda5eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 20:53:56 +0100 Subject: [PATCH 349/567] Math: better documentation for vector/quat constructors. --- src/Math/DualQuaternion.h | 6 ++++-- src/Math/Point2D.h | 21 ++++++++++++++------- src/Math/Point3D.h | 22 ++++++++++++++-------- src/Math/Quaternion.h | 24 ++++++++++++++++++------ src/Math/Vector.h | 8 +++++++- src/Math/Vector2.h | 6 ++++-- src/Math/Vector3.h | 13 ++++++++----- src/Math/Vector4.h | 14 ++++++++------ 8 files changed, 77 insertions(+), 37 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 0b399b4f3..1f060e9e5 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -64,7 +64,9 @@ template class DualQuaternion: public Dual> { /** * @brief Default constructor * - * All components set to zero except real scalar part, which is `1`. + * @f[ + * \hat q = [\boldsymbol 0, 1] + \epsilon [\boldsymbol 0, 0] + * @f] * @todoc Remove workaround when Doxygen is predictable */ #ifdef DOXYGEN_GENERATING_OUTPUT @@ -148,7 +150,7 @@ template class DualQuaternion: public Dual> { * @brief Conjugated dual quaternion * * Both quaternion and dual conjugation. @f[ - * \overline{\hat q^*} = q_0^* - \epsilon q_\epsilon^* = q_0^* + \epsilon [\boldsymbol q_{\epsilon V}, -q_S] + * \overline{\hat q^*} = q_0^* - \epsilon q_\epsilon^* = q_0^* + \epsilon [\boldsymbol q_{V \epsilon}, -q_{S \epsilon}] * @f] * @see quaternionConjugated(), dualConjugated(), Quaternion::conjugated(), * Dual::conjugated() diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h index 6172707ba..967a91692 100644 --- a/src/Math/Point2D.h +++ b/src/Math/Point2D.h @@ -37,29 +37,36 @@ template class Point2D: public Vector3 { /** * @brief Default constructor * - * X and Y components are set to zero, Z is set to one. + * @f[ + * \boldsymbol p = (0, 0, 1)^T + * @f] */ inline constexpr /*implicit*/ Point2D(): Vector3(T(0), T(0), T(1)) {} /** * @brief Constructor - * @param x X component - * @param y Y component - * @param z Z component + * + * @f[ + * \boldsymbol p = (x, y, z)^T + * @f] */ inline constexpr /*implicit*/ Point2D(T x, T y, T z = T(1)): Vector3(x, y, z) {} /** * @brief Constructor - * @param xy Two-component vector - * @param z Z component + * + * @f[ + * \boldsymbol p = (v_x, v_y, z)^T + * @f] */ inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z): Vector3(xy, z) {} /** * @brief Construct 2D point from 2D vector * - * Z component is set to `1`. + * @f[ + * \boldsymbol p = (v_x, v_y, 1)^T + * @f] */ inline constexpr explicit Point2D(const Vector2& xy): Vector3(xy, T(1)) {} diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h index a30e9c8ff..fbe97faa3 100644 --- a/src/Math/Point3D.h +++ b/src/Math/Point3D.h @@ -37,30 +37,36 @@ template class Point3D: public Vector4 { /** * @brief Default constructor * - * X, Y and Z components are set to zero, W is set to one. + * @f[ + * \boldsymbol p = (0, 0, 0, 1)^T + * @f] */ inline constexpr /*implicit*/ Point3D(): Vector4(T(0), T(0), T(0), T(1)) {} /** * @brief Constructor - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component + * + * @f[ + * \boldsymbol p = (x, y, z, w)^T + * @f] */ inline constexpr /*implicit*/ Point3D(T x, T y, T z, T w = T(1)): Vector4(x, y, z, w) {} /** * @brief Constructor - * @param xyz Three-component vector - * @param w W component + * + * @f[ + * \boldsymbol p = (v_x, v_y, v_z, w)^T + * @f] */ inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w): Vector4(xyz, w) {} /** * @brief Construct 3D point from 3D vector * - * W component is set to `1`. + * @f[ + * \boldsymbol p = (v_x, v_y, v_z, 1)^T + * @f] */ inline constexpr explicit Point3D(const Vector3& xyz): Vector4(xyz, T(1)) {} diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index a25049370..e26ce38df 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -124,17 +124,28 @@ template class Quaternion { /** * @brief Default constructor * - * %Vector part is set to zero, scalar part to `1`. + * @f[ + * q = [\boldsymbol 0, 1] + * @f] */ inline constexpr /*implicit*/ Quaternion(): _scalar(T(1)) {} - /** @brief Create quaternion from vector and scalar */ + /** + * @brief Construct quaternion from vector and scalar + * + * @f[ + * q = [\boldsymbol v, s] + * @f] + */ inline constexpr /*implicit*/ Quaternion(const Vector3& vector, T scalar): _vector(vector), _scalar(scalar) {} /** - * @brief Create quaternion from vector + * @brief Construct quaternion from vector * - * Scalar is set to `0`. + * To be used in transformations later. @f[ + * q = [\boldsymbol v, 0] + * @f] + * @see rotateVector(), rotateVectorNormalized() */ inline constexpr explicit Quaternion(const Vector3& vector): _vector(vector), _scalar(T(0)) {} @@ -388,10 +399,10 @@ template class Quaternion { /** * @brief Rotate vector with quaternion * - * @f[ + * See rotateVectorNormalized(), which is faster for normalized + * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] - * @see rotateVectorNormalized() */ inline Vector3 rotateVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); @@ -404,6 +415,7 @@ template class Quaternion { * normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] + * @see DualQuaternion::transformVectorNormalized() */ inline Vector3 rotateVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Vector.h b/src/Math/Vector.h index edc480ec2..3cc332854 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -90,7 +90,13 @@ template class Vector { return std::acos(dot(normalizedA, normalizedB)); } - /** @brief Construct zero-filled vector */ + /** + * @brief Default constructor + * + * @f[ + * \boldsymbol v = \boldsymbol 0 + * @f] + */ inline constexpr /*implicit*/ Vector(): _data() {} /** @todo Creating Vector from combination of vector and scalar types */ diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 2fa7116c2..371788021 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -79,8 +79,10 @@ template class Vector2: public Vector<2, T> { /** * @brief Constructor - * @param x X component - * @param y Y component + * + * @f[ + * \boldsymbol v = (x, y)^T + * @f] */ inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index a2ad90872..9c1996bab 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -112,16 +112,19 @@ template class Vector3: public Vector<3, T> { /** * @brief Constructor - * @param x X component - * @param y Y component - * @param z Z component + * + * @f[ + * \boldsymbol v = (x, y, z)^T + * @f] */ inline constexpr /*implicit*/ Vector3(T x, T y, T z): Vector<3, T>(x, y, z) {} /** * @brief Constructor - * @param xy Two-component vector - * @param z Z component + * + * @f[ + * \boldsymbol v = (v_x, v_y, z)^T + * @f] */ inline constexpr /*implicit*/ Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 329a96d94..29b4dc829 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -42,17 +42,19 @@ template class Vector4: public Vector<4, T> { /** * @brief Constructor - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component + * + * @f[ + * \boldsymbol v = (x, y, z, w)^T + * @f] */ inline constexpr /*implicit*/ Vector4(T x, T y, T z, T w): Vector<4, T>(x, y, z, w) {} /** * @brief Constructor - * @param xyz Three-component vector - * @param w W component + * + * @f[ + * \boldsymbol v = (v_x, v_y, v_z, w)^T + * @f] */ inline constexpr /*implicit*/ Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} From 03ae82b44819ef1ea58133da374e2d33b4e73386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 20:58:16 +0100 Subject: [PATCH 350/567] Math: creating DualQuaternion from vector. --- src/Math/DualQuaternion.h | 14 ++++++++++++++ src/Math/Test/DualQuaternionTest.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 1f060e9e5..2b132864c 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -84,6 +84,20 @@ template class DualQuaternion: public Dual> { */ inline constexpr /*implicit*/ DualQuaternion(const Quaternion& real, const Quaternion& dual): Dual>(real, dual) {} + /** + * @brief Construct dual quaternion from vector + * + * @f[ + * \hat q = [\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0] + * @f] + * @todoc Remove workaround when Doxygen is predictable + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit DualQuaternion(const Vector3& vector); + #else + inline constexpr explicit DualQuaternion(const Vector3& vector): Dual>({}, {vector, T(0)}) {} + #endif + /** * @brief Rotation angle of unit dual quaternion * diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index dfc41fcf9..8a653804d 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -27,6 +27,7 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); + void constructFromVector(); void norm(); @@ -49,6 +50,7 @@ typedef Math::Vector3 Vector3; DualQuaternionTest::DualQuaternionTest() { addTests(&DualQuaternionTest::construct, &DualQuaternionTest::constructDefault, + &DualQuaternionTest::constructFromVector, &DualQuaternionTest::norm, @@ -73,6 +75,10 @@ void DualQuaternionTest::constructDefault() { CORRADE_COMPARE(DualQuaternion(), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); } +void DualQuaternionTest::constructFromVector() { + CORRADE_COMPARE(DualQuaternion({1.0f, 2.0f, 3.0f}), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); +} + void DualQuaternionTest::norm() { CORRADE_COMPARE(DualQuaternion().norm(), 1.0f); From 0f130ad55da58a79a0d05eab32314cdd5d67c2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 21:29:47 +0100 Subject: [PATCH 351/567] Math: simplified Quaternion::rotateVector*() tests. Comparing to Matrix4 transformation. --- src/Math/Test/QuaternionTest.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 079c0b755..f17a6e93b 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -56,8 +56,11 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void debug(); }; +typedef Math::Matrix<3, float> Matrix3; +typedef Math::Matrix4 Matrix4; typedef Math::Quaternion Quaternion; typedef Math::Vector3 Vector3; +typedef Math::Vector4 Vector4; QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, @@ -239,7 +242,7 @@ void QuaternionTest::matrix() { float angle = deg(37.0f); Vector3 axis(1.0f/Constants::sqrt3()); Quaternion q = Quaternion::rotation(angle, axis); - Matrix<3, float> expected = Matrix4::rotation(angle, axis).rotationScaling(); + Matrix3 expected = Matrix4::rotation(angle, axis).rotationScaling(); CORRADE_COMPARE(q.matrix(), expected); /* Verify that negated quaternion gives the same rotation */ @@ -292,17 +295,18 @@ void QuaternionTest::slerp() { void QuaternionTest::rotateVector() { Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); - Vector3 v(0.0f, -3.6f, 0.7f); + Matrix4 m = Matrix4::rotationX(deg(23.0f)); + Vector3 v(5.0f, -3.6f, 0.7f); Vector3 rotated = a.rotateVector(v); - CORRADE_COMPARE(Vector3::angle(v.normalized(), rotated.normalized()), deg(23.0f)); - CORRADE_COMPARE(Vector3::cross(v, rotated).normalized(), Vector3::xAxis()); - CORRADE_COMPARE(rotated.length(), v.length()); + CORRADE_COMPARE(rotated, (m*Vector4(v, 0.0f)).xyz()); + CORRADE_COMPARE(rotated, Vector3(5.0f, -3.58733f, -0.762279f)); } void QuaternionTest::rotateVectorNormalized() { Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); - Vector3 v(0.0f, -3.6f, 0.7f); + Matrix4 m = Matrix4::rotationX(deg(23.0f)); + Vector3 v(5.0f, -3.6f, 0.7f); std::ostringstream o; Corrade::Utility::Error::setOutput(&o); @@ -310,10 +314,9 @@ void QuaternionTest::rotateVectorNormalized() { CORRADE_VERIFY(notRotated != notRotated); CORRADE_COMPARE(o.str(), "Math::Quaternion::rotateVectorNormalized(): quaternion must be normalized\n"); - Vector3 rotated = a.rotateVector(v); - CORRADE_COMPARE(Vector3::angle(v.normalized(), rotated.normalized()), deg(23.0f)); - CORRADE_COMPARE(Vector3::cross(v, rotated).normalized(), Vector3::xAxis()); - CORRADE_COMPARE(rotated.length(), v.length()); + Vector3 rotated = a.rotateVectorNormalized(v); + CORRADE_COMPARE(rotated, (m*Vector4(v, 0.0f)).xyz()); + CORRADE_COMPARE(rotated, a.rotateVector(v)); } void QuaternionTest::debug() { From 4697658ed29d8904ae971b664a1d1a2b9d1515c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 22:03:59 +0100 Subject: [PATCH 352/567] Math: ability to also multiply Dual with Dual of another underlying type. --- src/Math/Dual.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 45cc4f344..094c22805 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -125,7 +125,7 @@ template class Dual { * \hat a \hat b = a_0 b_0 + \epsilon (a_0 b_\epsilon + a_\epsilon b_0) * @f] */ - inline Dual operator*(const Dual& other) const { + template inline Dual operator*(const Dual& other) const { return {_real*other._real, _real*other._dual + _dual*other._real}; } @@ -174,7 +174,7 @@ template class Dual { inline Type operator-(const Dual>& other) const { \ return Dual>::operator-(other); \ } \ - inline Type operator*(const Dual>& other) const { \ + template inline Type operator*(const Dual& other) const { \ return Dual>::operator*(other); \ } \ template inline Type operator/(const Dual& other) const { \ From 0f554a49f64e051dd0f871e043270c9d8bf6b6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 22:07:57 +0100 Subject: [PATCH 353/567] Math: convenience function to transform points with DualQuaternion. --- src/Math/DualQuaternion.h | 18 +++++++++++++++++- src/Math/Quaternion.h | 3 ++- src/Math/Test/DualQuaternionTest.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 2b132864c..e65df7dfb 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -87,9 +87,10 @@ template class DualQuaternion: public Dual> { /** * @brief Construct dual quaternion from vector * - * @f[ + * To be used in transformations later. @f[ * \hat q = [\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0] * @f] + * @see transformPointNormalized() * @todoc Remove workaround when Doxygen is predictable */ #ifdef DOXYGEN_GENERATING_OUTPUT @@ -211,6 +212,21 @@ template class DualQuaternion: public Dual> { return quaternionConjugated(); } + /** + * @brief Rotate and translate point with normalized dual quaternion + * + * Expects that the dual quaternion is normalized. @f[ + * v' = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} + * @f] + * @see Quaternion::rotateVectorNormalized() + */ + inline Vector3 transformPointNormalized(const Vector3& vector) const { + CORRADE_ASSERT(MathTypeTraits>::equals(norm(), Dual(1)), + "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized", + Vector3(std::numeric_limits::quiet_NaN())); + return ((*this)*DualQuaternion(vector)*conjugated()).dual().vector(); + } + MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualQuaternion, Quaternion) private: diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index e26ce38df..3d57aa838 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -403,6 +403,7 @@ template class Quaternion { * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] + * @see DualQuaternion::transformPointNormalized() */ inline Vector3 rotateVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); @@ -415,7 +416,7 @@ template class Quaternion { * normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] - * @see DualQuaternion::transformVectorNormalized() + * @see DualQuaternion::transformPointNormalized() */ inline Vector3 rotateVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 8a653804d..382586469 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -18,6 +18,7 @@ #include "Math/Constants.h" #include "Math/DualQuaternion.h" +#include "Math/Matrix4.h" namespace Magnum { namespace Math { namespace Test { @@ -38,14 +39,17 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void rotation(); void translation(); + void transformPointNormalized(); void debug(); }; typedef Math::Dual Dual; +typedef Math::Matrix4 Matrix4; typedef Math::DualQuaternion DualQuaternion; typedef Math::Quaternion Quaternion; typedef Math::Vector3 Vector3; +typedef Math::Vector4 Vector4; DualQuaternionTest::DualQuaternionTest() { addTests(&DualQuaternionTest::construct, @@ -61,6 +65,7 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::rotation, &DualQuaternionTest::translation, + &DualQuaternionTest::transformPointNormalized, &DualQuaternionTest::debug); } @@ -138,6 +143,28 @@ void DualQuaternionTest::translation() { CORRADE_COMPARE(q.translation(), vec); } +void DualQuaternionTest::transformPointNormalized() { + DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); + DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); + Matrix4 m = Matrix4::translation({-1.0f, 2.0f, 3.0f})*Matrix4::rotationX(deg(23.0f)); + Matrix4 n = Matrix4::rotationX(deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); + Vector3 v(0.0f, -3.6f, 0.7f); + + std::ostringstream o; + Corrade::Utility::Error::setOutput(&o); + Vector3 notTransformed = (a*Dual(2)).transformPointNormalized(v); + CORRADE_VERIFY(notTransformed != notTransformed); + CORRADE_COMPARE(o.str(), "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized\n"); + + Vector3 transformedA = a.transformPointNormalized(v); + CORRADE_COMPARE(transformedA, (m*Vector4(v, 1.0f)).xyz()); + CORRADE_COMPARE(transformedA, Vector3(-1.0f, -1.58733f, 2.237721f)); + + Vector3 transformedB = b.transformPointNormalized(v); + CORRADE_COMPARE(transformedB, (n*Vector4(v, 1.0f)).xyz()); + CORRADE_COMPARE(transformedB, Vector3(-1.0f, -2.918512f, 2.780698f)); +} + void DualQuaternionTest::debug() { std::ostringstream o; From a49bb0d71816ef2f23c141e59e549345255815c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 22:32:43 +0100 Subject: [PATCH 354/567] Math: convenience functions for transforming vectors with matrices. It's now possible to conveniently transform 2D vectors and points with 3x3 matrices and 3D vectors/points with 4x4 matrices. Previous most low-level solution: Matrix4 m; Vector3 v; Vector3 a = (m*Vector4(v, 1.0f)).xyz(); Vector4 b = (m*Vector4(v, 0.0f)).xyz(); Another, more generalized solution for points was with Point2D/Point3D, adding a lot of confusion (what is that class and what does .vector()?): Vector3 a = (m*Point3D(v)).vector(); And the worst solution was with generic 2D/3D code (WTF!): auto a = (m*typename DimensionTraits::PointType(v)).vector(); Now it is just this, similar for both dimensions: Vector3 a = m.transformPoint(v); Vector3 b = m.transformVector(v); Note that transformation three-component vectors with 3x3 matrices or four-component vectors with 4x4 matrices is easy enough so it doesn't need any special convenience functions whatsoever: Vector3 c = m.rotation()*v; --- src/Math/DualQuaternion.h | 2 +- src/Math/Matrix3.h | 24 ++++++++++++++++++++++++ src/Math/Matrix4.h | 25 +++++++++++++++++++++++++ src/Math/Quaternion.h | 4 ++-- src/Math/Test/DualQuaternionTest.cpp | 4 ++-- src/Math/Test/Matrix3Test.cpp | 14 +++++++++++++- src/Math/Test/Matrix4Test.cpp | 14 +++++++++++++- src/Math/Test/QuaternionTest.cpp | 4 ++-- src/Physics/AxisAlignedBox.cpp | 4 ++-- src/Physics/Capsule.cpp | 4 ++-- src/Physics/Line.cpp | 4 ++-- src/Physics/Plane.cpp | 2 +- src/Physics/Point.cpp | 2 +- src/Physics/Sphere.cpp | 2 +- 14 files changed, 91 insertions(+), 18 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index e65df7dfb..d36d2e495 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -218,7 +218,7 @@ template class DualQuaternion: public Dual> { * Expects that the dual quaternion is normalized. @f[ * v' = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] - * @see Quaternion::rotateVectorNormalized() + * @see Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits>::equals(norm(), Dual(1)), diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index c209aabae..e76bbf8f2 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -204,6 +204,30 @@ template class Matrix3: public Matrix<3, T> { return from(inverseRotation, inverseRotation*-translation()); } + /** + * @brief Transform 2D vector with the matrix + * + * Translation is not involved in the transformation. @f[ + * \boldsymbol v' = \boldsymbol M (v_x, v_y, 0)^T + * @f] + * @see transformPoint(), Matrix4::transformVector() + */ + inline Vector2 transformVector(const Vector2& vector) const { + return ((*this)*Vector3(vector, T(0))).xy(); + } + + /** + * @brief Transform 2D point with the matrix + * + * Unlike in transformVector(), translation is also involved. @f[ + * \boldsymbol v' = \boldsymbol M (v_x, v_y, 1)^T + * @f] + * @see Matrix4::transformPoint() + */ + inline Vector2 transformPoint(const Vector2& vector) const { + return ((*this)*Vector3(vector, T(1))).xy(); + } + #ifndef DOXYGEN_GENERATING_OUTPUT inline Point2D operator*(const Point2D& other) const { return Matrix<3, T>::operator*(other); diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 4b5c85ce1..da1a0d9be 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -348,6 +348,31 @@ template class Matrix4: public Matrix<4, T> { return from(inverseRotation, inverseRotation*-translation()); } + /** + * @brief Transform 3D vector with the matrix + * + * Translation is not involved in the transformation. @f[ + * \boldsymbol v' = \boldsymbol M (v_x, v_y, v_z, 0)^T + * @f] + * @see transformPoint(), Quaternion::rotateVector(), + * Matrix3::transformVector() + */ + inline Vector3 transformVector(const Vector3& vector) const { + return ((*this)*Vector4(vector, T(0))).xyz(); + } + + /** + * @brief Transform 3D point with the matrix + * + * Unlike in transformVector(), translation is also involved. @f[ + * \boldsymbol v' = \boldsymbol M (v_x, v_y, v_z, 1)^T + * @f] + * @see DualQuaternion::transformPointNormalized(), Matrix3::transformPoint() + */ + inline Vector3 transformPoint(const Vector3& vector) const { + return ((*this)*Vector4(vector, T(1))).xyz(); + } + #ifndef DOXYGEN_GENERATING_OUTPUT inline Point3D operator*(const Point3D& other) const { return Matrix<4, T>::operator*(other); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 3d57aa838..24245c969 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -403,7 +403,7 @@ template class Quaternion { * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] - * @see DualQuaternion::transformPointNormalized() + * @see Matrix4::transformVector(), DualQuaternion::transformPointNormalized() */ inline Vector3 rotateVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); @@ -416,7 +416,7 @@ template class Quaternion { * normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] - * @see DualQuaternion::transformPointNormalized() + * @see Matrix4::transformVector(), DualQuaternion::transformPointNormalized() */ inline Vector3 rotateVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 382586469..896ab5c2a 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -157,11 +157,11 @@ void DualQuaternionTest::transformPointNormalized() { CORRADE_COMPARE(o.str(), "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized\n"); Vector3 transformedA = a.transformPointNormalized(v); - CORRADE_COMPARE(transformedA, (m*Vector4(v, 1.0f)).xyz()); + CORRADE_COMPARE(transformedA, m.transformPoint(v)); CORRADE_COMPARE(transformedA, Vector3(-1.0f, -1.58733f, 2.237721f)); Vector3 transformedB = b.transformPointNormalized(v); - CORRADE_COMPARE(transformedB, (n*Vector4(v, 1.0f)).xyz()); + CORRADE_COMPARE(transformedB, n.transformPoint(v)); CORRADE_COMPARE(transformedB, Vector3(-1.0f, -2.918512f, 2.780698f)); } diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index e5e57e11c..5f61137ca 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -38,6 +38,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void rotationPart(); void vectorParts(); void invertedEuclidean(); + void transform(); void debug(); void configuration(); @@ -50,6 +51,7 @@ typedef Math::Point2D Point2D; Matrix3Test::Matrix3Test() { addTests(&Matrix3Test::constructIdentity, + &Matrix3Test::translation, &Matrix3Test::scaling, &Matrix3Test::rotation, @@ -60,6 +62,8 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::rotationPart, &Matrix3Test::vectorParts, &Matrix3Test::invertedEuclidean, + &Matrix3Test::transform, + &Matrix3Test::debug, &Matrix3Test::configuration); } @@ -121,7 +125,7 @@ void Matrix3Test::reflection() { {0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(actual*actual, Matrix3()); - CORRADE_COMPARE((actual*Point2D(normal)).vector(), -normal); + CORRADE_COMPARE(actual.transformVector(normal), -normal); CORRADE_COMPARE(actual, expected); } @@ -203,6 +207,14 @@ void Matrix3Test::invertedEuclidean() { CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); } +void Matrix3Test::transform() { + Matrix3 a = Matrix3::translation({1.0f, -5.0f})*Matrix3::rotation(deg(90.0f)); + Vector2 v(1.0f, -2.0f); + + CORRADE_COMPARE(a.transformVector(v), Vector2(2.0f, 1.0f)); + CORRADE_COMPARE(a.transformPoint(v), Vector2(3.0f, -4.0f)); +} + void Matrix3Test::debug() { Matrix3 m({3.0f, 5.0f, 8.0f}, {4.0f, 4.0f, 7.0f}, diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 24c0debd2..b9c68eee3 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -43,6 +43,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotationPart(); void vectorParts(); void invertedEuclidean(); + void transform(); void debug(); void configuration(); @@ -55,6 +56,7 @@ typedef Math::Point3D Point3D; Matrix4Test::Matrix4Test() { addTests(&Matrix4Test::constructIdentity, + &Matrix4Test::translation, &Matrix4Test::scaling, &Matrix4Test::rotation, @@ -70,6 +72,8 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotationPart, &Matrix4Test::vectorParts, &Matrix4Test::invertedEuclidean, + &Matrix4Test::transform, + &Matrix4Test::debug, &Matrix4Test::configuration); } @@ -169,7 +173,7 @@ void Matrix4Test::reflection() { { 0.0f, 0.0f, 0.0f, 1.0f}); CORRADE_COMPARE(actual*actual, Matrix4()); - CORRADE_COMPARE((actual*Point3D(normal)).vector(), -normal); + CORRADE_COMPARE(actual.transformVector(normal), -normal); CORRADE_COMPARE(actual, expected); } @@ -277,6 +281,14 @@ void Matrix4Test::invertedEuclidean() { CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); } +void Matrix4Test::transform() { + Matrix4 a = Matrix4::translation({1.0f, -5.0f, 3.5f})*Matrix4::rotation(deg(90.0f), Vector3::zAxis()); + Vector3 v(1.0f, -2.0f, 5.5f); + + CORRADE_COMPARE(a.transformVector(v), Vector3(2.0f, 1.0f, 5.5f)); + CORRADE_COMPARE(a.transformPoint(v), Vector3(3.0f, -4.0f, 9.0f)); +} + void Matrix4Test::debug() { Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, {4.0f, 4.0f, 7.0f, 3.0f}, diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index f17a6e93b..1a39fc565 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -299,7 +299,7 @@ void QuaternionTest::rotateVector() { Vector3 v(5.0f, -3.6f, 0.7f); Vector3 rotated = a.rotateVector(v); - CORRADE_COMPARE(rotated, (m*Vector4(v, 0.0f)).xyz()); + CORRADE_COMPARE(rotated, m.transformVector(v)); CORRADE_COMPARE(rotated, Vector3(5.0f, -3.58733f, -0.762279f)); } @@ -315,7 +315,7 @@ void QuaternionTest::rotateVectorNormalized() { CORRADE_COMPARE(o.str(), "Math::Quaternion::rotateVectorNormalized(): quaternion must be normalized\n"); Vector3 rotated = a.rotateVectorNormalized(v); - CORRADE_COMPARE(rotated, (m*Vector4(v, 0.0f)).xyz()); + CORRADE_COMPARE(rotated, m.transformVector(v)); CORRADE_COMPARE(rotated, a.rotateVector(v)); } diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 786003a40..822315464 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -22,8 +22,8 @@ namespace Magnum { namespace Physics { template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { - _transformedMin = (matrix*typename DimensionTraits::PointType(_min)).vector(); - _transformedMax = (matrix*typename DimensionTraits::PointType(_max)).vector(); + _transformedMin = matrix.transformPoint(_min); + _transformedMax = matrix.transformPoint(_max); } template bool AxisAlignedBox::collides(const AbstractShape* other) const { diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 784b016d9..fd3fc9d79 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -28,8 +28,8 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { template void Capsule::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { - _transformedA = (matrix*typename DimensionTraits::PointType(_a)).vector(); - _transformedB = (matrix*typename DimensionTraits::PointType(_b)).vector(); + _transformedA = matrix.transformPoint(_a); + _transformedB = matrix.transformPoint(_b); float scaling = (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 49fbe566e..8f02bc887 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -21,8 +21,8 @@ namespace Magnum { namespace Physics { template void Line::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { - _transformedA = (matrix*typename DimensionTraits::PointType(_a)).vector(); - _transformedB = (matrix*typename DimensionTraits::PointType(_b)).vector(); + _transformedA = matrix.transformPoint(_a); + _transformedB = matrix.transformPoint(_b); } /* Explicitly instantiate the templates */ diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 77af71cc9..471f1a0ed 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -27,7 +27,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { void Plane::applyTransformationMatrix(const Matrix4& matrix) { - _transformedPosition = (matrix*Magnum::Point3D(_position)).xyz(); + _transformedPosition = matrix.transformPoint(_position); _transformedNormal = matrix.rotation()*_normal; } diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 53f697109..94d7d20af 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -21,7 +21,7 @@ namespace Magnum { namespace Physics { template void Point::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { - _transformedPosition = (matrix*typename DimensionTraits::PointType(_position)).vector(); + _transformedPosition = matrix.transformPoint(_position); } template class Point<2>; diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index c0cf2aa33..a307844d0 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -40,7 +40,7 @@ namespace { } template void Sphere::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { - _transformedPosition = (matrix*typename DimensionTraits::PointType(_position)).vector(); + _transformedPosition = matrix.transformPoint(_position); float scaling = (matrix.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } From 07c0c4d845324b12a74d0520e4b38bf1efff3d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Feb 2013 23:31:50 +0100 Subject: [PATCH 355/567] Math: added tests for composed dual quaternion parts. To be sure everything is implemented properly. --- src/Math/Test/DualQuaternionTest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 896ab5c2a..35c64dae0 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -39,6 +39,7 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void rotation(); void translation(); + void combinedTransformParts(); void transformPointNormalized(); void debug(); @@ -65,6 +66,7 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::rotation, &DualQuaternionTest::translation, + &DualQuaternionTest::combinedTransformParts, &DualQuaternionTest::transformPointNormalized, &DualQuaternionTest::debug); @@ -143,6 +145,20 @@ void DualQuaternionTest::translation() { CORRADE_COMPARE(q.translation(), vec); } +void DualQuaternionTest::combinedTransformParts() { + Vector3 translation = Vector3(-1.0f, 2.0f, 3.0f); + DualQuaternion a = DualQuaternion::translation(translation)*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); + DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation(translation); + + CORRADE_COMPARE(a.rotationAxis(), Vector3::xAxis()); + CORRADE_COMPARE(b.rotationAxis(), Vector3::xAxis()); + CORRADE_COMPARE(a.rotationAngle(), deg(23.0f)); + CORRADE_COMPARE(b.rotationAngle(), deg(23.0f)); + + CORRADE_COMPARE(a.translation(), translation); + CORRADE_COMPARE(b.translation(), Quaternion::rotation(deg(23.0f), Vector3::xAxis()).rotateVectorNormalized(translation)); +} + void DualQuaternionTest::transformPointNormalized() { DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); From 389e9194e01d4ec281778a71c1fa143af0035b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 11:29:16 +0100 Subject: [PATCH 356/567] Math: doc++ --- src/Math/DualQuaternion.h | 2 +- src/Math/Quaternion.h | 8 ++++---- src/Math/Vector.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index d36d2e495..9bf1d185c 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -218,7 +218,7 @@ template class DualQuaternion: public Dual> { * Expects that the dual quaternion is normalized. @f[ * v' = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] - * @see Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() + * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits>::equals(norm(), Dual(1)), diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 24245c969..8246ce995 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -344,10 +344,10 @@ template class Quaternion { /** * @brief %Quaternion length * - * @f[ + * See also dot() const which is faster for comparing length with other + * values. @f[ * |q| = \sqrt{q \cdot q} * @f] - * @see dot() const */ inline T length() const { return std::sqrt(dot()); @@ -403,7 +403,7 @@ template class Quaternion { * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] - * @see Matrix4::transformVector(), DualQuaternion::transformPointNormalized() + * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPointNormalized() */ inline Vector3 rotateVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); @@ -416,7 +416,7 @@ template class Quaternion { * normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] - * @see Matrix4::transformVector(), DualQuaternion::transformPointNormalized() + * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPointNormalized() */ inline Vector3 rotateVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 3cc332854..f1c603a0d 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -395,10 +395,10 @@ template class Vector { /** * @brief %Vector length * - * @f[ + * See also dot() const which is faster for comparing length with other + * values. @f[ * |\boldsymbol a| = \sqrt{\boldsymbol a \cdot \boldsymbol a} * @f] - * @see dot() const */ inline T length() const { return std::sqrt(dot()); From 83346ce023e9e9752a6b07f97a76d4971c501ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 11:29:57 +0100 Subject: [PATCH 357/567] Math: converting DualQuaternion to matrix. Also updated and simplified Quaternion to matrix test. --- src/Math/DualQuaternion.h | 10 ++++++++++ src/Math/Quaternion.h | 2 +- src/Math/Test/DualQuaternionTest.cpp | 12 +++++++++++- src/Math/Test/QuaternionTest.cpp | 10 ++++------ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 9bf1d185c..56039ea5d 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -20,6 +20,7 @@ */ #include "Math/Dual.h" +#include "Math/Matrix4.h" #include "Math/Quaternion.h" namespace Magnum { namespace Math { @@ -137,6 +138,15 @@ template class DualQuaternion: public Dual> { return (this->dual()*this->real().conjugated()).vector()*T(2); } + /** + * @brief Convert dual quaternion to transformation matrix + * + * @see Quaternion::matrix() + */ + Matrix4 matrix() const { + return Matrix4::from(this->real().matrix(), translation()); + } + /** * @brief Quaternion-conjugated dual quaternion * diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 8246ce995..74572bc55 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -200,7 +200,7 @@ template class Quaternion { /** * @brief Convert quaternion to rotation matrix * - * @see Matrix4::from(const Matrix<3, T>&, const Vector3&) + * @see DualQuaternion::matrix(), Matrix4::from(const Matrix<3, T>&, const Vector3&) */ Matrix<3, T> matrix() const { return { diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 35c64dae0..ed3f20e55 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -18,7 +18,6 @@ #include "Math/Constants.h" #include "Math/DualQuaternion.h" -#include "Math/Matrix4.h" namespace Magnum { namespace Math { namespace Test { @@ -40,6 +39,7 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void rotation(); void translation(); void combinedTransformParts(); + void matrix(); void transformPointNormalized(); void debug(); @@ -67,6 +67,7 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::rotation, &DualQuaternionTest::translation, &DualQuaternionTest::combinedTransformParts, + &DualQuaternionTest::matrix, &DualQuaternionTest::transformPointNormalized, &DualQuaternionTest::debug); @@ -159,6 +160,15 @@ void DualQuaternionTest::combinedTransformParts() { CORRADE_COMPARE(b.translation(), Quaternion::rotation(deg(23.0f), Vector3::xAxis()).rotateVectorNormalized(translation)); } +void DualQuaternionTest::matrix() { + DualQuaternion q = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); + Matrix4 m = Matrix4::rotationX(deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); + + /* Verify that negated dual quaternion gives the same transformation */ + CORRADE_COMPARE(q.matrix(), m); + CORRADE_COMPARE((-q).matrix(), m); +} + void DualQuaternionTest::transformPointNormalized() { DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 1a39fc565..fcf1994a1 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -239,14 +239,12 @@ void QuaternionTest::angle() { } void QuaternionTest::matrix() { - float angle = deg(37.0f); - Vector3 axis(1.0f/Constants::sqrt3()); - Quaternion q = Quaternion::rotation(angle, axis); - Matrix3 expected = Matrix4::rotation(angle, axis).rotationScaling(); - CORRADE_COMPARE(q.matrix(), expected); + Quaternion q = Quaternion::rotation(deg(37.0f), Vector3(1.0f/Constants::sqrt3())); + Matrix3 m = Matrix4::rotation(deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); /* Verify that negated quaternion gives the same rotation */ - CORRADE_COMPARE((-q).matrix(), expected); + CORRADE_COMPARE(q.matrix(), m); + CORRADE_COMPARE((-q).matrix(), m); } void QuaternionTest::lerp() { From fec6822187f1c75e8fbf75d99cb55c9ecd3baa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 13:38:23 +0100 Subject: [PATCH 358/567] Math: added sqrt() scalar/vector overload. --- src/Math/Functions.h | 15 +++++++++++++++ src/Math/Test/FunctionsTest.cpp | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index b313780b0..7db0b70dc 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -132,6 +132,21 @@ template Vector abs(const Vector& a } #endif +/** @brief Square root */ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline T sqrt(const T& a); +#else +template inline typename std::enable_if::value, T>::type sqrt(T a) { + return std::sqrt(a); +} +template Vector sqrt(const Vector& a) { + Vector out; + for(std::size_t i = 0; i != size; ++i) + out[i] = std::sqrt(a[i]); + return out; +} +#endif + /** @brief Clamp value diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 049c9be67..6fc7ea819 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -27,6 +27,7 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void min(); void max(); void abs(); + void sqrt(); void clamp(); void lerp(); void normalizeUnsigned(); @@ -50,6 +51,7 @@ FunctionsTest::FunctionsTest() { addTests(&FunctionsTest::min, &FunctionsTest::max, &FunctionsTest::abs, + &FunctionsTest::sqrt, &FunctionsTest::clamp, &FunctionsTest::lerp, &FunctionsTest::normalizeUnsigned, @@ -79,6 +81,11 @@ void FunctionsTest::abs() { CORRADE_COMPARE(Math::abs(Vector3i(5, -3, 2)), Vector3i(5, 3, 2)); } +void FunctionsTest::sqrt() { + CORRADE_COMPARE(Math::sqrt(16), 4); + CORRADE_COMPARE(Math::sqrt(Vector3i(256, 1, 0)), Vector3i(16, 1, 0)); +} + void FunctionsTest::clamp() { CORRADE_COMPARE(Math::clamp(0.5f, -1.0f, 5.0f), 0.5f); CORRADE_COMPARE(Math::clamp(-1.6f, -1.0f, 5.0f), -1.0f); From f1da7a08b4ddc27f25c3da0c869445bd20fa7e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 13:39:04 +0100 Subject: [PATCH 359/567] Math: added sqrt() overload for Dual. --- src/Math/Dual.h | 14 ++++++++++++++ src/Math/Test/DualTest.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 094c22805..ba75f66a1 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -19,6 +19,7 @@ * @brief Class Magnum::Math::Dual */ +#include #include #include "Math/MathTypeTraits.h" @@ -191,6 +192,19 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb return debug; } +/** @relates Dual +@brief Square root of dual number + +@f[ + \sqrt{\hat a} = \sqrt{a_0} + \epsilon \frac{a_\epsilon}{2 \sqrt{a_0}} +@f] +@see Math::sqrt(const T&) +*/ +template Dual sqrt(const Dual& dual) { + T sqrt0 = std::sqrt(dual.real()); + return {sqrt0, dual.dual()/(2*sqrt0)}; +} + }} #endif diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index 527b9c85d..19d74583a 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -33,6 +33,7 @@ class DualTest: public Corrade::TestSuite::Tester { void multiplyDivide(); void conjugated(); + void sqrt(); void debug(); }; @@ -49,6 +50,7 @@ DualTest::DualTest() { &DualTest::multiplyDivide, &DualTest::conjugated, + &DualTest::sqrt, &DualTest::debug); } @@ -104,6 +106,10 @@ void DualTest::conjugated() { CORRADE_COMPARE(Dual(1.0f, -6.5f).conjugated(), Dual(1.0f, 6.5f)); } +void DualTest::sqrt() { + CORRADE_COMPARE(Math::sqrt(Dual(16.0f, 2.0f)), Dual(4.0f, 0.25f)); +} + void DualTest::debug() { std::ostringstream o; From 12c786c4089c8804a6db07c4c1e78686bb50f05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 13:45:06 +0100 Subject: [PATCH 360/567] Math: renamed DualQuaternion::norm() to length(), added lengthSquared(). Hopefully this is properly implemented and properly named. On the other hand, having length everywhere (vectors, quaternions, complex numbers) and norm only at one place is inconsistent. --- src/Math/DualQuaternion.h | 30 +++++++++++++++++++--------- src/Math/Test/DualQuaternionTest.cpp | 21 +++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 56039ea5d..10a75cc25 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -185,15 +185,27 @@ template class DualQuaternion: public Dual> { } /** - * @brief %Dual quaternion norm + * @brief %Dual quaternion length squared * - * @f[ - * ||\hat q|| = \sqrt{\hat q^* \hat q} = ||q_0|| + \epsilon \frac{q_0 \cdot q_\epsilon}{||q_0||} + * Should be used instead of length() for comparing dual quaternion + * length with other values, because it doesn't compute the square root. @f[ + * |\hat q|^2 = \sqrt{\hat q^* \hat q}^2 = q_0 \cdot q_0 + \epsilon 2 (q_0 \cdot q_\epsilon) + * @f] + */ + inline Dual lengthSquared() const { + return {this->real().dot(), T(2)*Quaternion::dot(this->real(), this->dual())}; + } + + /** + * @brief %Dual quaternion length + * + * See lengthSquared() which is faster for comparing length with other + * values. @f[ + * |\hat q| = \sqrt{\hat q^* \hat q} = |q_0| + \epsilon \frac{q_0 \cdot q_\epsilon}{|q_0|} * @f] */ - inline Dual norm() const { - T norm = this->real().length(); - return {norm, Quaternion::dot(this->real(), this->dual())/norm}; + inline Dual length() const { + return Math::sqrt(lengthSquared()); } /** @@ -205,7 +217,7 @@ template class DualQuaternion: public Dual> { * @f] */ inline DualQuaternion inverted() const { - return quaternionConjugated()/Math::pow<2>(norm()); + return quaternionConjugated()/Math::pow<2>(length()); } /** @@ -217,7 +229,7 @@ template class DualQuaternion: public Dual> { * @f] */ inline DualQuaternion invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(norm(), T(1)), + CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), "Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized", {}); return quaternionConjugated(); } @@ -231,7 +243,7 @@ template class DualQuaternion: public Dual> { * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { - CORRADE_ASSERT(MathTypeTraits>::equals(norm(), Dual(1)), + CORRADE_ASSERT(MathTypeTraits>::equals(lengthSquared(), Dual(1)), "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*DualQuaternion(vector)*conjugated()).dual().vector(); diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index ed3f20e55..e18862dc5 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -29,7 +29,8 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void constructDefault(); void constructFromVector(); - void norm(); + void lengthSquared(); + void length(); void quaternionConjugated(); void dualConjugated(); @@ -57,7 +58,8 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::constructDefault, &DualQuaternionTest::constructFromVector, - &DualQuaternionTest::norm, + &DualQuaternionTest::lengthSquared, + &DualQuaternionTest::length, &DualQuaternionTest::quaternionConjugated, &DualQuaternionTest::dualConjugated, @@ -87,11 +89,18 @@ void DualQuaternionTest::constructFromVector() { CORRADE_COMPARE(DualQuaternion({1.0f, 2.0f, 3.0f}), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); } -void DualQuaternionTest::norm() { - CORRADE_COMPARE(DualQuaternion().norm(), 1.0f); +void DualQuaternionTest::lengthSquared() { + CORRADE_COMPARE(DualQuaternion().lengthSquared(), 1.0f); - DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 0.5f, -3.0f, 3.0f}, 2.0f}); - CORRADE_COMPARE(a.norm(), Dual(5.477226f, -0.821584f)); + DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); + CORRADE_COMPARE(a.lengthSquared(), Dual(30.0f, -9.0f)); +} + +void DualQuaternionTest::length() { + CORRADE_COMPARE(DualQuaternion().length(), 1.0f); + + DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); + CORRADE_COMPARE(a.length(), Dual(5.477226f, -0.821584f)); } void DualQuaternionTest::quaternionConjugated() { From 7e0d8d119f5441c234ff1d82ab65f11eb88f2ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 13:47:42 +0100 Subject: [PATCH 361/567] Math: ability to normalize DualQuaternion. Also hope that this is proper implementation. --- src/Math/DualQuaternion.h | 5 +++++ src/Math/Test/DualQuaternionTest.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 10a75cc25..3076acd42 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -208,6 +208,11 @@ template class DualQuaternion: public Dual> { return Math::sqrt(lengthSquared()); } + /** @brief Normalized quaternion (of length 1) */ + inline DualQuaternion normalized() const { + return (*this)/length(); + } + /** * @brief Inverted dual quaternion * diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index e18862dc5..bed18d4f4 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -31,6 +31,7 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void lengthSquared(); void length(); + void normalized(); void quaternionConjugated(); void dualConjugated(); @@ -60,6 +61,7 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::lengthSquared, &DualQuaternionTest::length, + &DualQuaternionTest::normalized, &DualQuaternionTest::quaternionConjugated, &DualQuaternionTest::dualConjugated, @@ -103,6 +105,13 @@ void DualQuaternionTest::length() { CORRADE_COMPARE(a.length(), Dual(5.477226f, -0.821584f)); } +void DualQuaternionTest::normalized() { + DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); + DualQuaternion b({{0.182574f, 0.365148f, 0.547723f}, -0.730297f}, {{0.118673f, -0.49295f, 0.629881f}, 0.255604f}); + CORRADE_COMPARE(a.normalized().length(), 1.0f); + CORRADE_COMPARE(a.normalized(), b); +} + void DualQuaternionTest::quaternionConjugated() { DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 0.5f, -3.1f, 3.3f}, 2.0f}); DualQuaternion b({{-1.0f, -2.0f, -3.0f}, -4.0f}, {{-0.5f, 3.1f, -3.3f}, 2.0f}); From 227517ff8911d451aa41443997bbcd6bc78ab3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 13:50:53 +0100 Subject: [PATCH 362/567] Math: added DualQuaternion::transformPoint(). --- src/Math/DualQuaternion.h | 18 ++++++++++++++++-- src/Math/Matrix4.h | 2 +- src/Math/Quaternion.h | 2 +- src/Math/Test/DualQuaternionTest.cpp | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 3076acd42..5ede6da05 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -239,11 +239,25 @@ template class DualQuaternion: public Dual> { return quaternionConjugated(); } + /** + * @brief Rotate and translate point with dual quaternion + * + * See rotateVectorNormalized(), which is faster for normalized dual + * quaternions. @f[ + * v' = qv \overline{\hat q^{-1}} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^{-1}} + * @f] + * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() + */ + inline Vector3 transformPoint(const Vector3& vector) const { + return ((*this)*DualQuaternion(vector)*inverted().dualConjugated()).dual().vector(); + } + /** * @brief Rotate and translate point with normalized dual quaternion * - * Expects that the dual quaternion is normalized. @f[ - * v' = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} + * Faster alternative to transformPoint(), expects that the dual + * quaternion is normalized. @f[ + * v' = qv \overline{\hat q^{-1}} = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index da1a0d9be..6fa43559b 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -367,7 +367,7 @@ template class Matrix4: public Matrix<4, T> { * Unlike in transformVector(), translation is also involved. @f[ * \boldsymbol v' = \boldsymbol M (v_x, v_y, v_z, 1)^T * @f] - * @see DualQuaternion::transformPointNormalized(), Matrix3::transformPoint() + * @see DualQuaternion::transformPoint(), Matrix3::transformPoint() */ inline Vector3 transformPoint(const Vector3& vector) const { return ((*this)*Vector4(vector, T(1))).xyz(); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 74572bc55..2b83b8d70 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -403,7 +403,7 @@ template class Quaternion { * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] - * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPointNormalized() + * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPoint() */ inline Vector3 rotateVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index bed18d4f4..bcc3aa50d 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -42,6 +42,7 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void translation(); void combinedTransformParts(); void matrix(); + void transformPoint(); void transformPointNormalized(); void debug(); @@ -72,6 +73,7 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::translation, &DualQuaternionTest::combinedTransformParts, &DualQuaternionTest::matrix, + &DualQuaternionTest::transformPoint, &DualQuaternionTest::transformPointNormalized, &DualQuaternionTest::debug); @@ -187,6 +189,22 @@ void DualQuaternionTest::matrix() { CORRADE_COMPARE((-q).matrix(), m); } +void DualQuaternionTest::transformPoint() { + DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); + DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); + Matrix4 m = Matrix4::translation({-1.0f, 2.0f, 3.0f})*Matrix4::rotationX(deg(23.0f)); + Matrix4 n = Matrix4::rotationX(deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); + Vector3 v(0.0f, -3.6f, 0.7f); + + Vector3 transformedA = (a*Dual(2)).transformPoint(v); + CORRADE_COMPARE(transformedA, m.transformPoint(v)); + CORRADE_COMPARE(transformedA, Vector3(-1.0f, -1.58733f, 2.237721f)); + + Vector3 transformedB = (b*Dual(2)).transformPoint(v); + CORRADE_COMPARE(transformedB, n.transformPoint(v)); + CORRADE_COMPARE(transformedB, Vector3(-1.0f, -2.918512f, 2.780698f)); +} + void DualQuaternionTest::transformPointNormalized() { DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); From c00f081b83c2eb41407cba8d04b5ae1ee2220d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 13:51:19 +0100 Subject: [PATCH 363/567] Using larger font in Doxygen documentation formulas. --- Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile b/Doxyfile index 88735c3e1..54e5ba71f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1190,7 +1190,7 @@ EXT_LINKS_IN_WINDOW = NO # to manually remove any form_*.png images from the HTML output directory # to force them to be regenerated. -FORMULA_FONTSIZE = 10 +FORMULA_FONTSIZE = 12 # Use the FORMULA_TRANPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are From e2591253ae19bb75310367b772530599610d2df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 17:15:31 +0100 Subject: [PATCH 364/567] Math: test constexpr swizzle(). --- src/Math/Test/SwizzleTest.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp index 9df00e89f..795d4297a 100644 --- a/src/Math/Test/SwizzleTest.cpp +++ b/src/Math/Test/SwizzleTest.cpp @@ -26,6 +26,7 @@ class SwizzleTest: public Corrade::TestSuite::Tester { void components(); void constants(); void sizes(); + void constExpressions(); }; typedef Vector<4, std::int32_t> Vector4i; @@ -33,7 +34,8 @@ typedef Vector<4, std::int32_t> Vector4i; SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::components, &SwizzleTest::constants, - &SwizzleTest::sizes); + &SwizzleTest::sizes, + &SwizzleTest::constExpressions); } void SwizzleTest::components() { @@ -53,6 +55,14 @@ void SwizzleTest::sizes() { (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); } +void SwizzleTest::constExpressions() { + constexpr auto a = swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7)); + CORRADE_COMPARE(a, Vector4i(5, 2, 7, 4)); + + constexpr auto b = swizzle<'1', 'w', '0', 'y'>(Vector4i(2, 4, 5, 7)); + CORRADE_COMPARE(b, Vector4i(1, 7, 0, 4)); +} + }}} CORRADE_TEST_MAIN(Magnum::Math::Test::SwizzleTest) From 184bf38fc1c660202f4bfe533bbc20e47303e7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 17:16:00 +0100 Subject: [PATCH 365/567] Math: test constexpr methods on Dual. --- src/Math/Test/DualTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index 19d74583a..5b2987075 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -28,6 +28,8 @@ class DualTest: public Corrade::TestSuite::Tester { void constructDefault(); void compare(); + void constExpressions(); + void addSubtract(); void negated(); void multiplyDivide(); @@ -45,6 +47,8 @@ DualTest::DualTest() { &DualTest::constructDefault, &DualTest::compare, + &DualTest::constExpressions, + &DualTest::addSubtract, &DualTest::negated, &DualTest::multiplyDivide, @@ -80,6 +84,26 @@ void DualTest::compare() { CORRADE_VERIFY(Dual(1.0f, 3.0f) != 1.0f); } +void DualTest::constExpressions() { + /* Default constructor */ + constexpr Dual a; + CORRADE_COMPARE(a, Dual(0.0f, 0.0f)); + + /* Value constructor */ + constexpr Dual b(2.0f, 3.0f); + CORRADE_COMPARE(b, Dual(2.0f, 3.0f)); + + /* Copy constructor */ + constexpr Dual c(b); + CORRADE_COMPARE(c, Dual(2.0f, 3.0f)); + + /* Data access */ + constexpr float e = b.real(); + constexpr float f = b.dual(); + CORRADE_COMPARE(e, 2.0f); + CORRADE_COMPARE(f, 3.0f); +} + void DualTest::addSubtract() { Dual a(2.0f, -7.5f); Dual b(-3.3f, 0.2f); From dccfc1f8ba4cdc125068719347dfd3bb9a76f632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 17:16:24 +0100 Subject: [PATCH 366/567] Math: test constexpr methods on Quaternion. --- src/Math/Test/QuaternionTest.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index fcf1994a1..285a62fbf 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -31,6 +31,8 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void constructFromVector(); void compare(); + void constExpressions(); + void addSubtract(); void negated(); void multiplyDivideScalar(); @@ -68,6 +70,8 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::constructFromVector, &QuaternionTest::compare, + &QuaternionTest::constExpressions, + &QuaternionTest::addSubtract, &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, @@ -114,6 +118,30 @@ void QuaternionTest::compare() { CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); } +void QuaternionTest::constExpressions() { + /* Default constructor */ + constexpr Quaternion a; + CORRADE_COMPARE(a, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); + + /* Value constructor */ + constexpr Quaternion b({1.0f, -3.0f, 7.0f}, 2.5f); + CORRADE_COMPARE(b, Quaternion({1.0f, -3.0f, 7.0f}, 2.5f)); + + /* Construct from vector */ + constexpr Quaternion c({2.0f, -3.0f, 1.5f}); + CORRADE_COMPARE(c, Quaternion({2.0f, -3.0f, 1.5f}, 0.0f)); + + /* Copy constructor */ + constexpr Quaternion d(b); + CORRADE_COMPARE(d, Quaternion({1.0f, -3.0f, 7.0f}, 2.5f)); + + /* Data access */ + constexpr Vector3 e = b.vector(); + constexpr float f = b.scalar(); + CORRADE_COMPARE(e, Vector3(1.0f, -3.0f, 7.0f)); + CORRADE_COMPARE(f, 2.5f); +} + void QuaternionTest::addSubtract() { Quaternion a({ 1.0f, 3.0f, -2.0f}, -4.0f); Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); From 5b1463fa0c651f09d405274894a9108663c960d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Feb 2013 17:16:42 +0100 Subject: [PATCH 367/567] Math: test constexpr methods on DualQuaternion. --- src/Math/Test/DualQuaternionTest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index bcc3aa50d..88481305e 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -29,6 +29,8 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void constructDefault(); void constructFromVector(); + void constExpressions(); + void lengthSquared(); void length(); void normalized(); @@ -60,6 +62,8 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::constructDefault, &DualQuaternionTest::constructFromVector, + &DualQuaternionTest::constExpressions, + &DualQuaternionTest::lengthSquared, &DualQuaternionTest::length, &DualQuaternionTest::normalized, @@ -93,6 +97,24 @@ void DualQuaternionTest::constructFromVector() { CORRADE_COMPARE(DualQuaternion({1.0f, 2.0f, 3.0f}), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); } +void DualQuaternionTest::constExpressions() { + /* Default constructor */ + constexpr DualQuaternion a; + CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); + + /* Value constructor */ + constexpr DualQuaternion b({{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})); + + /* Vector constructor */ + constexpr DualQuaternion c({1.5f, -5.0f, 3.0f}); + CORRADE_COMPARE(c, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.5f, -5.0f, 3.0f}, 0.0f})); + + /* Copy constructor */ + constexpr DualQuaternion d(b); + CORRADE_COMPARE(d, DualQuaternion({{1.0f, 2.0f, -3.0f}, -3.5f}, {{4.5f, -7.0f, 2.0f}, 1.0f})); +} + void DualQuaternionTest::lengthSquared() { CORRADE_COMPARE(DualQuaternion().lengthSquared(), 1.0f); From 9cb0b77d1ea7db4c37ea51d813ff37016767bfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 18 Feb 2013 18:06:09 +0100 Subject: [PATCH 368/567] Math: added underlying type typedef for remaining types. Also updated and unified documentation. --- src/Math/Dual.h | 7 ++++++- src/Math/DualQuaternion.h | 3 +++ src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 2 +- src/Math/Quaternion.h | 3 +++ src/Math/RectangularMatrix.h | 4 ++-- src/Math/Vector.h | 4 ++-- 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Math/Dual.h b/src/Math/Dual.h index ba75f66a1..b5f70f4b7 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -26,11 +26,16 @@ namespace Magnum { namespace Math { -/** @brief %Dual number */ +/** +@brief %Dual number +@tparam T Underlying data type +*/ template class Dual { template friend class Dual; public: + typedef T Type; /**< @brief Underlying data type */ + /** * @brief Default constructor * diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 5ede6da05..88f55582e 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -27,11 +27,14 @@ namespace Magnum { namespace Math { /** @brief %Dual quaternion +@tparam T Underlying data type @see Dual, Quaternion */ template class DualQuaternion: public Dual> { public: + typedef T Type; /**< @brief Underlying data type */ + /** * @brief Rotation dual quaternion * @param angle Rotation angle (counterclockwise, in radians) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index e76bbf8f2..5a181213d 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Math { /** @brief 3x3 matrix for transformations in 2D -@tparam T Data type +@tparam T Underlying data type Provides functions for transformations in 2D. See Matrix4 for 3D transformations. See also @ref matrix-vector for brief introduction. diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 6fa43559b..55234ba82 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Math { /** @brief 4x4 matrix for transformations in 3D -@tparam T Data type +@tparam T Underlying data type Provides functions for transformations in 3D. See Matrix3 for 2D transformations. See also @ref matrix-vector for brief introduction. diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 2b83b8d70..4e7cc1edf 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -32,11 +32,14 @@ namespace Magnum { namespace Math { /** @brief %Quaternion +@tparam T Underlying data type @see DualQuaternion, Magnum::Quaternion */ template class Quaternion { public: + typedef T Type; /**< @brief Underlying data type */ + /** * @brief Dot product * diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index f9df7752b..29189eab9 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -27,7 +27,7 @@ namespace Magnum { namespace Math { @brief Rectangular matrix @tparam cols Column count @tparam rows Row count -@tparam T Data type +@tparam T Underlying data type See @ref matrix-vector for brief introduction. See also Matrix (square) and Vector. @@ -42,7 +42,7 @@ template class RectangularMatrix { template friend class RectangularMatrix; public: - typedef T Type; /**< @brief Data type */ + typedef T Type; /**< @brief Underlying data type */ const static std::size_t Cols = cols; /**< @brief %Matrix column count */ const static std::size_t Rows = rows; /**< @brief %Matrix row count */ diff --git a/src/Math/Vector.h b/src/Math/Vector.h index f1c603a0d..843061517 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -35,7 +35,7 @@ namespace Magnum { namespace Math { /** @brief %Vector @tparam size %Vector size -@tparam T Data type +@tparam T Underlying data type See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Vector} @@ -46,7 +46,7 @@ template class Vector { template friend class Vector; public: - typedef T Type; /**< @brief Data type */ + typedef T Type; /**< @brief Underlying data type */ const static std::size_t Size = size; /**< @brief %Vector size */ /** From e94a596a8066012de4b6124207e8d9a1bf471a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 19 Feb 2013 20:45:44 +0100 Subject: [PATCH 369/567] Math: code cleanup, doc++ --- src/Math/DualQuaternion.h | 3 ++- src/Math/Matrix3.h | 5 ++--- src/Math/Matrix4.h | 7 +++---- src/Math/Quaternion.h | 11 ++++++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 88f55582e..5302ab46f 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -29,7 +29,8 @@ namespace Magnum { namespace Math { @brief %Dual quaternion @tparam T Underlying data type -@see Dual, Quaternion +Represents 3D rotation and translation. +@see Dual, Quaternion, Matrix4 */ template class DualQuaternion: public Dual> { public: diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 5a181213d..86862bc39 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -25,11 +25,10 @@ namespace Magnum { namespace Math { /** -@brief 3x3 matrix for transformations in 2D +@brief 3x3 matrix @tparam T Underlying data type -Provides functions for transformations in 2D. See Matrix4 for 3D -transformations. See also @ref matrix-vector for brief introduction. +Represents 2D transformation. See @ref matrix-vector for brief introduction. @see Magnum::Matrix3, SceneGraph::MatrixTransformation2D @configurationvalueref{Magnum::Math::Matrix3} */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 55234ba82..4db6c9c71 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -25,12 +25,11 @@ namespace Magnum { namespace Math { /** -@brief 4x4 matrix for transformations in 3D +@brief 4x4 matrix @tparam T Underlying data type -Provides functions for transformations in 3D. See Matrix3 for 2D -transformations. See also @ref matrix-vector for brief introduction. -@see Magnum::Matrix4, SceneGraph::MatrixTransformation3D +Represents 3D transformation. See @ref matrix-vector for brief introduction. +@see Magnum::Matrix4, DualQuaternion, SceneGraph::MatrixTransformation3D @configurationvalueref{Magnum::Math::Matrix4} */ template class Matrix4: public Matrix<4, T> { diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 4e7cc1edf..8f9a451be 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -34,7 +34,8 @@ namespace Magnum { namespace Math { @brief %Quaternion @tparam T Underlying data type -@see DualQuaternion, Magnum::Quaternion +Represents 3D rotation. +@see Magnum::Quaternion, DualQuaternion, Matrix4 */ template class Quaternion { public: @@ -238,7 +239,7 @@ template class Quaternion { * @see operator+=() */ inline Quaternion operator+(const Quaternion& other) const { - return Quaternion(*this)+=other; + return Quaternion(*this) += other; } /** @@ -271,7 +272,7 @@ template class Quaternion { * @see operator-=() */ inline Quaternion operator-(const Quaternion& other) const { - return Quaternion(*this)-=other; + return Quaternion(*this) -= other; } /** @@ -293,7 +294,7 @@ template class Quaternion { * @see operator*=(T) */ inline Quaternion operator*(T scalar) const { - return Quaternion(*this)*=scalar; + return Quaternion(*this) *= scalar; } /** @@ -315,7 +316,7 @@ template class Quaternion { * @see operator/=(T) */ inline Quaternion operator/(T scalar) const { - return Quaternion(*this)/=scalar; + return Quaternion(*this) /= scalar; } /** From 99be617278cfcc398dd2cae1f23dd90fe2dacbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 19 Feb 2013 21:07:24 +0100 Subject: [PATCH 370/567] Work-around preprocessor issues on Windows. I hate windows.h. --- src/Math/Matrix4.h | 5 +++++ src/SceneGraph/Camera3D.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 4db6c9c71..8799c05cd 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -22,6 +22,11 @@ #include "Matrix.h" #include "Point3D.h" +#ifdef WIN32 /* I so HATE windows.h */ +#undef near +#undef far +#endif + namespace Magnum { namespace Math { /** diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 4bd1cb309..91c8a6cd2 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -21,11 +21,6 @@ #include "AbstractCamera.h" -#ifdef WIN32 /* I so HATE windows.h */ -#undef near -#undef far -#endif - namespace Magnum { namespace SceneGraph { /** From 4e331cabbbf34979f59a5a02baa5f20046e299e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 19 Feb 2013 21:09:49 +0100 Subject: [PATCH 371/567] Fix linker issues on Windows. MagnumSceneGraphTestLib didn't have MagnumSceneGraph[Objects]_EXPORT defined, thus failing at link time, similar issue with MagnumMeshToolsTestLib. --- src/MeshTools/CMakeLists.txt | 2 +- src/SceneGraph/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index 4fb800958..5d6ecac9c 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -41,7 +41,7 @@ if(BUILD_TESTS) add_library(MagnumMeshToolsTestLib SHARED $ ${MagnumMeshTools_GracefulAssert_SRCS}) - set_target_properties(MagnumMeshToolsTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) + set_target_properties(MagnumMeshToolsTestLib PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT -DMagnumMeshTools_EXPORTS") target_link_libraries(MagnumMeshToolsTestLib Magnum) add_subdirectory(Test) diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 42d69ab81..906edde55 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -61,7 +61,7 @@ if(BUILD_TESTS) add_library(MagnumSceneGraphTestLib SHARED $ ${MagnumSceneGraph_GracefulAssert_SRCS}) - set_target_properties(MagnumSceneGraphTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) + set_target_properties(MagnumSceneGraphTestLib PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT -DMagnumSceneGraph_EXPORTS") target_link_libraries(MagnumSceneGraphTestLib Magnum) add_subdirectory(Test) From b32594c363e47b191049e6ea7e006f9e75db4d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 19 Feb 2013 21:11:29 +0100 Subject: [PATCH 372/567] Explicitly link MagnumMathTestLib to Corrade's Utility library. Would be linked later along TestSuite, but the linker complained now. --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b446f4e95..5fb41fd06 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -175,6 +175,9 @@ if(BUILD_TESTS) add_library(MagnumMathTestLib SHARED $) set_target_properties(MagnumMathTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) + if(WIN32) + target_link_libraries(MagnumMathTestLib ${CORRADE_UTILITY_LIBRARY}) + endif() add_library(MagnumTestLib SHARED $ From 687bd37b8165ba34317521e60101662eacb4d164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 19 Feb 2013 21:19:07 +0100 Subject: [PATCH 373/567] Math: initial complex number implementation. --- src/CMakeLists.txt | 1 + src/Math/CMakeLists.txt | 1 + src/Math/Complex.cpp | 27 +++++ src/Math/Complex.h | 218 ++++++++++++++++++++++++++++++++++ src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/ComplexTest.cpp | 129 ++++++++++++++++++++ 6 files changed, 377 insertions(+) create mode 100644 src/Math/Complex.cpp create mode 100644 src/Math/Complex.h create mode 100644 src/Math/Test/ComplexTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5fb41fd06..1fa36c4e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,6 +98,7 @@ add_library(MagnumObjects OBJECT ${Magnum_SRCS}) # Files shared between main library and math unit test library set(MagnumMath_SRCS + Math/Complex.cpp Math/DualQuaternion.cpp Math/Functions.cpp Math/Quaternion.cpp diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 4bcbf5743..1b7647b1c 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,5 +1,6 @@ set(MagnumMath_HEADERS BoolVector.h + Complex.h Constants.h Dual.h DualQuaternion.h diff --git a/src/Math/Complex.cpp b/src/Math/Complex.cpp new file mode 100644 index 000000000..0a6c5bd39 --- /dev/null +++ b/src/Math/Complex.cpp @@ -0,0 +1,27 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Complex.h" + +namespace Magnum { namespace Math { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Complex&); +#ifndef MAGNUM_TARGET_GLES +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Complex&); +#endif +#endif + +}} diff --git a/src/Math/Complex.h b/src/Math/Complex.h new file mode 100644 index 000000000..91630a9fd --- /dev/null +++ b/src/Math/Complex.h @@ -0,0 +1,218 @@ +#ifndef Magnum_Math_Complex_h +#define Magnum_Math_Complex_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Complex + */ + +#include + +#include "Math/MathTypeTraits.h" + +#include "magnumVisibility.h" + +namespace Magnum { namespace Math { + +/** +@brief %Complex number +@tparam T Data type + +Represents 2D rotation. +*/ +template class Complex { + public: + typedef T Type; /**< @brief Underlying data type */ + + /** + * @brief Default constructor + * + * @f[ + * c = 0 + i0 + * @f] + */ + inline constexpr /*implicit*/ Complex(): _real(T(0)), _imaginary(T(0)) {} + + /** + * @brief Construct complex from real and imaginary part + * + * @f[ + * c = a + ib + * @f] + */ + inline constexpr /*implicit*/ Complex(T real, T imaginary = T(0)): _real(real), _imaginary(imaginary) {} + + /** @brief Equality comparison */ + inline bool operator==(const Complex& other) const { + return MathTypeTraits::equals(_real, other._real) && + MathTypeTraits::equals(_imaginary, other._imaginary); + } + + /** @brief Non-equality comparison */ + inline bool operator!=(const Complex& other) const { + return !operator==(other); + } + + /** @brief Real part */ + inline constexpr T real() const { return _real; } + + /** @brief Imaginary part */ + inline constexpr T imaginary() const { return _imaginary; } + + /** + * @brief Add and assign complex + * + * The computation is done in-place. @f[ + * c_0 + c_1 = a_0 + a_1 + i(b_0 + b_1) + * @f] + */ + inline Complex& operator+=(const Complex& other) { + _real += other._real; + _imaginary += other._imaginary; + return *this; + } + + /** + * @brief Add complex + * + * @see operator+=() + */ + inline Complex operator+(const Complex& other) const { + return Complex(*this) += other; + } + + /** + * @brief Negated complex + * + * @f[ + * -c = -a -ib + * @f] + */ + inline Complex operator-() const { + return {-_real, -_imaginary}; + } + + /** + * @brief Subtract and assign complex + * + * The computation is done in-place. @f[ + * c_0 - c_1 = a_0 - a_1 + i(b_0 - b_1) + * @f] + */ + inline Complex& operator-=(const Complex& other) { + _real -= other._real; + _imaginary -= other._imaginary; + return *this; + } + + /** + * @brief Subtract complex + * + * @see operator-=() + */ + inline Complex operator-(const Complex& other) const { + return Complex(*this) -= other; + } + + /** + * @brief Multiply with scalar and assign + * + * The computation is done in-place. @f[ + * c \cdot t = ta + itb + * @f] + */ + inline Complex& operator*=(T scalar) { + _real *= scalar; + _imaginary *= scalar; + return *this; + } + + /** + * @brief Multiply with scalar + * + * @see operator*=(T) + */ + inline Complex operator*(T scalar) const { + return Complex(*this) *= scalar; + } + + /** + * @brief Divide with scalar and assign + * + * The computation is done in-place. @f[ + * \frac c t = \frac a t + i \frac b t + * @f] + */ + inline Complex& operator/=(T scalar) { + _real /= scalar; + _imaginary /= scalar; + return *this; + } + + /** + * @brief Divide with scalar + * + * @see operator/=(T) + */ + inline Complex operator/(T scalar) const { + return Complex(*this) /= scalar; + } + + private: + T _real, _imaginary; +}; + +/** @relates Complex +@brief Multiply scalar with complex + +Same as Complex::operator*(T) const. +*/ +template inline Complex operator*(T scalar, const Complex& complex) { + return complex*scalar; +} + +/** @relates Complex +@brief Divide complex with number and invert + +@f[ + \frac t c = \frac t a + i \frac t b +@f] +@see Complex::operator/() +*/ +template inline Complex operator/(T scalar, const Complex& complex) { + return {scalar/complex.real(), scalar/complex.imaginary()}; +} + +/** @debugoperator{Magnum::Math::Complex} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Complex& value) { + debug << "Complex("; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << value.real() << ", " << value.imaginary() << ")"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/* Explicit instantiation for commonly used types */ +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Complex&); +#ifndef MAGNUM_TARGET_GLES +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Complex&); +#endif +#endif + +}} + +#endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 1f70c8dcb..22b5ff493 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -17,6 +17,7 @@ corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualTest DualTest.cpp) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp new file mode 100644 index 000000000..f4c352252 --- /dev/null +++ b/src/Math/Test/ComplexTest.cpp @@ -0,0 +1,129 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/Complex.h" + +namespace Magnum { namespace Math { namespace Test { + +class ComplexTest: public Corrade::TestSuite::Tester { + public: + explicit ComplexTest(); + + void construct(); + void constructDefault(); + void compare(); + + void constExpressions(); + + void addSubtract(); + void negated(); + void multiplyDivideScalar(); + + void debug(); +}; + +ComplexTest::ComplexTest() { + addTests(&ComplexTest::construct, + &ComplexTest::constructDefault, + &ComplexTest::compare, + + &ComplexTest::constExpressions, + + &ComplexTest::addSubtract, + &ComplexTest::negated, + &ComplexTest::multiplyDivideScalar, + + &ComplexTest::debug); +} + +typedef Math::Complex Complex; + +void ComplexTest::construct() { + Complex c(0.5f, -3.7f); + CORRADE_COMPARE(c.real(), 0.5f); + CORRADE_COMPARE(c.imaginary(), -3.7f); + + CORRADE_COMPARE(Complex(2.0f), Complex(2.0f, 0.0f)); +} + +void ComplexTest::constructDefault() { + CORRADE_COMPARE(Complex(), Complex(0.0f, 0.0f)); +} + +void ComplexTest::compare() { + CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); +} + +void ComplexTest::constExpressions() { + /* Default constructor */ + constexpr Complex a; + CORRADE_COMPARE(a, Complex(0.0f, 0.0f)); + + /* Value constructor */ + constexpr Complex b(2.5f, -5.0f); + CORRADE_COMPARE(b, Complex(2.5f, -5.0f)); + + /* Copy constructor */ + constexpr Complex c(b); + CORRADE_COMPARE(c, Complex(2.5f, -5.0f)); + + /* Data access */ + constexpr float d = b.real(); + constexpr float e = c.imaginary(); + CORRADE_COMPARE(d, 2.5f); + CORRADE_COMPARE(e, -5.0f); +} + +void ComplexTest::addSubtract() { + Complex a( 1.7f, -3.7f); + Complex b(-3.6f, 0.2f); + Complex c(-1.9f, -3.5f); + + CORRADE_COMPARE(a + b, c); + CORRADE_COMPARE(c - b, a); +} + +void ComplexTest::negated() { + CORRADE_COMPARE(-Complex(2.5f, -7.4f), Complex(-2.5f, 7.4f)); +} + +void ComplexTest::multiplyDivideScalar() { + Complex a( 2.5f, -0.5f); + Complex b(-7.5f, 1.5f); + + CORRADE_COMPARE(a*-3.0f, b); + CORRADE_COMPARE(-3.0f*a, b); + CORRADE_COMPARE(b/-3.0f, a); + + Complex c(-0.8f, 4.0f); + CORRADE_COMPARE(-2.0f/a, c); +} + +void ComplexTest::debug() { + std::ostringstream o; + + Debug(&o) << Complex(2.5f, -7.5f); + CORRADE_COMPARE(o.str(), "Complex(2.5, -7.5)\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::ComplexTest) From f1e3453517457e580c4dce4d16d6d66ce34fb5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 17:26:57 +0100 Subject: [PATCH 374/567] Math: base class for units. --- src/Math/CMakeLists.txt | 1 + src/Math/Math.h | 2 + src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/UnitTest.cpp | 138 ++++++++++++++++++++++++++++++++ src/Math/Unit.h | 147 +++++++++++++++++++++++++++++++++++ 5 files changed, 289 insertions(+) create mode 100644 src/Math/Test/UnitTest.cpp create mode 100644 src/Math/Unit.h diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 1b7647b1c..813349648 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -15,6 +15,7 @@ set(MagnumMath_HEADERS Quaternion.h RectangularMatrix.h Swizzle.h + Unit.h Vector.h Vector2.h Vector3.h diff --git a/src/Math/Math.h b/src/Math/Math.h index 6259f89c2..88557f8d1 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -41,6 +41,8 @@ template class Quaternion; template class RectangularMatrix; +template class, class> class Unit; + template class Vector; template class Vector2; template class Vector3; diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 22b5ff493..e6bee9a10 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -16,6 +16,7 @@ corrade_add_test(MathMatrix3Test Matrix3Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathUnitTest UnitTest.cpp) corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualTest DualTest.cpp) diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp new file mode 100644 index 000000000..a0a57978b --- /dev/null +++ b/src/Math/Test/UnitTest.cpp @@ -0,0 +1,138 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Unit.h" + +namespace Magnum { namespace Math { namespace Test { + +class UnitTest: public Corrade::TestSuite::Tester { + public: + explicit UnitTest(); + + void construct(); + void constructDefault(); + void constructConversion(); + void compare(); + + void negated(); + void addSubtract(); + void multiplyDivide(); +}; + +UnitTest::UnitTest() { + addTests(&UnitTest::construct, + &UnitTest::constructDefault, + &UnitTest::constructConversion, + &UnitTest::compare, + + &UnitTest::negated, + &UnitTest::addSubtract, + &UnitTest::multiplyDivide); +} + +template struct Sec_; +typedef Unit Sec; +typedef Unit Secd; + +inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, Sec value) { + return debug << float(value); +} + +void UnitTest::construct() { + constexpr Sec a(25.0f); + CORRADE_COMPARE(float(a), 25.0f); +} + +void UnitTest::constructDefault() { + constexpr Sec b; + CORRADE_COMPARE(b, Sec(0.0f)); +} + +void UnitTest::constructConversion() { + constexpr Secd a(25.0); + constexpr Sec b(a); + CORRADE_COMPARE(b, Sec(25.0f)); +} + +void UnitTest::compare() { + CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()/2) == Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()*2) != Sec(25.0f)); + + constexpr bool c = Sec(3.0f) < Sec(3.0f); + constexpr bool d = Sec(3.0f) <= Sec(3.0f); + constexpr bool e = Sec(3.0f) >= Sec(3.0f); + constexpr bool f = Sec(3.0f) > Sec(3.0f); + CORRADE_VERIFY(!c); + CORRADE_VERIFY(d); + CORRADE_VERIFY(e); + CORRADE_VERIFY(!f); + + constexpr bool h = Sec(2.0f) < Sec(3.0f); + constexpr bool i = Sec(2.0f) <= Sec(3.0f); + constexpr bool j = Sec(3.0f) >= Sec(2.0f); + constexpr bool k = Sec(3.0f) > Sec(2.0f); + CORRADE_VERIFY(h); + CORRADE_VERIFY(i); + CORRADE_VERIFY(j); + CORRADE_VERIFY(k); + + constexpr bool l = Sec(3.0f) < Sec(2.0f); + constexpr bool m = Sec(3.0f) <= Sec(2.0f); + constexpr bool n = Sec(2.0f) >= Sec(3.0f); + constexpr bool o = Sec(2.0f) > Sec(3.0f); + CORRADE_VERIFY(!l); + CORRADE_VERIFY(!m); + CORRADE_VERIFY(!n); + CORRADE_VERIFY(!o); +} + +void UnitTest::negated() { + constexpr Sec a(25.0f); + constexpr Sec b(-a); + CORRADE_COMPARE(b, Sec(-25.0f)); +} + +void UnitTest::addSubtract() { + constexpr Sec a(3.0f); + constexpr Sec b(-4.0f); + constexpr Sec c(-1.0f); + + constexpr Sec d = a + b; + constexpr Sec e = c - a; + CORRADE_COMPARE(d, c); + CORRADE_COMPARE(e, b); +} + +void UnitTest::multiplyDivide() { + constexpr Sec a(3.0f); + constexpr Sec b(-4.5f); + constexpr Sec c(5.0f); + + constexpr Sec d = a*-1.5f; + constexpr Sec e = -1.5f*a; + constexpr Sec f = b/-1.5f; + CORRADE_COMPARE(d, b); + CORRADE_COMPARE(e, b); + CORRADE_COMPARE(f, a); + + constexpr float g = b/a; + CORRADE_COMPARE(g, -1.5f); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::UnitTest) diff --git a/src/Math/Unit.h b/src/Math/Unit.h new file mode 100644 index 000000000..5d2d0ecc3 --- /dev/null +++ b/src/Math/Unit.h @@ -0,0 +1,147 @@ +#ifndef Magnum_Math_Unit_h +#define Magnum_Math_Unit_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Unit + */ + +#include "Math/MathTypeTraits.h" + +namespace Magnum { namespace Math { + +/** +@brief Base class for units +@tparam T Underlying data type + +@see Deg, Rad +*/ +template class Derived, class T> class Unit { + template class, class> friend class Unit; + + public: + typedef T Type; /**< @brief Underlying data type */ + + /** @brief Default constructor */ + inline constexpr /*implicit*/ Unit(): value(T(0)) {} + + /** @brief Explicit conversion from unitless type */ + inline constexpr explicit Unit(T value): value(value) {} + + /** @brief Construct from another underlying type */ + template inline constexpr explicit Unit(Unit value): value(value.value) {} + + /** @brief Explicit conversion to underlying type */ + inline constexpr explicit operator T() const { return value; } + + /** @brief Equality comparison */ + inline constexpr bool operator==(Unit other) const { + return MathTypeTraits::equals(value, other.value); + } + + /** @brief Non-equality comparison */ + inline constexpr bool operator!=(Unit other) const { + return !operator==(other); + } + + /** @brief Less than comparison */ + inline constexpr bool operator<(Unit other) const { + return value < other.value; + } + + /** @brief Greater than comparison */ + inline constexpr bool operator>(Unit other) const { + return value > other.value; + } + + /** @brief Less than or equal comparison */ + inline constexpr bool operator<=(Unit other) const { + return !operator>(other); + } + + /** @brief Greater than or equal comparison */ + inline constexpr bool operator>=(Unit other) const { + return !operator<(other); + } + + /** @brief Negated value */ + inline constexpr Unit operator-() const { + return Unit(-value); + } + + /** @brief Add and assign value */ + inline Unit& operator+=(Unit other) { + value += other.value; + return *this; + } + + /** @brief Add value */ + inline constexpr Unit operator+(Unit other) const { + return Unit(value + other.value); + } + + /** @brief Subtract and assign value */ + inline Unit& operator-=(Unit other) { + value -= other.value; + return *this; + } + + /** @brief Subtract value */ + inline constexpr Unit operator-(Unit other) const { + return Unit(value - other.value); + } + + /** @brief Multiply with number and assign */ + inline Unit& operator*=(T number) { + value *= number; + return *this; + } + + /** @brief Multiply with number */ + inline constexpr Unit operator*(T number) const { + return Unit(value*number); + } + + /** @brief Divide with number and assign */ + inline Unit& operator/=(T number) { + value /= number; + return *this; + } + + /** @brief Divide with number */ + inline constexpr Unit operator/(T number) const { + return Unit(value/number); + } + + /** @brief Ratio of two values */ + inline constexpr T operator/(Unit other) const { + return value/other.value; + } + + private: + T value; +}; + +/** @relates Unit +@brief Multiply number with value +*/ +template class Derived, class T> inline constexpr Unit operator*(typename std::common_type::type number, const Unit& value) { + return value*number; +} + +}} + +#endif From ff929c04e94588f046382901ada6b5842dfc3bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 18:20:01 +0100 Subject: [PATCH 375/567] Math: type-safe implementation for degrees and radians. Next few commits will add requirement for "strongly typed" angles in all function parameters, e.g.: Matrix3::rotation(24.0_degf); Math::sin(1.047_radf); The purpose is to make angle entering less error-prone, e.g. not passing degrees when radians should be etc. --- src/CMakeLists.txt | 1 + src/Math/Angle.cpp | 29 ++++ src/Math/Angle.h | 248 +++++++++++++++++++++++++++++++++++ src/Math/CMakeLists.txt | 1 + src/Math/Math.h | 2 + src/Math/Test/AngleTest.cpp | 115 ++++++++++++++++ src/Math/Test/CMakeLists.txt | 1 + 7 files changed, 397 insertions(+) create mode 100644 src/Math/Angle.cpp create mode 100644 src/Math/Angle.h create mode 100644 src/Math/Test/AngleTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1fa36c4e0..788f83301 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,6 +98,7 @@ add_library(MagnumObjects OBJECT ${Magnum_SRCS}) # Files shared between main library and math unit test library set(MagnumMath_SRCS + Math/Angle.cpp Math/Complex.cpp Math/DualQuaternion.cpp Math/Functions.cpp diff --git a/src/Math/Angle.cpp b/src/Math/Angle.cpp new file mode 100644 index 000000000..73f128ac1 --- /dev/null +++ b/src/Math/Angle.cpp @@ -0,0 +1,29 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Angle.h" + +namespace Magnum { namespace Math { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Rad&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Deg&); +#ifndef MAGNUM_TARGET_GLES +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Rad&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Deg&); +#endif +#endif + +}} diff --git a/src/Math/Angle.h b/src/Math/Angle.h new file mode 100644 index 000000000..d579c1b39 --- /dev/null +++ b/src/Math/Angle.h @@ -0,0 +1,248 @@ +#ifndef Magnum_Math_Angle_h +#define Magnum_Math_Angle_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::Deg, Magnum::Math::Rad and related operators. + */ + +#include + +#include "Math/Constants.h" +#include "Math/Math.h" +#include "Math/Unit.h" + +#include "magnumVisibility.h" + +namespace Magnum { namespace Math { + +/** +@brief Angle in degrees + +Along with Rad provides convenience classes to make angle specification and +conversion less error-prone. + +@section Rad-usage Usage + +You can enter the value either by using literal: +@code +auto degrees = 60.0_degf; // type is Deg +auto radians = 1.047_rad; // type is Rad +@endcode + +Or explicitly convert unitless value (such as output from some function) to +either degrees or radians: +@code +double foo(); + +Deg degrees(35.0f); +Rad radians(foo()); +//degrees = 60.0f; // error, no implicit conversion +@endcode + +The classes support all arithmetic operations, such as addition, subtraction +or multiplication/division by unitless number: +@code +auto a = 60.0_degf + 17.35_degf; +auto b = -a + 23.0_degf*4; +//auto c = 60.0_degf*45.0_degf; // error, undefined resulting unit +@endcode + +It is also possible to compare angles with all comparison operators, but +comparison of degrees and radians is not possible without explicit conversion +to common type: +@code +Rad angle(); + +Deg x = angle(); // convert to degrees for easier comparison +if(x < 30.0_degf) foo(); +//if(x > 1.57_radf) bar(); // error, both need to be of the same type +@endcode + +It is possible to seamlessly convert between degrees and radians and explicitly +convert the value back to underlying type: +@code +float sine(Rad angle); +float a = sine(60.0_degf); // the same as sine(1.047_radf) +Deg b = 1.047_rad; // the same as 60.0_deg +float d = double(b); // 60.0 +//float e = b; // error, no implicit conversion +@endcode + +@section Rad-conversions Requirement of explicit conversion + +The requirement of explicit conversions from and to unitless types helps to +reduce unit-based errors. Consider following example with implicit conversions +allowed: +@code +float std::sin(float angle); +float sine(Rad angle); + +float a = 60.0f; // degrees +sine(a); // silent error, sine() expected radians + +auto b = 60.0_degf; // degrees +std::sin(b); // silent error, std::sin() expected radians +@endcode + +These silent errors are easily avoided by requiring explicit conversions: +@code +//sine(angleInDegrees); // compilation error +sine(Deg(angleInDegrees)); // explicitly specifying unit + +//std::sin(angleInDegrees); // compilation error +std::sin(float(Rad(angleInDegrees)); // required explicit conversion hints + // to user that this case needs special + // attention (i.e., conversion to radians) +@endcode +*/ +template class Deg: public Unit { + public: + /** @brief Default constructor */ + inline constexpr /*implicit*/ Deg() {} + + /** @brief Explicit constructor from unitless type */ + inline constexpr explicit Deg(T value): Unit(value) {} + + /** @brief Copy constructor */ + inline constexpr /*implicit*/ Deg(Unit value): Unit(value) {} + + /** @brief Construct from another underlying type */ + template inline constexpr explicit Deg(Unit value): Unit(value) {} + + /** + * @brief Construct degrees from radians + * + * Performs conversion from radians to degrees, i.e.: + * @f[ + * deg = 180 \frac {rad} \pi + * @f] + */ + inline constexpr /*implicit*/ Deg(Unit value); +}; + +#ifndef CORRADE_GCC46_COMPATIBILITY +/** @relates Deg +@brief Double-precision degree value literal + +Example usage: +@code +double cosine = Math::cos(60.0_deg); // cosine = 0.5 +double cosine = Math::cos(1.047_rad); // cosine = 0.5 +@endcode +@see operator""_degf(), operator""_rad() +@note Not available on GCC < 4.7. Use Deg::Deg(T) instead. +*/ +inline constexpr Deg operator "" _deg(long double value) { return Deg(value); } + +/** @relates Deg +@brief Single-precision degree value literal + +Example usage: +@code +float tangent = Math::tan(60.0_degf); // tangent = 1.732f +float tangent = Math::tan(1.047_radf); // tangent = 1.732f +@endcode +@see operator""_deg(), operator""_radf() +@note Not available on GCC < 4.7. Use Deg::Deg(T) instead. +*/ +inline constexpr Deg operator "" _degf(long double value) { return Deg(value); } +#endif + +/** +@brief Angle in radians + +See Deg for more information. +*/ +template class Rad: public Unit { + public: + /** @brief Default constructor */ + inline constexpr /*implicit*/ Rad() {} + + /** @brief Construct from unitless type */ + inline constexpr explicit Rad(T value): Unit(value) {} + + /** @brief Copy constructor */ + inline constexpr /*implicit*/ Rad(Unit value): Unit(value) {} + + /** @brief Construct from another underlying type */ + template inline constexpr explicit Rad(Unit value): Unit(value) {} + + /** + * @brief Construct radians from degrees + * + * Performs conversion from degrees to radians, i.e.: + * @f[ + * rad = deg \frac \pi 180 + * @f] + */ + inline constexpr /*implicit*/ Rad(Unit value); +}; + +#ifndef CORRADE_GCC46_COMPATIBILITY +/** @relates Rad +@brief Double-precision radian value literal + +See operator""_rad() for more information. +@see operator""_radf(), operator""_deg() +@note Not available on GCC < 4.7. Use Rad::Rad(T) instead. +*/ +inline constexpr Rad operator "" _rad(long double value) { return Rad(value); } + +/** @relates Rad +@brief Single-precision radian value literal + +See operator""_degf() for more information. +@see operator""_rad(), operator""_degf() +@note Not available on GCC < 4.7. Use Rad::Rad(T) instead. +*/ +inline constexpr Rad operator "" _radf(long double value) { return Rad(value); } +#endif + +template inline constexpr Deg::Deg(Unit value): Unit(T(180)*T(value)/Math::Constants::pi()) {} +template inline constexpr Rad::Rad(Unit value): Unit(T(value)*Math::Constants::pi()/T(180)) {} + +/** @debugoperator{Magnum::Math::Rad} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Rad& value) { + debug << "Rad("; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << T(value) << ")"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/** @debugoperator{Magnum::Math::Deg} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Deg& value) { + debug << "Deg("; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << T(value) << ")"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/* Explicit instantiation for commonly used types */ +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Rad&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Deg&); +#ifndef MAGNUM_TARGET_GLES +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Rad&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Deg&); +#endif +#endif + +}} + +#endif diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 813349648..e6d909a0c 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,4 +1,5 @@ set(MagnumMath_HEADERS + Angle.h BoolVector.h Complex.h Constants.h diff --git a/src/Math/Math.h b/src/Math/Math.h index 88557f8d1..31feb02b3 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -42,6 +42,8 @@ template class Quaternion; template class RectangularMatrix; template class, class> class Unit; +template class Deg; +template class Rad; template class Vector; template class Vector2; diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp new file mode 100644 index 000000000..dae6cef93 --- /dev/null +++ b/src/Math/Test/AngleTest.cpp @@ -0,0 +1,115 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/Angle.h" + +namespace Magnum { namespace Math { namespace Test { + +class AngleTest: public Corrade::TestSuite::Tester { + public: + explicit AngleTest(); + + void construct(); + void literals(); + void conversion(); + + void debugDeg(); + void debugRad(); +}; + +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Deg Degd; +typedef Math::Rad Radd; + +AngleTest::AngleTest() { + addTests(&AngleTest::construct, + &AngleTest::literals, + &AngleTest::conversion, + + &AngleTest::debugDeg, + &AngleTest::debugRad); +} + +void AngleTest::construct() { + /* Default constructor */ + constexpr Degd a; + constexpr Deg m; + CORRADE_COMPARE(double(a), 0.0f); + CORRADE_COMPARE(float(m), 0.0f); + + /* Value constructor */ + constexpr Deg b(25.0); + constexpr Radd n(3.14); + CORRADE_COMPARE(float(b), 25.0); + CORRADE_COMPARE(double(n), 3.14); + + /* Copy constructor */ + constexpr Deg c(b); + constexpr Radd o(n); + CORRADE_COMPARE(c, b); + CORRADE_COMPARE(o, n); + + /* Conversion operator */ + constexpr Degd d(b); + constexpr Rad p(n); + CORRADE_COMPARE(double(d), 25.0); + CORRADE_COMPARE(float(p), 3.14f); +} + +void AngleTest::literals() { + 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); + CORRADE_COMPARE(float(b), 25.0f); + + 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); + CORRADE_COMPARE(float(n), 3.14f); +} + +void AngleTest::conversion() { + constexpr Deg a(Rad(1.57079633f)); + CORRADE_COMPARE(float(a), 90.0f); + + constexpr Rad b(Deg(90.0)); + CORRADE_COMPARE(float(b), 1.57079633f); +} + +void AngleTest::debugDeg() { + std::ostringstream o; + + Debug(&o) << Deg(90.0); + CORRADE_COMPARE(o.str(), "Deg(90)\n"); +} + +void AngleTest::debugRad() { + std::ostringstream o; + + Debug(&o) << Rad(1.5708); + CORRADE_COMPARE(o.str(), "Rad(1.5708)\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::AngleTest) diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index e6bee9a10..c76ea26fb 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -17,6 +17,7 @@ corrade_add_test(MathMatrix4Test Matrix4Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathUnitTest UnitTest.cpp) +corrade_add_test(MathAngleTest AngleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualTest DualTest.cpp) From a3924c91763c80c19ce9f49aad36ba78c42d485f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 20:51:58 +0100 Subject: [PATCH 376/567] Brought Math::Deg/Rad and related operators to Magnum namespace. --- src/Magnum.h | 17 +++++++++++++++++ src/Math/Angle.h | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Magnum.h b/src/Magnum.h index 440d57a67..2fb91a908 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -54,6 +54,11 @@ namespace Math { template constexpr T deg(T value); template constexpr T rad(T value); template struct Constants; + + constexpr Rad operator "" _rad(long double); + constexpr Rad operator "" _radf(long double); + constexpr Deg operator "" _deg(long double); + constexpr Deg operator "" _degf(long double); } /* Bring debugging facility from Corrade::Utility namespace */ @@ -108,6 +113,12 @@ typedef Math::Quaternion Quaternion; /* Using float instead of GLfloat to not break KDevelop autocompletion */ typedef Math::Constants Constants; +/** @brief Angle in single-precision degrees */ +typedef Math::Deg Deg; + +/** @brief Angle in single-precision radians */ +typedef Math::Rad Rad; + /** @brief Floating-point rectangle */ typedef Math::Geometry::Rectangle Rectangle; @@ -118,6 +129,12 @@ typedef Math::Geometry::Rectangle Rectanglei; using Math::deg; using Math::rad; +/* Using angle literals from Math namespace */ +using Math::operator "" _deg; +using Math::operator "" _degf; +using Math::operator "" _rad; +using Math::operator "" _radf; + /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT /* Forward declarations for all types in root namespace */ diff --git a/src/Math/Angle.h b/src/Math/Angle.h index d579c1b39..c1b136b8c 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -108,6 +108,8 @@ std::sin(float(Rad(angleInDegrees)); // required explicit conversion hint // to user that this case needs special // attention (i.e., conversion to radians) @endcode + +@see Magnum::Deg, Magnum::Rad */ template class Deg: public Unit { public: @@ -143,7 +145,7 @@ Example usage: double cosine = Math::cos(60.0_deg); // cosine = 0.5 double cosine = Math::cos(1.047_rad); // cosine = 0.5 @endcode -@see operator""_degf(), operator""_rad() +@see Magnum::operator""_deg(), operator""_degf(), operator""_rad() @note Not available on GCC < 4.7. Use Deg::Deg(T) instead. */ inline constexpr Deg operator "" _deg(long double value) { return Deg(value); } @@ -156,7 +158,7 @@ Example usage: float tangent = Math::tan(60.0_degf); // tangent = 1.732f float tangent = Math::tan(1.047_radf); // tangent = 1.732f @endcode -@see operator""_deg(), operator""_radf() +@see Magnum::operator""_degf(), operator""_deg(), operator""_radf() @note Not available on GCC < 4.7. Use Deg::Deg(T) instead. */ inline constexpr Deg operator "" _degf(long double value) { return Deg(value); } @@ -166,6 +168,7 @@ inline constexpr Deg operator "" _degf(long double value) { return Deg class Rad: public Unit { public: @@ -197,7 +200,7 @@ template class Rad: public Unit { @brief Double-precision radian value literal See operator""_rad() for more information. -@see operator""_radf(), operator""_deg() +@see Magnum::operator""_rad(), operator""_radf(), operator""_deg() @note Not available on GCC < 4.7. Use Rad::Rad(T) instead. */ inline constexpr Rad operator "" _rad(long double value) { return Rad(value); } @@ -206,7 +209,7 @@ inline constexpr Rad operator "" _rad(long double value) { return Rad operator "" _radf(long double value) { return Rad(value); } From 1d4025467678c1cc5fb3ef40fb0a3c0da4e7836d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 20:59:10 +0100 Subject: [PATCH 377/567] Math: use Rad for Vector::angle(). --- src/Math/Test/VectorTest.cpp | 14 ++++++++------ src/Math/Vector.h | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 9035fdaeb..8772c487b 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -63,6 +63,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void configuration(); }; +typedef Math::Rad Rad; typedef Vector<3, float> Vector3; typedef Vector<4, float> Vector4; typedef Vector<4, std::int32_t> Vector4i; @@ -305,17 +306,18 @@ void VectorTest::projectedOntoNormalized() { void VectorTest::angle() { std::ostringstream o; Error::setOutput(&o); - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), - std::numeric_limits::quiet_NaN()); + auto angle = Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}); + CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); o.str(""); - CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), - std::numeric_limits::quiet_NaN()); + angle = Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()); + CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), Vector3(1.0f, -2.0f, 3.0f).normalized()), - rad(1.162514f)); + CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), + Vector3(1.0f, -2.0f, 3.0f).normalized()), + Rad(1.162514f)); } void VectorTest::debug() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 843061517..d8debb235 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -25,6 +25,7 @@ #include #include +#include "Math/Angle.h" #include "Math/BoolVector.h" #include "Math/MathTypeTraits.h" @@ -78,16 +79,16 @@ template class Vector { } /** - * @brief Angle between normalized vectors (in radians) + * @brief Angle between normalized vectors * * Expects that both vectors are normalized. @f[ * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| \cdot |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) * @f] */ - inline static T angle(const Vector& normalizedA, const Vector& normalizedB) { + inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), - "Math::Vector::angle(): vectors must be normalized", std::numeric_limits::quiet_NaN()); - return std::acos(dot(normalizedA, normalizedB)); + "Math::Vector::angle(): vectors must be normalized", Rad(std::numeric_limits::quiet_NaN())); + return Rad(std::acos(dot(normalizedA, normalizedB))); } /** From 830ce69da07e968e0534f324ae72e92898fc3a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 21:06:09 +0100 Subject: [PATCH 378/567] Math: using Rad in Matrix*::rotation*(). Also updated dependent functions and tests. --- doc/matrix-vector.dox | 4 +- doc/scenegraph.dox | 2 +- src/Math/Matrix3.h | 11 ++- src/Math/Matrix4.h | 51 ++++++------ src/Math/Test/Matrix3Test.cpp | 11 +-- src/Math/Test/Matrix4Test.cpp | 26 ++++--- src/Math/Vector3.h | 2 +- src/Physics/Test/CapsuleTest.cpp | 2 +- src/Physics/Test/LineTest.cpp | 2 +- src/Physics/Test/PlaneTest.cpp | 2 +- src/Physics/Test/SphereTest.cpp | 2 +- .../AbstractTranslationRotation2D.h | 6 +- .../AbstractTranslationRotation3D.h | 22 +++--- src/SceneGraph/Animable.h | 2 +- src/SceneGraph/Drawable.h | 2 +- .../EuclideanMatrixTransformation2D.h | 8 +- .../EuclideanMatrixTransformation3D.h | 39 ++++++---- src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/MatrixTransformation3D.h | 17 ++-- src/SceneGraph/Test/CameraTest.cpp | 2 +- .../EuclideanMatrixTransformation2DTest.cpp | 40 +++++----- .../EuclideanMatrixTransformation3DTest.cpp | 64 +++++++-------- .../Test/MatrixTransformation2DTest.cpp | 54 ++++++------- .../Test/MatrixTransformation3DTest.cpp | 78 +++++++++---------- src/SceneGraph/Test/ObjectTest.cpp | 36 ++++----- 25 files changed, 245 insertions(+), 242 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 5f5afec45..115e13991 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -74,7 +74,7 @@ Vectors are commonly used to specify various axes and scaling coefficients in transformations, you can use convenience functions instead of typing out all other elements: @code -Matrix4::rotation(deg(5.0f), Vector3::xAxis()); // {1.0f, 0.0f, 0.0f} +Matrix4::rotation(5.0_degf, Vector3::xAxis()); // {1.0f, 0.0f, 0.0f} Matrix3::translation(Vector2::yAxis(2.0f)); // {0.0f, 2.0f} Matrix4::scaling(Vector3::zScale(-10.0f)); // {1.0f, 1.0f, -10.0f} @endcode @@ -144,7 +144,7 @@ transformation: Matrix4 a = Matrix4::translation(Vector3::yAxis(4.0f)); Vector3 translation = a.translation(); -Matrix3 b = Matrix3::rotation(deg(15.f)); +Matrix3 b = Matrix3::rotation(15.0_degf)); Matrix<2, float> rotationScaling = b.rotationScaling(); Vector2 up = b.up(); @endcode diff --git a/doc/scenegraph.dox b/doc/scenegraph.dox index 4c478397b..28fec624d 100644 --- a/doc/scenegraph.dox +++ b/doc/scenegraph.dox @@ -88,7 +88,7 @@ transformation. For convenience you can use method chaining: Object3D* next = new Object3D; next->setParent(another) ->translate(Vector3::yAxis(3.0f)) - ->rotateY(deg(35.0f)); + ->rotateY(35.0_degf); @endcode @section scenegraph-features Object features diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 86862bc39..a67efd47f 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -62,14 +62,13 @@ template class Matrix3: public Matrix<3, T> { /** * @brief 2D rotation matrix - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * - * @see rotation() const, Matrix4::rotation(T, const Vector3&), deg(), - * rad() + * @see rotation() const, Matrix4::rotation(Rad, const Vector3&) */ - static Matrix3 rotation(T angle) { - T sine = std::sin(angle); - T cosine = std::cos(angle); + static Matrix3 rotation(Rad angle) { + T sine = std::sin(T(angle)); + T cosine = std::cos(T(angle)); return {{ cosine, sine, T(0)}, { -sine, cosine, T(0)}, diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 8799c05cd..c72dc52a9 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -70,21 +70,21 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D rotation around arbitrary axis - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * * Expects that the rotation axis is normalized. If possible, use * faster alternatives like rotationX(), rotationY() and rotationZ(). * @see rotation() const, DualQuaternion::rotation(), - * Quaternion::rotation(), Matrix3::rotation(T), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis(), deg(), rad() + * Quaternion::rotation(), Matrix3::rotation(Rad), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis() */ - static Matrix4 rotation(T angle, const Vector3& normalizedAxis) { + static Matrix4 rotation(Rad angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), "Math::Matrix4::rotation(): axis must be normalized", {}); - T sine = std::sin(angle); - T cosine = std::cos(angle); + T sine = std::sin(T(angle)); + T cosine = std::cos(T(angle)); T oneMinusCosine = T(1) - cosine; T xx = normalizedAxis.x()*normalizedAxis.x(); @@ -113,16 +113,15 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D rotation around X axis - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * * Faster than calling `Matrix4::rotation(angle, Vector3::xAxis())`. - * @see rotation(T, const Vector3&), rotationY(), rotationZ(), - * rotation() const, Quaternion::rotation(), Matrix3::rotation(T), - * deg(), rad() + * @see rotation(Rad, const Vector3&), rotationY(), rotationZ(), + * rotation() const, Quaternion::rotation(), Matrix3::rotation(Rad) */ - static Matrix4 rotationX(T angle) { - T sine = std::sin(angle); - T cosine = std::cos(angle); + static Matrix4 rotationX(Rad angle) { + T sine = std::sin(T(angle)); + T cosine = std::cos(T(angle)); return {{T(1), T(0), T(0), T(0)}, {T(0), cosine, sine, T(0)}, @@ -132,16 +131,15 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D rotation around Y axis - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * * Faster than calling `Matrix4::rotation(angle, Vector3::yAxis())`. - * @see rotation(T, const Vector3&), rotationX(), rotationZ(), - * rotation() const, Quaternion::rotation(), Matrix3::rotation(T), - * deg(), rad() + * @see rotation(Rad, const Vector3&), rotationX(), rotationZ(), + * rotation() const, Quaternion::rotation(), Matrix3::rotation(Rad) */ - static Matrix4 rotationY(T angle) { - T sine = std::sin(angle); - T cosine = std::cos(angle); + static Matrix4 rotationY(Rad angle) { + T sine = std::sin(T(angle)); + T cosine = std::cos(T(angle)); return {{cosine, T(0), -sine, T(0)}, { T(0), T(1), T(0), T(0)}, @@ -151,16 +149,15 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D rotation matrix around Z axis - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * * Faster than calling `Matrix4::rotation(angle, Vector3::zAxis())`. - * @see rotation(T, const Vector3&), rotationX(), rotationY(), - * rotation() const, Quaternion::rotation(), Matrix3::rotation(T), - * deg(), rad() + * @see rotation(Rad, const Vector3&), rotationX(), rotationY(), + * rotation() const, Quaternion::rotation(), Matrix3::rotation(Rad) */ - static Matrix4 rotationZ(T angle) { - T sine = std::sin(angle); - T cosine = std::cos(angle); + static Matrix4 rotationZ(Rad angle) { + T sine = std::sin(T(angle)); + T cosine = std::cos(T(angle)); return {{cosine, sine, T(0), T(0)}, { -sine, cosine, T(0), T(0)}, diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 5f61137ca..f0126f04f 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -44,6 +44,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void configuration(); }; +typedef Math::Deg Deg; typedef Math::Matrix3 Matrix3; typedef Math::Matrix<2, float> Matrix2; typedef Math::Vector2 Vector2; @@ -107,7 +108,7 @@ void Matrix3Test::rotation() { {-0.258819f, 0.965926f, 0.0f}, { 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix3::rotation(deg(15.0f)), matrix); + CORRADE_COMPARE(Matrix3::rotation(Deg(15.0f)), matrix); } void Matrix3Test::reflection() { @@ -165,7 +166,7 @@ void Matrix3Test::rotationPart() { Matrix2 expectedRotationPart(Vector2( 0.965926f, 0.258819f), Vector2(-0.258819f, 0.965926f)); - Matrix3 rotation = Matrix3::rotation(deg(15.0f)); + Matrix3 rotation = Matrix3::rotation(Deg(15.0f)); CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); Matrix3 rotationTransformed = Matrix3::translation({2.0f, 5.0f})*rotation*Matrix3::scaling(Vector2(9.0f)); @@ -196,19 +197,19 @@ void Matrix3Test::invertedEuclidean() { CORRADE_COMPARE(Matrix3::scaling(Vector2(2.0f)).invertedEuclidean(), Matrix3()); CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); - Matrix3 actual = Matrix3::rotation(deg(-74.0f))* + Matrix3 actual = Matrix3::rotation(Deg(-74.0f))* Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* Matrix3::translation({2.0f, -3.0f}); Matrix3 expected = Matrix3::translation({-2.0f, 3.0f})* Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* - Matrix3::rotation(deg(74.0f)); + Matrix3::rotation(Deg(74.0f)); CORRADE_COMPARE(actual.invertedEuclidean(), expected); CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); } void Matrix3Test::transform() { - Matrix3 a = Matrix3::translation({1.0f, -5.0f})*Matrix3::rotation(deg(90.0f)); + Matrix3 a = Matrix3::translation({1.0f, -5.0f})*Matrix3::rotation(Deg(90.0f)); Vector2 v(1.0f, -2.0f); CORRADE_COMPARE(a.transformVector(v), Vector2(2.0f, 1.0f)); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index b9c68eee3..c1d815587 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -49,6 +49,8 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void configuration(); }; +typedef Math::Deg Deg; +typedef Math::Rad Rad; typedef Math::Matrix4 Matrix4; typedef Math::Matrix<3, float> Matrix3; typedef Math::Vector3 Vector3; @@ -120,14 +122,14 @@ void Matrix4Test::rotation() { std::ostringstream o; Error::setOutput(&o); - CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); + CORRADE_COMPARE(Matrix4::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): axis must be normalized\n"); Matrix4 matrix({ 0.35612214f, -0.80181062f, 0.47987163f, 0.0f}, { 0.47987163f, 0.59757638f, 0.6423595f, 0.0f}, {-0.80181062f, 0.0015183985f, 0.59757638f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); + CORRADE_COMPARE(Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); } void Matrix4Test::rotationX() { @@ -135,8 +137,8 @@ void Matrix4Test::rotationX() { {0.0f, 0.90096887f, 0.43388374f, 0.0f}, {0.0f, -0.43388374f, 0.90096887f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::xAxis()), matrix); - CORRADE_COMPARE(Matrix4::rotationX(rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::xAxis()), matrix); + CORRADE_COMPARE(Matrix4::rotationX(Rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationY() { @@ -144,8 +146,8 @@ void Matrix4Test::rotationY() { { 0.0f, 1.0f, 0.0f, 0.0f}, {0.43388374f, 0.0f, 0.90096887f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); - CORRADE_COMPARE(Matrix4::rotationY(rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); + CORRADE_COMPARE(Matrix4::rotationY(Rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationZ() { @@ -153,8 +155,8 @@ void Matrix4Test::rotationZ() { {-0.43388374f, 0.90096887f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); - CORRADE_COMPARE(Matrix4::rotationZ(rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); + CORRADE_COMPARE(Matrix4::rotationZ(Rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::reflection() { @@ -232,7 +234,7 @@ void Matrix4Test::rotationPart() { Vector3( 0.47987163f, 0.59757638f, 0.6423595f), Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)); - Matrix4 rotation = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); + Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); CORRADE_COMPARE(rotation.rotation().determinant(), 1.0f); CORRADE_COMPARE(rotation.rotation()*rotation.rotation().transposed(), Matrix3()); CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); @@ -270,19 +272,19 @@ void Matrix4Test::invertedEuclidean() { CORRADE_COMPARE(Matrix4::scaling(Vector3(2.0f)).invertedEuclidean(), Matrix4()); CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); - Matrix4 actual = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized())* + Matrix4 actual = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized())* Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* Matrix4::translation({1.0f, 2.0f, -3.0f}); Matrix4 expected = Matrix4::translation({-1.0f, -2.0f, 3.0f})* Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* - Matrix4::rotation(deg(74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized()); + Matrix4::rotation(Deg(74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized()); CORRADE_COMPARE(actual.invertedEuclidean(), expected); CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); } void Matrix4Test::transform() { - Matrix4 a = Matrix4::translation({1.0f, -5.0f, 3.5f})*Matrix4::rotation(deg(90.0f), Vector3::zAxis()); + Matrix4 a = Matrix4::translation({1.0f, -5.0f, 3.5f})*Matrix4::rotation(Deg(90.0f), Vector3::zAxis()); Vector3 v(1.0f, -2.0f, 5.5f); CORRADE_COMPARE(a.transformVector(v), Vector3(2.0f, 1.0f, 5.5f)); diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 9c1996bab..d54f96f37 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -41,7 +41,7 @@ template class Vector3: public Vector<3, T> { * Usable for translation or rotation along given axis, for example: * @code * Matrix4::translation(Vector3::xAxis(5.0f)); // same as Matrix4::translation({5.0f, 0.0f, 0.0f}); - * Matrix4::rotation(deg(30.0f), Vector3::xAxis()); // same as Matrix::rotation(deg(30.0f), {1.0f, 0.0f, 0.0f}); + * Matrix4::rotation(30.0_degf, Vector3::xAxis()); // same as Matrix::rotation(30.0_degf, {1.0f, 0.0f, 0.0f}); * @endcode * @see yAxis(), zAxis(), xScale(), Matrix4::right() */ diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 60636bf5e..a3b0f9c16 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -39,7 +39,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::applyTransformation() { Physics::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); - capsule.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); + capsule.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::zAxis())); CORRADE_COMPARE(capsule.transformedA(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(capsule.transformedB(), Vector3(2.0f, -1.0f, -3.0f)); CORRADE_COMPARE(capsule.radius(), 7.0f); diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 2b9c8be2c..6f67631b8 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -34,7 +34,7 @@ LineTest::LineTest() { void LineTest::applyTransformation() { Physics::Line3D line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}); - line.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); + line.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::zAxis())); CORRADE_COMPARE(line.transformedA(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(line.transformedB(), Vector3(2.0f, -1.0f, -3.0f)); } diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index d3af840e0..14962e1de 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -40,7 +40,7 @@ PlaneTest::PlaneTest() { void PlaneTest::applyTransformation() { Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0}); - plane.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::xAxis())); + plane.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::xAxis())); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.0f, -3.0f, 2.0f)); CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), 0, -Constants::sqrt2())); diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index f53057f6d..a19477ac4 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -44,7 +44,7 @@ SphereTest::SphereTest() { void SphereTest::applyTransformation() { Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); - sphere.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::yAxis())); + sphere.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::yAxis())); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(3.0f, 2.0f, -1.0f)); CORRADE_COMPARE(sphere.transformedRadius(), 7.0f); diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index 215be0d49..33b178d47 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -49,13 +49,11 @@ class AbstractTranslationRotation2D: public AbstractTransformation<2, T> { /** * @brief Rotate object - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) - * - * @see deg(), rad() */ - virtual AbstractTranslationRotation2D* rotate(T angle, TransformationType type = TransformationType::Global) = 0; + virtual AbstractTranslationRotation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) = 0; }; }} diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index bfc63943d..d0f49b47b 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -50,54 +50,52 @@ class AbstractTranslationRotation3D: public AbstractTransformation<3, T> { /** * @brief Rotate object - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad(), Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() + * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis() */ - virtual AbstractTranslationRotation3D* rotate(T angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) = 0; + virtual AbstractTranslationRotation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) = 0; /** * @brief Rotate object around X axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * * In some implementations faster than calling * `rotate(angle, Vector3::xAxis())`. - * @see deg(), rad() */ - virtual AbstractTranslationRotation3D* rotateX(T angle, TransformationType type = TransformationType::Global) { + virtual AbstractTranslationRotation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { return rotate(angle, Math::Vector3::xAxis(), type); } /** * @brief Rotate object around Y axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * * In some implementations faster than calling * `rotate(angle, Vector3::yAxis())`. - * @see deg(), rad() */ - virtual AbstractTranslationRotation3D* rotateY(T angle, TransformationType type = TransformationType::Global) { + virtual AbstractTranslationRotation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { return rotate(angle, Math::Vector3::yAxis(), type); } /** * @brief Rotate object around Z axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * * In some implementations faster than calling * `rotate(angle, Vector3::zAxis())`. - * @see deg(), rad() */ - virtual AbstractTranslationRotation3D* rotateZ(T angle, TransformationType type = TransformationType::Global) { + virtual AbstractTranslationRotation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { return rotate(angle, Math::Vector3::zAxis(), type); } }; diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 3b21555e6..a58dbfea3 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -75,7 +75,7 @@ class AnimableObject: public Object3D, SceneGraph::Animable3D<> { } void animationStep(GLfloat time, GLfloat delta) override { - rotateX(deg(15.0f)*delta); // rotate at 15 degrees per second + rotateX(15.0_degf*delta); // rotate at 15 degrees per second } } @endcode diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 702d3d60c..daad699c9 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -59,7 +59,7 @@ SceneGraph::DrawableGroup3D<> drawables; (new DrawableObject(&scene, &drawables)) ->translate(Vector3::yAxis(-0.3f)) - ->rotateX(deg(30.0f)); + ->rotateX(30.0_degf); (new AnotherDrawableObject(&scene, &drawables)) ->translate(Vector3::zAxis(0.5f)); // ... diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index 3b497cf40..12fe4749c 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -98,13 +98,13 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { /** * @brief Rotate object - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad(), normalizeRotation() + * @see normalizeRotation(), Matrix3::rotation() */ - inline EuclideanMatrixTransformation2D* rotate(T angle, TransformationType type = TransformationType::Global) override { + inline EuclideanMatrixTransformation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::rotation(angle), type); return this; } @@ -115,6 +115,8 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * (normalized) * @param type Transformation type * @return Pointer to self (for method chaining) + * + * @see Matrix3::reflection() */ inline EuclideanMatrixTransformation2D* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { transform(Math::Matrix3::reflection(normal), type); diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index 693b2b6c1..35cda398e 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -90,7 +90,15 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { return this; } - /** @copydoc AbstractTranslationRotation3D::translate() */ + /** + * @brief Translate object + * @param vector Translation vector + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), + * Matrix4::translation() + */ inline EuclideanMatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::translation(vector), type); return this; @@ -98,54 +106,55 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { /** * @brief Rotate object - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad(), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis(), normalizeRotation() + * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation(), + * Matrix4::rotation() */ - inline EuclideanMatrixTransformation3D* rotate(T angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { + inline EuclideanMatrixTransformation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotation(angle, normalizedAxis), type); return this; } /** * @brief Rotate object around X axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad(), normalizeRotation() + * @see normalizeRotation(), Matrix4::rotationX() */ - inline EuclideanMatrixTransformation3D* rotateX(T angle, TransformationType type = TransformationType::Global) override { + inline EuclideanMatrixTransformation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationX(angle), type); return this; } /** * @brief Rotate object around Y axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad(), normalizeRotation() + * @see normalizeRotation(), Matrix4::rotationY() */ - inline EuclideanMatrixTransformation3D* rotateY(T angle, TransformationType type = TransformationType::Global) override { + inline EuclideanMatrixTransformation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationY(angle), type); return this; } /** * @brief Rotate object around Z axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see deg(), rad(), normalizeRotation() + * @see normalizeRotation(), Matrix4::rotationZ() */ - inline EuclideanMatrixTransformation3D* rotateZ(T angle, TransformationType type = TransformationType::Global) override { + inline EuclideanMatrixTransformation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationZ(angle), type); return this; } @@ -157,7 +166,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * Same as calling transform() with Matrix4::reflection(). + * @see Matrix4::reflection() */ inline EuclideanMatrixTransformation3D* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::reflection(normal), type); diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index 08f1fdbd0..87cb449fc 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -104,7 +104,7 @@ class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { * @copydoc AbstractTranslationRotationScaling2D::rotate() * Same as calling transform() with Matrix3::rotation(). */ - inline MatrixTransformation2D* rotate(T angle, TransformationType type = TransformationType::Global) override { + inline MatrixTransformation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::rotation(angle), type); return this; } diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index c5018a684..0c613cacb 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -104,49 +104,46 @@ class MatrixTransformation3D: public AbstractTranslationRotationScaling3D { * @copydoc AbstractTranslationRotationScaling3D::rotate() * Same as calling transform() with Matrix4::rotation(). */ - inline MatrixTransformation3D* rotate(T angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { + inline MatrixTransformation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotation(angle, normalizedAxis), type); return this; } /** * @brief Rotate object around X axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * * Same as calling transform() with Matrix4::rotationX(). - * @see deg(), rad() */ - inline MatrixTransformation3D* rotateX(T angle, TransformationType type = TransformationType::Global) override { + inline MatrixTransformation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationX(angle), type); return this; } /** * @brief Rotate object around Y axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * * Same as calling transform() with Matrix4::rotationY(). - * @see deg(), rad() */ - inline MatrixTransformation3D* rotateY(T angle, TransformationType type = TransformationType::Global) override { + inline MatrixTransformation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationY(angle), type); return this; } /** * @brief Rotate object around Z axis - * @param angle Angle in radians, counterclockwise + * @param angle Angle (counterclockwise) * @param type Transformation type * @return Pointer to self (for method chaining) * * Same as calling transform() with Matrix4::rotationZ(). - * @see deg(), rad() */ - inline MatrixTransformation3D* rotateZ(T angle, TransformationType type = TransformationType::Global) override { + inline MatrixTransformation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationZ(angle), type); return this; } diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 07d42dfc3..61f52a5cd 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -132,7 +132,7 @@ void CameraTest::projectionSizeOrthographic() { void CameraTest::projectionSizePerspective() { Object3D o; Camera3D camera(&o); - camera.setPerspective(deg(27.0f), 2.35f, 32.0f, 100); + camera.setPerspective(Deg(27.0f), 2.35f, 32.0f, 100); CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f, 0.204322f)); } diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp index d772b969e..6ae1df500 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -54,23 +54,23 @@ EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() { } void EuclideanMatrixTransformation2DTest::fromMatrix() { - Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::fromMatrix(m), m); } void EuclideanMatrixTransformation2DTest::toMatrix() { - Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::toMatrix(m), m); } void EuclideanMatrixTransformation2DTest::compose() { - Matrix3 parent = Matrix3::rotation(deg(17.0f)); + Matrix3 parent = Matrix3::rotation(Deg(17.0f)); Matrix3 child = Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::compose(parent, child), parent*child); } void EuclideanMatrixTransformation2DTest::inverted() { - Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3()); } @@ -78,13 +78,13 @@ void EuclideanMatrixTransformation2DTest::setTransformation() { /* Dirty after setting transformation */ Object2D o; o.setClean(); - o.rotate(deg(17.0f)); + o.rotate(Deg(17.0f)); CORRADE_VERIFY(o.isDirty()); /* Scene cannot be transformed */ Scene2D s; s.setClean(); - s.rotate(deg(17.0f)); + s.rotate(Deg(17.0f)); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); } @@ -92,14 +92,14 @@ void EuclideanMatrixTransformation2DTest::setTransformation() { void EuclideanMatrixTransformation2DTest::translate() { { Object2D o; - o.rotate(deg(17.0f)); + o.rotate(Deg(17.0f)); o.translate({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.rotate(deg(17.0f)); + o.rotate(Deg(17.0f)); o.translate({1.0f, -0.3f}, TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } } @@ -107,35 +107,35 @@ void EuclideanMatrixTransformation2DTest::rotate() { { Object2D o; o.translate({1.0f, -0.3f}); - o.rotate(deg(17.0f)); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + o.rotate(Deg(17.0f)); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } { Object2D o; o.translate({1.0f, -0.3f}); - o.rotate(deg(17.0f), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + o.rotate(Deg(17.0f), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } } void EuclideanMatrixTransformation2DTest::reflect() { { Object2D o; - o.rotate(deg(17.0f)); + o.rotate(Deg(17.0f)); o.reflect(Vector2(-1.0f/Constants::sqrt2())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.rotate(deg(17.0f)); + o.rotate(Deg(17.0f)); o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); } } void EuclideanMatrixTransformation2DTest::normalizeRotation() { Object2D o; - o.rotate(deg(17.0f)); + o.rotate(Deg(17.0f)); o.normalizeRotation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); } }}} diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp index ee1e79e0e..207b0d832 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -54,23 +54,23 @@ EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() { } void EuclideanMatrixTransformation3DTest::fromMatrix() { - Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::fromMatrix(m), m); } void EuclideanMatrixTransformation3DTest::toMatrix() { - Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::toMatrix(m), m); } void EuclideanMatrixTransformation3DTest::compose() { - Matrix4 parent = Matrix4::rotationX(deg(17.0f)); + Matrix4 parent = Matrix4::rotationX(Deg(17.0f)); Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::compose(parent, child), parent*child); } void EuclideanMatrixTransformation3DTest::inverted() { - Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4()); } @@ -78,13 +78,13 @@ void EuclideanMatrixTransformation3DTest::setTransformation() { /* Dirty after setting transformation */ Object3D o; o.setClean(); - o.rotateX(deg(17.0f)); + o.rotateX(Deg(17.0f)); CORRADE_VERIFY(o.isDirty()); /* Scene cannot be transformed */ Scene3D s; s.setClean(); - s.rotateX(deg(17.0f)); + s.rotateX(Deg(17.0f)); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); } @@ -92,14 +92,14 @@ void EuclideanMatrixTransformation3DTest::setTransformation() { void EuclideanMatrixTransformation3DTest::translate() { { Object3D o; - o.rotateX(deg(17.0f)); + o.rotateX(Deg(17.0f)); o.translate({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.rotateX(deg(17.0f)); + o.rotateX(Deg(17.0f)); o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); } } @@ -107,51 +107,51 @@ void EuclideanMatrixTransformation3DTest::rotate() { { Object3D o; o.translate({1.0f, -0.3f, 2.3f}); - o.rotateX(deg(17.0f)) - ->rotateY(deg(25.0f)) - ->rotateZ(deg(-23.0f)) - ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + o.rotateX(Deg(17.0f)) + ->rotateY(Deg(25.0f)) + ->rotateZ(Deg(-23.0f)) + ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* - Matrix4::rotationZ(deg(-23.0f))* - Matrix4::rotationY(deg(25.0f))* - Matrix4::rotationX(deg(17.0f))* + Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* + Matrix4::rotationZ(Deg(-23.0f))* + Matrix4::rotationY(Deg(25.0f))* + Matrix4::rotationX(Deg(17.0f))* Matrix4::translation({1.0f, -0.3f, 2.3f})); } { Object3D o; o.translate({1.0f, -0.3f, 2.3f}); - o.rotateX(deg(17.0f), TransformationType::Local) - ->rotateY(deg(25.0f), TransformationType::Local) - ->rotateZ(deg(-23.0f), TransformationType::Local) - ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + o.rotateX(Deg(17.0f), TransformationType::Local) + ->rotateY(Deg(25.0f), TransformationType::Local) + ->rotateZ(Deg(-23.0f), TransformationType::Local) + ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(deg(17.0f))* - Matrix4::rotationY(deg(25.0f))* - Matrix4::rotationZ(deg(-23.0f))* - Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + Matrix4::rotationX(Deg(17.0f))* + Matrix4::rotationY(Deg(25.0f))* + Matrix4::rotationZ(Deg(-23.0f))* + Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); } } void EuclideanMatrixTransformation3DTest::reflect() { { Object3D o; - o.rotateX(deg(17.0f)); + o.rotateX(Deg(17.0f)); o.reflect(Vector3(-1.0f/Constants::sqrt3())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.rotateX(deg(17.0f)); + o.rotateX(Deg(17.0f)); o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); } } void EuclideanMatrixTransformation3DTest::normalizeRotation() { Object3D o; - o.rotateX(deg(17.0f)); + o.rotateX(Deg(17.0f)); o.normalizeRotation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); } }}} diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp index 1960ad713..9b67c6fbf 100644 --- a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -56,23 +56,23 @@ MatrixTransformation2DTest::MatrixTransformation2DTest() { } void MatrixTransformation2DTest::fromMatrix() { - Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(MatrixTransformation2D<>::fromMatrix(m), m); } void MatrixTransformation2DTest::toMatrix() { - Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(MatrixTransformation2D<>::toMatrix(m), m); } void MatrixTransformation2DTest::compose() { - Matrix3 parent = Matrix3::rotation(deg(17.0f)); + Matrix3 parent = Matrix3::rotation(Deg(17.0f)); Matrix3 child = Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(MatrixTransformation2D<>::compose(parent, child), parent*child); } void MatrixTransformation2DTest::inverted() { - Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3()); } @@ -81,15 +81,15 @@ void MatrixTransformation2DTest::setTransformation() { Object2D o; o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); /* Scene cannot be transformed */ Scene2D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix3::rotation(deg(17.0f))); + s.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); } @@ -97,28 +97,28 @@ void MatrixTransformation2DTest::setTransformation() { void MatrixTransformation2DTest::transform() { { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.transform(Matrix3::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.transform(Matrix3::translation({1.0f, -0.3f}), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } } void MatrixTransformation2DTest::translate() { { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.translate({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.translate({1.0f, -0.3f}, TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } } @@ -126,41 +126,41 @@ void MatrixTransformation2DTest::rotate() { { Object2D o; o.setTransformation(Matrix3::translation({1.0f, -0.3f})); - o.rotate(deg(17.0f)); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + o.rotate(Deg(17.0f)); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } { Object2D o; o.setTransformation(Matrix3::translation({1.0f, -0.3f})); - o.rotate(deg(17.0f), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + o.rotate(Deg(17.0f), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } } void MatrixTransformation2DTest::scale() { { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.scale({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.scale({1.0f, -0.3f}, TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::scaling({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::scaling({1.0f, -0.3f})); } } void MatrixTransformation2DTest::reflect() { { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.reflect(Vector2(-1.0f/Constants::sqrt2())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.setTransformation(Matrix3::rotation(deg(17.0f))); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); } } diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index a3dcf35a8..8f664a80b 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -56,23 +56,23 @@ MatrixTransformation3DTest::MatrixTransformation3DTest() { } void MatrixTransformation3DTest::fromMatrix() { - Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); CORRADE_COMPARE(MatrixTransformation3D<>::fromMatrix(m), m); } void MatrixTransformation3DTest::toMatrix() { - Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); CORRADE_COMPARE(MatrixTransformation3D<>::toMatrix(m), m); } void MatrixTransformation3DTest::compose() { - Matrix4 parent = Matrix4::rotationX(deg(17.0f)); + Matrix4 parent = Matrix4::rotationX(Deg(17.0f)); Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(MatrixTransformation3D<>::compose(parent, child), parent*child); } void MatrixTransformation3DTest::inverted() { - Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); CORRADE_COMPARE(MatrixTransformation3D<>::inverted(m)*m, Matrix4()); } @@ -81,15 +81,15 @@ void MatrixTransformation3DTest::setTransformation() { Object3D o; o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); /* Scene cannot be transformed */ Scene3D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix4::rotationX(deg(17.0f))); + s.setTransformation(Matrix4::rotationX(Deg(17.0f))); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); } @@ -97,28 +97,28 @@ void MatrixTransformation3DTest::setTransformation() { void MatrixTransformation3DTest::transform() { { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f}), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); } } void MatrixTransformation3DTest::translate() { { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.translate({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); } } @@ -126,57 +126,57 @@ void MatrixTransformation3DTest::rotate() { { Object3D o; o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); - o.rotateX(deg(17.0f)) - ->rotateY(deg(25.0f)) - ->rotateZ(deg(-23.0f)) - ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + o.rotateX(Deg(17.0f)) + ->rotateY(Deg(25.0f)) + ->rotateZ(Deg(-23.0f)) + ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* - Matrix4::rotationZ(deg(-23.0f))* - Matrix4::rotationY(deg(25.0f))* - Matrix4::rotationX(deg(17.0f))* + Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* + Matrix4::rotationZ(Deg(-23.0f))* + Matrix4::rotationY(Deg(25.0f))* + Matrix4::rotationX(Deg(17.0f))* Matrix4::translation({1.0f, -0.3f, 2.3f})); } { Object3D o; o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); - o.rotateX(deg(17.0f), TransformationType::Local) - ->rotateY(deg(25.0f), TransformationType::Local) - ->rotateZ(deg(-23.0f), TransformationType::Local) - ->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + o.rotateX(Deg(17.0f), TransformationType::Local) + ->rotateY(Deg(25.0f), TransformationType::Local) + ->rotateZ(Deg(-23.0f), TransformationType::Local) + ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(deg(17.0f))* - Matrix4::rotationY(deg(25.0f))* - Matrix4::rotationZ(deg(-23.0f))* - Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + Matrix4::rotationX(Deg(17.0f))* + Matrix4::rotationY(Deg(25.0f))* + Matrix4::rotationZ(Deg(-23.0f))* + Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); } } void MatrixTransformation3DTest::scale() { { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.scale({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::scaling({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::scaling({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.scale({1.0f, -0.3f, 2.3f}, TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::scaling({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::scaling({1.0f, -0.3f, 2.3f})); } } void MatrixTransformation3DTest::reflect() { { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.reflect(Vector3(-1.0f/Constants::sqrt3())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.setTransformation(Matrix4::rotationX(deg(17.0f))); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); } } diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 322d4014b..14d241fbc 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -119,9 +119,9 @@ void ObjectTest::absoluteTransformation() { CORRADE_COMPARE(o.transformation(), Matrix4::translation(Vector3::xAxis(2.0f))); CORRADE_COMPARE(o.transformation(), o.transformationMatrix()); Object3D o2(&o); - o2.rotateY(deg(90.0f)); + o2.rotateY(Deg(90.0f)); CORRADE_COMPARE(o2.absoluteTransformation(), - Matrix4::translation(Vector3::xAxis(2.0f))*Matrix4::rotationY(deg(90.0f))); + Matrix4::translation(Vector3::xAxis(2.0f))*Matrix4::rotationY(Deg(90.0f))); CORRADE_COMPARE(o2.absoluteTransformation(), o2.absoluteTransformationMatrix()); /* Transformation of root object */ @@ -133,7 +133,7 @@ void ObjectTest::absoluteTransformation() { void ObjectTest::transformations() { Scene3D s; - Matrix4 initial = Matrix4::rotationX(deg(90.0f)).inverted(); + Matrix4 initial = Matrix4::rotationX(Deg(90.0f)).inverted(); /* Empty list */ CORRADE_COMPARE(s.transformations(std::vector(), initial), std::vector()); @@ -143,16 +143,16 @@ void ObjectTest::transformations() { /* One object */ Object3D first(&s); - first.rotateZ(deg(30.0f)); + first.rotateZ(Deg(30.0f)); Object3D second(&first); second.scale(Vector3(0.5f)); CORRADE_COMPARE(s.transformations({&second}, initial), std::vector{ - initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)) + initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)) }); /* One object and scene */ CORRADE_COMPARE(s.transformations({&second, &s}, initial), (std::vector{ - initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), + initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial })); @@ -160,15 +160,15 @@ void ObjectTest::transformations() { Object3D third(&first); third.translate(Vector3::xAxis(5.0f)); CORRADE_COMPARE(s.transformations({&second, &third}, initial), (std::vector{ - initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), - initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), + initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), + initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), })); /* Three objects with joint as one of them */ CORRADE_COMPARE(s.transformations({&second, &third, &first}, initial), (std::vector{ - initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), - initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), - initial*Matrix4::rotationZ(deg(30.0f)), + initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), + initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), + initial*Matrix4::rotationZ(Deg(30.0f)), })); } @@ -177,7 +177,7 @@ void ObjectTest::transformationsRelative() { Scene3D s; Object3D first(&s); - first.rotateZ(deg(30.0f)); + first.rotateZ(Deg(30.0f)); Object3D second(&first); second.scale(Vector3(0.5f)); Object3D third(&first); @@ -190,7 +190,7 @@ void ObjectTest::transformationsRelative() { /* Transformation relative to another object, not part of any scene (but should work) */ Object3D orphanParent1; - orphanParent1.rotate(deg(31.0f), Vector3(1.0f).normalized()); + orphanParent1.rotate(Deg(31.0f), Vector3(1.0f).normalized()); Object3D orphanParent(&orphanParent1); Object3D orphan1(&orphanParent); orphan1.scale(Vector3::xScale(3.0f)); @@ -215,15 +215,15 @@ void ObjectTest::transformationsOrphan() { void ObjectTest::transformationsDuplicate() { Scene3D s; Object3D first(&s); - first.rotateZ(deg(30.0f)); + first.rotateZ(Deg(30.0f)); Object3D second(&first); second.scale(Vector3(0.5f)); Object3D third(&first); third.translate(Vector3::xAxis(5.0f)); - Matrix4 firstExpected = Matrix4::rotationZ(deg(30.0f)); - Matrix4 secondExpected = Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)); - Matrix4 thirdExpected = Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)); + Matrix4 firstExpected = Matrix4::rotationZ(Deg(30.0f)); + Matrix4 secondExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)); + Matrix4 thirdExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)); CORRADE_COMPARE(s.transformations({&second, &third, &second, &first, &third}), (std::vector{ secondExpected, thirdExpected, secondExpected, firstExpected, thirdExpected })); @@ -267,7 +267,7 @@ void ObjectTest::setClean() { CachingInvertedFeature* childTwoFeature2 = new CachingInvertedFeature(childTwo); CachingObject* childThree = new CachingObject(childTwo); - childThree->rotate(deg(90.0f), Vector3::yAxis()); + childThree->rotate(Deg(90.0f), Vector3::yAxis()); /* Object is dirty at the beginning */ CORRADE_VERIFY(scene.isDirty()); From d16a6259b8f033d0ecb2808dd9bbee910127af3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 21:07:42 +0100 Subject: [PATCH 379/567] Math: using Rad for Matrix4::perspectiveProjection(). Also updated dependent functions and tests. --- src/Math/Matrix4.h | 6 +++--- src/Math/Test/Matrix4Test.cpp | 2 +- src/SceneGraph/Camera3D.h | 4 ++-- src/SceneGraph/Camera3D.hpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index c72dc52a9..757ebab21 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -216,15 +216,15 @@ template class Matrix4: public Matrix<4, T> { /** * @brief 3D perspective projection matrix - * @param fov Field of view angle (horizontal, in radians) + * @param fov Field of view angle (horizontal) * @param aspectRatio Aspect ratio * @param near Near clipping plane * @param far Far clipping plane * * @see orthographicProjection(), Matrix3::projection() */ - static Matrix4 perspectiveProjection(T fov, T aspectRatio, T near, T far) { - T xyScale = 2*std::tan(fov/2)*near; + static Matrix4 perspectiveProjection(Rad fov, T aspectRatio, T near, T far) { + T xyScale = 2*std::tan(T(fov)/2)*near; return perspectiveProjection(Vector2(xyScale, xyScale/aspectRatio), near, far); } diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index c1d815587..951b4b0c9 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -200,7 +200,7 @@ void Matrix4Test::perspectiveProjectionFov() { { 0.0f, 9.788454f, 0.0f, 0.0f}, { 0.0f, 0.0f, -1.9411764f, -1.0f}, { 0.0f, 0.0f, -94.1176452f, 0.0f}); - CORRADE_COMPARE(Matrix4::perspectiveProjection(deg(27.0f), 2.35f, 32.0f, 100), expected); + CORRADE_COMPARE(Matrix4::perspectiveProjection(Deg(27.0f), 2.35f, 32.0f, 100), expected); } void Matrix4Test::fromParts() { diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 91c8a6cd2..d10124ac2 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -83,7 +83,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { /** * @brief Set perspective projection - * @param fov Field of view angle (horizontal, in radians) + * @param fov Field of view angle (horizontal) * @param aspectRatio Aspect ratio * @param near Near clipping plane * @param far Far clipping plane @@ -91,7 +91,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { * * @see setOrthographic(), Matrix4::perspectiveProjection() */ - Camera3D* setPerspective(T fov, T aspectRatio, T near, T far); + Camera3D* setPerspective(Math::Rad fov, T aspectRatio, T near, T far); /** @brief Near clipping plane */ inline T near() const { return _near; } diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index 7bfe41db8..a64537345 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -46,7 +46,7 @@ template Camera3D* Camera3D::setPerspective(const Math::Vector2 Camera3D* Camera3D::setPerspective(T fov, T aspectRatio, T near, T far) { +template Camera3D* Camera3D::setPerspective(Math::Rad fov, T aspectRatio, T near, T far) { /** @todo Get near/far from the matrix */ _near = near; _far = far; From c293630c7ce9bfd9df692d3ed2132404fe691e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 21:09:49 +0100 Subject: [PATCH 380/567] Math: using Rad for Quaternion and DualQuaternion functions. --- src/Math/DualQuaternion.h | 6 ++-- src/Math/Quaternion.h | 20 ++++++------ src/Math/Test/DualQuaternionTest.cpp | 39 +++++++++++----------- src/Math/Test/QuaternionTest.cpp | 48 +++++++++++++++------------- 4 files changed, 58 insertions(+), 55 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 5302ab46f..3230272c8 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -46,9 +46,9 @@ template class DualQuaternion: public Dual> { * @f] * @see rotationAngle(), rotationAxis(), Quaternion::rotation(), * Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis(), deg(), rad() + * Vector3::zAxis() */ - inline static DualQuaternion rotation(T angle, const Vector3& normalizedAxis) { + inline static DualQuaternion rotation(Rad angle, const Vector3& normalizedAxis) { return {Quaternion::rotation(angle, normalizedAxis), {{}, T(0)}}; } @@ -112,7 +112,7 @@ template class DualQuaternion: public Dual> { * @f] * @see rotationAxis(), rotation(), Quaternion::rotationAngle() */ - inline T rotationAngle() const { + inline Math::Rad rotationAngle() const { return this->real().rotationAngle(); } diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 8f9a451be..ef87aa2ff 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -55,16 +55,16 @@ template class Quaternion { } /** - * @brief Angle between normalized quaternions (in radians) + * @brief Angle between normalized quaternions * * Expects that both quaternions are normalized. @f[ * \theta = acos \left( \frac{p \cdot q}{|p| \cdot |q|} \right) * @f] */ - inline static T angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { + inline static Rad angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), - "Math::Quaternion::angle(): quaternions must be normalized", std::numeric_limits::quiet_NaN()); - return angleInternal(normalizedA, normalizedB); + "Math::Quaternion::angle(): quaternions must be normalized", Rad(std::numeric_limits::quiet_NaN())); + return Rad(angleInternal(normalizedA, normalizedB)); } /** @@ -116,13 +116,13 @@ template class Quaternion { * @f] * @see rotationAngle(), rotationAxis(), DualQuaternion::rotation(), * Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis(), deg(), rad() + * Vector3::zAxis() */ - inline static Quaternion rotation(T angle, const Vector3& normalizedAxis) { + inline static Quaternion rotation(Rad angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), "Math::Quaternion::rotation(): axis must be normalized", {}); - return {normalizedAxis*std::sin(angle/2), std::cos(angle/2)}; + return {normalizedAxis*std::sin(T(angle)/2), std::cos(T(angle)/2)}; } /** @@ -177,11 +177,11 @@ template class Quaternion { * @f] * @see rotationAxis(), rotation() */ - inline T rotationAngle() const { + inline Rad rotationAngle() const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAngle(): quaternion must be normalized", - std::numeric_limits::quiet_NaN()); - return T(2)*std::acos(_scalar); + Rad(std::numeric_limits::quiet_NaN())); + return Rad(T(2)*std::acos(_scalar)); } /** diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 88481305e..ae44c49cd 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -50,6 +50,8 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void debug(); }; +typedef Math::Deg Deg; +typedef Math::Rad Rad; typedef Math::Dual Dual; typedef Math::Matrix4 Matrix4; typedef Math::DualQuaternion DualQuaternion; @@ -169,15 +171,14 @@ void DualQuaternionTest::rotation() { std::ostringstream o; Error::setOutput(&o); - float angle = deg(120.0f); Vector3 axis(1.0f/Constants::sqrt3()); - CORRADE_COMPARE(DualQuaternion::rotation(angle, axis*2.0f), DualQuaternion()); + CORRADE_COMPARE(DualQuaternion::rotation(Deg(120.0f), axis*2.0f), DualQuaternion()); CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); - DualQuaternion q = DualQuaternion::rotation(angle, axis); + DualQuaternion q = DualQuaternion::rotation(Deg(120.0f), axis); CORRADE_COMPARE(q, DualQuaternion({Vector3(0.5f, 0.5f, 0.5f), 0.5f}, {{}, 0.0f})); - CORRADE_COMPARE(q.rotationAngle(), angle); + CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); CORRADE_COMPARE(q.rotationAxis(), axis); } @@ -190,21 +191,21 @@ void DualQuaternionTest::translation() { void DualQuaternionTest::combinedTransformParts() { Vector3 translation = Vector3(-1.0f, 2.0f, 3.0f); - DualQuaternion a = DualQuaternion::translation(translation)*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); - DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation(translation); + DualQuaternion a = DualQuaternion::translation(translation)*DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis()); + DualQuaternion b = DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation(translation); CORRADE_COMPARE(a.rotationAxis(), Vector3::xAxis()); CORRADE_COMPARE(b.rotationAxis(), Vector3::xAxis()); - CORRADE_COMPARE(a.rotationAngle(), deg(23.0f)); - CORRADE_COMPARE(b.rotationAngle(), deg(23.0f)); + CORRADE_COMPARE_AS(a.rotationAngle(), Deg(23.0f), Rad); + CORRADE_COMPARE_AS(b.rotationAngle(), Deg(23.0f), Rad); CORRADE_COMPARE(a.translation(), translation); - CORRADE_COMPARE(b.translation(), Quaternion::rotation(deg(23.0f), Vector3::xAxis()).rotateVectorNormalized(translation)); + CORRADE_COMPARE(b.translation(), Quaternion::rotation(Deg(23.0f), Vector3::xAxis()).rotateVectorNormalized(translation)); } void DualQuaternionTest::matrix() { - DualQuaternion q = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); - Matrix4 m = Matrix4::rotationX(deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); + DualQuaternion q = DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); + Matrix4 m = Matrix4::rotationX(Deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); /* Verify that negated dual quaternion gives the same transformation */ CORRADE_COMPARE(q.matrix(), m); @@ -212,10 +213,10 @@ void DualQuaternionTest::matrix() { } void DualQuaternionTest::transformPoint() { - DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); - DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); - Matrix4 m = Matrix4::translation({-1.0f, 2.0f, 3.0f})*Matrix4::rotationX(deg(23.0f)); - Matrix4 n = Matrix4::rotationX(deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); + DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis()); + DualQuaternion b = DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); + Matrix4 m = Matrix4::translation({-1.0f, 2.0f, 3.0f})*Matrix4::rotationX(Deg(23.0f)); + Matrix4 n = Matrix4::rotationX(Deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); Vector3 v(0.0f, -3.6f, 0.7f); Vector3 transformedA = (a*Dual(2)).transformPoint(v); @@ -228,10 +229,10 @@ void DualQuaternionTest::transformPoint() { } void DualQuaternionTest::transformPointNormalized() { - DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(deg(23.0f), Vector3::xAxis()); - DualQuaternion b = DualQuaternion::rotation(deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); - Matrix4 m = Matrix4::translation({-1.0f, 2.0f, 3.0f})*Matrix4::rotationX(deg(23.0f)); - Matrix4 n = Matrix4::rotationX(deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); + DualQuaternion a = DualQuaternion::translation({-1.0f, 2.0f, 3.0f})*DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis()); + DualQuaternion b = DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({-1.0f, 2.0f, 3.0f}); + Matrix4 m = Matrix4::translation({-1.0f, 2.0f, 3.0f})*Matrix4::rotationX(Deg(23.0f)); + Matrix4 n = Matrix4::rotationX(Deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); Vector3 v(0.0f, -3.6f, 0.7f); std::ostringstream o; diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 285a62fbf..acf98e833 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -58,6 +58,8 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void debug(); }; +typedef Math::Deg Deg; +typedef Math::Rad Rad; typedef Math::Matrix<3, float> Matrix3; typedef Math::Matrix4 Matrix4; typedef Math::Quaternion Quaternion; @@ -227,48 +229,48 @@ void QuaternionTest::rotation() { std::ostringstream o; Error::setOutput(&o); - float angle = deg(120.0f); Vector3 axis(1.0f/Constants::sqrt3()); - CORRADE_COMPARE(Quaternion::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion()); + CORRADE_COMPARE(Quaternion::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion()); CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); - Quaternion q = Quaternion::rotation(angle, axis); + Quaternion q = Quaternion::rotation(Deg(120.0f), axis); CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f)); - CORRADE_COMPARE(q.rotationAngle(), angle); + CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); CORRADE_COMPARE(q.rotationAxis(), axis); CORRADE_COMPARE(q.rotationAxis().length(), 1.0f); /* Verify negative angle */ - Quaternion q2 = Quaternion::rotation(deg(-120.0f), axis); + Quaternion q2 = Quaternion::rotation(Deg(-120.0f), axis); CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f)); - CORRADE_COMPARE(q2.rotationAngle(), deg(120.0f)); + CORRADE_COMPARE_AS(q2.rotationAngle(), Deg(120.0f), Deg); CORRADE_COMPARE(q2.rotationAxis(), -axis); /* Default-constructed quaternion has zero angle and NaN axis */ - CORRADE_COMPARE(Quaternion().rotationAngle(), deg(0.0f)); + CORRADE_COMPARE_AS(Quaternion().rotationAngle(), Deg(0.0f), Deg); CORRADE_VERIFY(Quaternion().rotationAxis() != Quaternion().rotationAxis()); } void QuaternionTest::angle() { std::ostringstream o; Corrade::Utility::Error::setOutput(&o); - CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), {{4.0f, -3.0f, 2.0f}, -1.0f}), - std::numeric_limits::quiet_NaN()); + auto angle = Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), {{4.0f, -3.0f, 2.0f}, -1.0f}); + CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); o.str(""); - CORRADE_COMPARE(Quaternion::angle({{1.0f, 2.0f, -3.0f}, -4.0f}, Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), - std::numeric_limits::quiet_NaN()); + angle = Quaternion::angle({{1.0f, 2.0f, -3.0f}, -4.0f}, Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()); + CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); - CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), - rad(1.704528f)); + CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), + Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), + Rad(1.704528f)); } void QuaternionTest::matrix() { - Quaternion q = Quaternion::rotation(deg(37.0f), Vector3(1.0f/Constants::sqrt3())); - Matrix3 m = Matrix4::rotation(deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); + Quaternion q = Quaternion::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())); + Matrix3 m = Matrix4::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); /* Verify that negated quaternion gives the same rotation */ CORRADE_COMPARE(q.matrix(), m); @@ -276,8 +278,8 @@ void QuaternionTest::matrix() { } void QuaternionTest::lerp() { - Quaternion a = Quaternion::rotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); - Quaternion b = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); + Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); std::ostringstream o; Corrade::Utility::Error::setOutput(&o); @@ -298,8 +300,8 @@ void QuaternionTest::lerp() { } void QuaternionTest::slerp() { - Quaternion a = Quaternion::rotation(deg(15.0f), Vector3(1.0f/Constants::sqrt3())); - Quaternion b = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); + Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); std::ostringstream o; Corrade::Utility::Error::setOutput(&o); @@ -320,8 +322,8 @@ void QuaternionTest::slerp() { } void QuaternionTest::rotateVector() { - Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); - Matrix4 m = Matrix4::rotationX(deg(23.0f)); + Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); + Matrix4 m = Matrix4::rotationX(Deg(23.0f)); Vector3 v(5.0f, -3.6f, 0.7f); Vector3 rotated = a.rotateVector(v); @@ -330,8 +332,8 @@ void QuaternionTest::rotateVector() { } void QuaternionTest::rotateVectorNormalized() { - Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); - Matrix4 m = Matrix4::rotationX(deg(23.0f)); + Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); + Matrix4 m = Matrix4::rotationX(Deg(23.0f)); Vector3 v(5.0f, -3.6f, 0.7f); std::ostringstream o; From a220289067594d34e6ad3b50ef83e91f3250ee5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 21:10:28 +0100 Subject: [PATCH 381/567] Using Deg for Color hue. --- src/Color.h | 33 +++++++++++---------- src/Test/ColorTest.cpp | 65 +++++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Color.h b/src/Color.h index cd5ac19ee..bb256994d 100644 --- a/src/Color.h +++ b/src/Color.h @@ -32,15 +32,16 @@ namespace Implementation { /* Convert color from HSV */ template inline typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { - T hue, saturation, value; + Math::Deg hue; + T saturation, value; std::tie(hue, saturation, value) = hsv; /* Remove repeats */ - hue -= int(hue/T(360))*T(360); - if(hue < T(0)) hue += T(360); + hue -= int(T(hue)/T(360))*Math::Deg(360); + if(hue < Math::Deg(0)) hue += Math::Deg(360); - int h = int(hue/T(60)) % 6; - T f = hue/T(60) - h; + int h = int(T(hue)/T(60)) % 6; + T f = T(hue)/T(60) - h; T p = value * (T(1) - saturation); T q = value * (T(1) - f*saturation); @@ -61,7 +62,7 @@ template inline typename std::enable_if::value, Col } /* Internal hue computing function */ -template T hue(const Color3& color, T max, T delta) { +template Math::Deg hue(const Color3& color, T max, T delta) { T deltaInv60 = T(60)/delta; T hue(0); @@ -74,11 +75,11 @@ template T hue(const Color3& color, T max, T delta) { hue = (color.r()-color.g())*deltaInv60 + T(240); } - return hue; + return Math::Deg(hue); } /* Hue, saturation, value for floating-point types */ -template inline T hue(typename std::enable_if::value, const Color3&>::type color) { +template inline Math::Deg hue(typename std::enable_if::value, const Color3&>::type color) { T max = color.max(); T delta = max - color.min(); return hue(color, max, delta); @@ -93,7 +94,7 @@ template inline T value(typename std::enable_if inline typename Color3::FloatingPointType hue(typename std::enable_if::value, const Color3&>::type color) { +template inline Math::Deg::FloatingPointType> hue(typename std::enable_if::value, const Color3&>::type color) { return hue::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { @@ -137,8 +138,6 @@ is always in range in range @f$ [0.0, 360.0] @f$, saturation and value in range @f$ [0.0, 1.0] @f$. @see Color4 - -@todo Hue in degrees so users can use deg() */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ @@ -158,7 +157,7 @@ class Color3: public Math::Vector3 { * Hue in range @f$ [0.0, 360.0] @f$, saturation and value in * range @f$ [0.0, 1.0] @f$. */ - typedef std::tuple HSV; + typedef std::tuple, FloatingPointType, FloatingPointType> HSV; /** * @brief Create RGB color from HSV representation @@ -170,7 +169,7 @@ class Color3: public Math::Vector3 { return Implementation::fromHSV(hsv); } /** @overload */ - inline constexpr static Color3 fromHSV(FloatingPointType hue, FloatingPointType saturation, FloatingPointType value) { + inline constexpr static Color3 fromHSV(Math::Deg hue, FloatingPointType saturation, FloatingPointType value) { return fromHSV(std::make_tuple(hue, saturation, value)); } @@ -229,8 +228,8 @@ class Color3: public Math::Vector3 { * * @see saturation(), value(), toHSV(), fromHSV() */ - inline constexpr FloatingPointType hue() const { - return Implementation::hue(*this); + inline constexpr Math::Deg hue() const { + return Math::Deg(Implementation::hue(*this)); } /** @@ -287,7 +286,7 @@ class Color4: public Math::Vector4 { return Color4(Implementation::fromHSV(hsv), a); } /** @overload */ - inline constexpr static Color4 fromHSV(FloatingPointType hue, FloatingPointType saturation, FloatingPointType value, T alpha) { + inline constexpr static Color4 fromHSV(Math::Deg hue, FloatingPointType saturation, FloatingPointType value, T alpha) { return fromHSV(std::make_tuple(hue, saturation, value), alpha); } @@ -355,7 +354,7 @@ class Color4: public Math::Vector4 { } /** @copydoc Color3::hue() */ - inline constexpr FloatingPointType hue() const { + inline constexpr Math::Deg hue() const { return Implementation::hue(rgb()); } diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index d2dfb0526..e498e1da7 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -92,25 +92,25 @@ void ColorTest::access() { } void ColorTest::fromHue() { - CORRADE_COMPARE(Color3::fromHSV(27.0f, 1.0f, 1.0f), Color3(255, 114, 0)); - CORRADE_COMPARE(Color3::fromHSV(86.0f, 1.0f, 1.0f), Color3(144, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(134.0f, 1.0f, 1.0f), Color3(0, 255, 59)); - CORRADE_COMPARE(Color3::fromHSV(191.0f, 1.0f, 1.0f), Color3(0, 208, 255)); - CORRADE_COMPARE(Color3::fromHSV(269.0f, 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(317.0f, 1.0f, 1.0f), Color3(255, 0, 182)); + CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); + CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); + CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); + CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); } void ColorTest::hue() { - CORRADE_COMPARE(Color3(255, 115, 0).hue(), 27.058824f); - CORRADE_COMPARE(Color3(145, 255, 0).hue(), 85.882353f); - CORRADE_COMPARE(Color3(0, 255, 60).hue(), 134.11765f); - CORRADE_COMPARE(Color3(0, 208, 255).hue(), 191.05882f); - CORRADE_COMPARE(Color3(123, 0, 255).hue(), 268.94117f); - CORRADE_COMPARE(Color3(255, 0, 183).hue(), 316.94117f); + CORRADE_COMPARE(Color3(255, 115, 0).hue(), Deg(27.058824f)); + CORRADE_COMPARE(Color3(145, 255, 0).hue(), Deg(85.882353f)); + CORRADE_COMPARE(Color3(0, 255, 60).hue(), Deg(134.11765f)); + CORRADE_COMPARE(Color3(0, 208, 255).hue(), Deg(191.05882f)); + CORRADE_COMPARE(Color3(123, 0, 255).hue(), Deg(268.94117f)); + CORRADE_COMPARE(Color3(255, 0, 183).hue(), Deg(316.94117f)); } void ColorTest::fromSaturation() { - CORRADE_COMPARE(Color3::fromHSV(0.0f, 0.702f, 1.0f), Color3(255, 75, 75)); + CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 0.702f, 1.0f), Color3(255, 75, 75)); } void ColorTest::saturation() { @@ -119,7 +119,7 @@ void ColorTest::saturation() { } void ColorTest::fromValue() { - CORRADE_COMPARE(Color3::fromHSV(0.0f, 1.0f, 0.522f), Color3(133, 0, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 1.0f, 0.522f), Color3(133, 0, 0)); } void ColorTest::value() { @@ -127,34 +127,35 @@ void ColorTest::value() { } void ColorTest::hsv() { - CORRADE_COMPARE(Color3::fromHSV(230.0f, 0.749f, 0.427f), Color3(27, 40, 108)); + CORRADE_COMPARE(Color3::fromHSV(Deg(230.0f), 0.749f, 0.427f), Color3(27, 40, 108)); - float hue, saturation, value; + Deg hue; + float saturation, value; std::tie(hue, saturation, value) = Color3(27, 41, 109).toHSV(); - CORRADE_COMPARE(hue, 229.756106f); + CORRADE_COMPARE(hue, Deg(229.756106f)); CORRADE_COMPARE(saturation, 0.752294f); CORRADE_COMPARE(value, 0.427451f); } void ColorTest::hsvOverflow() { - CORRADE_COMPARE(Color3::fromHSV(27.0f-360.0f, 1.0f, 1.0f), Color3(255, 114, 0)); - CORRADE_COMPARE(Color3::fromHSV(86.0f-360.0f, 1.0f, 1.0f), Color3(144, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(134.0f-360.0f, 1.0f, 1.0f), Color3(0, 255, 59)); - CORRADE_COMPARE(Color3::fromHSV(191.0f-360.0f, 1.0f, 1.0f), Color3(0, 208, 255)); - CORRADE_COMPARE(Color3::fromHSV(269.0f-360.0f, 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(317.0f-360.0f, 1.0f, 1.0f), Color3(255, 0, 182)); - - CORRADE_COMPARE(Color3::fromHSV(360.0f+27.0f, 1.0f, 1.0f), Color3(255, 114, 0)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+86.0f, 1.0f, 1.0f), Color3(144, 255, 0)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+134.0f, 1.0f, 1.0f), Color3(0, 255, 59)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+191.0f, 1.0f, 1.0f), Color3(0, 208, 255)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+269.0f, 1.0f, 1.0f), Color3(123, 0, 255)); - CORRADE_COMPARE(Color3::fromHSV(360.0f+317.0f, 1.0f, 1.0f), Color3(255, 0, 182)); + CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3(255, 114, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3(144, 255, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3(0, 255, 59)); + CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3(0, 208, 255)); + CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3(123, 0, 255)); + CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3(255, 0, 182)); + + CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3(255, 114, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3(144, 255, 0)); + CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3(0, 255, 59)); + CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3(0, 208, 255)); + CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3(123, 0, 255)); + CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+317.0f), 1.0f, 1.0f), Color3(255, 0, 182)); } void ColorTest::hsvAlpha() { - CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(230.0f, 0.749f, 0.427f), 23), Color4(27, 40, 108, 23)); - CORRADE_COMPARE(Color4::fromHSV(230.0f, 0.749f, 0.427f, 23), Color4(27, 40, 108, 23)); + CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(Deg(230.0f), 0.749f, 0.427f), 23), Color4(27, 40, 108, 23)); + CORRADE_COMPARE(Color4::fromHSV(Deg(230.0f), 0.749f, 0.427f, 23), Color4(27, 40, 108, 23)); } void ColorTest::debug() { From 3ccc6a794e2cd449ac4762de2488aa7a0cbc7e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 21:11:21 +0100 Subject: [PATCH 382/567] Math: removed old deg()/rad() helpers. --- src/Magnum.h | 6 ------ src/Math/Constants.h | 27 ++------------------------- src/Math/Test/ConstantsTest.cpp | 10 +--------- 3 files changed, 3 insertions(+), 40 deletions(-) diff --git a/src/Magnum.h b/src/Magnum.h index 2fb91a908..653f66994 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -51,8 +51,6 @@ namespace Magnum { /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT namespace Math { - template constexpr T deg(T value); - template constexpr T rad(T value); template struct Constants; constexpr Rad operator "" _rad(long double); @@ -125,10 +123,6 @@ typedef Math::Geometry::Rectangle Rectangle; /** @brief Integer rectangle */ typedef Math::Geometry::Rectangle Rectanglei; -/* Copying angle converters from Math namespace */ -using Math::deg; -using Math::rad; - /* Using angle literals from Math namespace */ using Math::operator "" _deg; using Math::operator "" _degf; diff --git a/src/Math/Constants.h b/src/Math/Constants.h index d3c2a88cc..7f4e3aa6b 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Math::Constants, functions Magnum::Math::deg(), Magnum::Math::rad() + * @brief Class Magnum::Math::Constants */ namespace Magnum { namespace Math { @@ -34,7 +34,7 @@ template struct Constants { /** * @brief Pi * - * @see deg(), rad() + * @see Deg, Rad */ static inline constexpr T pi(); @@ -60,29 +60,6 @@ template<> struct Constants { }; #endif -/** -@brief Angle in degrees - -Function to make angle entering less error-prone. Converts the value to -radians at compile time. For example `deg(180.0f)` is converted to `3.14f`. - -Usable for entering e.g. rotation: -@code -Matrix4::rotation(deg(30.0f), Vector3::yAxis()); -@endcode - -@see Magnum::deg(), Constants, rad() -*/ -template inline constexpr T deg(T value) { return value*Constants::pi()/180; } - -/** -@brief Angle in radians - -See deg() for more information. -@see Magnum::rad() -*/ -template inline constexpr T rad(T value) { return value; } - }} #endif diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index 1bfe32b72..1354beacf 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -25,12 +25,10 @@ class ConstantsTest: public Corrade::TestSuite::Tester { ConstantsTest(); void constants(); - void degrad(); }; ConstantsTest::ConstantsTest() { - addTests(&ConstantsTest::constants, - &ConstantsTest::degrad); + addTests(&ConstantsTest::constants); } void ConstantsTest::constants() { @@ -41,12 +39,6 @@ void ConstantsTest::constants() { CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0); } -void ConstantsTest::degrad() { - CORRADE_COMPARE(deg(90.0), Constants::pi()/2); - CORRADE_COMPARE(deg(90.0f), Constants::pi()/2); - CORRADE_COMPARE(rad(Constants::pi()/2), Constants::pi()/2); -} - }}} CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) From 0dfa00b24d5b1b613429295727db51ddb6d24b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 21:11:45 +0100 Subject: [PATCH 383/567] Math: minor code cleanup. --- src/Math/Dual.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/Dual.h b/src/Math/Dual.h index b5f70f4b7..5ee1ecdc0 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Math { @tparam T Underlying data type */ template class Dual { - template friend class Dual; + template friend class Dual; public: typedef T Type; /**< @brief Underlying data type */ From c0a5e5dadd339fae9ca35666b2c0ba5762d0ddfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 00:37:55 +0100 Subject: [PATCH 384/567] Math: added sin(), cos() and tan() accepting either Rad or Deg. --- src/Math/Functions.h | 16 ++++++++++++++++ src/Math/Test/FunctionsTest.cpp | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index 7db0b70dc..a887121a8 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -71,6 +71,22 @@ std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number); */ std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number); +/** @brief Sine */ +template inline T sin(Rad angle) { return std::sin(T(angle)); } + +/** @brief Cosine */ +template inline T cos(Rad angle) { return std::cos(T(angle)); } + +/** @brief Tangent */ +template inline T tan(Rad angle) { return std::tan(T(angle)); } + +/** @todo Can't trigonometric functions be done with only one overload? */ +#ifndef DOXYGEN_GENERATING_OUTPUT +template inline T sin(Deg angle) { return sin(Rad(angle)); } +template inline T cos(Deg angle) { return cos(Rad(angle)); } +template inline T tan(Deg angle) { return tan(Rad(angle)); } +#endif + /** @{ @name Scalar/vector functions diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 6fc7ea819..70d261c66 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -40,8 +40,12 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void pow(); void log(); void log2(); + void trigonometric(); }; +typedef Math::Constants Constants; +typedef Math::Deg Deg; +typedef Math::Rad Rad; typedef Math::Vector3 Vector3; typedef Math::Vector3 Vector3ub; typedef Math::Vector3 Vector3b; @@ -60,9 +64,11 @@ FunctionsTest::FunctionsTest() { &FunctionsTest::denormalizeSigned, &FunctionsTest::renormalizeUnsinged, &FunctionsTest::renormalizeSinged, + &FunctionsTest::pow, &FunctionsTest::log, - &FunctionsTest::log2); + &FunctionsTest::log2, + &FunctionsTest::trigonometric); } void FunctionsTest::min() { @@ -242,6 +248,15 @@ void FunctionsTest::log2() { CORRADE_COMPARE(Math::log2(2153), 11); } +void FunctionsTest::trigonometric() { + CORRADE_COMPARE(Math::sin(Deg(30.0f)), 0.5f); + CORRADE_COMPARE(Math::sin(Rad(Constants::pi()/6)), 0.5f); + CORRADE_COMPARE(Math::cos(Deg(60.0f)), 0.5f); + CORRADE_COMPARE(Math::cos(Rad(Constants::pi()/3)), 0.5f); + CORRADE_COMPARE(Math::tan(Deg(45.0f)), 1.0f); + CORRADE_COMPARE(Math::tan(Rad(Constants::pi()/4)), 1.0f); +} + }}} CORRADE_TEST_MAIN(Magnum::Math::Test::FunctionsTest) From d8629fee09d12c4162d5e460ecee915af7e8d20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 01:22:10 +0100 Subject: [PATCH 385/567] Platform: don't allow SDL2 to redefine main(). --- src/Platform/Sdl2Application.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 281f00231..851d0004c 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -22,6 +22,9 @@ #include "Math/Vector2.h" #include "Magnum.h" +#ifdef _WIN32 /* Windows version of SDL2 redefines main(), we don't want that */ +#define SDL_MAIN_HANDLED +#endif #include #include #include From 0e5b676e27dc940b7e840514c1fbf5adb8827c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 01:24:38 +0100 Subject: [PATCH 386/567] Text: don't use HarfBuzz ICU functions. Apparently not needed at all. --- src/Text/TextRenderer.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 8af91b16e..355043860 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -16,7 +16,6 @@ #include "TextRenderer.h" #include -#include #include "Math/Point2D.h" #include "Math/Point3D.h" @@ -53,7 +52,6 @@ class TextLayouter { TextLayouter::TextLayouter(Font& font, const GLfloat size, const std::string& text): font(font), size(size) { /* Prepare HarfBuzz buffer */ buffer = hb_buffer_create(); - hb_buffer_set_unicode_funcs(buffer, hb_icu_get_unicode_funcs()); hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); From 027df556374fd7d01c329b53fbb53628560cc16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 09:40:27 +0100 Subject: [PATCH 387/567] Platform: doc++ --- src/Platform/GlutApplication.h | 2 +- src/Platform/Sdl2Application.h | 2 +- src/Platform/WindowlessGlxApplication.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 8345a4f13..06c91984f 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -42,7 +42,7 @@ changing cursor and mouse tracking and warping. @section GlutApplication-usage Usage You need to implement at least drawEvent() and viewportEvent() to be able to -draw on the screen. The subclass can be then used directly in `main()` - see +draw on the screen. The subclass can be then used directly in `main()` -- see convenience macro MAGNUM_GLUTAPPLICATION_MAIN(). @code class MyApplication: public Magnum::Platform::GlutApplication { diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 851d0004c..59f11c881 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -45,7 +45,7 @@ buffer. Supports keyboard and mouse handling. @section Sdl2Application-usage Usage You need to implement at least drawEvent() and viewportEvent() to be able to -draw on the screen. The subclass can be then used directly in `main()` - see +draw on the screen. The subclass can be then used directly in `main()` -- see convenience macro MAGNUM_SDL2APPLICATION_MAIN(). @code class MyApplication: public Magnum::Platform::Sdl2Application { diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index e3e2d2e39..1722e82e3 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -37,7 +37,7 @@ namespace Magnum { namespace Platform { @section WindowlessGlxApplication-usage Usage Place your code into exec(). The subclass can be then used directly in -`main()` - see convenience macro MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(). +`main()` -- see convenience macro MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(). @code class MyApplication: public Magnum::Platform::WindowlessGlxApplication { // implement required methods... From 3cbeb43078461fe836cb873688ee78a68cd41d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 10:25:30 +0100 Subject: [PATCH 388/567] Cleaned up includes. --- src/Math/Test/DualQuaternionTest.cpp | 1 - src/Math/Test/Matrix3Test.cpp | 1 - src/Math/Test/Matrix4Test.cpp | 1 - src/Math/Test/QuaternionTest.cpp | 1 - src/Math/Test/VectorTest.cpp | 1 - src/Physics/Capsule.cpp | 1 - src/Physics/Sphere.cpp | 1 - src/Physics/Test/AxisAlignedBoxTest.cpp | 1 - src/Physics/Test/CapsuleTest.cpp | 1 - src/Physics/Test/LineTest.cpp | 1 - src/Physics/Test/PlaneTest.cpp | 1 - src/Physics/Test/SphereTest.cpp | 1 - src/Primitives/Capsule.cpp | 1 - src/Primitives/Cylinder.cpp | 1 - src/SceneGraph/Test/CameraTest.cpp | 1 - src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp | 1 - src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp | 1 - src/SceneGraph/Test/MatrixTransformation2DTest.cpp | 1 - src/SceneGraph/Test/MatrixTransformation3DTest.cpp | 1 - src/SceneGraph/Test/ObjectTest.cpp | 1 - 20 files changed, 20 deletions(-) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index ae44c49cd..4f905bf3f 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -16,7 +16,6 @@ #include #include -#include "Math/Constants.h" #include "Math/DualQuaternion.h" namespace Magnum { namespace Math { namespace Test { diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index f0126f04f..47e5a8194 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -17,7 +17,6 @@ #include #include -#include "Math/Constants.h" #include "Math/Matrix3.h" namespace Magnum { namespace Math { namespace Test { diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 951b4b0c9..afd0a9247 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -17,7 +17,6 @@ #include #include -#include "Math/Constants.h" #include "Math/Matrix4.h" namespace Magnum { namespace Math { namespace Test { diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index acf98e833..9fd3b6fdf 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -16,7 +16,6 @@ #include #include -#include "Math/Constants.h" #include "Math/Matrix4.h" #include "Math/Quaternion.h" diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 8772c487b..4c5273d99 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -17,7 +17,6 @@ #include #include -#include "Math/Constants.h" #include "Math/Vector.h" namespace Magnum { namespace Math { namespace Test { diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index fd3fc9d79..9fcf061c8 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -15,7 +15,6 @@ #include "Capsule.h" -#include "Math/Constants.h" #include "Math/Functions.h" #include "Math/Matrix3.h" #include "Math/Matrix4.h" diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index a307844d0..f5c7e5d51 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -15,7 +15,6 @@ #include "Sphere.h" -#include "Math/Constants.h" #include "Math/Functions.h" #include "Math/Matrix3.h" #include "Math/Matrix4.h" diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index 700822895..ec8b0fde4 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "Math/Matrix4.h" #include "Physics/AxisAlignedBox.h" #include "Physics/Point.h" diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index a3b0f9c16..6d0233a45 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -13,7 +13,6 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Math/Constants.h" #include "Physics/Capsule.h" #include "Physics/Point.h" #include "Physics/Sphere.h" diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 6f67631b8..31cb982cb 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "Math/Matrix4.h" #include "Physics/Line.h" diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index 14962e1de..81d021ada 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -13,7 +13,6 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Math/Constants.h" #include "Physics/LineSegment.h" #include "Physics/Point.h" #include "Physics/Plane.h" diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index a19477ac4..544fc802e 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -13,7 +13,6 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Math/Constants.h" #include "Physics/LineSegment.h" #include "Physics/Point.h" #include "Physics/Sphere.h" diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 94863a6d3..6a0c45b58 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -15,7 +15,6 @@ #include "Capsule.h" -#include "Math/Constants.h" #include "Math/Point3D.h" namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 0b9b2488d..d62848917 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -15,7 +15,6 @@ #include "Cylinder.h" -#include "Math/Constants.h" #include "Math/Point3D.h" namespace Magnum { namespace Primitives { diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 61f52a5cd..a5d504365 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "SceneGraph/AbstractCamera.hpp" /* only for aspectRatioFix(), so it doesn't have to be exported */ #include "SceneGraph/Camera2D.h" #include "SceneGraph/Camera3D.h" diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp index 6ae1df500..7c8a112a1 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "SceneGraph/EuclideanMatrixTransformation2D.h" #include "SceneGraph/Scene.h" diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp index 207b0d832..63d16772e 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "SceneGraph/EuclideanMatrixTransformation3D.h" #include "SceneGraph/Scene.h" diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp index 9b67c6fbf..617743c4b 100644 --- a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "SceneGraph/MatrixTransformation2D.h" #include "SceneGraph/Scene.h" diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index 8f664a80b..9844869a2 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -15,7 +15,6 @@ #include -#include "Math/Constants.h" #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 14d241fbc..227a387e6 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -16,7 +16,6 @@ #include #include -#include "Math/Constants.h" #include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/Scene.h" From 92fb2243804e860e4b742aa835a42394f59858cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 11:30:21 +0100 Subject: [PATCH 389/567] Partially revert "Work-around preprocessor issues on Windows." Commit 99be617278cfcc398dd2cae1f23dd90fe2dacbed moved the #undef from SceneGraph/Camera3D.h to Math/Matrix4.h, but it seems that it needs to be in both places. --- src/Math/Matrix4.h | 2 +- src/SceneGraph/Camera3D.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 757ebab21..937fba39e 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -22,7 +22,7 @@ #include "Matrix.h" #include "Point3D.h" -#ifdef WIN32 /* I so HATE windows.h */ +#ifdef _WIN32 /* I so HATE windows.h */ #undef near #undef far #endif diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index d10124ac2..70a7258fe 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -21,6 +21,11 @@ #include "AbstractCamera.h" +#ifdef _WIN32 /* I so HATE windows.h */ +#undef near +#undef far +#endif + namespace Magnum { namespace SceneGraph { /** From 1cf2087817ba995f1f7d5a5f41b659380fc1087b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 11:32:52 +0100 Subject: [PATCH 390/567] Text: code cleanup -- merged two loops into one. --- src/Text/Font.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index cffabf54b..fccfc62e3 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -62,21 +62,16 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { /** @bug Crash when atlas is too small */ - /* Get character codes from string */ - std::vector charCodes; - charCodes.reserve(characters.size()); + /* Get glyph codes from characters */ + std::vector charIndices; + charIndices.reserve(characters.size()+1); + charIndices.push_back(0); for(std::size_t i = 0; i != characters.size(); ) { std::uint32_t codepoint; std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(characters, i); - charCodes.push_back(codepoint); + charIndices.push_back(FT_Get_Char_Index(_ftFont, codepoint)); } - /* Get character indices */ - std::vector charIndices; - charIndices.push_back(0); - for(std::uint32_t charCode: charCodes) - charIndices.push_back(FT_Get_Char_Index(_ftFont, charCode)); - /* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */ std::sort(charIndices.begin(), charIndices.end()); charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end()); From b38ec8152bd7c3400b1961ef74749477b418d02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 11:35:50 +0100 Subject: [PATCH 391/567] Text: ability to compile the library without HarfBuzz support. The text will be rendered without all the nifty features like kerning and it will most probably fail on everything non-latin, but HarfBuzz is currently PITA on some systems. HarfBuzz usage can be configured using USE_HARFBUZZ CMake option. --- CMakeLists.txt | 6 +++++ modules/FindMagnum.cmake | 2 +- src/Text/CMakeLists.txt | 12 +++++++--- src/Text/Font.cpp | 16 ++++++++++++- src/Text/Font.h | 10 ++++++-- src/Text/TextRenderer.cpp | 46 +++++++++++++++++++++++++++++++++++-- src/magnumConfigure.h.cmake | 1 + 7 files changed, 84 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b24e7f526..94132ebeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,9 @@ cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" OFF "NOT W cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) +# Library features +cmake_dependent_option(USE_HARFBUZZ "Use HarfBuzz in Text library" ON "WITH_TEXT" OFF) + if(${CMAKE_SYSTEM_NAME} STREQUAL NaCl) option(WITH_NACLAPPLICATION "Build NaClApplication library" OFF) else() @@ -66,6 +69,9 @@ endif() if(TARGET_DESKTOP_GLES) set(MAGNUM_TARGET_DESKTOP_GLES 1) endif() +if(USE_HARFBUZZ) + set(MAGNUM_USE_HARFBUZZ 1) +endif() # Installation paths set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 0774bc391..51f01af9b 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -23,7 +23,7 @@ # SceneGraph - Scene graph library # Shaders - Library with stock shaders # Text - Text rendering library (depends on TextureTools component, -# HarfBuzz and FreeType library) +# FreeType library and possibly HarfBuzz library) # TextureTools - TextureTools library # GlxApplication - GLX application (depends on X11 libraries) # XEglApplication - X/EGL application (depends on EGL and X11 libraries) diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index 26f254e3f..c97dcaed0 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -1,7 +1,10 @@ find_package(Freetype REQUIRED) -find_package(HarfBuzz REQUIRED) +include_directories(${FREETYPE_INCLUDE_DIRS}) -include_directories(${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS}) +if(USE_HARFBUZZ) + find_package(HarfBuzz REQUIRED) + include_directories(${HARFBUZZ_INCLUDE_DIRS}) +endif() set(MagnumText_SRCS Font.cpp @@ -17,7 +20,10 @@ set(MagnumText_HEADERS add_library(MagnumText SHARED ${MagnumText_SRCS}) -target_link_libraries(MagnumText Magnum MagnumTextureTools ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES}) +target_link_libraries(MagnumText Magnum MagnumTextureTools ${FREETYPE_LIBRARIES}) +if(USE_HARFBUZZ) + target_link_libraries(MagnumText ${HARFBUZZ_LIBRARIES}) +endif() install(TARGETS MagnumText DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumText_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Text) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index fccfc62e3..1b77e1442 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -18,7 +18,9 @@ #include #include #include FT_FREETYPE_H +#ifdef MAGNUM_USE_HARFBUZZ #include +#endif #include #include "Extensions.h" @@ -42,8 +44,10 @@ Font::Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSi void Font::finishConstruction() { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); + #ifdef MAGNUM_USE_HARFBUZZ /* Create Harfbuzz font */ _hbFont = hb_ft_font_create(_ftFont, nullptr); + #endif #ifndef MAGNUM_TARGET_GLES MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); @@ -126,18 +130,26 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { void Font::destroy() { if(!_ftFont) return; + #ifdef MAGNUM_USE_HARFBUZZ hb_font_destroy(_hbFont); + #endif FT_Done_Face(_ftFont); } void Font::move() { + #ifdef MAGNUM_USE_HARFBUZZ _hbFont = nullptr; + #endif _ftFont = nullptr; } Font::~Font() { destroy(); } -Font::Font(Font&& other): glyphs(std::move(other.glyphs)), _texture(std::move(other._texture)), _ftFont(other._ftFont), _hbFont(other._hbFont), _size(other._size) { +Font::Font(Font&& other): glyphs(std::move(other.glyphs)), _texture(std::move(other._texture)), _ftFont(other._ftFont), _size(other._size) + #ifdef MAGNUM_USE_HARFBUZZ + , _hbFont(other._hbFont) + #endif +{ other.move(); } @@ -147,7 +159,9 @@ Font& Font::operator=(Font&& other) { glyphs = std::move(other.glyphs); _texture = std::move(other._texture); _ftFont = other._ftFont; + #ifdef MAGNUM_USE_HARFBUZZ _hbFont = other._hbFont; + #endif _size = other._size; other.move(); diff --git a/src/Text/Font.h b/src/Text/Font.h index 1c12d55f2..208b6d0db 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -122,8 +122,12 @@ class MAGNUM_TEXT_EXPORT Font { /** @brief %Font texture atlas */ inline Texture2D& texture() { return _texture; } - /** @brief HarfBuzz font handle */ + /** @brief Font handle */ + #ifdef MAGNUM_USE_HARFBUZZ inline hb_font_t* font() { return _hbFont; } + #else + inline FT_Face font() { return _ftFont; } + #endif private: void MAGNUM_TEXT_LOCAL finishConstruction(); @@ -133,8 +137,10 @@ class MAGNUM_TEXT_EXPORT Font { std::unordered_map> glyphs; Texture2D _texture; FT_Face _ftFont; - hb_font_t* _hbFont; GLfloat _size; + #ifdef MAGNUM_USE_HARFBUZZ + hb_font_t* _hbFont; + #endif }; }} diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 355043860..4e54b86d7 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -15,7 +15,13 @@ #include "TextRenderer.h" +#ifdef MAGNUM_USE_HARFBUZZ #include +#else +#include +#include FT_FREETYPE_H +#include +#endif #include "Math/Point2D.h" #include "Math/Point3D.h" @@ -36,20 +42,33 @@ class TextLayouter { ~TextLayouter(); - inline std::uint32_t glyphCount() { return _glyphCount; } + inline std::uint32_t glyphCount() { + #ifdef MAGNUM_USE_HARFBUZZ + return _glyphCount; + #else + return glyphs.size(); + #endif + } std::tuple renderGlyph(const Vector2& cursorPosition, const std::uint32_t i); private: + #ifdef MAGNUM_USE_HARFBUZZ const Font& font; - const GLfloat size; hb_buffer_t* buffer; hb_glyph_info_t* glyphInfo; hb_glyph_position_t* glyphPositions; std::uint32_t _glyphCount; + #else + Font& font; + std::vector glyphs; + #endif + + const GLfloat size; }; TextLayouter::TextLayouter(Font& font, const GLfloat size, const std::string& text): font(font), size(size) { + #ifdef MAGNUM_USE_HARFBUZZ /* Prepare HarfBuzz buffer */ buffer = hb_buffer_create(); hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); @@ -62,23 +81,46 @@ TextLayouter::TextLayouter(Font& font, const GLfloat size, const std::string& te glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); + #else + /* Get glyph codes from characters */ + glyphs.reserve(text.size()+1); + for(std::size_t i = 0; i != text.size(); ) { + std::uint32_t codepoint; + std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); + glyphs.push_back(FT_Get_Char_Index(font.font(), codepoint)); + } + #endif } TextLayouter::~TextLayouter() { + #ifdef MAGNUM_USE_HARFBUZZ /* Destroy HarfBuzz buffer */ hb_buffer_destroy(buffer); + #endif } std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const std::uint32_t i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle texturePosition, textureCoordinates; + #ifdef MAGNUM_USE_HARFBUZZ std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; + #else + std::tie(texturePosition, textureCoordinates) = font[glyphs[i]]; + #endif + #ifdef MAGNUM_USE_HARFBUZZ /* Glyph offset and advance to next glyph in normalized coordinates */ Vector2 offset = Vector2(glyphPositions[i].x_offset, glyphPositions[i].y_offset)/(64*font.size()); Vector2 advance = Vector2(glyphPositions[i].x_advance, glyphPositions[i].y_advance)/(64*font.size()); + #else + /* Load glyph */ + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(font.font(), glyphs[i], FT_LOAD_DEFAULT) == 0); + const FT_GlyphSlot slot = font.font()->glyph; + Vector2 offset = Vector2(0, 0); /** @todo really? */ + Vector2 advance = Vector2(slot->advance.x, slot->advance.y)/(64*font.size()); + #endif /* Absolute quad position, composed from cursor position, glyph offset and texture position, denormalized to requested text size */ diff --git a/src/magnumConfigure.h.cmake b/src/magnumConfigure.h.cmake index 18f0ef842..61279ff38 100644 --- a/src/magnumConfigure.h.cmake +++ b/src/magnumConfigure.h.cmake @@ -2,3 +2,4 @@ #cmakedefine MAGNUM_TARGET_GLES2 #cmakedefine MAGNUM_TARGET_DESKTOP_GLES #cmakedefine MAGNUM_TARGET_NACL +#cmakedefine MAGNUM_USE_HARFBUZZ From 8e3005d6257ec5e01eeeb96db424efe62fac99aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 12:46:46 +0100 Subject: [PATCH 392/567] Updated FindGLEW.cmake, fixed Windows support. On Win it needs both *.dll and *.lib to be successfully linked, currently the variables must be set manually. --- modules/FindGLEW.cmake | 48 +++++++++++++++++++++++----------------- modules/FindMagnum.cmake | 2 +- src/CMakeLists.txt | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/modules/FindGLEW.cmake b/modules/FindGLEW.cmake index abc1b044a..ef623d969 100644 --- a/modules/FindGLEW.cmake +++ b/modules/FindGLEW.cmake @@ -3,33 +3,41 @@ # This module defines: # # GLEW_FOUND - True if GLEW library is found -# GLEW_LIBRARY - GLEW dynamic library +# GLEW_LIBRARIES - GLEW libraries # GLEW_INCLUDE_DIR - Include dir # -if(GLEW_LIBRARY AND GLEW_INCLUDE_DIR) - - set(GLEW_FOUND TRUE) +# Include dir +find_path(GLEW_INCLUDE_DIR + NAMES GL/glew.h) +# Library +if(NOT WIN32) + find_library(GLEW_LIBRARY GLEW) + set(GLEW_LIBRARIES_ GLEW_LIBRARY) + mark_as_advanced(GLEW_LIBRARY) else() + find_library(GLEW_LIBRARY_DLL glew32) + find_library(GLEW_LIBRARY_LIB glew32) + set(GLEW_LIBRARIES_ GLEW_LIBRARY_DLL GLEW_LIBRARY_LIB) + mark_as_advanced(GLEW_LIBRARY_DLL GLEW_LIBRARY_LIB) +endif() - # Library - if(NOT WIN32) - find_library(GLEW_LIBRARY GLEW) - else() - find_library(GLEW_LIBRARY glew32) - endif() +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args("GLEW" DEFAULT_MSG + ${GLEW_LIBRARIES_} + GLEW_INCLUDE_DIR) - # Include dir - find_path(GLEW_INCLUDE_DIR - NAMES glew.h - PATH_SUFFIXES GL - ) +if(NOT GLEW_FOUND) + return() +endif() - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args("GLEW" DEFAULT_MSG - GLEW_LIBRARY - GLEW_INCLUDE_DIR - ) +unset(GLEW_LIBRARIES_) +if(NOT WIN32) + set(GLEW_LIBRARIES ${GLEW_LIBRARY}) + mark_as_advanced(GLEW_LIBRARY) +else() + set(GLEW_LIBRARIES ${GLEW_LIBRARY_DLL} ${GLEW_LIBRARY_LIB}) + mark_as_advanced(GLEW_LIBRARY_DLL GLEW_LIBRARY_LIB) endif() diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 51f01af9b..55ec02cf1 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -262,7 +262,7 @@ else() set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${OPENGLES2_LIBRARY}) endif() if(NOT MAGNUM_TARGET_GLES) - set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${GLEW_LIBRARY}) + set(MAGNUM_LIBRARIES ${MAGNUM_LIBRARIES} ${GLEW_LIBRARIES}) endif() # Installation dirs diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 788f83301..ed0ce0c4a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -124,7 +124,7 @@ else() set(Magnum_LIBS ${Magnum_LIBS} ${OPENGLES2_LIBRARY}) endif() if(NOT TARGET_GLES) - set(Magnum_LIBS ${Magnum_LIBS} ${GLEW_LIBRARY}) + set(Magnum_LIBS ${Magnum_LIBS} ${GLEW_LIBRARIES}) endif() target_link_libraries(Magnum ${Magnum_LIBS}) From 122b1f3bbd18b986cc47f0803b54013525a4fdd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 14:57:27 +0100 Subject: [PATCH 393/567] Require HarfBuzz in FindMagnum.cmake only if it was compiled with it. --- modules/FindMagnum.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 55ec02cf1..240c27e83 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -90,6 +90,10 @@ string(FIND "${_magnumConfigure}" "#define MAGNUM_TARGET_DESKTOP_GLES" _TARGET_D if(NOT _TARGET_DESKTOP_GLES EQUAL -1) set(MAGNUM_TARGET_DESKTOP_GLES 1) endif() +string(FIND "${_magnumConfigure}" "#define MAGNUM_USE_HARFBUZZ" _USE_HARFBUZZ) +if(NOT _USE_HARFBUZZ EQUAL -1) + set(MAGNUM_USE_HARFBUZZ 1) +endif() if(NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES) find_package(OpenGL REQUIRED) @@ -212,10 +216,15 @@ foreach(component ${Magnum_FIND_COMPONENTS}) # Dependencies find_package(FreeType) - find_package(HarfBuzz) - if(NOT FREETYPE_FOUND OR NOT HARFBUZZ_FOUND) + if(NOT FREETYPE_FOUND) unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() + if(MAGNUM_USE_HARFBUZZ) + find_package(HarfBuzz) + if(NOT HARFBUZZ_FOUND) + unset(MAGNUM_${_COMPONENT}_LIBRARY) + endif() + endif() endif() # TextureTools library From 27020f62c18475d492ebaa72a53deb5578047601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 15:04:10 +0100 Subject: [PATCH 394/567] Updated documentation on building and library finding. --- doc/building.dox | 9 +++++++++ modules/FindMagnum.cmake | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/building.dox b/doc/building.dox index 863c405ad..9d84d17ca 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -81,9 +81,18 @@ specify which parts will be built and which not: - `WITH_PRIMITIVES` - Primitives library. - `WITH_SCENEGRAPH` - SceneGraph library. - `WITH_SHADERS` - Shaders library. + - `WITH_TEXT` - Text library. Enables also building of TextureTools. Requires + **FreeType** and possibly **HarfBuzz** library (see below). + - `WITH_TEXTURETOOLS` - TextureTools library. - `WITH_MAGNUMINFO` - `magnum-info` executable, provides information about Magnum engine and OpenGL capabilities. +Some dependencies are optional, although disabling them might reduce some +functionality: + + - `USE_HARFBUZZ` - Defaults to `ON`, disabling it will result in worse text + rendering (no kerning & ligatures) and possible issues with non-Latin text. + None of the application libraries is built by default, regardless to `WITH_EVERYTHING` is enabled or not: diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 240c27e83..4f9d96e06 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -23,7 +23,7 @@ # SceneGraph - Scene graph library # Shaders - Library with stock shaders # Text - Text rendering library (depends on TextureTools component, -# FreeType library and possibly HarfBuzz library) +# FreeType library and possibly HarfBuzz library, see below) # TextureTools - TextureTools library # GlxApplication - GLX application (depends on X11 libraries) # XEglApplication - X/EGL application (depends on EGL and X11 libraries) @@ -41,6 +41,14 @@ # MAGNUM_*_LIBRARIES - Component library and dependent libraries # MAGNUM_*_INCLUDE_DIRS - Include dirs of module dependencies # +# Features of found Magnum library are exposed in these variables: +# MAGNUM_TARGET_GLES - Defined if compiled for OpenGL ES +# MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0 +# MAGNUM_TARGET_DESKTOP_GLES - Defined if compiled with OpenGL ES emulation +# on desktop OpenGL +# MAGNUM_TARGET_NACL - Defined if compiled for Google Chrome Native Client +# MAGNUM_USE_HARFBUZZ - Defined if HarfBuzz library is used for text rendering +# # Additionally these variables are defined for internal usage: # MAGNUM_INCLUDE_DIR - Root include dir (w/o # dependencies) From b54f53743ec0db0931d369c2b68f1cf72962b454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 15:27:03 +0100 Subject: [PATCH 395/567] Platform: expose MAGNUM_USE_HARFBUZZ in magnum-info utility. --- src/Platform/magnum-info.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index 8418c8283..f3477c265 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -41,6 +41,9 @@ MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, a { Debug d; d << "Compilation flags:"; + #ifdef CORRADE_GCC46_COMPATIBILITY + d << "CORRADE_GCC46_COMPATIBILITY"; + #endif #ifdef MAGNUM_TARGET_GLES d << "MAGNUM_TARGET_GLES"; #endif @@ -53,8 +56,8 @@ MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, a #ifdef MAGNUM_TARGET_NACL d << "MAGNUM_TARGET_NACL"; #endif - #ifdef CORRADE_GCC46_COMPATIBILITY - d << "CORRADE_GCC46_COMPATIBILITY"; + #ifdef MAGNUM_USE_HARFBUZZ + d << "MAGNUM_USE_HARFBUZZ"; #endif } Debug() << ""; From d1a1b954dcae6010e2082423d89630e2954ce6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 15:29:10 +0100 Subject: [PATCH 396/567] Primitives: using strongly-typed angles. --- src/Primitives/Capsule.cpp | 29 +++++++++++++++-------------- src/Primitives/Capsule.h | 2 +- src/Primitives/Cylinder.cpp | 7 ++++--- src/Primitives/UVSphere.cpp | 6 +++--- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 6a0c45b58..edd224a53 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -15,6 +15,7 @@ #include "Capsule.h" +#include "Math/Functions.h" #include "Math/Point3D.h" namespace Magnum { namespace Primitives { @@ -24,13 +25,13 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std GLfloat height = 2.0f+length; GLfloat hemisphereTextureCoordsVIncrement = 1.0f/(hemisphereRings*height); - GLfloat hemisphereRingAngleIncrement = Constants::pi()/(2*hemisphereRings); + Rad hemisphereRingAngleIncrement = Rad(Constants::pi())/(2*hemisphereRings); /* Bottom cap vertex */ capVertex(-height/2, -1.0f, 0.0f); /* Rings of bottom hemisphere */ - hemisphereVertexRings(hemisphereRings-1, -length/2, -Constants::pi()/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); + hemisphereVertexRings(hemisphereRings-1, -length/2, -Rad(Constants::pi())/2+hemisphereRingAngleIncrement, hemisphereRingAngleIncrement, hemisphereTextureCoordsVIncrement, hemisphereTextureCoordsVIncrement); /* Rings of cylinder */ cylinderVertexRings(cylinderRings+1, -length/2, length/cylinderRings, 1.0f/height, length/(cylinderRings*height)); @@ -57,18 +58,18 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { textureCoords2D(0)->push_back({0.5, textureCoordsV}); } -void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { - GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; +void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, Rad startRingAngle, Rad ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { + Rad segmentAngleIncrement = 2*Rad(Constants::pi())/segments; GLfloat x, y, z; for(std::uint32_t i = 0; i != count; ++i) { - GLfloat ringAngle = startRingAngle + i*ringAngleIncrement; - x = z = std::cos(ringAngle); - y = std::sin(ringAngle); + Rad ringAngle = startRingAngle + i*ringAngleIncrement; + x = z = Math::cos(ringAngle); + y = Math::sin(ringAngle); for(std::uint32_t j = 0; j != segments; ++j) { - GLfloat segmentAngle = j*segmentAngleIncrement; - positions(0)->push_back({x*std::sin(segmentAngle), centerY+y, z*std::cos(segmentAngle)}); - normals(0)->push_back({x*std::sin(segmentAngle), y, z*std::cos(segmentAngle)}); + Rad segmentAngle = j*segmentAngleIncrement; + positions(0)->push_back({x*Math::sin(segmentAngle), centerY+y, z*Math::cos(segmentAngle)}); + normals(0)->push_back({x*Math::sin(segmentAngle), y, z*Math::cos(segmentAngle)}); if(textureCoords == TextureCoords::Generate) textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement}); @@ -84,12 +85,12 @@ void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloa } void Capsule::cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { - GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; + Rad segmentAngleIncrement = 2*Rad(Constants::pi())/segments; for(std::uint32_t i = 0; i != count; ++i) { for(std::uint32_t j = 0; j != segments; ++j) { - GLfloat segmentAngle = j*segmentAngleIncrement; - positions(0)->push_back({std::sin(segmentAngle), startY, std::cos(segmentAngle)}); - normals(0)->push_back({std::sin(segmentAngle), 0.0f, std::cos(segmentAngle)}); + Rad segmentAngle = j*segmentAngleIncrement; + positions(0)->push_back({Math::sin(segmentAngle), startY, Math::cos(segmentAngle)}); + normals(0)->push_back({Math::sin(segmentAngle), 0.0f, Math::cos(segmentAngle)}); if(textureCoords == TextureCoords::Generate) textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement}); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index a9cd054da..1ae25f78b 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -61,7 +61,7 @@ class Capsule: public Trade::MeshData3D { Capsule(std::uint32_t segments, TextureCoords textureCoords); void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV); - void hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void hemisphereVertexRings(std::uint32_t count, GLfloat centerY, Rad startRingAngle, Rad ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void bottomFaceRing(); void faceRings(std::uint32_t count, std::uint32_t offset = 1); diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index d62848917..406ecbd24 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -15,6 +15,7 @@ #include "Cylinder.h" +#include "Math/Functions.h" #include "Math/Point3D.h" namespace Magnum { namespace Primitives { @@ -47,11 +48,11 @@ Cylinder::Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, } void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { - GLfloat segmentAngleIncrement = 2*Constants::pi()/segments; + Rad segmentAngleIncrement = 2*Rad(Constants::pi())/segments; for(std::uint32_t i = 0; i != segments; ++i) { - GLfloat segmentAngle = i*segmentAngleIncrement; - positions(0)->push_back({std::sin(segmentAngle), y, std::cos(segmentAngle)}); + Rad segmentAngle = i*segmentAngleIncrement; + positions(0)->push_back({Math::sin(segmentAngle), y, Math::cos(segmentAngle)}); normals(0)->push_back(normal); if(textureCoords == TextureCoords::Generate) diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 5d181dd79..0746be437 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -15,7 +15,7 @@ #include "UVSphere.h" -#include "Math/Constants.h" +#include "Math/Angle.h" namespace Magnum { namespace Primitives { @@ -23,13 +23,13 @@ UVSphere::UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords te CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", ); GLfloat textureCoordsVIncrement = 1.0f/rings; - GLfloat ringAngleIncrement = Constants::pi()/rings; + Rad ringAngleIncrement = Rad(Constants::pi())/rings; /* Bottom cap vertex */ capVertex(-1.0f, -1.0f, 0.0f); /* Vertex rings */ - hemisphereVertexRings(rings-1, 0.0f, -Constants::pi()/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); + hemisphereVertexRings(rings-1, 0.0f, -Rad(Constants::pi())/2+ringAngleIncrement, ringAngleIncrement, textureCoordsVIncrement, textureCoordsVIncrement); /* Top cap vertex */ capVertex(1.0f, 1.0f, 1.0f); From 62ec12cf75c3735e95bb382fa29223e0377c12e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 20:46:58 +0100 Subject: [PATCH 397/567] Added typedefs for double-precision vector and matrix types. --- src/Magnum.h | 29 ++++++++++++++++++++++++----- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 3 ++- src/Math/Vector2.h | 2 +- src/Math/Vector3.h | 2 +- src/Math/Vector4.h | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Magnum.h b/src/Magnum.h index 653f66994..afe726912 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -65,13 +65,13 @@ using Corrade::Utility::Warning; using Corrade::Utility::Error; #endif -/** @brief Two-component floating-point vector */ +/** @brief Two-component float vector */ typedef Math::Vector2 Vector2; -/** @brief Three-component floating-point vector */ +/** @brief Three-component float vector */ typedef Math::Vector3 Vector3; -/** @brief Four-component floating-point vector */ +/** @brief Four-component float vector */ typedef Math::Vector4 Vector4; /** @brief Two-component signed integer vector */ @@ -92,18 +92,37 @@ typedef Math::Vector3 Vector3ui; /** @brief Four-component unsigned integer vector */ typedef Math::Vector4 Vector4ui; +#ifndef MAGNUM_TARGET_GLES +/** @brief Two-component double vector */ +typedef Math::Vector2 Vector2d; + +/** @brief Three-component double vector */ +typedef Math::Vector3 Vector3d; + +/** @brief Four-component double vector */ +typedef Math::Vector4 Vector4d; +#endif + /** @brief Two-dimensional floating-point homogeneous coordinates */ typedef Math::Point2D Point2D; /** @brief Three-dimensional floating-point homogeneous coordinates */ typedef Math::Point3D Point3D; -/** @brief 3x3 floating-point matrix */ +/** @brief 3x3 float matrix */ typedef Math::Matrix3 Matrix3; -/** @brief 4x4 floating-point matrix */ +/** @brief 4x4 float matrix */ typedef Math::Matrix4 Matrix4; +#ifndef MAGNUM_TARGET_GLES +/** @brief 3x3 double matrix */ +typedef Math::Matrix3 Matrix3d; + +/** @brief 4x4 double matrix */ +typedef Math::Matrix4 Matrix4d; +#endif + /** @brief Quaternion */ typedef Math::Quaternion Quaternion; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index a67efd47f..59398a3ad 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Math { @tparam T Underlying data type Represents 2D transformation. See @ref matrix-vector for brief introduction. -@see Magnum::Matrix3, SceneGraph::MatrixTransformation2D +@see Magnum::Matrix3, Magnum::Matrix3d, SceneGraph::MatrixTransformation2D @configurationvalueref{Magnum::Math::Matrix3} */ template class Matrix3: public Matrix<3, T> { diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 937fba39e..9e278dfc3 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -34,7 +34,8 @@ namespace Magnum { namespace Math { @tparam T Underlying data type Represents 3D transformation. See @ref matrix-vector for brief introduction. -@see Magnum::Matrix4, DualQuaternion, SceneGraph::MatrixTransformation3D +@see Magnum::Matrix4, Magnum::Matrix4d, DualQuaternion, + SceneGraph::MatrixTransformation3D @configurationvalueref{Magnum::Math::Matrix4} */ template class Matrix4: public Matrix<4, T> { diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 371788021..64f9cc368 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Math { @tparam T Data type See @ref matrix-vector for brief introduction. -@see Magnum::Vector2, Magnum::Vector2i, Magnum::Vector2ui +@see Magnum::Vector2, Magnum::Vector2i, Magnum::Vector2ui, Magnum::Vector2d @configurationvalueref{Magnum::Math::Vector2} */ template class Vector2: public Vector<2, T> { diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index d54f96f37..cb2c2486b 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Math { See @ref matrix-vector for brief introduction. See also Point2D for homogeneous two-dimensional coordinates. -@see Magnum::Vector3, Magnum::Vector3i, Magnum::Vector3ui +@see Magnum::Vector3, Magnum::Vector3i, Magnum::Vector3ui, Magnum::Vector3d @configurationvalueref{Magnum::Math::Vector3} */ template class Vector3: public Vector<3, T> { diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 29b4dc829..9c45d24b0 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Math { See @ref matrix-vector for brief introduction. See also Point3D for homogeneous three-dimensional coordinates. -@see Magnum::Vector4, Magnum::Vector4i, Magnum::Vector4ui +@see Magnum::Vector4, Magnum::Vector4i, Magnum::Vector4ui, Magnum::Vector4d @configurationvalueref{Magnum::Math::Vector4} */ template class Vector4: public Vector<4, T> { From 77d9773d37d839bfcdb049ba16db897e83beefd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 20:50:04 +0100 Subject: [PATCH 398/567] Removed linkage of AbstractShaderProgram::Attribute::Location. It now doesn't appear in symbol lists, avoiding nasty linker issues. --- src/AbstractShaderProgram.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 3fd055743..cf2abb445 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -320,8 +320,9 @@ class MAGNUM_EXPORT AbstractShaderProgram { */ template class Attribute { public: - /** @brief Location to which the attribute is bound */ - static const GLuint Location = location; + enum: GLuint { + Location = location /**< Location to which the attribute is bound */ + }; /** * @brief Type From 24bd924aa5bac7cf6715780909182449394c367a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 20:52:48 +0100 Subject: [PATCH 399/567] Consistent naming of attribute types in AbstractShaderProgram. --- src/AbstractShaderProgram.cpp | 4 ++-- src/AbstractShaderProgram.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 2f390ade3..664a6e800 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -657,8 +657,8 @@ std::size_t Attribute>::size(GLint components, DataType #endif #ifndef MAGNUM_TARGET_GLES2 - case DataType::UnsignedInt2101010REV: - case DataType::Int2101010REV: + case DataType::UnsignedInt2101010Rev: + case DataType::Int2101010Rev: CORRADE_INTERNAL_ASSERT(components == 4); return 4; #endif diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index cf2abb445..d69bf7fc9 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -352,7 +352,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl30 %Extension @extension{NV,half_float} * @requires_gles30 %Extension @es_extension{OES,vertex_half_float} */ - Half = GL_HALF_FLOAT, + HalfFloat = GL_HALF_FLOAT, /** Float. Only for float attribute types. */ Float = GL_FLOAT, @@ -375,7 +375,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl33 %Extension @extension{ARB,vertex_type_2_10_10_10_rev} * @requires_gles30 (no extension providing this functionality) */ - UnsignedInt2101010REV = GL_UNSIGNED_INT_2_10_10_10_REV, + UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, /** * Signed 2.10.10.10 packed integer. Only for @@ -383,7 +383,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl33 %Extension @extension{ARB,vertex_type_2_10_10_10_rev} * @requires_gles30 (no extension providing this functionality) */ - Int2101010REV = GL_INT_2_10_10_10_REV + Int2101010Rev = GL_INT_2_10_10_10_REV #endif }; #else From 3379e6c7943fb4c812593aecbe4918550ec9df9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 20:54:22 +0100 Subject: [PATCH 400/567] Ability to send less than all attribute components to the shader. Remaining unspecified components are set to 0, 0, 1, according to spec. Also cleaned up and simplified the internals, added debug output operators for attribute component count and types and tested the whole thing. --- src/AbstractShaderProgram.cpp | 179 ++++++++++- src/AbstractShaderProgram.h | 427 +++++++++++++++---------- src/Mesh.h | 41 ++- src/Test/AbstractShaderProgramTest.cpp | 219 +++++++++++++ src/Test/CMakeLists.txt | 1 + 5 files changed, 676 insertions(+), 191 deletions(-) create mode 100644 src/Test/AbstractShaderProgramTest.cpp diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 664a6e800..b8a3c03f1 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -586,7 +586,7 @@ void AbstractShaderProgram::uniformImplementationDSA(GLint location, const Math: #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -std::size_t Attribute::size(GLint components, DataType dataType) { +std::size_t FloatAttribute::size(GLint components, DataType dataType) { switch(dataType) { case DataType::UnsignedByte: case DataType::Byte: @@ -609,7 +609,8 @@ std::size_t Attribute::size(GLint components, DataType dataType) { return 0; } -std::size_t Attribute::size(GLint components, DataType dataType) { +#ifndef MAGNUM_TARGET_GLES2 +std::size_t IntAttribute::size(GLint components, DataType dataType) { switch(dataType) { case DataType::UnsignedByte: case DataType::Byte: @@ -625,9 +626,10 @@ std::size_t Attribute::size(GLint components, DataType dataType) { CORRADE_INTERNAL_ASSERT(false); return 0; } +#endif #ifndef MAGNUM_TARGET_GLES -std::size_t Attribute::size(GLint components, DataType dataType) { +std::size_t DoubleAttribute::size(GLint components, DataType dataType) { switch(dataType) { case DataType::Double: return 8*components; @@ -639,6 +641,10 @@ std::size_t Attribute::size(GLint components, DataType dataType) { #endif std::size_t Attribute>::size(GLint components, DataType dataType) { + #ifndef MAGNUM_TARGET_GLES + if(components == GL_BGRA) components = 4; + #endif + switch(dataType) { case DataType::UnsignedByte: case DataType::Byte: @@ -668,6 +674,173 @@ std::size_t Attribute>::size(GLint components, DataType return 0; } +Debug operator<<(Debug debug, SizedAttribute<1, 1>::Components value) { + switch(value) { + case SizedAttribute<1, 1>::Components::One: + return debug << "AbstractShaderProgram::Attribute::Components::One"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, SizedAttribute<1, 2>::Components value) { + switch(value) { + case SizedAttribute<1, 2>::Components::One: + return debug << "AbstractShaderProgram::Attribute::Components::One"; + case SizedAttribute<1, 2>::Components::Two: + return debug << "AbstractShaderProgram::Attribute::Components::Two"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, SizedAttribute<1, 3>::Components value) { + switch(value) { + case SizedAttribute<1, 3>::Components::One: + return debug << "AbstractShaderProgram::Attribute::Components::One"; + case SizedAttribute<1, 3>::Components::Two: + return debug << "AbstractShaderProgram::Attribute::Components::Two"; + case SizedAttribute<1, 3>::Components::Three: + return debug << "AbstractShaderProgram::Attribute::Components::Three"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, SizedAttribute<1, 4>::Components value) { + switch(value) { + case SizedAttribute<1, 4>::Components::One: + return debug << "AbstractShaderProgram::Attribute::Components::One"; + case SizedAttribute<1, 4>::Components::Two: + return debug << "AbstractShaderProgram::Attribute::Components::Two"; + case SizedAttribute<1, 4>::Components::Three: + return debug << "AbstractShaderProgram::Attribute::Components::Three"; + case SizedAttribute<1, 4>::Components::Four: + return debug << "AbstractShaderProgram::Attribute::Components::Four"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, SizedMatrixAttribute<2>::Components value) { + switch(value) { + case SizedMatrixAttribute<2>::Components::Two: + return debug << "AbstractShaderProgram::Attribute::Components::Two"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, SizedMatrixAttribute<3>::Components value) { + switch(value) { + case SizedMatrixAttribute<3>::Components::Three: + return debug << "AbstractShaderProgram::Attribute::Components::Three"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, SizedMatrixAttribute<4>::Components value) { + switch(value) { + case SizedMatrixAttribute<4>::Components::Four: + return debug << "AbstractShaderProgram::Attribute::Components::Four"; + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, Attribute>::Components value) { + switch(value) { + case Attribute>::Components::One: + return debug << "AbstractShaderProgram::Attribute::Components::One"; + case Attribute>::Components::Two: + return debug << "AbstractShaderProgram::Attribute::Components::Two"; + case Attribute>::Components::Three: + return debug << "AbstractShaderProgram::Attribute::Components::Three"; + case Attribute>::Components::Four: + return debug << "AbstractShaderProgram::Attribute::Components::Four"; + #ifndef MAGNUM_TARGET_GLES + case Attribute>::Components::BGRA: + return debug << "AbstractShaderProgram::Attribute::Components::BGRA"; + #endif + } + + return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; +} + +Debug operator<<(Debug debug, FloatAttribute::DataType value) { + switch(value) { + #define _c(value) case FloatAttribute::DataType::value: return debug << "AbstractShaderProgram::Attribute::DataType::" #value; + _c(UnsignedByte) + _c(Byte) + _c(UnsignedShort) + _c(Short) + _c(UnsignedInt) + _c(Int) + _c(HalfFloat) + _c(Float) + #ifndef MAGNUM_TARGET_GLES + _c(Double) + #endif + #undef _c + } + + return debug << "AbstractShaderProgram::Attribute::DataType::(invalid)"; +} + +#ifndef MAGNUM_TARGET_GLES2 +Debug operator<<(Debug debug, IntAttribute::DataType value) { + switch(value) { + #define _c(value) case IntAttribute::DataType::value: return debug << "AbstractShaderProgram::Attribute::DataType::" #value; + _c(UnsignedByte) + _c(Byte) + _c(UnsignedShort) + _c(Short) + _c(UnsignedInt) + _c(Int) + #undef _c + } + + return debug << "AbstractShaderProgram::Attribute::DataType::(invalid)"; +} +#endif + +#ifndef MAGNUM_TARGET_GLES +Debug operator<<(Debug debug, DoubleAttribute::DataType value) { + switch(value) { + #define _c(value) case DoubleAttribute::DataType::value: return debug << "AbstractShaderProgram::Attribute::DataType::" #value; + _c(Double) + #undef _c + } + + return debug << "AbstractShaderProgram::Attribute::DataType::(invalid)"; +} +#endif + +Debug operator<<(Debug debug, Attribute>::DataType value) { + switch(value) { + #define _c(value) case Attribute>::DataType::value: return debug << "AbstractShaderProgram::Attribute::DataType::" #value; + _c(UnsignedByte) + _c(Byte) + _c(UnsignedShort) + _c(Short) + _c(UnsignedInt) + _c(Int) + _c(HalfFloat) + _c(Float) + #ifndef MAGNUM_TARGET_GLES + _c(Double) + #endif + #ifndef MAGNUM_TARGET_GLES2 + _c(UnsignedInt2101010Rev) + _c(Int2101010Rev) + #endif + #undef _c + } + + return debug << "AbstractShaderProgram::Attribute::DataType::(invalid)"; +} + } #endif diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index d69bf7fc9..9a28886a0 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -33,7 +33,6 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct Attribute; - template struct AttributeTraits; } #endif @@ -330,7 +329,61 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Type used in shader code. * @see DataType */ - typedef typename Implementation::AttributeTraits::AttributeType Type; + typedef typename Implementation::Attribute::Type Type; + + /** + * @brief Component count + * + * Count of components passed to the shader. If passing smaller + * count of components than corresponding type has, unspecified + * components are set to default values (second and third to `0`, + * fourth to `1`). + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + enum class Components: GLint { + /** + * Only first component is specified. Second, third and + * fourth component are set to `0`, `0`, `1`, respectively. + * Only for scalar and vector types, not matrices. + */ + One = 1, + + /** + * First two components are specified. Third and fourth + * component are set to `0`, `1`, respectively. Only for + * two, three and four-component vector types and 2x2, 3x2 + * and 4x2 matrix types. + */ + Two = 2, + + /** + * First three components are specified. Fourth component is + * set to `1`. Only for three and four-component vector + * types, 2x3, 3x3 and 4x3 matrix types. + */ + Three = 3, + + /** + * All four components are specified. Only for four-component + * vector types and 2x4, 3x4 and 4x4 matrix types. + */ + Four = 4 + + #ifndef MAGNUM_TARGET_GLES + , + /** + * Four components with BGRA ordering. Only for four-component + * float vector type. + * @requires_gl32 %Extension @extension{ARB,vertex_array_bgra} + * @requires_gl Only RGBA component ordering is supported + * in OpenGL ES. + */ + BGRA = 1 << 1 + #endif + }; + #else + typedef typename Implementation::Attribute::Components Components; + #endif /** * @brief Data type @@ -400,16 +453,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * Normalize integer components. Only for float attribute * types. Default is to not normalize. */ - Normalize = 1 << 0, - - /** - * BGRA component ordering. Default is RGBA. Only for - * four-component float vector attribute type. - * @requires_gl32 %Extension @extension{ARB,vertex_array_bgra} - * @requires_gl Only RGBA component ordering is supported - * in OpenGL ES. - */ - BGRA = 1 << 1 + Normalize = 1 << 0 }; #else typedef typename Implementation::Attribute::DataOption DataOption; @@ -427,25 +471,42 @@ class MAGNUM_EXPORT AbstractShaderProgram { /** * @brief Constructor + * @param components Component count * @param dataType Type of passed data. Default is the * same as type used in shader (e.g. DataType::Integer * for Vector4i). * @param dataOptions Data options. Default is no options. */ - inline constexpr Attribute(DataType dataType = Implementation::Attribute::DefaultDataType, DataOptions dataOptions = DataOptions()): _dataType(dataType), _dataOptions(dataOptions) {} + inline constexpr Attribute(Components components, DataType dataType = Implementation::Attribute::DefaultDataType, DataOptions dataOptions = DataOptions()): _components(components), _dataType(dataType), _dataOptions(dataOptions) {} + + /** + * @brief Constructor + * @param dataType Type of passed data. Default is the + * same as type used in shader (e.g. DataType::Integer + * for Vector4i). + * @param dataOptions Data options. Default is no options. + * + * Component count is set to the same value as in type used in + * shader (e.g. @ref Components "Components::Three" for Vector3). + */ + inline constexpr Attribute(DataType dataType = Implementation::Attribute::DefaultDataType, DataOptions dataOptions = DataOptions()): _components(Implementation::Attribute::DefaultComponents), _dataType(dataType), _dataOptions(dataOptions) {} + + /** @brief Component count of passed data */ + inline constexpr Components components() const { return _components; } /** @brief Type of passed data */ inline constexpr DataType dataType() const { return _dataType; } /** @brief Size of passed data */ inline std::size_t dataSize() const { - return Implementation::Attribute::size(Implementation::Attribute::components(), _dataType); + return Implementation::Attribute::size(GLint(_components)*Implementation::Attribute::vectorCount(), _dataType); } /** @brief Data options */ inline constexpr DataOptions dataOptions() const { return _dataOptions; } private: + const Components _components; const DataType _dataType; const DataOptions _dataOptions; }; @@ -1065,63 +1126,81 @@ class MAGNUM_EXPORT AbstractShaderProgram { State state; }; -#ifndef DOXYGEN_GENERATING_OUTPUT -namespace Implementation { - -template struct Attribute {}; - -template<> struct Attribute { - enum class DataType: GLenum { - UnsignedByte = GL_UNSIGNED_BYTE, - Byte = GL_BYTE, - UnsignedShort = GL_UNSIGNED_SHORT, - Short = GL_SHORT, - UnsignedInt = GL_UNSIGNED_INT, - Int = GL_INT, - #ifndef MAGNUM_TARGET_GLES2 - HalfFloat = GL_HALF_FLOAT, - #else - HalfFloat = GL_HALF_FLOAT_OES, - #endif - Float = GL_FLOAT - - #ifndef MAGNUM_TARGET_GLES - , - Double = GL_DOUBLE - #endif - }; +#ifdef DOXYGEN_GENERATING_OUTPUT +/** @debugoperator{Magnum::AbstractShaderProgram::Attribute} */ +template Debug operator<<(Debug debug, AbstractShaderProgram::Attribute::Components); - enum class DataOption: std::uint8_t { - Normalized = 1 << 0 - }; +/** @debugoperator{Magnum::AbstractShaderProgram::Attribute} */ +template Debug operator<<(Debug debug, AbstractShaderProgram::Attribute::DataType); +#endif - typedef Corrade::Containers::EnumSet DataOptions; +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { - static const DataType DefaultDataType = DataType::Float; +/* Base for sized attributes */ +template struct SizedAttribute; - inline constexpr static GLint components(DataOptions = {}) { return 1; } - static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); - inline constexpr static std::size_t vectorCount() { return 1; } +/* Vector attribute sizes */ +template struct SizedVectorAttribute { + inline constexpr static std::size_t vectorCount() { return cols; } }; - -CORRADE_ENUMSET_OPERATORS(Attribute::DataOptions) - -template struct Attribute>: public Attribute { - inline constexpr static GLint components(DataOptions = {}) { return vectorSize; } - inline constexpr static std::size_t vectorCount() { return 1; } +template<> struct SizedAttribute<1, 1>: SizedVectorAttribute<1> { + enum class Components: GLint { One = 1 }; + constexpr static Components DefaultComponents = Components::One; }; - -template struct Attribute>: public Attribute { - inline constexpr static GLint components(DataOptions = {}) { return rows; } - inline constexpr static std::size_t vectorCount() { return cols; } +template<> struct SizedAttribute<1, 2>: SizedVectorAttribute<1> { + enum class Components: GLint { One = 1, Two = 2 }; + constexpr static Components DefaultComponents = Components::Two; }; - -template struct Attribute>: public Attribute { - inline constexpr static GLint components(DataOptions = {}) { return matrixSize; } - inline constexpr static std::size_t vectorCount() { return matrixSize; } +template<> struct SizedAttribute<1, 3>: SizedVectorAttribute<1> { + enum class Components: GLint { One = 1, Two = 2, Three = 3 }; + constexpr static Components DefaultComponents = Components::Three; +}; +template<> struct SizedAttribute<1, 4>: SizedVectorAttribute<1> { + enum class Components: GLint { One = 1, Two = 2, Three = 3, Four = 4 }; + constexpr static Components DefaultComponents = Components::Four; +}; +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 1>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 2>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 3>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedAttribute<1, 4>::Components value); + +/* Matrix attribute sizes */ +template struct SizedMatrixAttribute; +template<> struct SizedMatrixAttribute<2> { + enum class Components: GLint { Two = 2 }; + constexpr static Components DefaultComponents = Components::Two; +}; +template<> struct SizedMatrixAttribute<3> { + enum class Components: GLint { Three = 3 }; + constexpr static Components DefaultComponents = Components::Three; +}; +template<> struct SizedMatrixAttribute<4> { + enum class Components: GLint { Four = 4 }; + constexpr static Components DefaultComponents = Components::Four; }; +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<2>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<3>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, SizedMatrixAttribute<4>::Components value); +template<> struct SizedAttribute<2, 2>: SizedVectorAttribute<2>, SizedMatrixAttribute<2> {}; +template<> struct SizedAttribute<3, 3>: SizedVectorAttribute<3>, SizedMatrixAttribute<3> {}; +template<> struct SizedAttribute<4, 4>: SizedVectorAttribute<4>, SizedMatrixAttribute<4> {}; +#ifndef MAGNUM_TARGET_GLES2 +template<> struct SizedAttribute<2, 3>: SizedVectorAttribute<2>, SizedMatrixAttribute<3> {}; +template<> struct SizedAttribute<3, 2>: SizedVectorAttribute<3>, SizedMatrixAttribute<2> {}; +template<> struct SizedAttribute<2, 4>: SizedVectorAttribute<2>, SizedMatrixAttribute<4> {}; +template<> struct SizedAttribute<4, 2>: SizedVectorAttribute<4>, SizedMatrixAttribute<2> {}; +template<> struct SizedAttribute<3, 4>: SizedVectorAttribute<3>, SizedMatrixAttribute<4> {}; +template<> struct SizedAttribute<4, 3>: SizedVectorAttribute<4>, SizedMatrixAttribute<3> {}; +#endif + +/* Base for attributes */ +template struct Attribute; + +/* Base for float attributes */ +struct FloatAttribute { + typedef GLfloat Type; -template<> struct Attribute> { enum class DataType: GLenum { UnsignedByte = GL_UNSIGNED_BYTE, Byte = GL_BYTE, @@ -1135,46 +1214,31 @@ template<> struct Attribute> { HalfFloat = GL_HALF_FLOAT_OES, #endif Float = GL_FLOAT + #ifndef MAGNUM_TARGET_GLES , Double = GL_DOUBLE #endif - #ifndef MAGNUM_TARGET_GLES2 - , - UnsignedInt2101010REV = GL_UNSIGNED_INT_2_10_10_10_REV, - Int2101010REV = GL_INT_2_10_10_10_REV - #endif }; + constexpr static DataType DefaultDataType = DataType::Float; enum class DataOption: std::uint8_t { Normalized = 1 << 0 - - #ifndef MAGNUM_TARGET_GLES - , - BGRA = 2 << 0 - #endif }; - typedef Corrade::Containers::EnumSet DataOptions; - static const DataType DefaultDataType = DataType::Float; - - #ifndef MAGNUM_TARGET_GLES - inline constexpr static GLint components(DataOptions options = {}) { - return options & DataOption::BGRA ? GL_BGRA : 4; - } - #else - inline constexpr static GLint components(DataOptions = {}) { return 4; } - #endif - static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); - inline constexpr static std::size_t vectorCount() { return 1; } }; -typedef Math::Vector<4, GLfloat> _Vector4; -CORRADE_ENUMSET_OPERATORS(Attribute<_Vector4>::DataOptions) +CORRADE_ENUMSET_OPERATORS(FloatAttribute::DataOptions) + +Debug MAGNUM_EXPORT operator<<(Debug debug, FloatAttribute::DataType value); + +#ifndef MAGNUM_TARGET_GLES2 +/* Base for int attributes */ +struct IntAttribute { + typedef GLint Type; -template<> struct Attribute { enum class DataType: GLenum { UnsignedByte = GL_UNSIGNED_BYTE, Byte = GL_BYTE, @@ -1183,135 +1247,148 @@ template<> struct Attribute { UnsignedInt = GL_UNSIGNED_INT, Int = GL_INT }; + constexpr static DataType DefaultDataType = DataType::Int; enum class DataOption: std::uint8_t {}; - typedef Corrade::Containers::EnumSet DataOptions; - static const DataType DefaultDataType = DataType::Int; - - inline constexpr static GLint components() { return 1; } static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; -template<> struct Attribute { - typedef Attribute::DataType DataType; - typedef Attribute::DataOption DataOption; +Debug MAGNUM_EXPORT operator<<(Debug debug, IntAttribute::DataType value); - typedef Corrade::Containers::EnumSet DataOptions; +/* Base for unsigned int attributes */ +struct UnsignedIntAttribute { + typedef GLuint Type; + + typedef IntAttribute::DataType DataType; + constexpr static DataType DefaultDataType = DataType::UnsignedInt; - static const DataType DefaultDataType = DataType::UnsignedInt; + typedef IntAttribute::DataOption DataOption; + typedef Corrade::Containers::EnumSet DataOptions; - inline constexpr static GLint components() { return 1; } inline static std::size_t size(GLint components, DataType dataType) { - return Attribute::size(components, dataType); + return IntAttribute::size(components, dataType); } }; - -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size_; } -}; - -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size_; } -}; +#endif #ifndef MAGNUM_TARGET_GLES -template<> struct Attribute { +/* Base for double attributes */ +struct DoubleAttribute { + typedef GLdouble Type; + enum class DataType: GLenum { Double = GL_DOUBLE }; + constexpr static DataType DefaultDataType = DataType::Double; enum class DataOption: std::uint8_t {}; - typedef Corrade::Containers::EnumSet DataOptions; - static const DataType DefaultDataType = DataType::Double; - - inline constexpr static GLint components() { return 1; } - inline constexpr static std::size_t vectorCount() { return 1; } static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return rows; } - inline constexpr static std::size_t vectorCount() { return cols; } -}; +Debug MAGNUM_EXPORT operator<<(Debug debug, DoubleAttribute::DataType value); +#endif -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size_; } - inline constexpr static std::size_t vectorCount() { return size_; } -}; +/* Floating-point four-component vector is absolutely special case */ +template<> struct Attribute> { + typedef GLfloat Type; -template struct Attribute>: public Attribute { - inline constexpr static GLint components() { return size_; } - inline constexpr static std::size_t vectorCount() { return size_; } -}; -#endif + enum class Components: GLint { + One = 1, + Two = 2, + Three = 3, + Four = 4 + #ifndef MAGNUM_TARGET_GLES + , + BGRA = GL_BGRA + #endif + }; + constexpr static Components DefaultComponents = Components::Four; + + enum class DataType: GLenum { + UnsignedByte = GL_UNSIGNED_BYTE, + Byte = GL_BYTE, + UnsignedShort = GL_UNSIGNED_SHORT, + Short = GL_SHORT, + UnsignedInt = GL_UNSIGNED_INT, + Int = GL_INT, + #ifndef MAGNUM_TARGET_GLES2 + HalfFloat = GL_HALF_FLOAT, + #else + HalfFloat = GL_HALF_FLOAT_OES, + #endif + Float = GL_FLOAT + #ifndef MAGNUM_TARGET_GLES + , + Double = GL_DOUBLE + #endif + #ifndef MAGNUM_TARGET_GLES2 + , + UnsignedInt2101010Rev = GL_UNSIGNED_INT_2_10_10_10_REV, + Int2101010Rev = GL_INT_2_10_10_10_REV + #endif + }; + constexpr static DataType DefaultDataType = DataType::Float; -template struct Attribute>: public Attribute> {}; -template struct Attribute>: public Attribute> {}; -template struct Attribute>: public Attribute> {}; + enum class DataOption: std::uint8_t { + Normalized = 1 << 0 + }; + typedef Corrade::Containers::EnumSet DataOptions; -template struct Attribute>: public Attribute> {}; -template struct Attribute>: public Attribute> {}; + inline constexpr static std::size_t vectorCount() { return 1; } + + static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); +}; -template struct Attribute>: public Attribute> {}; -template struct Attribute>: public Attribute> {}; +typedef Math::Vector<4, GLfloat> _Vector4; +CORRADE_ENUMSET_OPERATORS(Attribute<_Vector4>::DataOptions) -template struct Attribute>: public Attribute> {}; -template struct Attribute>: public Attribute> {}; +Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute>::DataType value); -/* Types allowed as GLSL attributes */ -template<> struct AttributeTraits { typedef GLuint AttributeType; }; -template<> struct AttributeTraits { typedef GLint AttributeType; }; -template<> struct AttributeTraits { typedef GLfloat AttributeType; }; +/* Common float, int, unsigned int and double scalar attributes */ +template<> struct Attribute: FloatAttribute, SizedAttribute<1, 1> {}; +#ifndef MAGNUM_TARGET_GLES2 +template<> struct Attribute: IntAttribute, SizedAttribute<1, 1> {}; +template<> struct Attribute: UnsignedIntAttribute, SizedAttribute<1, 1> {}; #ifndef MAGNUM_TARGET_GLES -template<> struct AttributeTraits { typedef GLdouble AttributeType; }; +template<> struct Attribute: DoubleAttribute, SizedAttribute<1, 1> {}; +#endif #endif -/* Only some vectors can be used as attributes */ -template struct VectorAttributeTraits {}; -template<> struct VectorAttributeTraits { typedef GLuint AttributeType; }; -template<> struct VectorAttributeTraits { typedef GLint AttributeType; }; -template<> struct VectorAttributeTraits { typedef GLfloat AttributeType; }; +/* Common float, int, unsigned int and double vector attributes */ +template struct Attribute>: FloatAttribute, SizedAttribute<1, size_> {}; +#ifndef MAGNUM_TARGET_GLES2 +template struct Attribute>: IntAttribute, SizedAttribute<1, size_> {}; +template struct Attribute>: UnsignedIntAttribute, SizedAttribute<1, size_> {}; #ifndef MAGNUM_TARGET_GLES -template<> struct VectorAttributeTraits { typedef GLdouble AttributeType; }; +template struct Attribute>: DoubleAttribute, SizedAttribute<1, size_> {}; #endif - -template struct AttributeTraits>: VectorAttributeTraits {}; -template struct AttributeTraits>: VectorAttributeTraits {}; -template struct AttributeTraits>: VectorAttributeTraits {}; - -template struct AttributeTraits>: AttributeTraits> {}; -template struct AttributeTraits>: AttributeTraits> {}; -template struct AttributeTraits>: AttributeTraits> {}; -template struct AttributeTraits>: AttributeTraits> {}; -template struct AttributeTraits>: AttributeTraits> {}; -template struct AttributeTraits>: AttributeTraits> {}; -template struct AttributeTraits>: AttributeTraits> {}; - -/* Only some floating-point matrices can be used as attributes */ -template struct MatrixAttributeTraits {}; -template<> struct MatrixAttributeTraits { typedef GLfloat AttributeType; }; +#endif +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; + +/* Common float and double rectangular matrix attributes */ +template struct Attribute>: FloatAttribute, SizedAttribute {}; #ifndef MAGNUM_TARGET_GLES -template<> struct MatrixAttributeTraits { typedef GLdouble AttributeType; }; +template struct Attribute>: DoubleAttribute, SizedAttribute {}; #endif -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; -#ifndef MAGNUM_TARGET_GLES2 -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; +/* Common float and double square matrix attributes */ +template struct Attribute>: Attribute> {}; +#ifndef MAGNUM_TARGET_GLES +template struct Attribute>: Attribute> {}; #endif - -template struct AttributeTraits>: MatrixAttributeTraits {}; -template struct AttributeTraits>: MatrixAttributeTraits {}; +template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; } #endif diff --git a/src/Mesh.h b/src/Mesh.h index 959a0f334..60edb1c8b 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -163,24 +163,39 @@ mesh->setPrimitive(plane.primitive()) // Custom shader with colors specified as four floating-point values class MyShader: public AbstractShaderProgram { public: + typedef Attribute<0, Vector3> Position; typedef Attribute<1, Color4<>> Color; // ... }; Mesh* mesh; -Buffer* colorBuffer; -// Fill vertex buffer with colors specified as four-byte BGRA (e.g. directly +// Fill position buffer with positions specified as two-component XY (i.e., +// no Z component, which is meant to be always 0) +Buffer* positionBuffer; +Vector2 positions[30] = { + // ... +}; + +// Specify layout of positions buffer -- only two components, unspecified Z +// component will be automatically set to 0 +mesh->addVertexBuffer(positionBuffer, 0, + MyShader::Position(MyShader::Position::Components::Two)); + +// Fill color buffer with colors specified as four-byte BGRA (e.g. directly // from TGA file) +Buffer* colorBuffer; GLubyte colors[4*30] = { // ... }; colorBuffer.setData(colors, Buffer::Usage::StaticDraw); -// Specify layout of color buffer -- each component is unsigned byte, we want -// to normalize them from [0, 255] to [0.0f, 1.0f] and reorder from BGRA -mesh->addVertexBuffer(colorBuffer, 0, - MyShader::Color(MyShader::Color::DataType::UsignedByte, MyShader::Color::DataOption::Normalized|MyShader::Color::DataOption::BGRA)); +// Specify layout of color buffer -- BGRA, each component unsigned byte and we +// want to normalize them from [0, 255] to [0.0f, 1.0f] +mesh->addVertexBuffer(colorBuffer, 0, MyShader::Color( + MyShader::Color::Components::BGRA, + MyShader::Color::DataType::UnsignedByte, + MyShader::Color::DataOption::Normalized)); @endcode @section Mesh-drawing Rendering meshes @@ -797,25 +812,25 @@ class MAGNUM_EXPORT Mesh { } inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} - template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::Type, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) (this->*attributePointerImplementation)(Attribute{ buffer, location+i, - Implementation::Attribute::components(attribute.dataOptions()), + static_cast(attribute.components()), static_cast(attribute.dataType()), - !!(attribute.dataOptions() & AbstractShaderProgram::Attribute::DataOption::Normalized), + bool(attribute.dataOptions() & AbstractShaderProgram::Attribute::DataOption::Normalized), offset, stride }); } #ifndef MAGNUM_TARGET_GLES2 - template inline void addVertexAttribute(typename std::enable_if::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::Type>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { (this->*attributeIPointerImplementation)(IntegerAttribute{ buffer, location, - Implementation::Attribute::components(), + static_cast(attribute.components()), static_cast(attribute.dataType()), offset, stride @@ -823,12 +838,12 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES - template inline void addVertexAttribute(typename std::enable_if::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::Type, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) (this->*attributeLPointerImplementation)(LongAttribute{ buffer, location+i, - Implementation::Attribute::components(), + static_cast(attribute.components()), static_cast(attribute.dataType()), offset, stride diff --git a/src/Test/AbstractShaderProgramTest.cpp b/src/Test/AbstractShaderProgramTest.cpp new file mode 100644 index 000000000..7a3de5032 --- /dev/null +++ b/src/Test/AbstractShaderProgramTest.cpp @@ -0,0 +1,219 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "AbstractShaderProgram.h" + +namespace Magnum { namespace Test { + +class AbstractShaderProgramTest: public Corrade::TestSuite::Tester { + public: + explicit AbstractShaderProgramTest(); + + void attributeScalar(); + void attributeScalarInt(); + void attributeScalarUnsignedInt(); + void attributeScalarDouble(); + + void attributeVector(); + void attributeVectorInt(); + void attributeVectorUnsignedInt(); + void attributeVectorDouble(); + void attributeVector4(); + void attributeVectorBGRA(); + + void attributeMatrix(); + void attributeMatrixDouble(); +}; + +AbstractShaderProgramTest::AbstractShaderProgramTest() { + addTests(&AbstractShaderProgramTest::attributeScalar, + &AbstractShaderProgramTest::attributeScalarInt, + &AbstractShaderProgramTest::attributeScalarUnsignedInt, + &AbstractShaderProgramTest::attributeScalarDouble, + + &AbstractShaderProgramTest::attributeVector, + &AbstractShaderProgramTest::attributeVectorInt, + &AbstractShaderProgramTest::attributeVectorUnsignedInt, + &AbstractShaderProgramTest::attributeVectorDouble, + &AbstractShaderProgramTest::attributeVector4, + &AbstractShaderProgramTest::attributeVectorBGRA, + + &AbstractShaderProgramTest::attributeMatrix, + &AbstractShaderProgramTest::attributeMatrixDouble); +} + +void AbstractShaderProgramTest::attributeScalar() { + typedef AbstractShaderProgram::Attribute<3, GLfloat> Attribute; + CORRADE_COMPARE(Attribute::Location, 3); + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::One); + CORRADE_VERIFY(!a.dataOptions()); + CORRADE_COMPARE(a.dataSize(), 4); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::Float); + + /* Options */ + Attribute b(Attribute::DataType::UnsignedShort, Attribute::DataOption::Normalized); + CORRADE_COMPARE(b.dataSize(), 2); + CORRADE_VERIFY(b.dataOptions() <= Attribute::DataOption::Normalized); +} + +void AbstractShaderProgramTest::attributeScalarInt() { + typedef AbstractShaderProgram::Attribute<3, GLint> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.dataSize(), 4); + + /* Options */ + Attribute b(Attribute::DataType::Short); + CORRADE_COMPARE(b.dataSize(), 2); +} + +void AbstractShaderProgramTest::attributeScalarUnsignedInt() { + typedef AbstractShaderProgram::Attribute<3, GLuint> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.dataSize(), 4); + + /* Options */ + Attribute b(Attribute::DataType::UnsignedByte); + CORRADE_COMPARE(b.dataSize(), 1); +} + +void AbstractShaderProgramTest::attributeScalarDouble() { + #ifndef MAGNUM_TARGET_GLES + typedef AbstractShaderProgram::Attribute<3, GLdouble> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.dataSize(), 8); + #else + CORRADE_SKIP("Double attributes are not available in OpenGL ES."); + #endif +} + +void AbstractShaderProgramTest::attributeVector() { + typedef AbstractShaderProgram::Attribute<3, Vector3> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::Three); + CORRADE_COMPARE(a.dataSize(), 3*4); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::Float); + + /* Options */ + Attribute b(Attribute::Components::Two, Attribute::DataType::Double); + CORRADE_COMPARE(b.components(), Attribute::Components::Two); + CORRADE_COMPARE(b.dataSize(), 2*8); +} + +void AbstractShaderProgramTest::attributeVectorInt() { + typedef AbstractShaderProgram::Attribute<3, Vector2i> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::Two); + CORRADE_COMPARE(a.dataSize(), 2*4); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::Int); + + /* Options */ + Attribute b(Attribute::Components::One, Attribute::DataType::Int); + CORRADE_COMPARE(b.dataSize(), 4); +} + +void AbstractShaderProgramTest::attributeVectorUnsignedInt() { + typedef AbstractShaderProgram::Attribute<3, Vector4ui> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::Four); + CORRADE_COMPARE(a.dataSize(), 4*4); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::UnsignedInt); + + /* Options */ + Attribute b(Attribute::Components::Three, Attribute::DataType::UnsignedShort); + CORRADE_COMPARE(b.dataSize(), 3*2); +} + +void AbstractShaderProgramTest::attributeVectorDouble() { + #ifndef MAGNUM_TARGET_GLES + typedef AbstractShaderProgram::Attribute<3, Vector2d> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::Two); + CORRADE_COMPARE(a.dataSize(), 2*8); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::Double); + + /* Options */ + Attribute b(Attribute::Components::One); + CORRADE_COMPARE(b.dataSize(), 8); + #else + CORRADE_SKIP("Double attributes are not available in OpenGL ES."); + #endif +} + +void AbstractShaderProgramTest::attributeVector4() { + typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute; + + /* Custom type */ + Attribute a(Attribute::DataType::UnsignedInt2101010Rev); + CORRADE_COMPARE(a.dataSize(), 4); +} + +void AbstractShaderProgramTest::attributeVectorBGRA() { + #ifndef MAGNUM_TARGET_GLES + typedef AbstractShaderProgram::Attribute<3, Vector4> Attribute; + + /* BGRA */ + Attribute a(Attribute::Components::BGRA); + CORRADE_COMPARE(a.dataSize(), 4*4); + #else + CORRADE_SKIP("BGRA attribute component ordering is not available in OpenGL ES."); + #endif +} + +void AbstractShaderProgramTest::attributeMatrix() { + typedef AbstractShaderProgram::Attribute<3, Matrix3> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::Three); + CORRADE_COMPARE(a.dataSize(), 3*3*4); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::Float); +} + +void AbstractShaderProgramTest::attributeMatrixDouble() { + #ifndef MAGNUM_TARGET_GLES + typedef AbstractShaderProgram::Attribute<3, Matrix4d> Attribute; + + /* Default constructor */ + Attribute a; + CORRADE_COMPARE(a.components(), Attribute::Components::Four); + CORRADE_COMPARE(a.dataSize(), 4*4*8); + CORRADE_COMPARE(a.dataType(), Attribute::DataType::Double); + #else + CORRADE_SKIP("Double attributes are not available in OpenGL ES."); + #endif +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::AbstractShaderProgramTest) diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 44d840117..5b4b97791 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,4 +1,5 @@ corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum) +corrade_add_test(AbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARIES Magnum) corrade_add_test(ArrayTest ArrayTest.cpp) corrade_add_test(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MeshTest MeshTest.cpp LIBRARIES Magnum) From c2f4359bd742030b3a2236f3a2c828b8957e18bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 21:18:42 +0100 Subject: [PATCH 401/567] Math: added strongly-typed asin(), acos() and atan(). --- src/Math/Functions.h | 9 +++++++++ src/Math/Test/FunctionsTest.cpp | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index a887121a8..e1b5582e7 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -87,6 +87,15 @@ template inline T cos(Deg angle) { return cos(Rad(angle)); } template inline T tan(Deg angle) { return tan(Rad(angle)); } #endif +/** @brief Arc sine */ +template inline Rad asin(T value) { return Rad(std::asin(value)); } + +/** @brief Arc cosine */ +template inline Rad acos(T value) { return Rad(std::acos(value)); } + +/** @brief Arc tangent */ +template inline Rad atan(T value) { return Rad(std::atan(value)); } + /** @{ @name Scalar/vector functions diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 70d261c66..c0d8e2809 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -251,10 +251,15 @@ void FunctionsTest::log2() { void FunctionsTest::trigonometric() { CORRADE_COMPARE(Math::sin(Deg(30.0f)), 0.5f); CORRADE_COMPARE(Math::sin(Rad(Constants::pi()/6)), 0.5f); + CORRADE_COMPARE_AS(Math::asin(0.5f), Deg(30.0f), Deg); + CORRADE_COMPARE(Math::cos(Deg(60.0f)), 0.5f); CORRADE_COMPARE(Math::cos(Rad(Constants::pi()/3)), 0.5f); + CORRADE_COMPARE_AS(Math::acos(0.5f), Deg(60.0f), Deg); + CORRADE_COMPARE(Math::tan(Deg(45.0f)), 1.0f); CORRADE_COMPARE(Math::tan(Rad(Constants::pi()/4)), 1.0f); + CORRADE_COMPARE_AS(Math::atan(1.0f), Deg(45.0f), Deg); } }}} From 556c714805976792bc03721c08e8f2624c6627d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 21:30:06 +0100 Subject: [PATCH 402/567] Primitives: fixed Icosphere subdivision. --- src/Primitives/Icosphere.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 9377eb68e..4f24331d6 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -64,6 +64,7 @@ template class Icosphere { }); MeshTools::clean(*indices(), *normals(0)); + positions(0)->clear(); positions(0)->reserve(normals(0)->size()); for(auto i: *normals(0)) positions(0)->push_back(Point3D(i)); } From 89c76e2267322eeebfe147eefa4565f8292f104e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 21 Feb 2013 23:42:18 +0100 Subject: [PATCH 403/567] Trade: got rid of Point2D/3D in MeshData in favor of Vector2/Vector3. Positions were originally done using Point2D/3D to simplify their transformation using matrices and to some extent simplify their usage in shaders. But now the disadvantages exceeded the advantages: * They take 50% more for 2D positions and 33% more for 3D positions, as last coordinate is always equal to 1, on the other hand when last coordinate is errorneously not equal to 1 they have crazy behavior. * Normalizing them or transforming them with anything else than with matrices is PITA, as we need to strip the last component, do the transformation, and then add the component back. * All transformation handling classes (Complex, DualComplex, Quaternion, DualQuaternion, Matrix3, Matrix4) now have convenience functions for transforming points specified directly as Vector2/Vector3 (and also for transforming vectors). * When someone wants to use homogeneous coordinates with crazy last component values, they can do so with plain Vector3 for 2D and Vector4 for 3D and it will be less confusing than using Point2D/3D which no important detail hidden. --- src/Primitives/Capsule.cpp | 6 +++--- src/Primitives/Crosshair.cpp | 7 +++---- src/Primitives/Cube.cpp | 6 +++--- src/Primitives/Cylinder.cpp | 2 +- src/Primitives/Icosphere.cpp | 7 +++---- src/Primitives/Icosphere.h | 4 +--- src/Primitives/Plane.cpp | 6 +++--- src/Primitives/Square.cpp | 6 +++--- src/Primitives/Test/CapsuleTest.cpp | 6 +++--- src/Primitives/Test/CylinderTest.cpp | 6 +++--- src/Primitives/Test/UVSphereTest.cpp | 6 +++--- src/Trade/MeshData2D.cpp | 2 +- src/Trade/MeshData2D.h | 8 ++++---- src/Trade/MeshData3D.cpp | 2 +- src/Trade/MeshData3D.h | 8 ++++---- 15 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index edd224a53..94b6b8e5d 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -16,11 +16,11 @@ #include "Capsule.h" #include "Math/Functions.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" namespace Magnum { namespace Primitives { -Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), 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; @@ -48,7 +48,7 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std topFaceRing(); } -Capsule::Capsule(std::uint32_t segments, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(std::uint32_t segments, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); diff --git a/src/Primitives/Crosshair.cpp b/src/Primitives/Crosshair.cpp index 26b323d65..e38084498 100644 --- a/src/Primitives/Crosshair.cpp +++ b/src/Primitives/Crosshair.cpp @@ -15,22 +15,21 @@ #include "Crosshair.h" -#include "Math/Point2D.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "Trade/MeshData2D.h" #include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { Trade::MeshData2D Crosshair2D::wireframe() { - return Trade::MeshData2D(Mesh::Primitive::Lines, nullptr, {new std::vector{ + return Trade::MeshData2D(Mesh::Primitive::Lines, nullptr, {new std::vector{ {-1.0f, 0.0f}, {1.0f, 0.0f}, { 0.0f, -1.0f}, {0.0f, 1.0f} }}, {}); } Trade::MeshData3D Crosshair3D::wireframe() { - return Trade::MeshData3D(Mesh::Primitive::Lines, nullptr, {new std::vector{ + return Trade::MeshData3D(Mesh::Primitive::Lines, nullptr, {new std::vector{ {-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, { 0.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, -1.0f}, {0.0f, 0.0f, 1.0f} diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 51d5a4c02..6c63afdc6 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -15,7 +15,7 @@ #include "Cube.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { @@ -28,7 +28,7 @@ Trade::MeshData3D Cube::solid() { 12, 13, 14, 12, 14, 15, /* -Z */ 16, 17, 18, 16, 18, 19, /* -Y */ 20, 21, 22, 20, 22, 23 /* -X */ - }, {new std::vector{ + }, {new std::vector{ {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, /* +Z */ @@ -97,7 +97,7 @@ Trade::MeshData3D Cube::wireframe() { 4, 5, 5, 6, 6, 7, 7, 4, /* -Z */ 1, 5, 2, 6, /* +X */ 0, 4, 3, 7 /* -X */ - }, {new std::vector{ + }, {new std::vector{ {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 406ecbd24..8b47b67f4 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -16,7 +16,7 @@ #include "Cylinder.h" #include "Math/Functions.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" namespace Magnum { namespace Primitives { diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 0be978c15..f7e003ba3 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -15,7 +15,7 @@ #include "Icosphere.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" namespace Magnum { namespace Primitives { @@ -40,7 +40,7 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vecto 7, 1, 0, 3, 9, 8, 4, 8, 0 -}, {new std::vector}, {new std::vector{ +}, {new std::vector}, {new std::vector{ {0.0f, -0.525731f, 0.850651f}, {0.850651f, 0.0f, 0.525731f}, {0.850651f, 0.0f, -0.525731f}, @@ -54,8 +54,7 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vecto {0.0f, 0.525731f, -0.850651f}, {0.0f, 0.525731f, 0.850651f} }}, {}) { - positions(0)->reserve(normals(0)->size()); - for(auto i: *normals(0)) positions(0)->push_back(Point3D(i)); + positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }} diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 4f24331d6..79f5583e3 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -64,9 +64,7 @@ template class Icosphere { }); MeshTools::clean(*indices(), *normals(0)); - positions(0)->clear(); - positions(0)->reserve(normals(0)->size()); - for(auto i: *normals(0)) positions(0)->push_back(Point3D(i)); + positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }; diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 8bcd58c4c..3bf69aca2 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -15,13 +15,13 @@ #include "Plane.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "Trade/MeshData3D.h" namespace Magnum { namespace Primitives { Trade::MeshData3D Plane::solid() { - return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ + return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, {-1.0f, -1.0f, 0.0f}, @@ -35,7 +35,7 @@ Trade::MeshData3D Plane::solid() { } Trade::MeshData3D Plane::wireframe() { - return Trade::MeshData3D(Mesh::Primitive::LineLoop, nullptr, {new std::vector{ + return Trade::MeshData3D(Mesh::Primitive::LineLoop, nullptr, {new std::vector{ {-1.0f, -1.0f, 0.0f}, {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index fe2dcd971..9a20cc4d0 100644 --- a/src/Primitives/Square.cpp +++ b/src/Primitives/Square.cpp @@ -15,13 +15,13 @@ #include "Square.h" -#include "Math/Point2D.h" +#include "Math/Vector2.h" #include "Trade/MeshData2D.h" namespace Magnum { namespace Primitives { Trade::MeshData2D Square::solid() { - return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ + return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector{ {1.0f, -1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, @@ -30,7 +30,7 @@ Trade::MeshData2D Square::solid() { } Trade::MeshData2D Square::wireframe() { - return Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {new std::vector{ + return Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {new std::vector{ {-1.0f, -1.0f}, {1.0f, -1.0f}, {1.0f, 1.0f}, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index a39871d77..84177dc4a 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -19,7 +19,7 @@ #include #include -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "Primitives/Capsule.h" using Corrade::TestSuite::Compare::Container; @@ -42,7 +42,7 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::withoutTextureCoords() { Capsule capsule(2, 2, 3, 1.0f); - CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, @@ -107,7 +107,7 @@ void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withTextureCoords() { Capsule capsule(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate); - CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector{ + CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.20711f, 0.707107f}, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index dd951d8e5..5e847a984 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -16,7 +16,7 @@ #include #include -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "Primitives/Cylinder.h" using Corrade::TestSuite::Compare::Container; @@ -39,7 +39,7 @@ CylinderTest::CylinderTest() { void CylinderTest::withoutAnything() { Cylinder cylinder(2, 3, 3.0f); - CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector{ {0.0f, -1.5f, 1.0f}, {0.866025f, -1.5f, -0.5f}, {-0.866025f, -1.5f, -0.5f}, @@ -76,7 +76,7 @@ void CylinderTest::withoutAnything() { void CylinderTest::withTextureCoordsAndCaps() { Cylinder cylinder(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds); - CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector{ + CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector{ {0.0f, -1.5f, 0.0f}, {0.0f, -1.5f, 1.0f}, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 20c88f625..494a6f4d0 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -16,7 +16,7 @@ #include #include -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "Primitives/UVSphere.h" using Corrade::TestSuite::Compare::Container; @@ -39,7 +39,7 @@ UVSphereTest::UVSphereTest() { void UVSphereTest::withoutTextureCoords() { UVSphere sphere(3, 3); - CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, @@ -77,7 +77,7 @@ void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withTextureCoords() { UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); - CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector{ + CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector{ {0.0f, -1.0f, 0.0f}, {0.0f, -0.5f, 0.866025f}, diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp index b143396bb..810fc0c96 100644 --- a/src/Trade/MeshData2D.cpp +++ b/src/Trade/MeshData2D.cpp @@ -15,7 +15,7 @@ #include "MeshData2D.h" -#include "Math/Point2D.h" +#include "Math/Vector2.h" namespace Magnum { namespace Trade { diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index c41ae1697..85f6ea7d3 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -47,7 +47,7 @@ class MAGNUM_EXPORT MeshData2D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + inline MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} /** @brief Move constructor */ MeshData2D(MeshData2D&&) = default; @@ -77,8 +77,8 @@ class MAGNUM_EXPORT MeshData2D { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(std::uint32_t id) { return _positions[id]; } - inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(std::uint32_t id) { return _positions[id]; } + inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ /** @brief Count of 2D texture coordinate arrays */ inline std::uint32_t textureCoords2DArrayCount() const { return _textureCoords2D.size(); } @@ -95,7 +95,7 @@ class MAGNUM_EXPORT MeshData2D { private: Mesh::Primitive _primitive; std::vector* _indices; - std::vector*> _positions; + std::vector*> _positions; std::vector*> _textureCoords2D; }; diff --git a/src/Trade/MeshData3D.cpp b/src/Trade/MeshData3D.cpp index e76968720..bfca98c39 100644 --- a/src/Trade/MeshData3D.cpp +++ b/src/Trade/MeshData3D.cpp @@ -15,7 +15,7 @@ #include "MeshData3D.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" namespace Magnum { namespace Trade { diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index eed0c1650..17a1ac802 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -48,7 +48,7 @@ class MAGNUM_EXPORT MeshData3D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Move constructor */ MeshData3D(MeshData3D&&) = default; @@ -78,8 +78,8 @@ class MAGNUM_EXPORT MeshData3D { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(std::uint32_t id) { return _positions[id]; } - inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(std::uint32_t id) { return _positions[id]; } + inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ /** @brief Count of normal arrays */ inline std::uint32_t normalArrayCount() const { return _normals.size(); } @@ -108,7 +108,7 @@ class MAGNUM_EXPORT MeshData3D { private: Mesh::Primitive _primitive; std::vector* _indices; - std::vector*> _positions; + std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D; }; From 616a31f4d2693f65f142202861c18d149d9c014e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 00:30:55 +0100 Subject: [PATCH 404/567] Shaders: got rid of Point2D/3D in positions in favor of Vector2/Vector3. Originally it was for more convenient usage of homogeneous coordinates in shaders themselves, but it is actually not needed: * When passing three-component vector (3D position) to `vec4`, the last coordinate is implicitly set to `1`, thus there is no need to pass it explicitly in each attribute. * On the other hand, when passing three-component vector (2D position in homogeneous coordinates) to `vec3` with Z explicitly set to `1`, it still needs some swizzle magic to extend it to `vec4` gl_Position. Passing it as two-component vector results in nearly the same magic while saving precious memory. --- src/Shaders/AbstractTextShader.h | 2 +- src/Shaders/FlatShader.h | 2 +- src/Shaders/FlatShader2D.vert | 6 +++--- src/Shaders/PhongShader.h | 2 +- src/Shaders/TextShader2D.vert | 6 +++--- src/Shaders/VertexColorShader.h | 2 +- src/Shaders/VertexColorShader2D.vert | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h index 350b519ac..8f391c1f5 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractTextShader.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders { template class AbstractTextShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Texture coordinates */ typedef Attribute<1, Vector2> TextureCoordinates; diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index 93a020a4a..6eb110a3c 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -38,7 +38,7 @@ Draws whole mesh with one color. template class MAGNUM_SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; explicit FlatShader(); diff --git a/src/Shaders/FlatShader2D.vert b/src/Shaders/FlatShader2D.vert index b976b595c..a976a1c7f 100644 --- a/src/Shaders/FlatShader2D.vert +++ b/src/Shaders/FlatShader2D.vert @@ -9,11 +9,11 @@ uniform highp mat3 transformationProjectionMatrix; #endif #ifdef EXPLICIT_ATTRIB_LOCATION -layout(location = 0) in highp vec3 position; +layout(location = 0) in highp vec2 position; #else -in highp vec3 position; +in highp vec2 position; #endif void main() { - gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0); } diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index b37d93361..a82f4c93b 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -35,7 +35,7 @@ otherwise falls back to GLSL 1.20. */ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: - typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ + typedef Attribute<0, Vector3> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ explicit PhongShader(); diff --git a/src/Shaders/TextShader2D.vert b/src/Shaders/TextShader2D.vert index 98ee96d84..9b3816650 100644 --- a/src/Shaders/TextShader2D.vert +++ b/src/Shaders/TextShader2D.vert @@ -10,16 +10,16 @@ uniform highp mat3 transformationProjectionMatrix; #endif #ifdef EXPLICIT_ATTRIB_LOCATION -layout(location = 0) in highp vec3 position; +layout(location = 0) in highp vec2 position; layout(location = 1) in mediump vec2 textureCoordinates; #else -in highp vec3 position; +in highp vec2 position; in mediump vec2 textureCoordinates; #endif out vec2 fragmentTextureCoordinates; void main() { - gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0); fragmentTextureCoordinates = textureCoordinates; } diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 3ac86aaec..4f0275d3f 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -38,7 +38,7 @@ Draws vertex-colored mesh. template class MAGNUM_SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::PointType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Vertex color */ typedef Attribute<1, Color3<>> Color; diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index ff300a5b1..1272488e2 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/src/Shaders/VertexColorShader2D.vert @@ -10,16 +10,16 @@ uniform highp mat3 transformationProjectionMatrix; #endif #ifdef EXPLICIT_ATTRIB_LOCATION -layout(location = 0) in highp vec3 position; +layout(location = 0) in highp vec2 position; layout(location = 1) in lowp vec3 color; #else -in highp vec3 position; +in highp vec2 position; in lowp vec3 color; #endif out lowp vec3 interpolatedColor; void main() { - gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0); interpolatedColor = color; } From faf94c74e21f8dc7f145c084015fbea5e8d0e25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 00:50:02 +0100 Subject: [PATCH 405/567] Adapted to recent meshdata/shader changes. --- src/AbstractShaderProgram.h | 4 +--- src/DebugTools/ObjectRenderer.cpp | 8 ++++---- src/Mesh.h | 8 ++++---- src/Text/TextRenderer.cpp | 24 ++++++++++++------------ src/Text/TextRenderer.h | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 9a28886a0..53b69ce6c 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -46,7 +46,7 @@ functions and properties: - %Attribute definitions with location and type for configuring meshes, for example: @code -typedef Attribute<0, Point3D> Position; +typedef Attribute<0, Vector3> Position; typedef Attribute<1, Vector3> Normal; typedef Attribute<2, Vector2> TextureCoordinates; @endcode @@ -1371,8 +1371,6 @@ template struct Attribute>: Dou template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; -template struct Attribute>: Attribute> {}; -template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 137df6a73..3deac8cdc 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -33,12 +33,12 @@ template<> struct Renderer<2> { inline static ResourceKey indexBuffer() { return {"object2d-indices"}; } inline static ResourceKey mesh() { return {"object2d"}; } - static const std::array positions; + static const std::array positions; static const std::array, 8> colors; static const std::array indices; }; -const std::array Renderer<2>::positions{{ +const std::array Renderer<2>::positions{{ { 0.0f, 0.0f}, { 1.0f, 0.0f}, /* X axis */ { 0.9f, 0.1f}, @@ -78,12 +78,12 @@ template<> struct Renderer<3> { inline static ResourceKey indexBuffer() { return {"object3d-indices"}; } inline static ResourceKey mesh() { return {"object3d"}; } - static const std::array positions; + static const std::array positions; static const std::array, 12> colors; static const std::array indices; }; -const std::array Renderer<3>::positions{{ +const std::array Renderer<3>::positions{{ { 0.0f, 0.0f, 0.0f}, { 1.0f, 0.0f, 0.0f}, /* X axis */ { 0.9f, 0.1f, 0.0f}, diff --git a/src/Mesh.h b/src/Mesh.h index 60edb1c8b..3f2c554f2 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -64,7 +64,7 @@ mesh is empty and no draw commands are issued when calling draw(). // Custom shader, needing only position data class MyShader: public AbstractShaderProgram { public: - typedef Attribute<0, Point3D> Position; + typedef Attribute<0, Vector3> Position; // ... }; @@ -72,7 +72,7 @@ Mesh* mesh; Buffer* vertexBuffer; // Fill vertex buffer with position data -static constexpr Point3D positions[30] = { +static constexpr Vector3 positions[30] = { // ... }; vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); @@ -109,7 +109,7 @@ mesh->setPrimitive(plane.primitive()) // Custom shader class MyShader: public AbstractShaderProgram { public: - typedef Attribute<0, Point3D> Position; + typedef Attribute<0, Vector3> Position; // ... }; @@ -117,7 +117,7 @@ Buffer *vertexBuffer, *indexBuffer; Mesh* mesh; // Fill vertex buffer with position data -static constexpr Point3D positions[300] = { +static constexpr Vector3 positions[300] = { // ... }; vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 4e54b86d7..4339d78f5 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -23,8 +23,6 @@ #include #endif -#include "Math/Point2D.h" -#include "Math/Point3D.h" #include "Context.h" #include "Extensions.h" #include "Mesh.h" @@ -151,30 +149,30 @@ template void createIndices(void* output, const std::uint32_t glyphCoun } } -template typename DimensionTraits::PointType point(const Vector2& vec); +template typename DimensionTraits::VectorType point(const Vector2& vec); -template<> inline Point2D point<2>(const Vector2& vec) { - return swizzle<'x', 'y', '1'>(vec); +template<> inline Vector2 point<2>(const Vector2& vec) { + return vec; } -template<> inline Point3D point<3>(const Vector2& vec) { - return swizzle<'x', 'y', '0', '1'>(vec); +template<> inline Vector3 point<3>(const Vector2& vec) { + return {vec, 1.0f}; } template struct Vertex { - typename DimensionTraits::PointType position; + typename DimensionTraits::VectorType position; Vector2 texcoords; }; } -template std::tuple::PointType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { +template std::tuple::VectorType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { TextLayouter layouter(font, size, text); const std::uint32_t vertexCount = layouter.glyphCount()*4; /* Output data */ - std::vector::PointType> positions; + std::vector::VectorType> positions; std::vector texcoords; positions.reserve(vertexCount); texcoords.reserve(vertexCount); @@ -210,7 +208,8 @@ template std::tuple(positions[1]), swizzle<'x', 'y'>(positions[positions.size()-2])}; return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle); } @@ -270,7 +269,8 @@ template std::tuple TextRenderer(vertices[1].position), swizzle<'x', 'y'>(vertices[vertices.size()-2].position)}; /* Configure mesh */ Mesh mesh; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 89328520c..4c2a1c7f6 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -109,7 +109,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * Returns tuple with vertex positions, texture coordinates, indices * and rectangle spanning the rendered text. */ - static std::tuple::PointType>, std::vector, std::vector, Rectangle> render(Font& font, GLfloat size, const std::string& text); + static std::tuple::VectorType>, std::vector, std::vector, Rectangle> render(Font& font, GLfloat size, const std::string& text); /** * @brief Render text From 33f3a0a7dd959e740ff1c1132f99501ed43f5fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 01:17:53 +0100 Subject: [PATCH 406/567] Physics: removed unneeded includes. --- src/Physics/Box.cpp | 1 - src/Physics/Plane.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index d71c6d570..677855a3b 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -16,7 +16,6 @@ #include "Box.h" #include "Math/Matrix4.h" -#include "Math/Point3D.h" namespace Magnum { namespace Physics { diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 471f1a0ed..b354447d9 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -18,7 +18,6 @@ #include #include "Math/Matrix4.h" -#include "Math/Point3D.h" #include "Math/Geometry/Intersection.h" #include "LineSegment.h" From 3de3a6861ede55e1835fe8c4b9b448443809c380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 01:19:00 +0100 Subject: [PATCH 407/567] MeshTools: got rid of Point2D/3D in favor of Vector2/Vector3. --- src/MeshTools/CombineIndexedArrays.h | 2 +- src/MeshTools/GenerateFlatNormals.cpp | 10 +++++----- src/MeshTools/GenerateFlatNormals.h | 4 ++-- src/MeshTools/Test/GenerateFlatNormalsTest.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index cb8d0bbd4..07cef4980 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -106,7 +106,7 @@ of some STL functions like shown below. Also if one index array is shader by more than one attribute array, just pass the index array more times. Example: @code std::vector vertexIndices; -std::vector positions; +std::vector positions; std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 0ea2de883..2c5195728 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -15,12 +15,12 @@ #include "GenerateFlatNormals.h" -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "MeshTools/Clean.h" namespace Magnum { namespace MeshTools { -std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { +std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple, std::vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ @@ -29,8 +29,8 @@ std::tuple, std::vector> generateFlatNormals std::vector normals; normals.reserve(indices.size()/3); for(std::size_t i = 0; i != indices.size(); i += 3) { - Vector3 normal = Vector3::cross(positions[indices[i+2]].xyz()-positions[indices[i+1]].xyz(), - positions[indices[i]].xyz()-positions[indices[i+1]].xyz()).normalized(); + Vector3 normal = Vector3::cross(positions[indices[i+2]]-positions[indices[i+1]], + positions[indices[i]]-positions[indices[i+1]]).normalized(); /* Use the same normal for all three vertices of the face */ normalIndices.push_back(normals.size()); @@ -40,7 +40,7 @@ std::tuple, std::vector> generateFlatNormals } /* Clean duplicate normals and return */ - clean(normalIndices, normals); + MeshTools::clean(normalIndices, normals); return std::make_tuple(normalIndices, normals); } diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index 35a6e8047..cdccb6d7e 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -39,7 +39,7 @@ For each face generates one normal vector, removes duplicates before returning. Example usage: @code std::vector vertexIndices; -std::vector positions; +std::vector positions; std::vector normalIndices; std::vector normals; @@ -51,7 +51,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 64107680e..25a867e82 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -16,7 +16,7 @@ #include #include -#include "Math/Point3D.h" +#include "Math/Vector3.h" #include "MeshTools/GenerateFlatNormals.h" namespace Magnum { namespace MeshTools { namespace Test { From 865c9d5eedcc9133ea2d979eb70b602a412601e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 01:20:14 +0100 Subject: [PATCH 408/567] Removed DimensionTraits::PointType. Not needed anymore. --- src/DimensionTraits.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index e2b49e430..71785aa3e 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -35,14 +35,6 @@ template struct DimensionTraits { */ typedef U VectorType; - /** - * @brief Point type - * - * Floating-point Math::Point2D or Math::Point3D for 2D or 3D. No point - * type defined for one dimension and integral types. - */ - typedef U PointType; - /** * @brief Matrix type * @@ -73,14 +65,12 @@ template<> struct DimensionTraits<2, float> { DimensionTraits() = delete; typedef Math::Vector2 VectorType; - typedef Math::Point2D PointType; typedef Math::Matrix3 MatrixType; }; template<> struct DimensionTraits<2, double> { DimensionTraits() = delete; typedef Math::Vector2 VectorType; - typedef Math::Point2D PointType; typedef Math::Matrix3 MatrixType; }; @@ -96,14 +86,12 @@ template<> struct DimensionTraits<3, float> { DimensionTraits() = delete; typedef Math::Vector3 VectorType; - typedef Math::Point3D PointType; typedef Math::Matrix4 MatrixType; }; template<> struct DimensionTraits<3, double> { DimensionTraits() = delete; typedef Math::Vector3 VectorType; - typedef Math::Point3D PointType; typedef Math::Matrix4 MatrixType; }; #endif From 58d156bc4795a1486f717ac4369f4ca3563d4467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 01:22:05 +0100 Subject: [PATCH 409/567] Math: removed Point2D/Point3D altogether. --- doc/matrix-vector.dox | 11 +--- src/Magnum.h | 6 -- src/Math/CMakeLists.txt | 2 - src/Math/Math.h | 3 - src/Math/Matrix3.h | 10 +--- src/Math/Matrix4.h | 10 +--- src/Math/Point2D.h | 105 ---------------------------------- src/Math/Point3D.h | 105 ---------------------------------- src/Math/Test/CMakeLists.txt | 2 - src/Math/Test/Matrix3Test.cpp | 1 - src/Math/Test/Matrix4Test.cpp | 1 - src/Math/Test/Point2DTest.cpp | 66 --------------------- src/Math/Test/Point3DTest.cpp | 66 --------------------- src/Math/Vector3.h | 3 +- src/Math/Vector4.h | 3 +- 15 files changed, 9 insertions(+), 385 deletions(-) delete mode 100644 src/Math/Point2D.h delete mode 100644 src/Math/Point3D.h delete mode 100644 src/Math/Test/Point2DTest.cpp delete mode 100644 src/Math/Test/Point3DTest.cpp diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 115e13991..c1ded9d3f 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -26,16 +26,14 @@ return the most specialized type known to make subsequent operations more convenient - columns of %RectangularMatrix are returned as %Vector, but when accessing columns of e.g. %Matrix3, they are returned as %Vector3. -There are also even more specialized subclasses - Point2D, Point3D for -creating points with homogeneous coordinates and Color3, Color4 for color -handling and conversion. +There are also even more specialized subclasses, e.g. Color3 and Color4 for +color handling and conversion. @section matrix-vector-construction Constructing matrices and vectors Default constructors of RectangularMatrix and Vector (and Vector2, Vector3, Vector4, Color3) create zero-filled objects. Matrix (and Matrix3, Matrix4) is -by default constructed as identity matrix. Point2D and Point3D have -homogeneous component set to one, Color4 has alpha value set to opaque. +by default constructed as identity matrix. Color4 has alpha value set to opaque. @code RectangularMatrix<2, 3, int> a; // zero-filled Vector<3, int> b; // zero-filled @@ -43,9 +41,6 @@ Vector<3, int> b; // zero-filled Matrix<3, int> identity; // diagonal set to 1 Matrix<3, int> zero(Matrix<3, int>::Zero); // zero-filled -Point2D c; // {0, 0, 1} -Point3D d; // {0, 0, 0, 1} - Color4 black1; // {0.0f, 0.0f, 0.0f, 1.0f} Color4 black2; // {0, 0, 0, 255} @endcode diff --git a/src/Magnum.h b/src/Magnum.h index afe726912..f5dd8a4ed 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -103,12 +103,6 @@ typedef Math::Vector3 Vector3d; typedef Math::Vector4 Vector4d; #endif -/** @brief Two-dimensional floating-point homogeneous coordinates */ -typedef Math::Point2D Point2D; - -/** @brief Three-dimensional floating-point homogeneous coordinates */ -typedef Math::Point3D Point3D; - /** @brief 3x3 float matrix */ typedef Math::Matrix3 Matrix3; diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index e6d909a0c..287d96427 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -11,8 +11,6 @@ set(MagnumMath_HEADERS Matrix.h Matrix3.h Matrix4.h - Point2D.h - Point3D.h Quaternion.h RectangularMatrix.h Swizzle.h diff --git a/src/Math/Math.h b/src/Math/Math.h index 31feb02b3..8124b0a3b 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -34,9 +34,6 @@ template class Matrix; template class Matrix3; template class Matrix4; -template class Point2D; -template class Point3D; - template class Quaternion; template class RectangularMatrix; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 59398a3ad..d1a455d64 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -19,8 +19,8 @@ * @brief Class Magnum::Math::Matrix3 */ -#include "Matrix.h" -#include "Point2D.h" +#include "Math/Matrix.h" +#include "Math/Vector3.h" namespace Magnum { namespace Math { @@ -226,12 +226,6 @@ template class Matrix3: public Matrix<3, T> { return ((*this)*Vector3(vector, T(1))).xy(); } - #ifndef DOXYGEN_GENERATING_OUTPUT - inline Point2D operator*(const Point2D& other) const { - return Matrix<3, T>::operator*(other); - } - #endif - MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(3, 3, Matrix3) MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix3, Vector3, 3) }; diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 9e278dfc3..1684f816d 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -19,8 +19,8 @@ * @brief Class Magnum::Math::Matrix4 */ -#include "Matrix.h" -#include "Point3D.h" +#include "Math/Matrix.h" +#include "Math/Vector4.h" #ifdef _WIN32 /* I so HATE windows.h */ #undef near @@ -375,12 +375,6 @@ template class Matrix4: public Matrix<4, T> { return ((*this)*Vector4(vector, T(1))).xyz(); } - #ifndef DOXYGEN_GENERATING_OUTPUT - inline Point3D operator*(const Point3D& other) const { - return Matrix<4, T>::operator*(other); - } - #endif - MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(4, 4, Matrix4) MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4) }; diff --git a/src/Math/Point2D.h b/src/Math/Point2D.h deleted file mode 100644 index 967a91692..000000000 --- a/src/Math/Point2D.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef Magnum_Math_Point2D_h -#define Magnum_Math_Point2D_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::Math::Point2D - */ - -#include "Vector3.h" - -namespace Magnum { namespace Math { - -/** -@brief Two-dimensional homogeneous coordinates -@tparam T Data type - -Same as Vector3, except that constructors have default value for Z component -set to one. See also @ref matrix-vector for brief introduction. -@see Magnum::Point2D, Point3D -@configurationvalueref{Magnum::Math::Point2D} -*/ -template class Point2D: public Vector3 { - public: - /** - * @brief Default constructor - * - * @f[ - * \boldsymbol p = (0, 0, 1)^T - * @f] - */ - inline constexpr /*implicit*/ Point2D(): Vector3(T(0), T(0), T(1)) {} - - /** - * @brief Constructor - * - * @f[ - * \boldsymbol p = (x, y, z)^T - * @f] - */ - inline constexpr /*implicit*/ Point2D(T x, T y, T z = T(1)): Vector3(x, y, z) {} - - /** - * @brief Constructor - * - * @f[ - * \boldsymbol p = (v_x, v_y, z)^T - * @f] - */ - inline constexpr /*implicit*/ Point2D(const Vector2& xy, T z): Vector3(xy, z) {} - - /** - * @brief Construct 2D point from 2D vector - * - * @f[ - * \boldsymbol p = (v_x, v_y, 1)^T - * @f] - */ - inline constexpr explicit Point2D(const Vector2& xy): Vector3(xy, T(1)) {} - - /** @copydoc Vector::Vector(const Vector&) */ - template inline constexpr explicit Point2D(const Vector<3, U>& other): Vector3(other) {} - - /** @brief Copy constructor */ - inline constexpr Point2D(const Vector<3, T>& other): Vector3(other) {} - - /** - * @brief Vector part of the point - * - * Equivalent to calling xy(). Useful for seamless 2D/3D integration. - * @see Point3D::vector() - */ - inline Vector2& vector() { return Vector3::xy(); } - inline constexpr Vector2 vector() const { return Vector3::xy(); } /**< @overload */ - - MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point2D, 3) -}; - -MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3) - -/** @debugoperator{Magnum::Math::Point2D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point2D& value) { - return debug << static_cast&>(value); -} - -}} - -namespace Corrade { namespace Utility { - /** @configurationvalue{Magnum::Math::Point2D} */ - template struct ConfigurationValue>: public ConfigurationValue> {}; -}} - -#endif diff --git a/src/Math/Point3D.h b/src/Math/Point3D.h deleted file mode 100644 index fbe97faa3..000000000 --- a/src/Math/Point3D.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef Magnum_Math_Point3D_h -#define Magnum_Math_Point3D_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::Math::Point3D - */ - -#include "Vector4.h" - -namespace Magnum { namespace Math { - -/** -@brief Three-dimensional homogeneous coordinates -@tparam T Data type - -Same as Vector4, except that constructors have default value for W component -set to one. See also @ref matrix-vector for brief introduction. -@see Magnum::Point3D, Point2D -@configurationvalueref{Magnum::Math::Point3D} -*/ -template class Point3D: public Vector4 { - public: - /** - * @brief Default constructor - * - * @f[ - * \boldsymbol p = (0, 0, 0, 1)^T - * @f] - */ - inline constexpr /*implicit*/ Point3D(): Vector4(T(0), T(0), T(0), T(1)) {} - - /** - * @brief Constructor - * - * @f[ - * \boldsymbol p = (x, y, z, w)^T - * @f] - */ - inline constexpr /*implicit*/ Point3D(T x, T y, T z, T w = T(1)): Vector4(x, y, z, w) {} - - /** - * @brief Constructor - * - * @f[ - * \boldsymbol p = (v_x, v_y, v_z, w)^T - * @f] - */ - inline constexpr /*implicit*/ Point3D(const Vector3& xyz, T w): Vector4(xyz, w) {} - - /** - * @brief Construct 3D point from 3D vector - * - * @f[ - * \boldsymbol p = (v_x, v_y, v_z, 1)^T - * @f] - */ - inline constexpr explicit Point3D(const Vector3& xyz): Vector4(xyz, T(1)) {} - - /** @copydoc Vector::Vector(const Vector&) */ - template inline constexpr explicit Point3D(const Vector<4, U>& other): Vector4(other) {} - - /** @brief Copy constructor */ - inline constexpr Point3D(const Vector<4, T>& other): Vector4(other) {} - - /** - * @brief Vector part of the point - * - * Equivalent to calling xyz(). Useful for seamless 2D/3D integration. - * @see Point2D::vector() - */ - inline Vector3& vector() { return Vector4::xyz(); } - inline constexpr Vector3 vector() const { return Vector4::xyz(); } /**< @overload */ - - MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point3D, 4) -}; - -MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4) - -/** @debugoperator{Magnum::Math::Point3D} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point3D& value) { - return debug << static_cast&>(value); -} - -}} - -namespace Corrade { namespace Utility { - /** @configurationvalue{Magnum::Math::Point3D} */ - template struct ConfigurationValue>: public ConfigurationValue> {}; -}} - -#endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index c76ea26fb..d5e0f63f0 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -7,8 +7,6 @@ corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector3Test Vector3Test.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector4Test Vector4Test.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(MathPoint2DTest Point2DTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(MathPoint3DTest Point3DTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathRectangularMatrixTest RectangularMatrixTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathMatrixTest MatrixTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 47e5a8194..3ac4de620 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -47,7 +47,6 @@ typedef Math::Deg Deg; typedef Math::Matrix3 Matrix3; typedef Math::Matrix<2, float> Matrix2; typedef Math::Vector2 Vector2; -typedef Math::Point2D Point2D; Matrix3Test::Matrix3Test() { addTests(&Matrix3Test::constructIdentity, diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index afd0a9247..434ff84d7 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -53,7 +53,6 @@ typedef Math::Rad Rad; typedef Math::Matrix4 Matrix4; typedef Math::Matrix<3, float> Matrix3; typedef Math::Vector3 Vector3; -typedef Math::Point3D Point3D; Matrix4Test::Matrix4Test() { addTests(&Matrix4Test::constructIdentity, diff --git a/src/Math/Test/Point2DTest.cpp b/src/Math/Test/Point2DTest.cpp deleted file mode 100644 index e3e29e9c3..000000000 --- a/src/Math/Test/Point2DTest.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include -#include -#include - -#include "Math/Point2D.h" - -namespace Magnum { namespace Math { namespace Test { - -class Point2DTest: public Corrade::TestSuite::Tester { - public: - Point2DTest(); - - void construct(); - void debug(); - void configuration(); -}; - -typedef Math::Point2D Point2D; - -Point2DTest::Point2DTest() { - addTests(&Point2DTest::construct, - &Point2DTest::debug, - &Point2DTest::configuration); -} - -void Point2DTest::construct() { - CORRADE_COMPARE(Point2D(), (Vector<3, float>(0.0f, 0.0f, 1.0f))); - CORRADE_COMPARE(Point2D(1, 2), (Vector<3, float>(1.0f, 2.0f, 1.0f))); - CORRADE_COMPARE(Point2D(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); -} - -void Point2DTest::debug() { - std::ostringstream o; - Debug(&o) << Point2D(0.5f, 15.0f, 1.0f); - CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n"); -} - -void Point2DTest::configuration() { - Corrade::Utility::Configuration c; - - Point2D vec(3.0f, 3.125f, 9.55f); - std::string value("3 3.125 9.55"); - - c.setValue("point", vec); - CORRADE_COMPARE(c.value("point"), value); - CORRADE_COMPARE(c.value("point"), vec); -} - -}}} - -CORRADE_TEST_MAIN(Magnum::Math::Test::Point2DTest) diff --git a/src/Math/Test/Point3DTest.cpp b/src/Math/Test/Point3DTest.cpp deleted file mode 100644 index 9ac4f30c0..000000000 --- a/src/Math/Test/Point3DTest.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include -#include -#include - -#include "Math/Point3D.h" - -namespace Magnum { namespace Math { namespace Test { - -class Point3DTest: public Corrade::TestSuite::Tester { - public: - Point3DTest(); - - void construct(); - void debug(); - void configuration(); -}; - -typedef Math::Point3D Point3D; - -Point3DTest::Point3DTest() { - addTests(&Point3DTest::construct, - &Point3DTest::debug, - &Point3DTest::configuration); -} - -void Point3DTest::construct() { - CORRADE_COMPARE(Point3D(), Point3D(0.0f, 0.0f, 0.0f, 1.0f)); - CORRADE_COMPARE(Point3D(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); - CORRADE_COMPARE(Point3D(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); -} - -void Point3DTest::debug() { - std::ostringstream o; - Debug(&o) << Point3D(0.5f, 15.0f, 1.0f, 1.0f); - CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n"); -} - -void Point3DTest::configuration() { - Corrade::Utility::Configuration c; - - Point3D vec(3.0f, 3.125f, 9.0f, 9.55f); - std::string value("3 3.125 9 9.55"); - - c.setValue("point", vec); - CORRADE_COMPARE(c.value("point"), value); - CORRADE_COMPARE(c.value("point"), vec); -} - -}}} - -CORRADE_TEST_MAIN(Magnum::Math::Test::Point3DTest) diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index cb2c2486b..f0ed34d9c 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -28,8 +28,7 @@ namespace Magnum { namespace Math { @brief Three-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. See also Point2D for -homogeneous two-dimensional coordinates. +See @ref matrix-vector for brief introduction. @see Magnum::Vector3, Magnum::Vector3i, Magnum::Vector3ui, Magnum::Vector3d @configurationvalueref{Magnum::Math::Vector3} */ diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 9c45d24b0..846634544 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -27,8 +27,7 @@ namespace Magnum { namespace Math { @brief Four-component vector @tparam T Data type -See @ref matrix-vector for brief introduction. See also Point3D for -homogeneous three-dimensional coordinates. +See @ref matrix-vector for brief introduction. @see Magnum::Vector4, Magnum::Vector4i, Magnum::Vector4ui, Magnum::Vector4d @configurationvalueref{Magnum::Math::Vector4} */ From a7f7e76da8b9c6d56cd259dd130b5d1f979e0a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 11:41:18 +0100 Subject: [PATCH 410/567] Added TODOs. --- src/AbstractImage.h | 4 ++++ src/AbstractTexture.h | 1 + src/Context.h | 2 ++ src/Physics/AxisAlignedBox.h | 1 + src/Physics/Box.h | 1 + src/Physics/Capsule.h | 1 + src/Physics/Sphere.h | 1 + src/Query.h | 1 + 8 files changed, 12 insertions(+) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 57a02caa4..2ba2279c7 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -32,6 +32,10 @@ namespace Magnum { See Image, ImageWrapper, BufferImage, Trade::ImageData documentation for more information. +@todo Where to put glClampColor() and glPixelStore() encapsulation? It is +needed in AbstractFramebuffer::read(), Texture::setImage() etc (i.e. all +functions operating with images). It also possibly needs to be "stackable" to +easily revert the state back. */ class MAGNUM_EXPORT AbstractImage { AbstractImage(const AbstractImage& other) = delete; diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index d1f468953..2ec6975dc 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -63,6 +63,7 @@ performed by OpenGL in order to preserve the data. If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} is not available, these functions do nothing. +@todo all texture [level] parameters, global texture parameters @todo Add glPixelStore encapsulation @todo Texture copying @todo Move constructor/assignment - how to avoid creation of empty texture and diff --git a/src/Context.h b/src/Context.h index d0cb02b45..569ac877f 100644 --- a/src/Context.h +++ b/src/Context.h @@ -127,6 +127,8 @@ Provides access to version and extension information. Instance available through Context::current() is automatically created during construction of *Application classes in Platform namespace so you can safely assume that the instance is available during whole lifetime of *Application object. +@todo @extension{ATI,meminfo}, @extension{NVX,gpu_memory_info}, GPU temperature? + (here or where?) */ class MAGNUM_EXPORT Context { Context(const Context&) = delete; diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 2b6eb7f4a..aa4756c49 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -31,6 +31,7 @@ namespace Magnum { namespace Physics { @brief Axis-aligned box @see AxisAlignedBox2D, AxisAlignedBox3D +@todo Assert for rotation */ template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 67c0b80a0..acb24e091 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -32,6 +32,7 @@ namespace Magnum { namespace Physics { @todo Use quat + position + size instead? @see Box2D, Box3D +@todo Assert for skew */ template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { public: diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 9fd8e15d8..0e0184a08 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -33,6 +33,7 @@ namespace Magnum { namespace Physics { Unlike other elements the capsule doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Capsule2D, Capsule3D +@todo Assert for asymmetric scaling */ template class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape { public: diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 8d95f2512..5c60df747 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -33,6 +33,7 @@ namespace Magnum { namespace Physics { Unlike other elements the sphere doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Sphere2D, Sphere3D +@todo Assert for asymmetric scaling */ template class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape { public: diff --git a/src/Query.h b/src/Query.h index ff3f9ca22..f768c8ca7 100644 --- a/src/Query.h +++ b/src/Query.h @@ -355,6 +355,7 @@ GLuint timeElapsed2 = q3.result()-tmp; Using this query results in fewer OpenGL calls when doing more measures. @requires_gl33 %Extension @extension{ARB,timer_query} @requires_gl Timer query is not available in OpenGL ES. +@todo timestamp with glGet + example usage */ class TimeQuery: public AbstractQuery { public: From 9dbd8c9356d9dcd0bcfcc61d9bd10dd7cfd455f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 11:47:13 +0100 Subject: [PATCH 411/567] Math: renamed Quaternion::rotateVector*() to transformVector*(). Now it is consistent with Matrix and can be easily used in templates. --- src/Math/DualQuaternion.h | 6 +++--- src/Math/Matrix4.h | 2 +- src/Math/Quaternion.h | 12 ++++++------ src/Math/Test/DualQuaternionTest.cpp | 2 +- src/Math/Test/QuaternionTest.cpp | 22 +++++++++++----------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 3230272c8..c83611238 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -246,11 +246,11 @@ template class DualQuaternion: public Dual> { /** * @brief Rotate and translate point with dual quaternion * - * See rotateVectorNormalized(), which is faster for normalized dual + * See transformPointNormalized(), which is faster for normalized dual * quaternions. @f[ * v' = qv \overline{\hat q^{-1}} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^{-1}} * @f] - * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() + * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::transformVector() */ inline Vector3 transformPoint(const Vector3& vector) const { return ((*this)*DualQuaternion(vector)*inverted().dualConjugated()).dual().vector(); @@ -263,7 +263,7 @@ template class DualQuaternion: public Dual> { * quaternion is normalized. @f[ * v' = qv \overline{\hat q^{-1}} = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] - * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::rotateVectorNormalized() + * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::transformVectorNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits>::equals(lengthSquared(), Dual(1)), diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 1684f816d..9b5f2a275 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -356,7 +356,7 @@ template class Matrix4: public Matrix<4, T> { * Translation is not involved in the transformation. @f[ * \boldsymbol v' = \boldsymbol M (v_x, v_y, v_z, 0)^T * @f] - * @see transformPoint(), Quaternion::rotateVector(), + * @see transformPoint(), Quaternion::transformVector(), * Matrix3::transformVector() */ inline Vector3 transformVector(const Vector3& vector) const { diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index ef87aa2ff..8fe41b9db 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -149,7 +149,7 @@ template class Quaternion { * To be used in transformations later. @f[ * q = [\boldsymbol v, 0] * @f] - * @see rotateVector(), rotateVectorNormalized() + * @see transformVector(), transformVectorNormalized() */ inline constexpr explicit Quaternion(const Vector3& vector): _vector(vector), _scalar(T(0)) {} @@ -403,28 +403,28 @@ template class Quaternion { /** * @brief Rotate vector with quaternion * - * See rotateVectorNormalized(), which is faster for normalized + * See transformVectorNormalized(), which is faster for normalized * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPoint() */ - inline Vector3 rotateVector(const Vector3& vector) const { + inline Vector3 transformVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); } /** * @brief Rotate vector with normalized quaternion * - * Faster alternative to rotateVector(), expects that the quaternion is + * Faster alternative to transformVector(), expects that the quaternion is * normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPointNormalized() */ - inline Vector3 rotateVectorNormalized(const Vector3& vector) const { + inline Vector3 transformVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), - "Math::Quaternion::rotateVectorNormalized(): quaternion must be normalized", + "Math::Quaternion::transformVectorNormalized(): quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*Quaternion(vector)*conjugated()).vector(); } diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 4f905bf3f..771acf398 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -199,7 +199,7 @@ void DualQuaternionTest::combinedTransformParts() { CORRADE_COMPARE_AS(b.rotationAngle(), Deg(23.0f), Rad); CORRADE_COMPARE(a.translation(), translation); - CORRADE_COMPARE(b.translation(), Quaternion::rotation(Deg(23.0f), Vector3::xAxis()).rotateVectorNormalized(translation)); + CORRADE_COMPARE(b.translation(), Quaternion::rotation(Deg(23.0f), Vector3::xAxis()).transformVector(translation)); } void DualQuaternionTest::matrix() { diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 9fd3b6fdf..250e958c7 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -51,8 +51,8 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void matrix(); void lerp(); void slerp(); - void rotateVector(); - void rotateVectorNormalized(); + void transformVector(); + void transformVectorNormalized(); void debug(); }; @@ -92,8 +92,8 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::matrix, &QuaternionTest::lerp, &QuaternionTest::slerp, - &QuaternionTest::rotateVector, - &QuaternionTest::rotateVectorNormalized, + &QuaternionTest::transformVector, + &QuaternionTest::transformVectorNormalized, &QuaternionTest::debug); } @@ -320,30 +320,30 @@ void QuaternionTest::slerp() { CORRADE_COMPARE(slerp, Quaternion({0.119165f, 0.0491109f, 0.0491109f}, 0.990442f)); } -void QuaternionTest::rotateVector() { +void QuaternionTest::transformVector() { Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); Matrix4 m = Matrix4::rotationX(Deg(23.0f)); Vector3 v(5.0f, -3.6f, 0.7f); - Vector3 rotated = a.rotateVector(v); + Vector3 rotated = a.transformVector(v); CORRADE_COMPARE(rotated, m.transformVector(v)); CORRADE_COMPARE(rotated, Vector3(5.0f, -3.58733f, -0.762279f)); } -void QuaternionTest::rotateVectorNormalized() { +void QuaternionTest::transformVectorNormalized() { Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); Matrix4 m = Matrix4::rotationX(Deg(23.0f)); Vector3 v(5.0f, -3.6f, 0.7f); std::ostringstream o; Corrade::Utility::Error::setOutput(&o); - Vector3 notRotated = (a*2).rotateVectorNormalized(v); + Vector3 notRotated = (a*2).transformVectorNormalized(v); CORRADE_VERIFY(notRotated != notRotated); - CORRADE_COMPARE(o.str(), "Math::Quaternion::rotateVectorNormalized(): quaternion must be normalized\n"); + CORRADE_COMPARE(o.str(), "Math::Quaternion::transformVectorNormalized(): quaternion must be normalized\n"); - Vector3 rotated = a.rotateVectorNormalized(v); + Vector3 rotated = a.transformVectorNormalized(v); CORRADE_COMPARE(rotated, m.transformVector(v)); - CORRADE_COMPARE(rotated, a.rotateVector(v)); + CORRADE_COMPARE(rotated, a.transformVector(v)); } void QuaternionTest::debug() { From d1f222d8d9eb4a5fefe9be0399d4459e1b125868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 12:20:17 +0100 Subject: [PATCH 412/567] Math: don't include Functions.h in Quaternion only for T squared. --- src/Math/DualQuaternion.h | 2 +- src/Math/Quaternion.h | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index c83611238..869f4dd0d 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -226,7 +226,7 @@ template class DualQuaternion: public Dual> { * @f] */ inline DualQuaternion inverted() const { - return quaternionConjugated()/Math::pow<2>(length()); + return quaternionConjugated()/pow2(length()); } /** diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 8fe41b9db..1f2e02178 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -23,7 +23,6 @@ #include #include -#include "Math/Functions.h" #include "Math/MathTypeTraits.h" #include "Math/Matrix.h" #include "Math/Vector3.h" @@ -198,7 +197,7 @@ template class Quaternion { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAxis(): quaternion must be normalized", {}); - return _vector/std::sqrt(1-pow<2>(_scalar)); + return _vector/std::sqrt(1-pow2(_scalar)); } /** @@ -208,15 +207,15 @@ template class Quaternion { */ Matrix<3, T> matrix() const { return { - Vector<3, T>(T(1) - 2*pow<2>(_vector.y()) - 2*pow<2>(_vector.z()), + Vector<3, T>(T(1) - 2*pow2(_vector.y()) - 2*pow2(_vector.z()), 2*_vector.x()*_vector.y() + 2*_vector.z()*_scalar, 2*_vector.x()*_vector.z() - 2*_vector.y()*_scalar), Vector<3, T>(2*_vector.x()*_vector.y() - 2*_vector.z()*_scalar, - T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.z()), + T(1) - 2*pow2(_vector.x()) - 2*pow2(_vector.z()), 2*_vector.y()*_vector.z() + 2*_vector.x()*_scalar), Vector<3, T>(2*_vector.x()*_vector.z() + 2*_vector.y()*_scalar, 2*_vector.y()*_vector.z() - 2*_vector.x()*_scalar, - T(1) - 2*pow<2>(_vector.x()) - 2*pow<2>(_vector.y())) + T(1) - 2*pow2(_vector.x()) - 2*pow2(_vector.y())) }; } @@ -430,6 +429,11 @@ template class Quaternion { } private: + /* Used to avoid including Functions.h */ + inline constexpr static T pow2(T value) { + return value*value; + } + /* Used in angle() and slerp() (no assertions) */ inline static T angleInternal(const Quaternion& normalizedA, const Quaternion& normalizedB) { return std::acos(dot(normalizedA, normalizedB)); From f58d152df3e9aa77aca346da53f61da7bba88e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 13:37:42 +0100 Subject: [PATCH 413/567] Math: use lengthSquared() instead of length() squared. Forgot to change this to avoid sqrt(). --- src/Math/DualQuaternion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 869f4dd0d..05cf448d4 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -226,7 +226,7 @@ template class DualQuaternion: public Dual> { * @f] */ inline DualQuaternion inverted() const { - return quaternionConjugated()/pow2(length()); + return quaternionConjugated()/lengthSquared(); } /** From 723488fe97f715289ac455c61ff5fc412d9abb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 15:13:04 +0100 Subject: [PATCH 414/567] Added QtCreator stuff to .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 659b2d8c0..d1ef973af 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ pkg *~ *.kate-swp *.pkg.tar.xz +CMakeLists.txt.user* From 9464e805e16b212ccc6f8b81c96d1efbad14ef29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 16:47:26 +0100 Subject: [PATCH 415/567] Use {} instead of "". Calls default std::string constructor instead of converting from const char*, might possibly save unneeded allocation. --- src/Math/Test/Matrix3Test.cpp | 2 +- src/Math/Test/Matrix4Test.cpp | 2 +- src/Math/Test/MatrixTest.cpp | 2 +- src/Math/Test/QuaternionTest.cpp | 6 +++--- src/Math/Test/RectangularMatrixTest.cpp | 2 +- src/Math/Test/VectorTest.cpp | 4 ++-- src/Mesh.cpp | 4 ++-- src/Physics/Test/AbstractShapeTest.cpp | 2 +- src/Platform/EglContextHandler.cpp | 2 +- src/Test/ColorTest.cpp | 2 +- src/Test/ResourceManagerTest.cpp | 2 +- src/Trade/AbstractImporter.h | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 3ac4de620..2739fccf1 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -191,7 +191,7 @@ void Matrix3Test::invertedEuclidean() { CORRADE_COMPARE(m.invertedEuclidean(), Matrix3()); CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): unexpected values on last row\n"); - o.str(""); + o.str({}); CORRADE_COMPARE(Matrix3::scaling(Vector2(2.0f)).invertedEuclidean(), Matrix3()); CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 434ff84d7..f997450bb 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -266,7 +266,7 @@ void Matrix4Test::invertedEuclidean() { CORRADE_COMPARE(m.invertedEuclidean(), Matrix4()); CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): unexpected values on last row\n"); - o.str(""); + o.str({}); CORRADE_COMPARE(Matrix4::scaling(Vector3(2.0f)).invertedEuclidean(), Matrix4()); CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 330a86b04..1cd499397 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -168,7 +168,7 @@ void MatrixTest::debug() { " 8, 7, 8, 5,\n" " 4, 3, 0, 9)\n"); - o.str(""); + o.str({}); Debug(&o) << "a" << Matrix4() << "b" << Matrix4(); CORRADE_COMPARE(o.str(), "a Matrix(1, 0, 0, 0,\n" " 0, 1, 0, 0,\n" diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 250e958c7..e35d3ffc3 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -257,7 +257,7 @@ void QuaternionTest::angle() { CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); - o.str(""); + o.str({}); angle = Quaternion::angle({{1.0f, 2.0f, -3.0f}, -4.0f}, Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()); CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); @@ -288,7 +288,7 @@ void QuaternionTest::lerp() { CORRADE_COMPARE(notLerpA.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::lerp(): quaternions must be normalized\n"); - o.str(""); + o.str({}); Quaternion notLerpB = Quaternion::lerp(a, b*-3.0f, 0.35f); CORRADE_COMPARE(notLerpB.vector(), Vector3()); CORRADE_COMPARE(notLerpB.scalar(), std::numeric_limits::quiet_NaN()); @@ -310,7 +310,7 @@ void QuaternionTest::slerp() { CORRADE_COMPARE(notSlerpA.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::slerp(): quaternions must be normalized\n"); - o.str(""); + o.str({}); Quaternion notSlerpB = Quaternion::slerp(a, b*-3.0f, 0.35f); CORRADE_COMPARE(notSlerpB.vector(), Vector3()); CORRADE_COMPARE(notSlerpB.scalar(), std::numeric_limits::quiet_NaN()); diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 95aefcc8b..5f3e8867f 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -398,7 +398,7 @@ void RectangularMatrixTest::debug() { " 8, 7, 8,\n" " 4, 3, 0)\n"); - o.str(""); + o.str({}); Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, std::int8_t>(); CORRADE_COMPARE(o.str(), "a Matrix(0, 0, 0,\n" " 0, 0, 0,\n" diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 4c5273d99..d334430a3 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -309,7 +309,7 @@ void VectorTest::angle() { CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); - o.str(""); + o.str({}); angle = Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()); CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); @@ -324,7 +324,7 @@ void VectorTest::debug() { Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n"); - o.str(""); + o.str({}); Debug(&o) << "a" << Vector4() << "b" << Vector4(); CORRADE_COMPARE(o.str(), "a Vector(0, 0, 0, 0) b Vector(0, 0, 0, 0)\n"); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 2275d197d..f78cd89de 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -376,7 +376,7 @@ std::string ConfigurationValue::toString(Magnum::Mesh:: #undef _c } - return ""; + return {}; } Magnum::Mesh::Primitive ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { @@ -401,7 +401,7 @@ std::string ConfigurationValue::toString(Magnum::Mesh:: #undef _c } - return ""; + return {}; } Magnum::Mesh::IndexType ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { diff --git a/src/Physics/Test/AbstractShapeTest.cpp b/src/Physics/Test/AbstractShapeTest.cpp index 973041087..575d1d6df 100644 --- a/src/Physics/Test/AbstractShapeTest.cpp +++ b/src/Physics/Test/AbstractShapeTest.cpp @@ -36,7 +36,7 @@ void AbstractShapeTest::debug() { Debug(&o) << AbstractShape2D::Type::ShapeGroup; CORRADE_COMPARE(o.str(), "AbstractShape2D::Type::ShapeGroup\n"); - o.str(""); + o.str({}); Debug(&o) << AbstractShape3D::Type::Plane; CORRADE_COMPARE(o.str(), "AbstractShape3D::Type::Plane\n"); } diff --git a/src/Platform/EglContextHandler.cpp b/src/Platform/EglContextHandler.cpp index 92cae17b6..a002feace 100644 --- a/src/Platform/EglContextHandler.cpp +++ b/src/Platform/EglContextHandler.cpp @@ -119,7 +119,7 @@ const char* EglContextHandler::errorString(EGLint error) { #undef _error } - return ""; + return {}; } }} diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index e498e1da7..b7af66ad9 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -163,7 +163,7 @@ void ColorTest::debug() { Debug(&o) << Color3f(0.5f, 0.75f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 1)\n"); - o.str(""); + o.str({}); Debug(&o) << Color4f(0.5f, 0.75f, 0.0f, 1.0f); CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 0, 1)\n"); } diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 25ec60ac4..6028555d8 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -132,7 +132,7 @@ void ResourceManagerTest::stateDisallowed() { rm.set("data", &d, ResourceDataState::Loading, ResourcePolicy::Resident); CORRADE_COMPARE(out.str(), "ResourceManager::set(): data should be null if and only if state is NotFound or Loading\n"); - out.str(""); + out.str({}); rm.set("data", nullptr, ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_COMPARE(out.str(), "ResourceManager::set(): data should be null if and only if state is NotFound or Loading\n"); } diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index f31d18dbd..8bc77668f 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -62,7 +62,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { typedef Corrade::Containers::EnumSet Features; /** @brief Constructor */ - inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = ""): Plugin(manager, plugin) {} + inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = {}): Plugin(manager, plugin) {} /** @brief Features supported by this importer */ virtual Features features() const = 0; From 4ad85dceca88e104266611cb4c2286f386590b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 16:48:55 +0100 Subject: [PATCH 416/567] Math: fixed debug output operator for Deg and Rad. It was currently not possible to print this, as the resulting type is neither Deg nor Rad: Debug() << 23.0_degf - 5.0_degf; --- src/Math/Angle.cpp | 8 ++++---- src/Math/Angle.h | 12 ++++++------ src/Math/Test/AngleTest.cpp | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Math/Angle.cpp b/src/Math/Angle.cpp index 73f128ac1..bbf6ed37c 100644 --- a/src/Math/Angle.cpp +++ b/src/Math/Angle.cpp @@ -18,11 +18,11 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Rad&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Deg&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Rad&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Deg&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); #endif #endif diff --git a/src/Math/Angle.h b/src/Math/Angle.h index c1b136b8c..a692572fc 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -219,7 +219,7 @@ template inline constexpr Deg::Deg(Unit value): Unit template inline constexpr Rad::Rad(Unit value): Unit(T(value)*Math::Constants::pi()/T(180)) {} /** @debugoperator{Magnum::Math::Rad} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Rad& value) { +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Unit& value) { debug << "Rad("; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); debug << T(value) << ")"; @@ -228,7 +228,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb } /** @debugoperator{Magnum::Math::Deg} */ -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Deg& value) { +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Unit& value) { debug << "Deg("; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); debug << T(value) << ")"; @@ -238,11 +238,11 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb /* Explicit instantiation for commonly used types */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Rad&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Deg&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Rad&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Deg&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); #endif #endif diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp index dae6cef93..fbd71685c 100644 --- a/src/Math/Test/AngleTest.cpp +++ b/src/Math/Test/AngleTest.cpp @@ -92,22 +92,32 @@ void AngleTest::conversion() { constexpr Deg a(Rad(1.57079633f)); CORRADE_COMPARE(float(a), 90.0f); - constexpr Rad b(Deg(90.0)); + constexpr Rad b(Deg(90.0f)); CORRADE_COMPARE(float(b), 1.57079633f); } void AngleTest::debugDeg() { std::ostringstream o; - Debug(&o) << Deg(90.0); + Debug(&o) << Deg(90.0f); CORRADE_COMPARE(o.str(), "Deg(90)\n"); + + /* Verify that this compiles */ + o.str({}); + Debug(&o) << Deg(56.0f) - Deg(34.0f); + CORRADE_COMPARE(o.str(), "Deg(22)\n"); } void AngleTest::debugRad() { std::ostringstream o; - Debug(&o) << Rad(1.5708); + Debug(&o) << Rad(1.5708f); CORRADE_COMPARE(o.str(), "Rad(1.5708)\n"); + + /* Verify that this compiles */ + o.str({}); + Debug(&o) << Rad(1.5708f) - Rad(3.1416f); + CORRADE_COMPARE(o.str(), "Rad(-1.5708)\n"); } }}} From d2af0888804ad805b7e99135638dd5d7213ae06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 15:08:28 +0100 Subject: [PATCH 417/567] Math: doc++ --- src/Math/Complex.h | 16 ++++++++-------- src/Math/Matrix3.h | 4 ++-- src/Math/Matrix4.h | 4 ++-- src/Math/Quaternion.h | 10 +++++----- src/Math/Vector.h | 10 +++++----- src/Math/Vector2.h | 2 +- src/Math/Vector3.h | 4 ++-- src/Math/Vector4.h | 4 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 91630a9fd..06ba2f59f 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -47,7 +47,7 @@ template class Complex { inline constexpr /*implicit*/ Complex(): _real(T(0)), _imaginary(T(0)) {} /** - * @brief Construct complex from real and imaginary part + * @brief Construct complex number from real and imaginary part * * @f[ * c = a + ib @@ -73,10 +73,10 @@ template class Complex { inline constexpr T imaginary() const { return _imaginary; } /** - * @brief Add and assign complex + * @brief Add complex number and assign * * The computation is done in-place. @f[ - * c_0 + c_1 = a_0 + a_1 + i(b_0 + b_1) + * c_0 + c_1 = (a_0 + a_1) + i(b_0 + b_1) * @f] */ inline Complex& operator+=(const Complex& other) { @@ -86,7 +86,7 @@ template class Complex { } /** - * @brief Add complex + * @brief Add complex number * * @see operator+=() */ @@ -95,7 +95,7 @@ template class Complex { } /** - * @brief Negated complex + * @brief Negated complex number * * @f[ * -c = -a -ib @@ -106,10 +106,10 @@ template class Complex { } /** - * @brief Subtract and assign complex + * @brief Subtract complex number and assign * * The computation is done in-place. @f[ - * c_0 - c_1 = a_0 - a_1 + i(b_0 - b_1) + * c_0 - c_1 = (a_0 - a_1) + i(b_0 - b_1) * @f] */ inline Complex& operator-=(const Complex& other) { @@ -119,7 +119,7 @@ template class Complex { } /** - * @brief Subtract complex + * @brief Subtract complex number * * @see operator-=() */ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index d1a455d64..4e60a23bf 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -206,7 +206,7 @@ template class Matrix3: public Matrix<3, T> { * @brief Transform 2D vector with the matrix * * Translation is not involved in the transformation. @f[ - * \boldsymbol v' = \boldsymbol M (v_x, v_y, 0)^T + * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ 0 \end{pmatrix} * @f] * @see transformPoint(), Matrix4::transformVector() */ @@ -218,7 +218,7 @@ template class Matrix3: public Matrix<3, T> { * @brief Transform 2D point with the matrix * * Unlike in transformVector(), translation is also involved. @f[ - * \boldsymbol v' = \boldsymbol M (v_x, v_y, 1)^T + * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ 1 \end{pmatrix} * @f] * @see Matrix4::transformPoint() */ diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 9b5f2a275..eb6e3fb8e 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -354,7 +354,7 @@ template class Matrix4: public Matrix<4, T> { * @brief Transform 3D vector with the matrix * * Translation is not involved in the transformation. @f[ - * \boldsymbol v' = \boldsymbol M (v_x, v_y, v_z, 0)^T + * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ v_z \\ 0 \end{pmatrix} * @f] * @see transformPoint(), Quaternion::transformVector(), * Matrix3::transformVector() @@ -367,7 +367,7 @@ template class Matrix4: public Matrix<4, T> { * @brief Transform 3D point with the matrix * * Unlike in transformVector(), translation is also involved. @f[ - * \boldsymbol v' = \boldsymbol M (v_x, v_y, v_z, 1)^T + * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ v_z \\ 1 \end{pmatrix} * @f] * @see DualQuaternion::transformPoint(), Matrix3::transformPoint() */ diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 1f2e02178..6eeb8d37a 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -57,7 +57,7 @@ template class Quaternion { * @brief Angle between normalized quaternions * * Expects that both quaternions are normalized. @f[ - * \theta = acos \left( \frac{p \cdot q}{|p| \cdot |q|} \right) + * \theta = acos \left( \frac{p \cdot q}{|p| |q|} \right) = acos(p \cdot q) * @f] */ inline static Rad angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { @@ -93,7 +93,7 @@ template class Quaternion { * Expects that both quaternions are normalized. @f[ * q_{SLERP} = \frac{sin((1 - t) \theta) q_A + sin(t \theta) q_B}{sin \theta} * ~~~~~~~~~~ - * \theta = acos \left( \frac{q_A \cdot q_B}{|q_A| \cdot |q_B|} \right) + * \theta = acos \left( \frac{q_A \cdot q_B}{|q_A| \cdot |q_B|} \right) = acos(q_A \cdot q_B) * @f] * @see lerp() */ @@ -338,7 +338,7 @@ template class Quaternion { * with other values, because it doesn't compute the square root. @f[ * q \cdot q = \boldsymbol q_V \cdot \boldsymbol q_V + q_S^2 * @f] - * @see dot(const Quaternion&, const Quaternion&) + * @see dot(const Quaternion&, const Quaternion&) */ inline T dot() const { return dot(*this, *this); @@ -377,7 +377,7 @@ template class Quaternion { * * See invertedNormalized() which is faster for normalized * quaternions. @f[ - * q^{-1} = \frac{q^*}{|q|^2} = \frac{[-\boldsymbol q_V, q_S]}{q \cdot q} + * q^{-1} = \frac{q^*}{|q|^2} = \frac{q^*}{q \cdot q} * @f] */ inline Quaternion inverted() const { @@ -389,7 +389,7 @@ template class Quaternion { * * Equivalent to conjugated(). Expects that the quaternion is * normalized. @f[ - * q^{-1} = q^* = [-\boldsymbol q_V, q_S] + * q^{-1} = \frac{q^*}{|q|^2} = q^* * @f] */ inline Quaternion invertedNormalized() const { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index d8debb235..9d3f472fa 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -82,7 +82,7 @@ template class Vector { * @brief Angle between normalized vectors * * Expects that both vectors are normalized. @f[ - * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| \cdot |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) + * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) * @f] */ inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { @@ -141,10 +141,9 @@ template class Vector { /** * @brief Raw data - * @return One-dimensional array of `size*size` length in column-major - * order. + * @return One-dimensional array of `size*size` length. * - * @see operator[] + * @see operator[]() */ inline T* data() { return _data; } inline constexpr const T* data() const { return _data; } /**< @overload */ @@ -387,7 +386,7 @@ template class Vector { * other values, because it doesn't compute the square root. @f[ * \boldsymbol a \cdot \boldsymbol a = \sum_{i=0}^{n-1} \boldsymbol a_i^2 * @f] - * @see dot(const Vector&, const Vector&) + * @see dot(const Vector&, const Vector&) */ inline T dot() const { return dot(*this, *this); @@ -400,6 +399,7 @@ template class Vector { * values. @f[ * |\boldsymbol a| = \sqrt{\boldsymbol a \cdot \boldsymbol a} * @f] + * @todo something like std::hypot() for possibly better precision? */ inline T length() const { return std::sqrt(dot()); diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 64f9cc368..397d9bc16 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -81,7 +81,7 @@ template class Vector2: public Vector<2, T> { * @brief Constructor * * @f[ - * \boldsymbol v = (x, y)^T + * \boldsymbol v = \begin{pmatrix} x \\ y \end{pmatrix} * @f] */ inline constexpr /*implicit*/ Vector2(T x, T y): Vector<2, T>(x, y) {} diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index f0ed34d9c..1c92d26d1 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -113,7 +113,7 @@ template class Vector3: public Vector<3, T> { * @brief Constructor * * @f[ - * \boldsymbol v = (x, y, z)^T + * \boldsymbol v = \begin{pmatrix} x \\ y \\ z \end{pmatrix} * @f] */ inline constexpr /*implicit*/ Vector3(T x, T y, T z): Vector<3, T>(x, y, z) {} @@ -122,7 +122,7 @@ template class Vector3: public Vector<3, T> { * @brief Constructor * * @f[ - * \boldsymbol v = (v_x, v_y, z)^T + * \boldsymbol v = \begin{pmatrix} v_x \\ v_y \\ z \end{pmatrix} * @f] */ inline constexpr /*implicit*/ Vector3(const Vector2& xy, T z): Vector<3, T>(xy[0], xy[1], z) {} diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 846634544..d54000222 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -43,7 +43,7 @@ template class Vector4: public Vector<4, T> { * @brief Constructor * * @f[ - * \boldsymbol v = (x, y, z, w)^T + * \boldsymbol v = \begin{pmatrix} x \\ y \\ z \\ w \end{pmatrix} * @f] */ inline constexpr /*implicit*/ Vector4(T x, T y, T z, T w): Vector<4, T>(x, y, z, w) {} @@ -52,7 +52,7 @@ template class Vector4: public Vector<4, T> { * @brief Constructor * * @f[ - * \boldsymbol v = (v_x, v_y, v_z, w)^T + * \boldsymbol v = \begin{pmatrix} v_x \\ v_y \\ v_z \\ w \end{pmatrix} * @f] */ inline constexpr /*implicit*/ Vector4(const Vector3& xyz, T w): Vector<4, T>(xyz[0], xyz[1], xyz[2], w) {} From b509ff02ea3240e4aaf693cf8c7b7e01ef557ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 15:49:37 +0100 Subject: [PATCH 418/567] Math: complex number multiplication. --- src/Math/Complex.h | 12 ++++++++++++ src/Math/Test/ComplexTest.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 06ba2f59f..71710f371 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -171,6 +171,18 @@ template class Complex { return Complex(*this) /= scalar; } + /** + * @brief Multiply with complex number + * + * @f[ + * c_0 c_1 = (a_0 + ib_0)(a_1 + ib_1) = (a_0 a_1 - b_0 b_1) + i(a_1 b_0 + a_0 b_1) + * @f] + */ + inline Complex operator*(const Complex& other) const { + return {_real*other._real - _imaginary*other._imaginary, + _imaginary*other._real + _real*other._imaginary}; + } + private: T _real, _imaginary; }; diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index f4c352252..8c06bcf2f 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -33,6 +33,7 @@ class ComplexTest: public Corrade::TestSuite::Tester { void addSubtract(); void negated(); void multiplyDivideScalar(); + void multiply(); void debug(); }; @@ -47,6 +48,7 @@ ComplexTest::ComplexTest() { &ComplexTest::addSubtract, &ComplexTest::negated, &ComplexTest::multiplyDivideScalar, + &ComplexTest::multiply, &ComplexTest::debug); } @@ -117,6 +119,15 @@ void ComplexTest::multiplyDivideScalar() { CORRADE_COMPARE(-2.0f/a, c); } +void ComplexTest::multiply() { + Complex a( 5.0f, 3.0f); + Complex b( 6.0f, -7.0f); + Complex c(51.0f, -17.0f); + + CORRADE_COMPARE(a*b, c); + CORRADE_COMPARE(b*a, c); +} + void ComplexTest::debug() { std::ostringstream o; From dc5a19f952d13e0d5d21b8a614deee653430a9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 15:58:46 +0100 Subject: [PATCH 419/567] Math: complex number dot product, length and normalization. --- src/Math/Complex.h | 42 +++++++++++++++++++++++++++++++++++ src/Math/Test/ComplexTest.cpp | 33 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 71710f371..72fed26e3 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -37,6 +37,18 @@ template class Complex { public: typedef T Type; /**< @brief Underlying data type */ + /** + * @brief Dot product + * + * @f[ + * c_0 \cdot c_1 = c_0 \overline{c_1} = (a_0 a_1 + b_0 b_1) + i(a_1 b_0 - a_0 b_1) + * @f] + * @see dot() const + */ + inline static Complex dot(const Complex& a, const Complex& b) { + return a*b.conjugated(); + } + /** * @brief Default constructor * @@ -183,6 +195,36 @@ template class Complex { _imaginary*other._real + _real*other._imaginary}; } + /** + * @brief Dot product of the complex number + * + * Should be used instead of length() for comparing complex number length + * with other values, because it doesn't compute the square root. @f[ + * c \cdot c = c \overline c = a^2 + b^2 + * @f] + * @see dot(const Complex&, const Complex&) + */ + inline T dot() const { + return _real*_real + _imaginary*_imaginary; + } + + /** + * @brief %Complex number length + * + * See also dot() const which is faster for comparing length with other + * values. @f[ + * |c| = \sqrt{c \overline c} = \sqrt{a^2 + b^2} + * @f] + */ + inline T length() const { + return std::hypot(_real, _imaginary); + } + + /** @brief Normalized complex number (of unit length) */ + inline Complex normalized() const { + return (*this)/length(); + } + private: T _real, _imaginary; }; diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 8c06bcf2f..9916ed582 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -35,6 +35,11 @@ class ComplexTest: public Corrade::TestSuite::Tester { void multiplyDivideScalar(); void multiply(); + void dot(); + void dotSelf(); + void length(); + void normalized(); + void debug(); }; @@ -50,6 +55,11 @@ ComplexTest::ComplexTest() { &ComplexTest::multiplyDivideScalar, &ComplexTest::multiply, + &ComplexTest::dot, + &ComplexTest::dotSelf, + &ComplexTest::length, + &ComplexTest::normalized, + &ComplexTest::debug); } @@ -128,6 +138,29 @@ void ComplexTest::multiply() { CORRADE_COMPARE(b*a, c); } +void ComplexTest::dot() { + Complex a(5.0f, 3.0f); + Complex b(6.0f, -7.0f); + + CORRADE_COMPARE(Complex::dot(a, b), Complex(9.0f, 53.0f)); +} + +void ComplexTest::dotSelf() { + CORRADE_COMPARE(Complex(-4.0f, 3.0f).dot(), 25.0f); +} + +void ComplexTest::length() { + CORRADE_COMPARE(Complex(-4.0f, 3.0f).length(), 5.0f); +} + +void ComplexTest::normalized() { + Complex a(-3.0f, 4.0f); + Complex b(-0.6f, 0.8f); + + CORRADE_COMPARE(a.normalized(), b); + CORRADE_COMPARE(a.normalized().length(), 1.0f); +} + void ComplexTest::debug() { std::ostringstream o; From 728b9a3f2ea291cbedae1cfb60bc33a17c3c833b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 15:00:46 +0100 Subject: [PATCH 420/567] Math: construct identity transformation by default. Square matrices already had that, (dual) quaternions too, making that the default also with complex numbers. Updated the documentation to reflect that. --- src/Math/Complex.h | 6 +++--- src/Math/DualQuaternion.h | 4 ++-- src/Math/Matrix3.h | 10 ++++++++-- src/Math/Matrix4.h | 10 ++++++++-- src/Math/Quaternion.h | 4 ++-- src/Math/Test/ComplexTest.cpp | 5 +++-- src/Math/Test/DualQuaternionTest.cpp | 5 +---- src/Math/Test/QuaternionTest.cpp | 1 + src/Math/Vector.h | 2 +- 9 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 72fed26e3..a0c640d53 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -52,11 +52,11 @@ template class Complex { /** * @brief Default constructor * - * @f[ - * c = 0 + i0 + * Constructs unit complex number. @f[ + * c = 1 + i0 * @f] */ - inline constexpr /*implicit*/ Complex(): _real(T(0)), _imaginary(T(0)) {} + inline constexpr /*implicit*/ Complex(): _real(T(1)), _imaginary(T(0)) {} /** * @brief Construct complex number from real and imaginary part diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 05cf448d4..bd68b8d36 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -69,7 +69,7 @@ template class DualQuaternion: public Dual> { /** * @brief Default constructor * - * @f[ + * Creates unit dual quaternion. @f[ * \hat q = [\boldsymbol 0, 1] + \epsilon [\boldsymbol 0, 0] * @f] * @todoc Remove workaround when Doxygen is predictable @@ -212,7 +212,7 @@ template class DualQuaternion: public Dual> { return Math::sqrt(lengthSquared()); } - /** @brief Normalized quaternion (of length 1) */ + /** @brief Normalized quaternion (of unit length) */ inline DualQuaternion normalized() const { return (*this)/length(); } diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 4e60a23bf..d93050281 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -116,8 +116,14 @@ template class Matrix3: public Matrix<3, T> { /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {} - /** @copydoc Matrix::Matrix(IdentityType, T) */ - /** @todo Use constexpr implementation in Matrix, when done */ + /** + * @brief Default constructor + * + * Creates identity matrix. You can also explicitly call this + * constructor with `Matrix3 m(Matrix3::Identity);`. Optional parameter + * @p value allows you to specify value on diagonal. + * @todo Use constexpr implementation in Matrix, when done + */ inline constexpr /*implicit*/ Matrix3(typename Matrix<3, T>::IdentityType = (Matrix<3, T>::Identity), T value = T(1)): Matrix<3, T>( Vector<3, T>(value, T(0), T(0)), Vector<3, T>( T(0), value, T(0)), diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index eb6e3fb8e..b77f5bbf6 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -249,8 +249,14 @@ template class Matrix4: public Matrix<4, T> { /** @copydoc Matrix::Matrix(ZeroType) */ inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {} - /** @copydoc Matrix::Matrix(IdentityType, T) */ - /** @todo Use constexpr implementation in Matrix, when done */ + /** + * @brief Default constructor + * + * Creates identity matrix. You can also explicitly call this + * constructor with `Matrix4 m(Matrix4::Identity);`. Optional parameter + * @p value allows you to specify value on diagonal. + * @todo Use constexpr implementation in Matrix, when done + */ inline constexpr /*implicit*/ Matrix4(typename Matrix<4, T>::IdentityType = (Matrix<4, T>::Identity), T value = T(1)): Matrix<4, T>( Vector<4, T>(value, T(0), T(0), T(0)), Vector<4, T>( T(0), value, T(0), T(0)), diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 6eeb8d37a..1c11fea04 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -127,7 +127,7 @@ template class Quaternion { /** * @brief Default constructor * - * @f[ + * Creates unit quaternion. @f[ * q = [\boldsymbol 0, 1] * @f] */ @@ -356,7 +356,7 @@ template class Quaternion { return std::sqrt(dot()); } - /** @brief Normalized quaternion (of length 1) */ + /** @brief Normalized quaternion (of unit length) */ inline Quaternion normalized() const { return (*this)/length(); } diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 9916ed582..d8ffeb85d 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -74,7 +74,8 @@ void ComplexTest::construct() { } void ComplexTest::constructDefault() { - CORRADE_COMPARE(Complex(), Complex(0.0f, 0.0f)); + CORRADE_COMPARE(Complex(), Complex(1.0f, 0.0f)); + CORRADE_COMPARE(Complex().length(), 1.0f); } void ComplexTest::compare() { @@ -87,7 +88,7 @@ void ComplexTest::compare() { void ComplexTest::constExpressions() { /* Default constructor */ constexpr Complex a; - CORRADE_COMPARE(a, Complex(0.0f, 0.0f)); + CORRADE_COMPARE(a, Complex(1.0f, 0.0f)); /* Value constructor */ constexpr Complex b(2.5f, -5.0f); diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 771acf398..da954935f 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -92,6 +92,7 @@ void DualQuaternionTest::construct() { void DualQuaternionTest::constructDefault() { CORRADE_COMPARE(DualQuaternion(), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); + CORRADE_COMPARE(DualQuaternion().length(), 1.0f); } void DualQuaternionTest::constructFromVector() { @@ -117,15 +118,11 @@ void DualQuaternionTest::constExpressions() { } void DualQuaternionTest::lengthSquared() { - CORRADE_COMPARE(DualQuaternion().lengthSquared(), 1.0f); - DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); CORRADE_COMPARE(a.lengthSquared(), Dual(30.0f, -9.0f)); } void DualQuaternionTest::length() { - CORRADE_COMPARE(DualQuaternion().length(), 1.0f); - DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); CORRADE_COMPARE(a.length(), Dual(5.477226f, -0.821584f)); } diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index e35d3ffc3..6b2e357ae 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -106,6 +106,7 @@ void QuaternionTest::construct() { void QuaternionTest::constructDefault() { CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); + CORRADE_COMPARE(Quaternion().length(), 1.0f); } void QuaternionTest::constructFromVector() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 9d3f472fa..e07862b63 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -405,7 +405,7 @@ template class Vector { return std::sqrt(dot()); } - /** @brief Normalized vector (of length 1) */ + /** @brief Normalized vector (of unit length) */ inline Vector normalized() const { return *this/length(); } From fc8750c51f69b33bf4f56fb5601011fbb6fc45a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 16:17:06 +0100 Subject: [PATCH 421/567] Math: conjugation and inversion of complex numbers. Also updated related Quaternion and DualQuaternion documentation. --- src/Math/Complex.h | 41 +++++++++++++++++++++++++++++++++++ src/Math/DualQuaternion.h | 1 + src/Math/Quaternion.h | 1 + src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/ComplexTest.cpp | 39 +++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index a0c640d53..923d39c72 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Math::Complex */ +#include +#include #include #include "Math/MathTypeTraits.h" @@ -225,6 +227,45 @@ template class Complex { return (*this)/length(); } + /** + * @brief Conjugated complex number + * + * @f[ + * \overline c = a - ib + * @f] + */ + inline Complex conjugated() const { + return {_real, -_imaginary}; + } + + /** + * @brief Inverted complex number + * + * See invertedNormalized() which is faster for normalized + * complex numbers. @f[ + * c^{-1} = \frac{\overline c}{c \overline c} = \frac{\overline c}{a^2 + b^2} + * @f] + */ + inline Complex inverted() const { + return conjugated()/dot(); + } + + /** + * @brief Inverted normalized complex number + * + * Equivalent to conjugated(). Expects that the complex number is + * normalized. @f[ + * c^{-1} = \frac{\overline c}{c \overline c} = \frac{\overline c}{a^2 + b^2} = \overline c + * @f] + * @see inverted() + */ + inline Complex invertedNormalized() const { + CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + "Math::Complex::invertedNormalized(): complex number must be normalized", + Complex(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); + return conjugated(); + } + private: T _real, _imaginary; }; diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index bd68b8d36..35d67565c 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -236,6 +236,7 @@ template class DualQuaternion: public Dual> { * normalized. @f[ * \hat q^{-1} = \frac{\hat q^*}{||\hat q||^2} = \hat q^* * @f] + * @see inverted() */ inline DualQuaternion invertedNormalized() const { CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 1c11fea04..0c284a8ac 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -391,6 +391,7 @@ template class Quaternion { * normalized. @f[ * q^{-1} = \frac{q^*}{|q|^2} = q^* * @f] + * @see inverted() */ inline Quaternion invertedNormalized() const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index d5e0f63f0..76d7980dc 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -26,6 +26,7 @@ set_target_properties( MathVectorTest MathMatrix3Test MathMatrix4Test + MathComplexTest MathDualQuaternionTest MathQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index d8ffeb85d..8b0f1ec7a 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -40,6 +40,10 @@ class ComplexTest: public Corrade::TestSuite::Tester { void length(); void normalized(); + void conjugated(); + void inverted(); + void invertedNormalized(); + void debug(); }; @@ -60,6 +64,10 @@ ComplexTest::ComplexTest() { &ComplexTest::length, &ComplexTest::normalized, + &ComplexTest::conjugated, + &ComplexTest::inverted, + &ComplexTest::invertedNormalized, + &ComplexTest::debug); } @@ -162,6 +170,37 @@ void ComplexTest::normalized() { CORRADE_COMPARE(a.normalized().length(), 1.0f); } +void ComplexTest::conjugated() { + CORRADE_COMPARE(Complex(-3.0f, 4.5f).conjugated(), Complex(-3.0f, -4.5f)); +} + +void ComplexTest::inverted() { + Complex a(-3.0f, 4.0f); + Complex b(-0.12f, -0.16f); + + Complex inverted = a.inverted(); + CORRADE_COMPARE(a*inverted, Complex()); + CORRADE_COMPARE(inverted*a, Complex()); + CORRADE_COMPARE(inverted, b); +} + +void ComplexTest::invertedNormalized() { + std::ostringstream o; + Error::setOutput(&o); + + Complex a(-0.6f, 0.8f); + Complex b(-0.6f, -0.8f); + + Complex notInverted = (a*2).invertedNormalized(); + CORRADE_VERIFY(notInverted != notInverted); + CORRADE_COMPARE(o.str(), "Math::Complex::invertedNormalized(): complex number must be normalized\n"); + + Complex inverted = a.invertedNormalized(); + CORRADE_COMPARE(a*inverted, Complex()); + CORRADE_COMPARE(inverted*a, Complex()); + CORRADE_COMPARE(inverted, b); +} + void ComplexTest::debug() { std::ostringstream o; From 4ebd20448225c562dd716ebfc98deb69d81342ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 16:54:19 +0100 Subject: [PATCH 422/567] Math: angle between two complex numbers. Also crosslinked the documentation with similar functions in Vector and Quaternion. --- src/Math/Complex.h | 15 +++++++++++++++ src/Math/Quaternion.h | 1 + src/Math/Test/ComplexTest.cpp | 27 +++++++++++++++++++++++++++ src/Math/Test/QuaternionTest.cpp | 11 +++++++---- src/Math/Vector.h | 1 + 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 923d39c72..93122b74b 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -23,6 +23,7 @@ #include #include +#include "Math/Angle.h" #include "Math/MathTypeTraits.h" #include "magnumVisibility.h" @@ -51,6 +52,20 @@ template class Complex { return a*b.conjugated(); } + /** + * @brief Angle between normalized complex numbers + * + * Expects that both complex numbers are normalized. @f[ + * \theta = acos \left( \frac{Re(c_0 \cdot c_1))}{|c_0| |c_1|} \right) = acos (a_0 a_1 + b_0 b_1) + * @f] + * @see Quaternion::angle(), Vector::angle() + */ + inline static Rad angle(const Complex& normalizedA, const Complex& normalizedB) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + "Math::Complex::angle(): complex numbers must be normalized", Rad(std::numeric_limits::quiet_NaN())); + return Rad(std::acos(normalizedA._real*normalizedB._real + normalizedA._imaginary*normalizedB._imaginary)); + } + /** * @brief Default constructor * diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 0c284a8ac..5edfee668 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -59,6 +59,7 @@ template class Quaternion { * Expects that both quaternions are normalized. @f[ * \theta = acos \left( \frac{p \cdot q}{|p| |q|} \right) = acos(p \cdot q) * @f] + * @see Complex::angle(), Vector::angle() */ inline static Rad angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 8b0f1ec7a..f448f2003 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -17,6 +17,7 @@ #include #include "Math/Complex.h" +#include "Math/Vector2.h" namespace Magnum { namespace Math { namespace Test { @@ -44,6 +45,8 @@ class ComplexTest: public Corrade::TestSuite::Tester { void inverted(); void invertedNormalized(); + void angle(); + void debug(); }; @@ -68,10 +71,14 @@ ComplexTest::ComplexTest() { &ComplexTest::inverted, &ComplexTest::invertedNormalized, + &ComplexTest::angle, + &ComplexTest::debug); } +typedef Math::Rad Rad; typedef Math::Complex Complex; +typedef Math::Vector2 Vector2; void ComplexTest::construct() { Complex c(0.5f, -3.7f); @@ -201,6 +208,26 @@ void ComplexTest::invertedNormalized() { CORRADE_COMPARE(inverted, b); } +void ComplexTest::angle() { + std::ostringstream o; + Error::setOutput(&o); + auto angle = Complex::angle(Complex(1.5f, -2.0f).normalized(), {-4.0f, 3.5f}); + CORRADE_VERIFY(angle != angle); + CORRADE_COMPARE(o.str(), "Math::Complex::angle(): complex numbers must be normalized\n"); + + o.str({}); + angle = Complex::angle({1.5f, -2.0f}, Complex(-4.0f, 3.5f).normalized()); + CORRADE_VERIFY(angle != angle); + CORRADE_COMPARE(o.str(), "Math::Complex::angle(): complex numbers must be normalized\n"); + + /* Verify also that the angle is the same as angle between 2D vectors */ + angle = Complex::angle(Complex( 1.5f, -2.0f).normalized(), + Complex(-4.0f, 3.5f).normalized()); + CORRADE_COMPARE(angle, Vector2::angle(Vector2( 1.5f, -2.0f).normalized(), + Vector2(-4.0f, 3.5f).normalized())); + CORRADE_COMPARE(angle, Rad(2.933128f)); +} + void ComplexTest::debug() { std::ostringstream o; diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 6b2e357ae..3b6ad4955 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -253,7 +253,7 @@ void QuaternionTest::rotation() { void QuaternionTest::angle() { std::ostringstream o; - Corrade::Utility::Error::setOutput(&o); + Error::setOutput(&o); auto angle = Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), {{4.0f, -3.0f, 2.0f}, -1.0f}); CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); @@ -263,9 +263,12 @@ void QuaternionTest::angle() { CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); - CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), - Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), - Rad(1.704528f)); + /* Verify also that the angle is the same as angle between 4D vectors */ + angle = Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), + Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()); + CORRADE_COMPARE(angle, Vector4::angle(Vector4(1.0f, 2.0f, -3.0f, -4.0f).normalized(), + Vector4(4.0f, -3.0f, 2.0f, -1.0f).normalized())); + CORRADE_COMPARE(angle, Rad(1.704528f)); } void QuaternionTest::matrix() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index e07862b63..8630cca78 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -84,6 +84,7 @@ template class Vector { * Expects that both vectors are normalized. @f[ * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) * @f] + * @see Quaternion::angle(), Complex::angle() */ inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), From e7ceddf0fc2dd7fc02aeb31a665c0669bb7656f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 17:55:00 +0100 Subject: [PATCH 423/567] Math: rotation complex number. --- src/Math/Complex.h | 24 ++++++++++++++++++++++++ src/Math/Matrix3.h | 3 ++- src/Math/Quaternion.h | 6 +++--- src/Math/Test/ComplexTest.cpp | 17 +++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 93122b74b..62053251c 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -66,6 +66,19 @@ template class Complex { return Rad(std::acos(normalizedA._real*normalizedB._real + normalizedA._imaginary*normalizedB._imaginary)); } + /** + * @brief Rotation complex number + * @param angle Rotation angle (counterclockwise) + * + * @f[ + * c = cos \theta + i sin \theta + * @f] + * @see rotationAngle(), Matrix3::rotation(), Quaternion::rotation() + */ + inline static Complex rotation(Rad angle) { + return {std::cos(T(angle)), std::sin(T(angle))}; + } + /** * @brief Default constructor * @@ -101,6 +114,17 @@ template class Complex { /** @brief Imaginary part */ inline constexpr T imaginary() const { return _imaginary; } + /** + * @brief Rotation angle of complex number + * + * @f[ + * \theta = atan2(b, a) + * @f] + */ + inline Rad rotationAngle() const { + return Rad(std::atan2(_imaginary, _real)); + } + /** * @brief Add complex number and assign * diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index d93050281..87be55128 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -64,7 +64,8 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D rotation matrix * @param angle Rotation angle (counterclockwise) * - * @see rotation() const, Matrix4::rotation(Rad, const Vector3&) + * @see rotation() const, Complex::rotation(), + * Matrix4::rotation(Rad, const Vector3&) */ static Matrix3 rotation(Rad angle) { T sine = std::sin(T(angle)); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 5edfee668..6ce8ae078 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -108,15 +108,15 @@ template class Quaternion { /** * @brief Rotation quaternion - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * * Expects that the rotation axis is normalized. @f[ * q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] * @f] * @see rotationAngle(), rotationAxis(), DualQuaternion::rotation(), - * Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis() + * Matrix4::rotation(), Complex::rotation(), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis() */ inline static Quaternion rotation(Rad angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index f448f2003..c0a25c62a 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -46,6 +46,7 @@ class ComplexTest: public Corrade::TestSuite::Tester { void invertedNormalized(); void angle(); + void rotation(); void debug(); }; @@ -72,10 +73,12 @@ ComplexTest::ComplexTest() { &ComplexTest::invertedNormalized, &ComplexTest::angle, + &ComplexTest::rotation, &ComplexTest::debug); } +typedef Math::Deg Deg; typedef Math::Rad Rad; typedef Math::Complex Complex; typedef Math::Vector2 Vector2; @@ -228,6 +231,20 @@ void ComplexTest::angle() { CORRADE_COMPARE(angle, Rad(2.933128f)); } +void ComplexTest::rotation() { + Complex a = Complex::rotation(Deg(120.0f)); + CORRADE_COMPARE(a, Complex(-0.5f, 0.8660254f)); + CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); + + /* Verify negative angle */ + Complex b = Complex::rotation(Deg(-240.0f)); + CORRADE_COMPARE(b, Complex(-0.5f, 0.8660254f)); + CORRADE_COMPARE_AS(b.rotationAngle(), Deg(120.0f), Rad); + + /* Default-constructed complex number has zero angle */ + CORRADE_COMPARE_AS(Complex().rotationAngle(), Deg(0.0f), Rad); +} + void ComplexTest::debug() { std::ostringstream o; From 8aade865717237437d07d758afa1b65c5d93fe96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 18:12:54 +0100 Subject: [PATCH 424/567] Math: converting complex number to rotation matrix. --- src/Math/Complex.h | 21 +++++++++++++++++---- src/Math/Test/ComplexTest.cpp | 13 ++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 62053251c..cdd512df7 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -23,10 +23,7 @@ #include #include -#include "Math/Angle.h" -#include "Math/MathTypeTraits.h" - -#include "magnumVisibility.h" +#include "Math/Matrix.h" namespace Magnum { namespace Math { @@ -125,6 +122,22 @@ template class Complex { return Rad(std::atan2(_imaginary, _real)); } + /** + * @brief Convert complex number to rotation matrix + * + * @f[ + * M = \begin{pmatrix} + * a & -b \\ + * b & a + * \end{pmatrix} + * @f] + * @see Matrix3::from(const Matrix<2, T>&, const Vector2&) + */ + Matrix<2, T> matrix() const { + return {Vector<2, T>(_real, _imaginary), + Vector<2, T>(-_imaginary, _real)}; + } + /** * @brief Add complex number and assign * diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index c0a25c62a..c414a8f13 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -17,7 +17,7 @@ #include #include "Math/Complex.h" -#include "Math/Vector2.h" +#include "Math/Matrix3.h" namespace Magnum { namespace Math { namespace Test { @@ -47,6 +47,7 @@ class ComplexTest: public Corrade::TestSuite::Tester { void angle(); void rotation(); + void matrix(); void debug(); }; @@ -74,6 +75,7 @@ ComplexTest::ComplexTest() { &ComplexTest::angle, &ComplexTest::rotation, + &ComplexTest::matrix, &ComplexTest::debug); } @@ -82,6 +84,8 @@ typedef Math::Deg Deg; typedef Math::Rad Rad; typedef Math::Complex Complex; typedef Math::Vector2 Vector2; +typedef Math::Matrix3 Matrix3; +typedef Math::Matrix<2, float> Matrix2; void ComplexTest::construct() { Complex c(0.5f, -3.7f); @@ -245,6 +249,13 @@ void ComplexTest::rotation() { CORRADE_COMPARE_AS(Complex().rotationAngle(), Deg(0.0f), Rad); } +void ComplexTest::matrix() { + Complex a = Complex::rotation(Deg(37.0f)); + Matrix2 m = Matrix3::rotation(Deg(37.0f)).rotationScaling(); + + CORRADE_COMPARE(a.matrix(), m); +} + void ComplexTest::debug() { std::ostringstream o; From 93952cd72abb3c4bb318707b05b173fba4c8ee8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 18:26:21 +0100 Subject: [PATCH 425/567] Math: converting Vector2 to Complex and back. --- src/Math/Complex.h | 22 ++++++++++++++++++++++ src/Math/Test/ComplexTest.cpp | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index cdd512df7..1950a85c8 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -24,6 +24,7 @@ #include #include "Math/Matrix.h" +#include "Math/Vector2.h" namespace Magnum { namespace Math { @@ -94,6 +95,16 @@ template class Complex { */ inline constexpr /*implicit*/ Complex(T real, T imaginary = T(0)): _real(real), _imaginary(imaginary) {} + /** + * @brief Construct complex number from vector + * + * To be used in transformations later. @f[ + * c = v_x + iv_y + * @f] + * @see operator Vector2(), transformVector(), transformVectorNormalized() + */ + inline constexpr explicit Complex(const Vector2& vector): _real(vector.x()), _imaginary(vector.y()) {} + /** @brief Equality comparison */ inline bool operator==(const Complex& other) const { return MathTypeTraits::equals(_real, other._real) && @@ -111,6 +122,17 @@ template class Complex { /** @brief Imaginary part */ inline constexpr T imaginary() const { return _imaginary; } + /** + * @brief Convert complex number to vector + * + * @f[ + * \boldsymbol v = \begin{pmatrix} a \\ b \end{pmatrix} + * @f] + */ + inline constexpr explicit operator Vector2() const { + return {_real, _imaginary}; + } + /** * @brief Rotation angle of complex number * diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index c414a8f13..697b4a376 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -27,6 +27,7 @@ class ComplexTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); + void constructFromVector(); void compare(); void constExpressions(); @@ -55,6 +56,7 @@ class ComplexTest: public Corrade::TestSuite::Tester { ComplexTest::ComplexTest() { addTests(&ComplexTest::construct, &ComplexTest::constructDefault, + &ComplexTest::constructFromVector, &ComplexTest::compare, &ComplexTest::constExpressions, @@ -100,6 +102,14 @@ void ComplexTest::constructDefault() { CORRADE_COMPARE(Complex().length(), 1.0f); } +void ComplexTest::constructFromVector() { + Vector2 vec(1.5f, -3.0f); + + Complex a(vec); + CORRADE_COMPARE(a, Complex(1.5f, -3.0f)); + CORRADE_COMPARE(Vector2(a), vec); +} + void ComplexTest::compare() { CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); From d59b620fd96f095c1910adfc762b94b03a9d1186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 22 Feb 2013 18:46:29 +0100 Subject: [PATCH 426/567] Math: transforming vectors with complex numbers. --- src/Math/Complex.h | 29 +++++++++++++++++++++++++++++ src/Math/DualQuaternion.h | 6 ++++-- src/Math/Matrix3.h | 8 +++++--- src/Math/Matrix4.h | 9 +++++---- src/Math/Quaternion.h | 11 +++++++---- src/Math/Test/ComplexTest.cpp | 30 ++++++++++++++++++++++++++++++ src/Math/Test/QuaternionTest.cpp | 2 +- 7 files changed, 81 insertions(+), 14 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 1950a85c8..36f559263 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -340,6 +340,35 @@ template class Complex { return conjugated(); } + /** + * @brief Rotate vector with complex number + * + * See transformVectorNormalized(), which is faster for normalized + * complex numbers. @f[ + * v' = \frac c {|c|} v = \frac c {|c|} (v_x + iv_y) + * @f] + * @see Complex(const Vector2&), operator Vector2(), Matrix3::transformVector() + */ + inline Vector2 transformVector(const Vector2& vector) const { + return Vector2(normalized()*Complex(vector)); + } + + /** + * @brief Rotate vector with normalized complex number + * + * Faster alternative to transformVector(), expects that the complex + * number is normalized. @f[ + * v' = \frac c {|c|} v = cv = c(v_x + iv_y) + * @f] + * @see Complex(const Vector2&), operator Vector2(), Matrix3::transformVector() + */ + inline Vector2 transformVectorNormalized(const Vector2& vector) const { + CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + "Math::Complex::transformVectorNormalized(): complex number must be normalized", + Vector2(std::numeric_limits::quiet_NaN())); + return Vector2((*this)*Complex(vector)); + } + private: T _real, _imaginary; }; diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 35d67565c..543383718 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -251,7 +251,8 @@ template class DualQuaternion: public Dual> { * quaternions. @f[ * v' = qv \overline{\hat q^{-1}} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^{-1}} * @f] - * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::transformVector() + * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), + * Quaternion::transformVector() */ inline Vector3 transformPoint(const Vector3& vector) const { return ((*this)*DualQuaternion(vector)*inverted().dualConjugated()).dual().vector(); @@ -264,7 +265,8 @@ template class DualQuaternion: public Dual> { * quaternion is normalized. @f[ * v' = qv \overline{\hat q^{-1}} = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] - * @see DualQuaternion(const Vector3&), Matrix4::transformPoint(), Quaternion::transformVectorNormalized() + * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), + * Quaternion::transformVectorNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits>::equals(lengthSquared(), Dual(1)), diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 87be55128..f9b1b09b5 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -212,10 +212,11 @@ template class Matrix3: public Matrix<3, T> { /** * @brief Transform 2D vector with the matrix * - * Translation is not involved in the transformation. @f[ + * Unlike in transformPoint(), translation is not involved in the + * transformation. @f[ * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ 0 \end{pmatrix} * @f] - * @see transformPoint(), Matrix4::transformVector() + * @see Complex::transformVector(), Matrix4::transformVector() */ inline Vector2 transformVector(const Vector2& vector) const { return ((*this)*Vector3(vector, T(0))).xy(); @@ -224,7 +225,8 @@ template class Matrix3: public Matrix<3, T> { /** * @brief Transform 2D point with the matrix * - * Unlike in transformVector(), translation is also involved. @f[ + * Unlike in transformVector(), translation is also involved in the + * transformation. @f[ * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ 1 \end{pmatrix} * @f] * @see Matrix4::transformPoint() diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index b77f5bbf6..198aa8c65 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -359,11 +359,11 @@ template class Matrix4: public Matrix<4, T> { /** * @brief Transform 3D vector with the matrix * - * Translation is not involved in the transformation. @f[ + * Unlike in transformVector(), translation is not involved in the + * transformation. @f[ * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ v_z \\ 0 \end{pmatrix} * @f] - * @see transformPoint(), Quaternion::transformVector(), - * Matrix3::transformVector() + * @see Quaternion::transformVector(), Matrix3::transformVector() */ inline Vector3 transformVector(const Vector3& vector) const { return ((*this)*Vector4(vector, T(0))).xyz(); @@ -372,7 +372,8 @@ template class Matrix4: public Matrix<4, T> { /** * @brief Transform 3D point with the matrix * - * Unlike in transformVector(), translation is also involved. @f[ + * Unlike in transformVector(), translation is also involved in the + * transformation. @f[ * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ v_z \\ 1 \end{pmatrix} * @f] * @see DualQuaternion::transformPoint(), Matrix3::transformPoint() diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 6ce8ae078..a7c04bb22 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -408,7 +408,8 @@ template class Quaternion { * quaternions. @f[ * v' = qvq^{-1} = q [\boldsymbol v, 0] q^{-1} * @f] - * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPoint() + * @see Quaternion(const Vector3&), vector(), Matrix4::transformVector(), + * DualQuaternion::transformPoint(), Complex::transformVector() */ inline Vector3 transformVector(const Vector3& vector) const { return ((*this)*Quaternion(vector)*inverted()).vector(); @@ -417,11 +418,13 @@ template class Quaternion { /** * @brief Rotate vector with normalized quaternion * - * Faster alternative to transformVector(), expects that the quaternion is - * normalized. @f[ + * Faster alternative to transformVector(), expects that the quaternion + * is normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] - * @see Quaternion(const Vector3&), Matrix4::transformVector(), DualQuaternion::transformPointNormalized() + * @see Quaternion(const Vector3&), vector(), Matrix4::transformVector(), + * DualQuaternion::transformPointNormalized(), + * Complex::transformVectorNormalized() */ inline Vector3 transformVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 697b4a376..a93db8ccf 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -49,6 +49,8 @@ class ComplexTest: public Corrade::TestSuite::Tester { void angle(); void rotation(); void matrix(); + void transformVector(); + void transformVectorNormalized(); void debug(); }; @@ -78,6 +80,8 @@ ComplexTest::ComplexTest() { &ComplexTest::angle, &ComplexTest::rotation, &ComplexTest::matrix, + &ComplexTest::transformVector, + &ComplexTest::transformVectorNormalized, &ComplexTest::debug); } @@ -266,6 +270,32 @@ void ComplexTest::matrix() { CORRADE_COMPARE(a.matrix(), m); } +void ComplexTest::transformVector() { + Complex a = Complex::rotation(Deg(23.0f)); + Matrix3 m = Matrix3::rotation(Deg(23.0f)); + Vector2 v(-3.6f, 0.7f); + + Vector2 rotated = a.transformVector(v); + CORRADE_COMPARE(rotated, m.transformVector(v)); + CORRADE_COMPARE(rotated, Vector2(-3.58733f, -0.762279f)); +} + +void ComplexTest::transformVectorNormalized() { + Complex a = Complex::rotation(Deg(23.0f)); + Matrix3 m = Matrix3::rotation(Deg(23.0f)); + Vector2 v(-3.6f, 0.7f); + + std::ostringstream o; + Error::setOutput(&o); + Vector2 notRotated = (a*2).transformVectorNormalized(v); + CORRADE_VERIFY(notRotated != notRotated); + CORRADE_COMPARE(o.str(), "Math::Complex::transformVectorNormalized(): complex number must be normalized\n"); + + Vector2 rotated = a.transformVectorNormalized(v); + CORRADE_COMPARE(rotated, m.transformVector(v)); + CORRADE_COMPARE(rotated, a.transformVector(v)); +} + void ComplexTest::debug() { std::ostringstream o; diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 3b6ad4955..da7b16ed8 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -340,7 +340,7 @@ void QuaternionTest::transformVectorNormalized() { Vector3 v(5.0f, -3.6f, 0.7f); std::ostringstream o; - Corrade::Utility::Error::setOutput(&o); + Error::setOutput(&o); Vector3 notRotated = (a*2).transformVectorNormalized(v); CORRADE_VERIFY(notRotated != notRotated); CORRADE_COMPARE(o.str(), "Math::Quaternion::transformVectorNormalized(): quaternion must be normalized\n"); From 02235a5a49ab03be727b546ebb6eb30b5373fe60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Feb 2013 16:06:27 +0100 Subject: [PATCH 427/567] Math: forgot to add Complex to forward-declaration header. --- src/Math/Math.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Math/Math.h b/src/Math/Math.h index 8124b0a3b..2f11f3023 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -27,6 +27,7 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT /* Class Constants used only statically */ +template class Complex; template class Dual; template class DualQuaternion; From b847eee75024cc0a11a55d5017f55608e5de90fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Feb 2013 16:09:42 +0100 Subject: [PATCH 428/567] Brought Complex and DualQuaternion to Magnum namespace. --- src/Magnum.h | 8 +++++++- src/Math/Complex.h | 1 + src/Math/DualQuaternion.h | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Magnum.h b/src/Magnum.h index f5dd8a4ed..05b6b5c17 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -117,9 +117,15 @@ typedef Math::Matrix3 Matrix3d; typedef Math::Matrix4 Matrix4d; #endif -/** @brief Quaternion */ +/** @brief %Complex number */ +typedef Math::Complex Complex; + +/** @brief %Quaternion */ typedef Math::Quaternion Quaternion; +/** @brief %Dual quaternion */ +typedef Math::DualQuaternion DualQuaternion; + /** @brief Floating-point constants */ /* Using float instead of GLfloat to not break KDevelop autocompletion */ typedef Math::Constants Constants; diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 36f559263..24c25d9dd 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -33,6 +33,7 @@ namespace Magnum { namespace Math { @tparam T Data type Represents 2D rotation. +@see Magnum::Complex, Matrix3 */ template class Complex { public: diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 543383718..d528c1a5a 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Math { @tparam T Underlying data type Represents 3D rotation and translation. -@see Dual, Quaternion, Matrix4 +@see Magnum::DualQuaternion, Dual, Quaternion, Matrix4 */ template class DualQuaternion: public Dual> { public: From c00195c24bc0b1dc8fad2bd616e87be2322f6df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Feb 2013 16:10:57 +0100 Subject: [PATCH 429/567] MeshTools: reworked and updated transform*(). Also added just-to-be-sure unit test. --- src/MeshTools/Test/CMakeLists.txt | 1 + src/MeshTools/Test/TransformTest.cpp | 109 +++++++++++++++++++++++++++ src/MeshTools/Transform.h | 109 ++++++++++++++++++++++++--- 3 files changed, 209 insertions(+), 10 deletions(-) create mode 100644 src/MeshTools/Test/TransformTest.cpp diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index e98374b66..369e6d411 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -7,6 +7,7 @@ corrade_add_test(MeshToolsInterleaveTest InterleaveTest.cpp) corrade_add_test(MeshToolsSubdivideTest SubdivideTest.cpp) # corrade_add_test(MeshToolsSubdivideCleanBenchmark SubdivideCleanBenchmark.h SubdivideCleanBenchmark.cpp MagnumPrimitives) corrade_add_test(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools) +corrade_add_test(MeshToolsTransformTest TransformTest.cpp LIBRARIES MagnumMeshTools) # Graceful assert for testing set_target_properties(MeshToolsCombineIndexedArraysTest MeshToolsInterleaveTest MeshToolsSubdivideTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/MeshTools/Test/TransformTest.cpp b/src/MeshTools/Test/TransformTest.cpp new file mode 100644 index 000000000..b6f3e16c4 --- /dev/null +++ b/src/MeshTools/Test/TransformTest.cpp @@ -0,0 +1,109 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/Matrix3.h" +#include "Magnum.h" +#include "MeshTools/Transform.h" + +namespace Magnum { namespace MeshTools { namespace Test { + +class TransformTest: public Corrade::TestSuite::Tester { + public: + explicit TransformTest(); + + void transformVectors2D(); + void transformVectors3D(); + + void transformPoints2D(); + void transformPoints3D(); +}; + +TransformTest::TransformTest() { + addTests(&TransformTest::transformVectors2D, + &TransformTest::transformVectors3D, + + &TransformTest::transformPoints2D, + &TransformTest::transformPoints3D); +} + +constexpr static std::array points2D{{ + {-3.0f, 4.0f}, + { 2.5f, -15.0f} +}}; + +constexpr static std::array points2DRotated{{ + {-4.0f, -3.0f}, + {15.0f, 2.5f} +}}; + +constexpr static std::array points2DRotatedTranslated{{ + {-4.0f, -4.0f}, + {15.0f, 1.5f} +}}; + +constexpr static std::array points3D{{ + {-3.0f, 4.0f, 34.0f}, + { 2.5f, -15.0f, 1.5f} +}}; + +constexpr static std::array points3DRotated{{ + {-4.0f, -3.0f, 34.0f}, + {15.0f, 2.5f, 1.5f} +}}; + +constexpr static std::array points3DRotatedTranslated{{ + {-4.0f, -4.0f, 34.0f}, + {15.0f, 1.5f, 1.5f} +}}; + +void TransformTest::transformVectors2D() { + auto matrix = MeshTools::transformVectors(Matrix3::rotation(Deg(90.0f)), points2D); + auto complex = MeshTools::transformVectors(Complex::rotation(Deg(90.0f)), points2D); + + CORRADE_COMPARE(matrix, points2DRotated); + CORRADE_COMPARE(complex, points2DRotated); +} + +void TransformTest::transformVectors3D() { + auto matrix = MeshTools::transformVectors(Matrix4::rotationZ(Deg(90.0f)), points3D); + auto complex = MeshTools::transformVectors(Quaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); + + CORRADE_COMPARE(matrix, points3DRotated); + CORRADE_COMPARE(complex, points3DRotated); +} + +void TransformTest::transformPoints2D() { + auto matrix = MeshTools::transformPoints( + Matrix3::translation(Vector2::yAxis(-1.0f))*Matrix3::rotation(Deg(90.0f)), points2D); + + CORRADE_COMPARE(matrix, points2DRotatedTranslated); +} + +void TransformTest::transformPoints3D() { + auto matrix = MeshTools::transformPoints( + Matrix4::translation(Vector3::yAxis(-1.0f))*Matrix4::rotationZ(Deg(90.0f)), points3D); + auto complex = MeshTools::transformPoints( + DualQuaternion::translation(Vector3::yAxis(-1.0f))*DualQuaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); + + CORRADE_COMPARE(matrix, points3DRotatedTranslated); + CORRADE_COMPARE(complex, points3DRotatedTranslated); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TransformTest) diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h index 9ad5b3ceb..9ce7b07ae 100644 --- a/src/MeshTools/Transform.h +++ b/src/MeshTools/Transform.h @@ -16,27 +16,116 @@ */ /** @file - * @brief Function Magnum::MeshTools::transform() + * @brief Function Magnum::MeshTools::transformVectorsInPlace(), Magnum::MeshTools::transformVectors(), Magnum::MeshTools::transformPointsInPlace(), Magnum::MeshTools::transformPoints() */ -#include "Math/Matrix.h" +#include "Math/Complex.h" +#include "Math/DualQuaternion.h" +#include "Math/Matrix3.h" namespace Magnum { namespace MeshTools { /** -@brief Transform vertices using given matrix +@brief Transform vectors in-place using given transformation -Usable for mesh transformations that would otherwise negatively affect -dependent objects, such as (uneven) scaling. Example usage: +Usable for one-time mesh transformations that would otherwise negatively affect +dependent objects, such as (uneven) scaling. Accepts any forward-iterable type +with compatible vector type as @p vectors. Expects that @ref Math::Quaternion "Quaternion" +or @ref Math::Complex "Complex" is normalized, no further requirements are for +transformation matrices. +Unlike in transformPointsInPlace(), the transformation does not involve +translation. + +Example usage: +@code +std::vector vectors; +auto transformation = Quaternion::rotation(35.0_degf, Vector3::yAxis()); +MeshTools::transformVectorsInPlace(rotation, vectors); +@endcode + +@see transformVectors(), Matrix3::transformVector(), Matrix4::transformVector(), + Complex::transformVectorNormalized(), Quaternion::transformVectorNormalized() +@todo GPU transform feedback implementation (otherwise this is only bad joke) +*/ +template void transformVectorsInPlace(const Math::Quaternion& normalizedQuaternion, U& vectors) { + for(auto& vector: vectors) vector = normalizedQuaternion.transformVectorNormalized(vector); +} + +/** @overload */ +template void transformVectorsInPlace(const Math::Complex& normalizedComplex, U& vectors) { + for(auto& vector: vectors) vector = normalizedComplex.transformVectorNormalized(vector); +} + +/** @overload */ +template void transformVectorsInPlace(const Math::Matrix3& matrix, U& vectors) { + for(auto& vector: vectors) vector = matrix.transformVector(vector); +} + +/** @overload */ +template void transformVectorsInPlace(const Math::Matrix4& matrix, U& vectors) { + for(auto& vector: vectors) vector = matrix.transformVector(vector); +} + +/** +@brief Transform vectors using given transformation + +Returns transformed vectors instead of modifying them in-place. See +transformVectorsInPlace() for more information. +*/ +template U transformVectors(const T& transformation, U vectors) { + U result(std::move(vectors)); + transformVectorsInPlace(transformation, result); + return result; +} + +/** +@brief Transform points in-place using given transformation + +Usable for one-time mesh transformations that would otherwise negatively affect +dependent objects, such as (uneven) scaling. Accepts any forward-iterable type +with compatible vector type as @p vectors. Expects that +@ref Math::DualQuaternion "DualQuaternion" is normalized, no further +requirements are for transformation matrices. + +Unlike in transformVectorsInPlace(), the transformation also involves +translation. + +Example usage: @code -std::vector vertices; -MeshTools::transform(Matrix4::scaling({2.0f, 0.5f, 0.0f}), vertices); +std::vector points; +auto transformation = DualQuaternion::rotation(35.0_degf, Vector3::yAxis())* + DualQuaternion::translation({0.5f, -1.0f, 3.0f}); +MeshTools::transformPointsInPlace(rotation, points); @endcode + +@see transformPoints(), Matrix3::transformPoint(), Matrix4::transformPoint(), + DualQuaternion::transformPointNormalized() +*/ +template void transformPointsInPlace(const Math::DualQuaternion& normalizedDualQuaternion, U& points) { + for(auto& point: points) point = normalizedDualQuaternion.transformPointNormalized(point); +} + +/** @overload */ +template void transformPointsInPlace(const Math::Matrix3& matrix, U& points) { + for(auto& point: points) point = matrix.transformPoint(point); +} + +/** @overload */ +template void transformPointsInPlace(const Math::Matrix4& matrix, U& points) { + for(auto& point: points) point = matrix.transformPoint(point); +} + +/** +@brief Transform points using given transformation + +Returns transformed points instead of modifying them in-place. See +transformPointsInPlace() for more information. */ -template inline void transform(const Math::Matrix& matrix, U& vertices) { - for(Math::Vector& vertex: vertices) - vertex = matrix*vertex; +template U transformPoints(const T& transformation, U vectors) { + U result(std::move(vectors)); + transformPointsInPlace(transformation, result); + return result; } }} From e432d3dc3cc73204e581505ee2fcaebe5734240c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Such=C3=BD?= Date: Sat, 23 Feb 2013 17:19:44 +0100 Subject: [PATCH 430/567] Doc fix --- doc/building.dox | 2 +- doc/coding-style.dox | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/building.dox b/doc/building.dox index 9d84d17ca..da7cdeb9f 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -182,7 +182,7 @@ You will need [Native Client SDK](https://developers.google.com/native-client/be Tested version is `pepper_22`. Make sure you have `toolchains` Git submodule updated, as -@ref building-download "explained above". Don't forget to adapt `NACL_PREFIX +@ref building-download "explained above". Don't forget to adapt `NACL_PREFIX` variable in `generic/NaCl-glibc-x86-32.cmake` and `generic/NaCl-glibc-x86-64.cmake` to path where your SDK is installed. Default is `/usr/nacl`. You may need to adapt also `NACL_TOOLCHAIN_PATH` so CMake is able to find the compiler. diff --git a/doc/coding-style.dox b/doc/coding-style.dox index 4a19a405b..6817a1e16 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -35,7 +35,7 @@ removing redundant prefixes) is encouraged. @subsubsection cpp-forward-declarations Forward declarations and forward declaration headers -When an namespace has classes which are commonly forward-declared, consider +When a namespace has classes which are commonly forward-declared, consider making a forward declaration header - it should have the same name as the namespace itself and contain foward declarations for all classes, enums and copies of all meaningful typedefs. See @ref compilation-forward-declarations From fab0aa1544e7f6215644b0098000e40206a187f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 14:14:05 +0100 Subject: [PATCH 431/567] Math: expect fail on non-uniform scaling in Matrix*::rotation(). Not implemented yet, added TODO. --- src/Math/Matrix3.h | 3 +++ src/Math/Matrix4.h | 3 +++ src/Math/Test/Matrix3Test.cpp | 28 +++++++++++++++++++++++----- src/Math/Test/Matrix4Test.cpp | 32 +++++++++++++++++++++++--------- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index f9b1b09b5..3cd3f6135 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -157,12 +157,15 @@ template class Matrix3: public Matrix<3, T> { * * Normalized upper-left 2x2 part of the matrix. * @see rotationScaling() const, rotation(T), Matrix4::rotation() const + * @todo assert uniform scaling (otherwise this would be garbage) */ inline Matrix<2, T> rotation() const { return {(*this)[0].xy().normalized(), (*this)[1].xy().normalized()}; } + /** @todo uniform scaling extraction */ + /** * @brief Right-pointing 2D vector * diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 198aa8c65..36af432c4 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -293,6 +293,7 @@ template class Matrix4: public Matrix<4, T> { * Normalized upper-left 3x3 part of the matrix. * @see rotationScaling() const, rotation(T, const Vector3&), * Matrix3::rotation() const + * @todo assert uniform scaling (otherwise this would be garbage) */ inline Matrix<3, T> rotation() const { /* Not Matrix3, because it is for affine 2D transformations */ @@ -301,6 +302,8 @@ template class Matrix4: public Matrix<4, T> { (*this)[2].xyz().normalized()}; } + /** @todo uniform scaling extraction */ + /** * @brief Right-pointing 3D vector * diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 2739fccf1..5cf07abb9 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -161,14 +161,32 @@ void Matrix3Test::rotationScalingPart() { } void Matrix3Test::rotationPart() { + Matrix3 rotation = Matrix3::rotation(Deg(15.0f)); Matrix2 expectedRotationPart(Vector2( 0.965926f, 0.258819f), Vector2(-0.258819f, 0.965926f)); - Matrix3 rotation = Matrix3::rotation(Deg(15.0f)); - CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); - - Matrix3 rotationTransformed = Matrix3::translation({2.0f, 5.0f})*rotation*Matrix3::scaling(Vector2(9.0f)); - CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart); + /* For rotation and translation this is the same as rotationScaling() */ + Matrix3 rotationTranslation = rotation*Matrix3::translation({2.0f, 5.0f}); + Matrix2 rotationTranslationPart = rotationTranslation.rotation(); + CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling()); + CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart); + + /* Test uniform scaling */ + Matrix3 rotationScaling = rotation*Matrix3::scaling(Vector2(9.0f)); + Matrix2 rotationScalingPart = rotationScaling.rotation(); + CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f); + CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix2()); + CORRADE_COMPARE(rotationScalingPart, expectedRotationPart); + + /* Fails on non-uniform scaling */ + { + CORRADE_EXPECT_FAIL("Assertion on uniform scaling is not implemented yet."); + std::ostringstream o; + Error::setOutput(&o); + Matrix3 rotationScaling2 = rotation*Matrix3::scaling(Vector2::yScale(3.5f)); + CORRADE_COMPARE(o.str(), "Math::Matrix3::rotation(): the matrix doesn't have uniform scaling\n"); + CORRADE_COMPARE(rotationScaling2, Matrix3(Matrix3::Zero)); + } } void Matrix3Test::vectorParts() { diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index f997450bb..da5f96e57 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -228,19 +228,33 @@ void Matrix4Test::rotationScalingPart() { } void Matrix4Test::rotationPart() { + Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); Matrix3 expectedRotationPart(Vector3( 0.35612214f, -0.80181062f, 0.47987163f), Vector3( 0.47987163f, 0.59757638f, 0.6423595f), Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)); - Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); - CORRADE_COMPARE(rotation.rotation().determinant(), 1.0f); - CORRADE_COMPARE(rotation.rotation()*rotation.rotation().transposed(), Matrix3()); - CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); - - Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3(9.0f)); - CORRADE_COMPARE(rotationTransformed.rotation().determinant(), 1.0f); - CORRADE_COMPARE(rotationTransformed.rotation()*rotationTransformed.rotation().transposed(), Matrix3()); - CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart); + /* For rotation and translation this is the same as rotationScaling() */ + Matrix4 rotationTranslation = rotation*Matrix4::translation({2.0f, 5.0f, -3.0f}); + Matrix3 rotationTranslationPart = rotationTranslation.rotation(); + CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling()); + CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart); + + /* Test uniform scaling */ + Matrix4 rotationScaling = rotation*Matrix4::scaling(Vector3(9.0f)); + Matrix3 rotationScalingPart = rotationScaling.rotation(); + CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f); + CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix3()); + CORRADE_COMPARE(rotationScalingPart, expectedRotationPart); + + /* Fails on non-uniform scaling */ + { + CORRADE_EXPECT_FAIL("Assertion on uniform scaling is not implemented yet."); + std::ostringstream o; + Error::setOutput(&o); + Matrix4 rotationScaling2 = rotation*Matrix4::scaling(Vector3::yScale(3.5f)); + CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): the matrix doesn't have uniform scaling\n"); + CORRADE_COMPARE(rotationScaling2, Matrix4(Matrix4::Zero)); + } } void Matrix4Test::vectorParts() { From 2468d2497f8cc856e4b08704912331e69cacc4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 14:15:40 +0100 Subject: [PATCH 432/567] Math: doc++ --- doc/matrix-vector.dox | 4 ++-- src/Math/DualQuaternion.h | 14 +++++++------- src/Math/Matrix3.h | 5 +++-- src/Math/Matrix4.h | 7 ++++--- src/Math/Quaternion.h | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index c1ded9d3f..c12adb0b6 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -128,8 +128,8 @@ Color3 and Color4 name their components `rgba` instead of `xyzw`. For more involved operations with components there is the swizzle() function: @code -Vector4 original(-1, 2, 3, 4); -Vector4 bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } +Vector<4, int> original(-1, 2, 3, 4); +Vector<4, int> bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } Vector<6, int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } @endcode diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index d528c1a5a..8c2e87b82 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -212,7 +212,7 @@ template class DualQuaternion: public Dual> { return Math::sqrt(lengthSquared()); } - /** @brief Normalized quaternion (of unit length) */ + /** @brief Normalized dual quaternion (of unit length) */ inline DualQuaternion normalized() const { return (*this)/length(); } @@ -220,9 +220,9 @@ template class DualQuaternion: public Dual> { /** * @brief Inverted dual quaternion * - * See invertedNormalized() which is faster for normalized - * dual quaternions. @f[ - * \hat q^{-1} = \frac{\hat q^*}{||\hat q||^2} + * See invertedNormalized() which is faster for normalized dual + * quaternions. @f[ + * \hat q^{-1} = \frac{\hat q^*}{|\hat q|^2} * @f] */ inline DualQuaternion inverted() const { @@ -234,7 +234,7 @@ template class DualQuaternion: public Dual> { * * Equivalent to quaternionConjugated(). Expects that the quaternion is * normalized. @f[ - * \hat q^{-1} = \frac{\hat q^*}{||\hat q||^2} = \hat q^* + * \hat q^{-1} = \frac{\hat q^*}{|\hat q|^2} = \hat q^* * @f] * @see inverted() */ @@ -249,7 +249,7 @@ template class DualQuaternion: public Dual> { * * See transformPointNormalized(), which is faster for normalized dual * quaternions. @f[ - * v' = qv \overline{\hat q^{-1}} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^{-1}} + * v' = \hat q v \overline{\hat q^{-1}} = \hat q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^{-1}} * @f] * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), * Quaternion::transformVector() @@ -263,7 +263,7 @@ template class DualQuaternion: public Dual> { * * Faster alternative to transformPoint(), expects that the dual * quaternion is normalized. @f[ - * v' = qv \overline{\hat q^{-1}} = qv \overline{\hat q^*} = q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} + * v' = \hat q v \overline{\hat q^{-1}} = \hat q v \overline{\hat q^*} = \hat q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), * Quaternion::transformVectorNormalized() diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 3cd3f6135..e67e909cf 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -170,7 +170,7 @@ template class Matrix3: public Matrix<3, T> { * @brief Right-pointing 2D vector * * First two elements of first column. - * @see Vector2::xAxis() + * @see up(), Vector2::xAxis(), Matrix4::right() */ inline Vector2& right() { return (*this)[0].xy(); } inline constexpr Vector2 right() const { return (*this)[0].xy(); } /**< @overload */ @@ -179,7 +179,7 @@ template class Matrix3: public Matrix<3, T> { * @brief Up-pointing 2D vector * * First two elements of second column. - * @see Vector2::yAxis() + * @see right(), Vector2::yAxis(), Matrix4::up() */ inline Vector2& up() { return (*this)[1].xy(); } inline constexpr Vector2 up() const { return (*this)[1].xy(); } /**< @overload */ @@ -220,6 +220,7 @@ template class Matrix3: public Matrix<3, T> { * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ 0 \end{pmatrix} * @f] * @see Complex::transformVector(), Matrix4::transformVector() + * @todo extract 2x2 matrix and multiply directly? (benchmark that) */ inline Vector2 transformVector(const Vector2& vector) const { return ((*this)*Vector3(vector, T(0))).xy(); diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 36af432c4..dfa9dad5f 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -308,7 +308,7 @@ template class Matrix4: public Matrix<4, T> { * @brief Right-pointing 3D vector * * First three elements of first column. - * @see Vector3::xAxis() + * @see up(), backward(), Vector3::xAxis(), Matrix3::right() */ inline Vector3& right() { return (*this)[0].xyz(); } inline constexpr Vector3 right() const { return (*this)[0].xyz(); } /**< @overload */ @@ -317,7 +317,7 @@ template class Matrix4: public Matrix<4, T> { * @brief Up-pointing 3D vector * * First three elements of second column. - * @see Vector3::yAxis() + * @see right(), backward(), Vector3::yAxis(), Matrix3::up() */ inline Vector3& up() { return (*this)[1].xyz(); } inline constexpr Vector3 up() const { return (*this)[1].xyz(); } /**< @overload */ @@ -326,7 +326,7 @@ template class Matrix4: public Matrix<4, T> { * @brief Backward-pointing 3D vector * * First three elements of third column. - * @see Vector3::yAxis() + * @see right(), up(), Vector3::yAxis() */ inline Vector3& backward() { return (*this)[2].xyz(); } inline constexpr Vector3 backward() const { return (*this)[2].xyz(); } /**< @overload */ @@ -367,6 +367,7 @@ template class Matrix4: public Matrix<4, T> { * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ v_z \\ 0 \end{pmatrix} * @f] * @see Quaternion::transformVector(), Matrix3::transformVector() + * @todo extract 3x3 matrix and multiply directly? (benchmark that) */ inline Vector3 transformVector(const Vector3& vector) const { return ((*this)*Vector4(vector, T(0))).xyz(); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index a7c04bb22..de204ca00 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -44,7 +44,7 @@ template class Quaternion { * @brief Dot product * * @f[ - * p \cdot q = \boldsymbol p_V \cdot \boldsymbol q_V + p_S q_S + * p \cdot q = \boldsymbol p_V \cdot \boldsymbol q_V + p_S q_S * @f] * @see dot() const */ From b0d79bbad8c0dd8349a461efd76c0eaa06dbf469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:45:06 +0100 Subject: [PATCH 433/567] Math: minor code cleanup. --- src/Math/DualQuaternion.h | 4 ++-- src/Math/Math.h | 4 ++-- src/Math/Test/CMakeLists.txt | 4 ++-- src/Math/Test/DualQuaternionTest.cpp | 1 - src/Math/Test/QuaternionTest.cpp | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 8c2e87b82..6ebbd74ea 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -239,7 +239,7 @@ template class DualQuaternion: public Dual> { * @see inverted() */ inline DualQuaternion invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(lengthSquared(), T(1)), + CORRADE_ASSERT(lengthSquared() == Dual(1), "Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized", {}); return quaternionConjugated(); } @@ -269,7 +269,7 @@ template class DualQuaternion: public Dual> { * Quaternion::transformVectorNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { - CORRADE_ASSERT(MathTypeTraits>::equals(lengthSquared(), Dual(1)), + CORRADE_ASSERT(lengthSquared() == Dual(1), "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*DualQuaternion(vector)*conjugated()).dual().vector(); diff --git a/src/Math/Math.h b/src/Math/Math.h index 2f11f3023..a05da0a1c 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -27,8 +27,8 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT /* Class Constants used only statically */ -template class Complex; -template class Dual; +template class Complex; +template class Dual; template class DualQuaternion; template class Matrix; diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 76d7980dc..e0e8b22be 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -17,8 +17,8 @@ corrade_add_test(MathSwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathUnitTest UnitTest.cpp) corrade_add_test(MathAngleTest AngleTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualTest DualTest.cpp) +corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib) @@ -27,6 +27,6 @@ set_target_properties( MathMatrix3Test MathMatrix4Test MathComplexTest - MathDualQuaternionTest MathQuaternionTest + MathDualQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index da954935f..0a49372ab 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -56,7 +56,6 @@ typedef Math::Matrix4 Matrix4; typedef Math::DualQuaternion DualQuaternion; typedef Math::Quaternion Quaternion; typedef Math::Vector3 Vector3; -typedef Math::Vector4 Vector4; DualQuaternionTest::DualQuaternionTest() { addTests(&DualQuaternionTest::construct, diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index da7b16ed8..06f3e9ac8 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -212,7 +212,7 @@ void QuaternionTest::invertedNormalized() { Quaternion a = Quaternion({1.0f, 3.0f, -2.0f}, -4.0f); std::ostringstream o; - Corrade::Utility::Error::setOutput(&o); + Error::setOutput(&o); Quaternion notInverted = a.invertedNormalized(); CORRADE_COMPARE(notInverted.vector(), Vector3()); CORRADE_COMPARE(notInverted.scalar(), std::numeric_limits::quiet_NaN()); @@ -221,7 +221,7 @@ void QuaternionTest::invertedNormalized() { Quaternion aNormalized = a.normalized(); Quaternion inverted = aNormalized.invertedNormalized(); CORRADE_COMPARE(aNormalized*inverted, Quaternion()); - CORRADE_COMPARE(inverted*aNormalized.normalized(), Quaternion()); + CORRADE_COMPARE(inverted*aNormalized, Quaternion()); CORRADE_COMPARE(inverted, Quaternion({-1.0f, -3.0f, 2.0f}, -4.0f)/std::sqrt(30.0f)); } From e8e2b5d5482c2f1e130f41ec499cb2f5f88dbe0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 14:15:55 +0100 Subject: [PATCH 434/567] Math: constexpr internal DualQuaternion constructor. --- src/Math/DualQuaternion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 6ebbd74ea..8000e8480 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -279,7 +279,7 @@ template class DualQuaternion: public Dual> { private: /* Used by Dual operators and dualConjugated() */ - DualQuaternion(const Dual>& other): Dual>(other) {} + inline constexpr DualQuaternion(const Dual>& other): Dual>(other) {} }; /** @debugoperator{Magnum::Math::DualQuaternion} */ From 6ed315b79b75a5ad31435d2ed8384bd53dce7367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 14:16:26 +0100 Subject: [PATCH 435/567] Math: properly test constexpr in Complex from Vector2 constructor. --- src/Math/Test/ComplexTest.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index a93db8ccf..fcae80108 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -130,15 +130,21 @@ void ComplexTest::constExpressions() { constexpr Complex b(2.5f, -5.0f); CORRADE_COMPARE(b, Complex(2.5f, -5.0f)); + /* Vector constructor */ + constexpr Complex c(Vector2(-1.0f, 2.2f)); + CORRADE_COMPARE(c, Complex(-1.0f, 2.2f)); + /* Copy constructor */ - constexpr Complex c(b); - CORRADE_COMPARE(c, Complex(2.5f, -5.0f)); + constexpr Complex d(b); + CORRADE_COMPARE(d, Complex(2.5f, -5.0f)); /* Data access */ - constexpr float d = b.real(); - constexpr float e = c.imaginary(); - CORRADE_COMPARE(d, 2.5f); - CORRADE_COMPARE(e, -5.0f); + constexpr float e = b.real(); + constexpr float f = b.imaginary(); + constexpr Vector2 g(b); + CORRADE_COMPARE(e, 2.5f); + CORRADE_COMPARE(f, -5.0f); + CORRADE_COMPARE(g, Vector2(2.5f, -5.0f)); } void ComplexTest::addSubtract() { From 6edc26ff01914fe751214ee753a6e91f9f8979f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:45:18 +0100 Subject: [PATCH 436/567] Math: more explicit Quaternion-from-Vector constructor test. For better readability, nothing more. --- src/Math/Test/DualQuaternionTest.cpp | 4 ++-- src/Math/Test/QuaternionTest.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 0a49372ab..d31e7b552 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -95,7 +95,7 @@ void DualQuaternionTest::constructDefault() { } void DualQuaternionTest::constructFromVector() { - CORRADE_COMPARE(DualQuaternion({1.0f, 2.0f, 3.0f}), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); + CORRADE_COMPARE(DualQuaternion(Vector3(1.0f, 2.0f, 3.0f)), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); } void DualQuaternionTest::constExpressions() { @@ -108,7 +108,7 @@ void DualQuaternionTest::constExpressions() { CORRADE_COMPARE(b, DualQuaternion({{1.0f, 2.0f, -3.0f}, -3.5f}, {{4.5f, -7.0f, 2.0f}, 1.0f})); /* Vector constructor */ - constexpr DualQuaternion c({1.5f, -5.0f, 3.0f}); + constexpr DualQuaternion c(Vector3(1.5f, -5.0f, 3.0f)); CORRADE_COMPARE(c, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.5f, -5.0f, 3.0f}, 0.0f})); /* Copy constructor */ diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 06f3e9ac8..b4472e768 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -110,7 +110,7 @@ void QuaternionTest::constructDefault() { } void QuaternionTest::constructFromVector() { - CORRADE_COMPARE(Quaternion({1.0f, 2.0f, 3.0f}), Quaternion({1.0f, 2.0f, 3.0f}, 0.0f)); + CORRADE_COMPARE(Quaternion(Vector3(1.0f, 2.0f, 3.0f)), Quaternion({1.0f, 2.0f, 3.0f}, 0.0f)); } void QuaternionTest::compare() { @@ -130,7 +130,7 @@ void QuaternionTest::constExpressions() { CORRADE_COMPARE(b, Quaternion({1.0f, -3.0f, 7.0f}, 2.5f)); /* Construct from vector */ - constexpr Quaternion c({2.0f, -3.0f, 1.5f}); + constexpr Quaternion c(Vector3(2.0f, -3.0f, 1.5f)); CORRADE_COMPARE(c, Quaternion({2.0f, -3.0f, 1.5f}, 0.0f)); /* Copy constructor */ From 1eea843538593ad64ff7dd85316a18c602783c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:12:06 +0100 Subject: [PATCH 437/567] Math: don't allow implicit conversion of T to Complex. Brain failure #1. --- src/Math/Complex.h | 2 +- src/Math/Test/ComplexTest.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 24c25d9dd..603a4a545 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -94,7 +94,7 @@ template class Complex { * c = a + ib * @f] */ - inline constexpr /*implicit*/ Complex(T real, T imaginary = T(0)): _real(real), _imaginary(imaginary) {} + inline constexpr /*implicit*/ Complex(T real, T imaginary): _real(real), _imaginary(imaginary) {} /** * @brief Construct complex number from vector diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index fcae80108..f9dafcaee 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -97,8 +97,6 @@ void ComplexTest::construct() { Complex c(0.5f, -3.7f); CORRADE_COMPARE(c.real(), 0.5f); CORRADE_COMPARE(c.imaginary(), -3.7f); - - CORRADE_COMPARE(Complex(2.0f), Complex(2.0f, 0.0f)); } void ComplexTest::constructDefault() { From c847e1551fe8fa0e1800eb462a737c439a706b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:14:16 +0100 Subject: [PATCH 438/567] Math: "dot product" of Complex is real number. Brain failure #2. Also I don't know if such thing as dot product exists here :-) --- src/Math/Complex.h | 14 +++++++------- src/Math/Test/ComplexTest.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 603a4a545..4d46217b1 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -43,12 +43,12 @@ template class Complex { * @brief Dot product * * @f[ - * c_0 \cdot c_1 = c_0 \overline{c_1} = (a_0 a_1 + b_0 b_1) + i(a_1 b_0 - a_0 b_1) + * c_0 \cdot c_1 = a_0 a_1 + b_0 b_1 * @f] * @see dot() const */ - inline static Complex dot(const Complex& a, const Complex& b) { - return a*b.conjugated(); + inline static T dot(const Complex& a, const Complex& b) { + return a._real*b._real + a._imaginary*b._imaginary; } /** @@ -277,12 +277,12 @@ template class Complex { * * Should be used instead of length() for comparing complex number length * with other values, because it doesn't compute the square root. @f[ - * c \cdot c = c \overline c = a^2 + b^2 + * c \cdot c = a^2 + b^2 * @f] * @see dot(const Complex&, const Complex&) */ inline T dot() const { - return _real*_real + _imaginary*_imaginary; + return dot(*this, *this); } /** @@ -290,7 +290,7 @@ template class Complex { * * See also dot() const which is faster for comparing length with other * values. @f[ - * |c| = \sqrt{c \overline c} = \sqrt{a^2 + b^2} + * |c| = \sqrt{c \cdot c} * @f] */ inline T length() const { @@ -318,7 +318,7 @@ template class Complex { * * See invertedNormalized() which is faster for normalized * complex numbers. @f[ - * c^{-1} = \frac{\overline c}{c \overline c} = \frac{\overline c}{a^2 + b^2} + * c^{-1} = \frac{\overline c}{|c|^2} = \frac{\overline c}{c \cdot c} * @f] */ inline Complex inverted() const { diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index f9dafcaee..fb169465f 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -183,7 +183,7 @@ void ComplexTest::dot() { Complex a(5.0f, 3.0f); Complex b(6.0f, -7.0f); - CORRADE_COMPARE(Complex::dot(a, b), Complex(9.0f, 53.0f)); + CORRADE_COMPARE(Complex::dot(a, b), 9.0f); } void ComplexTest::dotSelf() { From d0fe15737ad89d6d2f8c7ac5b735a98fa8f19a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:15:12 +0100 Subject: [PATCH 439/567] Math: mark complex conjugate with asterisk, not overline. Makes it consistent with quaternion conjugate and less confusing for future DualComplex implementation (as dual conjugate is with overline too). --- src/Math/Complex.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 4d46217b1..64773b217 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -306,7 +306,7 @@ template class Complex { * @brief Conjugated complex number * * @f[ - * \overline c = a - ib + * c^* = a - ib * @f] */ inline Complex conjugated() const { @@ -318,7 +318,7 @@ template class Complex { * * See invertedNormalized() which is faster for normalized * complex numbers. @f[ - * c^{-1} = \frac{\overline c}{|c|^2} = \frac{\overline c}{c \cdot c} + * c^{-1} = \frac{c^*}{|c|^2} = \frac{c^*}{c \cdot c} * @f] */ inline Complex inverted() const { @@ -330,7 +330,7 @@ template class Complex { * * Equivalent to conjugated(). Expects that the complex number is * normalized. @f[ - * c^{-1} = \frac{\overline c}{c \overline c} = \frac{\overline c}{a^2 + b^2} = \overline c + * c^{-1} = \frac{c^*}{c \cdot c} = c^* * @f] * @see inverted() */ From 143783004b9649f1a7d239b283e0ab44216224c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:17:01 +0100 Subject: [PATCH 440/567] Math: make Complex::invertedNormalized() consistent with Quaternion. --- src/Math/Complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 64773b217..de6e0334c 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -337,7 +337,7 @@ template class Complex { inline Complex invertedNormalized() const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), "Math::Complex::invertedNormalized(): complex number must be normalized", - Complex(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); + Complex(std::numeric_limits::quiet_NaN(), {})); return conjugated(); } From e522293c22861a5a8aec79fac6a5e37258627c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:18:20 +0100 Subject: [PATCH 441/567] Math: forgot to test DualQuaternion::invertedNormalized(). --- src/Math/Test/DualQuaternionTest.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index d31e7b552..ab0e52aad 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -38,6 +38,7 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void dualConjugated(); void conjugated(); void inverted(); + void invertedNormalized(); void rotation(); void translation(); @@ -72,6 +73,7 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::dualConjugated, &DualQuaternionTest::conjugated, &DualQuaternionTest::inverted, + &DualQuaternionTest::invertedNormalized, &DualQuaternionTest::rotation, &DualQuaternionTest::translation, @@ -155,11 +157,27 @@ void DualQuaternionTest::conjugated() { } void DualQuaternionTest::inverted() { - DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 2.5f, -3.1f, 3.3f}, 2.0f}); - DualQuaternion b({{-0.033333f, -0.066667f, -0.1f}, -0.133333f}, {{-0.087333f, 0.095333f, -0.122f}, 0.050667f}); + DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 2.5f, -3.1f, 3.3f}, 2.0f}); + DualQuaternion b({{-1.0f, -2.0f, -3.0f}, -4.0f}, {{-2.5f, 3.1f, -3.3f}, 2.0f}); CORRADE_COMPARE(a*a.inverted(), DualQuaternion()); - CORRADE_COMPARE(a.inverted(), b); + CORRADE_COMPARE(a.inverted(), b/Dual(30.0f, -3.6f)); +} + +void DualQuaternionTest::invertedNormalized() { + DualQuaternion a({{ 1.0f, 2.0f, 3.0f}, -4.0f}, {{ 2.5f, -3.1f, 3.3f}, 2.0f}); + DualQuaternion b({{-1.0f, -2.0f, -3.0f}, -4.0f}, {{-2.5f, 3.1f, -3.3f}, 2.0f}); + + std::ostringstream o; + Error::setOutput(&o); + CORRADE_COMPARE(a.invertedNormalized(), DualQuaternion()); + CORRADE_COMPARE(o.str(), "Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized\n"); + + DualQuaternion normalized = a.normalized(); + DualQuaternion inverted = normalized.invertedNormalized(); + CORRADE_COMPARE(normalized*inverted, DualQuaternion()); + CORRADE_COMPARE(inverted*normalized, DualQuaternion()); + CORRADE_COMPARE(inverted, b/Math::sqrt(Dual(30.0f, -3.6f))); } void DualQuaternionTest::rotation() { From f6d1a158f8c75e90bf1b0abd8685ba6e9374a0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 14:25:40 +0100 Subject: [PATCH 442/567] Math: initial implementation of dual complex numbers. --- src/CMakeLists.txt | 1 + src/Math/CMakeLists.txt | 1 + src/Math/DualComplex.cpp | 27 +++++++ src/Math/DualComplex.h | 125 ++++++++++++++++++++++++++++++ src/Math/Math.h | 1 + src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/DualComplexTest.cpp | 106 +++++++++++++++++++++++++ 7 files changed, 262 insertions(+) create mode 100644 src/Math/DualComplex.cpp create mode 100644 src/Math/DualComplex.h create mode 100644 src/Math/Test/DualComplexTest.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed0ce0c4a..56b94d28d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,7 @@ add_library(MagnumObjects OBJECT ${Magnum_SRCS}) set(MagnumMath_SRCS Math/Angle.cpp Math/Complex.cpp + Math/DualComplex.cpp Math/DualQuaternion.cpp Math/Functions.cpp Math/Quaternion.cpp diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 287d96427..e8c9997fb 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -4,6 +4,7 @@ set(MagnumMath_HEADERS Complex.h Constants.h Dual.h + DualComplex.h DualQuaternion.h Functions.h Math.h diff --git a/src/Math/DualComplex.cpp b/src/Math/DualComplex.cpp new file mode 100644 index 000000000..128f2f767 --- /dev/null +++ b/src/Math/DualComplex.cpp @@ -0,0 +1,27 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "DualComplex.h" + +namespace Magnum { namespace Math { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualComplex&); +#ifndef MAGNUM_TARGET_GLES +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualComplex&); +#endif +#endif + +}} diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h new file mode 100644 index 000000000..26c51879a --- /dev/null +++ b/src/Math/DualComplex.h @@ -0,0 +1,125 @@ +#ifndef Magnum_Math_DualComplex_h +#define Magnum_Math_DualComplex_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Math::DualComplex + */ + +#include "Math/Dual.h" +#include "Math/Complex.h" + +namespace Magnum { namespace Math { + +/** +@brief %Dual complex number +@tparam T Underlying data type + +Represents 2D rotation and translation. +@see Dual, Complex, Matrix3 +*/ +template class DualComplex: public Dual> { + public: + typedef T Type; /**< @brief Underlying data type */ + + /** + * @brief Default constructor + * + * Creates unit dual complex number. @f[ + * \hat c = (0 + i1) + \epsilon (0 + i0) + * @f] + * @todoc Remove workaround when Doxygen is predictable + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + inline constexpr /*implicit*/ DualComplex(); + #else + inline constexpr /*implicit*/ DualComplex(): Dual>({}, {T(0), T(0)}) {} + #endif + + /** + * @brief Construct dual complex number from real and dual part + * + * @f[ + * \hat c = c_0 + \epsilon c_\epsilon + * @f] + */ + inline constexpr /*implicit*/ DualComplex(const Complex& real, const Complex& dual): Dual>(real, dual) {} + + /** + * @brief Complex-conjugated dual complex number + * + * @f[ + * \hat c^* = c^*_0 + c^*_\epsilon + * @f] + * @see dualConjugated(), conjugated(), Complex::conjugated() + */ + inline DualComplex complexConjugated() const { + return {this->real().conjugated(), this->dual().conjugated()}; + } + + /** + * @brief Dual-conjugated dual complex number + * + * @f[ + * \overline{\hat c} = c_0 - \epsilon c_\epsilon + * @f] + * @see complexConjugated(), conjugated(), Dual::conjugated() + */ + inline DualComplex dualConjugated() const { + return Dual>::conjugated(); + } + + /** + * @brief Conjugated dual complex number + * + * Both complex and dual conjugation. @f[ + * \overline{\hat c^*} = c^*_0 - \epsilon c^*_\epsilon = c^*_0 + \epsilon(-a_\epsilon + ib_\epsilon) + * @f] + * @see complexConjugated(), dualConjugated(), Complex::conjugated(), + * Dual::conjugated() + */ + inline DualComplex conjugated() const { + return {this->real().conjugated(), {-this->dual().real(), this->dual().imaginary()}}; + } + + MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Complex) + + private: + /* Used by Dual operators and dualConjugated() */ + inline constexpr DualComplex(const Dual>& other): Dual>(other) {} +}; + +/** @debugoperator{Magnum::Math::DualQuaternion} */ +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const DualComplex& value) { + debug << "DualComplex({"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); + debug << value.real().real() << ", " << value.real().imaginary() << "}, {" + << value.dual().real() << ", " << value.dual().imaginary() << "})"; + debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true); + return debug; +} + +/* Explicit instantiation for commonly used types */ +#ifndef DOXYGEN_GENERATING_OUTPUT +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualComplex&); +#ifndef MAGNUM_TARGET_GLES +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualComplex&); +#endif +#endif + +}} + +#endif diff --git a/src/Math/Math.h b/src/Math/Math.h index a05da0a1c..11915afd7 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -29,6 +29,7 @@ namespace Magnum { namespace Math { template class Complex; template class Dual; +template class DualComplex; template class DualQuaternion; template class Matrix; diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index e0e8b22be..6a88a4676 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -19,6 +19,7 @@ corrade_add_test(MathAngleTest AngleTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualTest DualTest.cpp) corrade_add_test(MathComplexTest ComplexTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathDualComplexTest DualComplexTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathQuaternionTest QuaternionTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp new file mode 100644 index 000000000..5548f71cf --- /dev/null +++ b/src/Math/Test/DualComplexTest.cpp @@ -0,0 +1,106 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include +#include + +#include "Math/DualComplex.h" + +namespace Magnum { namespace Math { namespace Test { + +class DualComplexTest: public Corrade::TestSuite::Tester { + public: + explicit DualComplexTest(); + + void construct(); + void constructDefault(); + + void constExpressions(); + + void complexConjugated(); + void dualConjugated(); + void conjugated(); + + void debug(); +}; + +typedef Math::Complex Complex; +typedef Math::DualComplex DualComplex; + +DualComplexTest::DualComplexTest() { + addTests(&DualComplexTest::construct, + &DualComplexTest::constructDefault, + + &DualComplexTest::constExpressions, + + &DualComplexTest::complexConjugated, + &DualComplexTest::dualConjugated, + &DualComplexTest::conjugated, + + &DualComplexTest::debug); +} + +void DualComplexTest::construct() { + DualComplex a({-1.0f, 2.5f}, {3.0f, -7.5f}); + CORRADE_COMPARE(a.real(), Complex(-1.0f, 2.5f)); + CORRADE_COMPARE(a.dual(), Complex(3.0f, -7.5f)); +} + +void DualComplexTest::constructDefault() { + CORRADE_COMPARE(DualComplex(), DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); +} + +void DualComplexTest::constExpressions() { + /* Default constructor */ + constexpr DualComplex a; + CORRADE_COMPARE(a, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); + + /* Value constructor */ + constexpr DualComplex b({-1.0f, 2.5f}, {3.0f, -7.5f}); + CORRADE_COMPARE(b, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); + + /* Copy constructor */ + constexpr DualComplex d(b); + CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); +} + +void DualComplexTest::complexConjugated() { + DualComplex a({-1.0f, 2.5f}, {3.0f, -7.5f}); + DualComplex b({-1.0f, -2.5f}, {3.0f, 7.5f}); + CORRADE_COMPARE(a.complexConjugated(), b); +} + +void DualComplexTest::dualConjugated() { + DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f}); + DualComplex b({-1.0f, 2.5f}, {-3.0f, 7.5f}); + CORRADE_COMPARE(a.dualConjugated(), b); +} + +void DualComplexTest::conjugated() { + DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f}); + DualComplex b({-1.0f, -2.5f}, {-3.0f, -7.5f}); + CORRADE_COMPARE(a.conjugated(), b); +} + +void DualComplexTest::debug() { + std::ostringstream o; + + Debug(&o) << DualComplex({-1.0f, -2.5f}, {-3.0f, -7.5f}); + CORRADE_COMPARE(o.str(), "DualComplex({-1, -2.5}, {-3, -7.5})\n"); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::DualComplexTest) From d7bfd913984f0180228ad6dec3438464e8eb1f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:19:39 +0100 Subject: [PATCH 443/567] Math: length and normalization of DualComplex. --- src/Math/DualComplex.h | 29 +++++++++++++++++++++++++++++ src/Math/Test/DualComplexTest.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 26c51879a..417d17a1f 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -95,6 +95,35 @@ template class DualComplex: public Dual> { return {this->real().conjugated(), {-this->dual().real(), this->dual().imaginary()}}; } + /** + * @brief %Complex number length squared + * + * Should be used instead of length() for comparing complex number + * length with other values, because it doesn't compute the square root. @f[ + * |\hat c|^2 = \sqrt{\hat c^* \hat c}^2 = c_0 \cdot c_0 + \epsilon 2 (c_0 \cdot c_\epsilon) + * @f] + */ + inline Dual lengthSquared() const { + return {this->real().dot(), T(2)*Complex::dot(this->real(), this->dual())}; + } + + /** + * @brief %Dual quaternion length + * + * See lengthSquared() which is faster for comparing length with other + * values. @f[ + * |\hat c| = \sqrt{\hat{c^*} \hat c} = |c_0| + \epsilon \frac{c_0 \cdot c_\epsilon}{|c_0|} + * @f] + */ + inline Dual length() const { + return Math::sqrt(lengthSquared()); + } + + /** @brief Normalized dual complex number (of unit length) */ + inline DualComplex normalized() const { + return (*this)/length(); + } + MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Complex) private: diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 5548f71cf..c82f310e5 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -29,6 +29,10 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void constExpressions(); + void lengthSquared(); + void length(); + void normalized(); + void complexConjugated(); void dualConjugated(); void conjugated(); @@ -37,6 +41,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { }; typedef Math::Complex Complex; +typedef Math::Dual Dual; typedef Math::DualComplex DualComplex; DualComplexTest::DualComplexTest() { @@ -45,6 +50,10 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::constExpressions, + &DualComplexTest::lengthSquared, + &DualComplexTest::length, + &DualComplexTest::normalized, + &DualComplexTest::complexConjugated, &DualComplexTest::dualConjugated, &DualComplexTest::conjugated, @@ -60,6 +69,7 @@ void DualComplexTest::construct() { void DualComplexTest::constructDefault() { CORRADE_COMPARE(DualComplex(), DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); + CORRADE_COMPARE(DualComplex().length(), 1.0f); } void DualComplexTest::constExpressions() { @@ -76,6 +86,23 @@ void DualComplexTest::constExpressions() { CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); } +void DualComplexTest::lengthSquared() { + DualComplex a({-1.0f, 3.0f}, {0.5f, -2.0f}); + CORRADE_COMPARE(a.lengthSquared(), Dual(10.0f, -13.0f)); +} + +void DualComplexTest::length() { + DualComplex a({-1.0f, 3.0f}, {0.5f, -2.0f}); + CORRADE_COMPARE(a.length(), Dual(3.162278f, -2.05548f)); +} + +void DualComplexTest::normalized() { + DualComplex a({-1.0f, 3.0f}, {0.5f, -2.0f}); + DualComplex b({-0.316228f, 0.948683f}, {-0.0474342f, -0.0158114f}); + CORRADE_COMPARE(a.normalized().length(), 1.0f); + CORRADE_COMPARE(a.normalized(), b); +} + void DualComplexTest::complexConjugated() { DualComplex a({-1.0f, 2.5f}, {3.0f, -7.5f}); DualComplex b({-1.0f, -2.5f}, {3.0f, 7.5f}); From fbac6662faee0fe88406adca403ff6cb6ea1f08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:20:00 +0100 Subject: [PATCH 444/567] Math: inversion of DualComplex. --- src/Math/DualComplex.h | 27 +++++++++++++++++++++++++++ src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/DualComplexTest.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 417d17a1f..10e3a7a5a 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -124,6 +124,33 @@ template class DualComplex: public Dual> { return (*this)/length(); } + /** + * @brief Inverted dual complex number + * + * See invertedNormalized() which is faster for normalized dual complex + * numbers. @f[ + * \hat c^{-1} = \frac{\hat c^*}{|\hat c|^2} + * @f] + */ + inline DualComplex inverted() const { + return complexConjugated()/lengthSquared(); + } + + /** + * @brief Inverted normalized dual complex number + * + * Equivalent to complexConjugated(). Expects that the complex number + * is normalized. @f[ + * \hat c^{-1} = \frac{\hat c^*}{|\hat c|^2} = \hat c^* + * @f] + * @see inverted() + */ + inline DualComplex invertedNormalized() const { + CORRADE_ASSERT(lengthSquared() == Dual(1), + "Math::DualComplex::invertedNormalized(): dual complex number must be normalized", {}); + return complexConjugated(); + } + MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Complex) private: diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 6a88a4676..1e1570ddd 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -28,6 +28,7 @@ set_target_properties( MathMatrix3Test MathMatrix4Test MathComplexTest + MathDualComplexTest MathQuaternionTest MathDualQuaternionTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index c82f310e5..15b9644f9 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -36,6 +36,8 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void complexConjugated(); void dualConjugated(); void conjugated(); + void inverted(); + void invertedNormalized(); void debug(); }; @@ -57,6 +59,8 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::complexConjugated, &DualComplexTest::dualConjugated, &DualComplexTest::conjugated, + &DualComplexTest::inverted, + &DualComplexTest::invertedNormalized, &DualComplexTest::debug); } @@ -121,6 +125,30 @@ void DualComplexTest::conjugated() { CORRADE_COMPARE(a.conjugated(), b); } +void DualComplexTest::inverted() { + DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f}); + DualComplex b({-1.0f, -2.5f}, { 3.0f, 7.5f}); + + CORRADE_COMPARE(a*a.inverted(), DualComplex()); + CORRADE_COMPARE(a.inverted(), b/Dual(7.25f, -43.5f)); +} + +void DualComplexTest::invertedNormalized() { + DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f}); + DualComplex b({-1.0f, -2.5f}, { 3.0f, 7.5f}); + + std::ostringstream o; + Error::setOutput(&o); + CORRADE_COMPARE(a.invertedNormalized(), DualComplex()); + CORRADE_COMPARE(o.str(), "Math::DualComplex::invertedNormalized(): dual complex number must be normalized\n"); + + DualComplex normalized = a.normalized(); + DualComplex inverted = normalized.invertedNormalized(); + CORRADE_COMPARE(normalized*inverted, DualComplex()); + CORRADE_COMPARE(inverted*normalized, DualComplex()); + CORRADE_COMPARE(inverted, b/Math::sqrt(Dual(7.25f, -43.5f))); +} + void DualComplexTest::debug() { std::ostringstream o; From 1a5e18564e7e466f904ab25f3095b876a626e6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:35:16 +0100 Subject: [PATCH 445/567] Math: rotation dual complex number. --- src/Math/Complex.h | 1 + src/Math/DualComplex.h | 26 ++++++++++++++++++++++++++ src/Math/DualQuaternion.h | 6 +++--- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 6 +++--- src/Math/Quaternion.h | 2 +- src/Math/Test/DualComplexTest.cpp | 12 ++++++++++++ 7 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index de6e0334c..665523e1c 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -140,6 +140,7 @@ template class Complex { * @f[ * \theta = atan2(b, a) * @f] + * @see rotation(), DualComplex::rotationAngle() */ inline Rad rotationAngle() const { return Rad(std::atan2(_imaginary, _real)); diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 10e3a7a5a..483011ee7 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -35,6 +35,20 @@ template class DualComplex: public Dual> { public: typedef T Type; /**< @brief Underlying data type */ + /** + * @brief Rotation dual complex number + * @param angle Rotation angle (counterclockwise) + * + * @f[ + * \hat c = (cos \theta + i sin \theta) + \epsilon (0 + i0) + * @f] + * @see rotationAngle(), Complex::rotation(), Matrix3::rotation(), + * DualQuaternion::rotation() + */ + inline static DualComplex rotation(Rad angle) { + return {Complex::rotation(angle), {{}, {}}}; + } + /** * @brief Default constructor * @@ -58,6 +72,18 @@ template class DualComplex: public Dual> { */ inline constexpr /*implicit*/ DualComplex(const Complex& real, const Complex& dual): Dual>(real, dual) {} + /** + * @brief Rotation angle of dual complex number + * + * @f[ + * \theta = atan2(b_0, a_0) + * @f] + * @see rotation(), Complex::rotationAngle() + */ + inline Rad rotationAngle() const { + return this->real().rotationAngle(); + } + /** * @brief Complex-conjugated dual complex number * diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 8000e8480..3f58a20bd 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -38,15 +38,15 @@ template class DualQuaternion: public Dual> { /** * @brief Rotation dual quaternion - * @param angle Rotation angle (counterclockwise, in radians) + * @param angle Rotation angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * * Expects that the rotation axis is normalized. @f[ * \hat q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] + \epsilon [\boldsymbol 0, 0] * @f] * @see rotationAngle(), rotationAxis(), Quaternion::rotation(), - * Matrix4::rotation(), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis() + * Matrix4::rotation(), DualComplex::rotation(), Vector3::xAxis(), + * Vector3::yAxis(), Vector3::zAxis() */ inline static DualQuaternion rotation(Rad angle, const Vector3& normalizedAxis) { return {Quaternion::rotation(angle, normalizedAxis), {{}, T(0)}}; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index e67e909cf..8f9ae7002 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -64,7 +64,7 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D rotation matrix * @param angle Rotation angle (counterclockwise) * - * @see rotation() const, Complex::rotation(), + * @see rotation() const, Complex::rotation(), DualComplex::rotation(), * Matrix4::rotation(Rad, const Vector3&) */ static Matrix3 rotation(Rad angle) { diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index dfa9dad5f..8333b2271 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -76,9 +76,9 @@ template class Matrix4: public Matrix<4, T> { * * Expects that the rotation axis is normalized. If possible, use * faster alternatives like rotationX(), rotationY() and rotationZ(). - * @see rotation() const, DualQuaternion::rotation(), - * Quaternion::rotation(), Matrix3::rotation(Rad), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis() + * @see rotation() const, Quaternion::rotation(), DualQuaternion::rotation(), + * Matrix3::rotation(Rad), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis() */ static Matrix4 rotation(Rad angle, const Vector3& normalizedAxis) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index de204ca00..8592e26f9 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -175,7 +175,7 @@ template class Quaternion { * Expects that the quaternion is normalized. @f[ * \theta = 2 \cdot acos q_S * @f] - * @see rotationAxis(), rotation() + * @see rotationAxis(), rotation(), DualQuaternion::rotationAngle() */ inline Rad rotationAngle() const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 15b9644f9..38cc9e38b 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -39,9 +39,13 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void inverted(); void invertedNormalized(); + void rotation(); + void debug(); }; +typedef Math::Deg Deg; +typedef Math::Rad Rad; typedef Math::Complex Complex; typedef Math::Dual Dual; typedef Math::DualComplex DualComplex; @@ -62,6 +66,8 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::inverted, &DualComplexTest::invertedNormalized, + &DualComplexTest::rotation, + &DualComplexTest::debug); } @@ -149,6 +155,12 @@ void DualComplexTest::invertedNormalized() { CORRADE_COMPARE(inverted, b/Math::sqrt(Dual(7.25f, -43.5f))); } +void DualComplexTest::rotation() { + DualComplex a = DualComplex::rotation(Deg(120.0f)); + CORRADE_COMPARE(a, DualComplex({-0.5f, 0.8660254f}, {0.0f, 0.0f})); + CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); +} + void DualComplexTest::debug() { std::ostringstream o; From bdc02ddd196b8a4ee284155178aaa9627c1573a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Feb 2013 18:45:31 +0100 Subject: [PATCH 446/567] Math: translation dual complex number. --- src/Math/DualComplex.h | 26 ++++++++++++++++++++++++++ src/Math/DualQuaternion.h | 5 +++-- src/Math/Matrix3.h | 5 +++-- src/Math/Test/DualComplexTest.cpp | 10 ++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 483011ee7..d03186a80 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -49,6 +49,20 @@ template class DualComplex: public Dual> { return {Complex::rotation(angle), {{}, {}}}; } + /** + * @brief Translation dual complex number + * @param vector Translation vector + * + * @f[ + * \hat c = (0 + i1) + \epsilon (v_x + iv_y) + * @f] + * @see translation() const, Matrix3::translation(const Vector2&), + * DualQuaternion::translation(), Vector2::xAxis(), Vector2::yAxis() + */ + inline static DualComplex translation(const Vector2& vector) { + return {{}, {vector.x(), vector.y()}}; + } + /** * @brief Default constructor * @@ -84,6 +98,18 @@ template class DualComplex: public Dual> { return this->real().rotationAngle(); } + /** + * @brief Translation part of dual complex number + * + * @f[ + * \boldsymbol a = (c_\epsilon c_0^*) + * @f] + * @see translation(const Vector2&) + */ + inline Vector2 translation() const { + return Vector2(this->dual()*this->real().conjugated()); + } + /** * @brief Complex-conjugated dual complex number * diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 3f58a20bd..b9a9f67ad 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -59,8 +59,9 @@ template class DualQuaternion: public Dual> { * @f[ * \hat q = [\boldsymbol 0, 1] + \epsilon [\frac{\boldsymbol v}{2}, 0] * @f] - * @see translation() const, Matrix3::translation(const Vector2&), - * Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() + * @see translation() const, Matrix4::translation(const Vector3&), + * DualComplex::translation(), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis() */ inline static DualQuaternion translation(const Vector3& vector) { return {{}, {vector/T(2), T(0)}}; diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 8f9ae7002..e36b9a7ef 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -38,8 +38,9 @@ template class Matrix3: public Matrix<3, T> { * @brief 2D translation matrix * @param vector Translation vector * - * @see translation(), Matrix4::translation(const Vector3&), - * Vector2::xAxis(), Vector2::yAxis() + * @see translation(), DualComplex::translation(), + * Matrix4::translation(const Vector3&), Vector2::xAxis(), + * Vector2::yAxis() */ inline constexpr static Matrix3 translation(const Vector2& vector) { return {{ T(1), T(0), T(0)}, diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 38cc9e38b..dd3ab5968 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -40,6 +40,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void invertedNormalized(); void rotation(); + void translation(); void debug(); }; @@ -49,6 +50,7 @@ typedef Math::Rad Rad; typedef Math::Complex Complex; typedef Math::Dual Dual; typedef Math::DualComplex DualComplex; +typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { addTests(&DualComplexTest::construct, @@ -67,6 +69,7 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::invertedNormalized, &DualComplexTest::rotation, + &DualComplexTest::translation, &DualComplexTest::debug); } @@ -161,6 +164,13 @@ void DualComplexTest::rotation() { CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); } +void DualComplexTest::translation() { + Vector2 vec(1.5f, -3.5f); + DualComplex a = DualComplex::translation(vec); + CORRADE_COMPARE(a, DualComplex({}, {1.5f, -3.5f})); + CORRADE_COMPARE(a.translation(), vec); +} + void DualComplexTest::debug() { std::ostringstream o; From c019dc7781978c8fa97d9aef7c58330bfb660814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 25 Feb 2013 21:20:04 +0100 Subject: [PATCH 447/567] Math: test that transformation (dual) complex/quat is normalized. --- src/Math/Test/ComplexTest.cpp | 1 + src/Math/Test/DualQuaternionTest.cpp | 2 ++ src/Math/Test/QuaternionTest.cpp | 1 + 3 files changed, 4 insertions(+) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index fb169465f..76136dbbf 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -255,6 +255,7 @@ void ComplexTest::angle() { void ComplexTest::rotation() { Complex a = Complex::rotation(Deg(120.0f)); + CORRADE_COMPARE(a.length(), 1.0f); CORRADE_COMPARE(a, Complex(-0.5f, 0.8660254f)); CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index ab0e52aad..7e64be636 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -190,6 +190,7 @@ void DualQuaternionTest::rotation() { CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); DualQuaternion q = DualQuaternion::rotation(Deg(120.0f), axis); + CORRADE_COMPARE(q.length(), 1.0f); CORRADE_COMPARE(q, DualQuaternion({Vector3(0.5f, 0.5f, 0.5f), 0.5f}, {{}, 0.0f})); CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); CORRADE_COMPARE(q.rotationAxis(), axis); @@ -198,6 +199,7 @@ void DualQuaternionTest::rotation() { void DualQuaternionTest::translation() { Vector3 vec(1.0f, -3.5f, 0.5f); DualQuaternion q = DualQuaternion::translation(vec); + CORRADE_COMPARE(q.length(), 1.0f); CORRADE_COMPARE(q, DualQuaternion({}, {{0.5f, -1.75f, 0.25f}, 0.0f})); CORRADE_COMPARE(q.translation(), vec); } diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index b4472e768..11b28527b 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -235,6 +235,7 @@ void QuaternionTest::rotation() { CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); Quaternion q = Quaternion::rotation(Deg(120.0f), axis); + CORRADE_COMPARE(q.length(), 1.0f); CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f)); CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); CORRADE_COMPARE(q.rotationAxis(), axis); From 5e2f8db651dbc696e2a7c6d4e89f93a63f82da48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 25 Feb 2013 21:49:39 +0100 Subject: [PATCH 448/567] Math: test also that DualComplex transformations are normalized. Fails for translation. --- src/Math/Test/DualComplexTest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index dd3ab5968..180a444db 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -160,6 +160,7 @@ void DualComplexTest::invertedNormalized() { void DualComplexTest::rotation() { DualComplex a = DualComplex::rotation(Deg(120.0f)); + CORRADE_COMPARE(a.length(), 1.0f); CORRADE_COMPARE(a, DualComplex({-0.5f, 0.8660254f}, {0.0f, 0.0f})); CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); } @@ -167,6 +168,7 @@ void DualComplexTest::rotation() { void DualComplexTest::translation() { Vector2 vec(1.5f, -3.5f); DualComplex a = DualComplex::translation(vec); + CORRADE_COMPARE(a.length(), 1.0f); CORRADE_COMPARE(a, DualComplex({}, {1.5f, -3.5f})); CORRADE_COMPARE(a.translation(), vec); } From 8ff9118275080aa1d681da8ec5cfcf860e33d689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 25 Feb 2013 21:50:51 +0100 Subject: [PATCH 449/567] Math: test DualComplex transformation combination. Also fails. --- src/Math/Test/DualComplexTest.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 180a444db..c6f7dabbc 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -41,6 +41,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void rotation(); void translation(); + void combinedTransformParts(); void debug(); }; @@ -70,6 +71,7 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::rotation, &DualComplexTest::translation, + &DualComplexTest::combinedTransformParts, &DualComplexTest::debug); } @@ -173,6 +175,17 @@ void DualComplexTest::translation() { CORRADE_COMPARE(a.translation(), vec); } +void DualComplexTest::combinedTransformParts() { + Vector2 translation = Vector2(-1.5f, 2.75f); + DualComplex a = DualComplex::translation(translation)*DualComplex::rotation(Deg(23.0f)); + DualComplex b = DualComplex::rotation(Deg(23.0f))*DualComplex::translation(translation); + + CORRADE_COMPARE_AS(a.rotationAngle(), Deg(23.0f), Rad); + CORRADE_COMPARE_AS(b.rotationAngle(), Deg(23.0f), Rad); + CORRADE_COMPARE(a.translation(), translation); + CORRADE_COMPARE(b.translation(), Complex::rotation(Deg(23.0f)).transformVector(translation)); +} + void DualComplexTest::debug() { std::ostringstream o; From 90f5a006c4e02717c50e0850878d137925531c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 25 Feb 2013 21:51:26 +0100 Subject: [PATCH 450/567] Math: reworked DualComplex to actually work. The tests now pass and it works similarly to transformation matrix multiplication/inversion in 2D, but it hasn't any connection to dual numbers anymore. --- src/Math/DualComplex.h | 83 ++++++++++++++++++++++++------- src/Math/Test/DualComplexTest.cpp | 44 +++++++++------- 2 files changed, 92 insertions(+), 35 deletions(-) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index d03186a80..4cc1deea2 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -30,6 +30,8 @@ namespace Magnum { namespace Math { Represents 2D rotation and translation. @see Dual, Complex, Matrix3 +@todo Can this be done similarly as in dual quaternions? It sort of works, but + the math beneath is weird. */ template class DualComplex: public Dual> { public: @@ -107,7 +109,19 @@ template class DualComplex: public Dual> { * @see translation(const Vector2&) */ inline Vector2 translation() const { - return Vector2(this->dual()*this->real().conjugated()); + return Vector2(this->dual()); + } + + /** + * @brief Multipy with dual complex number + * + * @f[ + * \hat a \hat b = a_0 b_0 + \epsilon (a_0 b_\epsilon + a_\epsilon) + * @f] + * @todo can this be done similarly to dual quaternions? + */ + inline DualComplex operator*(const DualComplex& other) const { + return {this->real()*other.real(), this->real()*other.dual() + this->dual()}; } /** @@ -152,11 +166,12 @@ template class DualComplex: public Dual> { * * Should be used instead of length() for comparing complex number * length with other values, because it doesn't compute the square root. @f[ - * |\hat c|^2 = \sqrt{\hat c^* \hat c}^2 = c_0 \cdot c_0 + \epsilon 2 (c_0 \cdot c_\epsilon) + * |\hat c|^2 = c_0 \cdot c_0 = |c_0|^2 * @f] + * @todo Can this be done similarly to dual quaternins? */ - inline Dual lengthSquared() const { - return {this->real().dot(), T(2)*Complex::dot(this->real(), this->dual())}; + inline T lengthSquared() const { + return this->real().dot(); } /** @@ -164,16 +179,24 @@ template class DualComplex: public Dual> { * * See lengthSquared() which is faster for comparing length with other * values. @f[ - * |\hat c| = \sqrt{\hat{c^*} \hat c} = |c_0| + \epsilon \frac{c_0 \cdot c_\epsilon}{|c_0|} + * |\hat c| = \sqrt{c_0 \cdot c_0} = |c_0| * @f] + * @todo can this be done similarly to dual quaternions? */ - inline Dual length() const { - return Math::sqrt(lengthSquared()); + inline T length() const { + return this->real().length(); } - /** @brief Normalized dual complex number (of unit length) */ + /** + * @brief Normalized dual complex number (of unit length) + * + * @f[ + * c' = \frac{c_0}{|c_0|} + * @f] + * @todo can this be done similarly to dual quaternions? + */ inline DualComplex normalized() const { - return (*this)/length(); + return {this->real()/length(), this->dual()}; } /** @@ -181,33 +204,57 @@ template class DualComplex: public Dual> { * * See invertedNormalized() which is faster for normalized dual complex * numbers. @f[ - * \hat c^{-1} = \frac{\hat c^*}{|\hat c|^2} + * \hat c^{-1} = c_0^{-1} - \epsilon c_\epsilon * @f] + * @todo can this be done similarly to dual quaternions? */ inline DualComplex inverted() const { - return complexConjugated()/lengthSquared(); + return DualComplex(this->real().inverted(), {{}, {}})*DualComplex({}, -this->dual()); } /** * @brief Inverted normalized dual complex number * - * Equivalent to complexConjugated(). Expects that the complex number - * is normalized. @f[ - * \hat c^{-1} = \frac{\hat c^*}{|\hat c|^2} = \hat c^* + * Expects that the complex number is normalized. @f[ + * \hat c^{-1} = c_0^{-1} - \epsilon c_\epsilon = c_0^* - \epsilon c_\epsilon * @f] * @see inverted() + * @todo can this be done similarly to dual quaternions? */ inline DualComplex invertedNormalized() const { - CORRADE_ASSERT(lengthSquared() == Dual(1), - "Math::DualComplex::invertedNormalized(): dual complex number must be normalized", {}); - return complexConjugated(); + return DualComplex(this->real().invertedNormalized(), {{}, {}})*DualComplex({}, -this->dual()); } - MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Complex) + /* Verbatim copy of DUAL_SUBCLASS_IMPLEMENTATION(), as we need to hide + Dual's operator*() and operator/() */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline DualComplex operator-() const { + return Dual>::operator-(); + } + inline DualComplex& operator+=(const Dual>& other) { + Dual>::operator+=(other); + return *this; + } + inline DualComplex operator+(const Dual>& other) const { + return Dual>::operator+(other); + } + inline DualComplex& operator-=(const Dual>& other) { + Dual>::operator-=(other); + return *this; + } + inline DualComplex operator-(const Dual>& other) const { + return Dual>::operator-(other); + } + #endif private: /* Used by Dual operators and dualConjugated() */ inline constexpr DualComplex(const Dual>& other): Dual>(other) {} + + /* Just to be sure nobody uses this, as it wouldn't probably work with + our operator*() */ + using Dual>::operator*; + using Dual>::operator/; }; /** @debugoperator{Magnum::Math::DualQuaternion} */ diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index c6f7dabbc..2a37f25c1 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -17,6 +17,7 @@ #include #include "Math/DualComplex.h" +#include "Math/DualQuaternion.h" namespace Magnum { namespace Math { namespace Test { @@ -29,6 +30,8 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void constExpressions(); + void multiply(); + void lengthSquared(); void length(); void normalized(); @@ -59,6 +62,8 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::constExpressions, + &DualComplexTest::multiply, + &DualComplexTest::lengthSquared, &DualComplexTest::length, &DualComplexTest::normalized, @@ -101,19 +106,25 @@ void DualComplexTest::constExpressions() { CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); } +void DualComplexTest::multiply() { + DualComplex a({-1.5f, 2.0f}, { 3.0f, -6.5f}); + DualComplex b({ 2.0f, -7.5f}, {-0.5f, 1.0f});; + CORRADE_COMPARE(a*b, DualComplex({12.0f, 15.25f}, {1.75f, -9.0f})); +} + void DualComplexTest::lengthSquared() { DualComplex a({-1.0f, 3.0f}, {0.5f, -2.0f}); - CORRADE_COMPARE(a.lengthSquared(), Dual(10.0f, -13.0f)); + CORRADE_COMPARE(a.lengthSquared(), 10.0f); } void DualComplexTest::length() { DualComplex a({-1.0f, 3.0f}, {0.5f, -2.0f}); - CORRADE_COMPARE(a.length(), Dual(3.162278f, -2.05548f)); + CORRADE_COMPARE(a.length(), 3.162278f); } void DualComplexTest::normalized() { DualComplex a({-1.0f, 3.0f}, {0.5f, -2.0f}); - DualComplex b({-0.316228f, 0.948683f}, {-0.0474342f, -0.0158114f}); + DualComplex b({-0.316228f, 0.948683f}, {0.5f, -2.0f}); CORRADE_COMPARE(a.normalized().length(), 1.0f); CORRADE_COMPARE(a.normalized(), b); } @@ -137,27 +148,26 @@ void DualComplexTest::conjugated() { } void DualComplexTest::inverted() { - DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f}); - DualComplex b({-1.0f, -2.5f}, { 3.0f, 7.5f}); - + DualComplex a({-1.0f, 1.5f}, {3.0f, -7.5f}); + DualComplex b({-0.307692f, -0.461538f}, {4.384616f, -0.923077f}); CORRADE_COMPARE(a*a.inverted(), DualComplex()); - CORRADE_COMPARE(a.inverted(), b/Dual(7.25f, -43.5f)); + CORRADE_COMPARE(a.inverted(), b); } void DualComplexTest::invertedNormalized() { - DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f}); - DualComplex b({-1.0f, -2.5f}, { 3.0f, 7.5f}); + DualComplex a({-0.316228f, 0.9486831f}, { 3.0f, -2.5f}); + DualComplex b({-0.316228f, -0.9486831f}, {3.320391f, 2.05548f}); std::ostringstream o; Error::setOutput(&o); - CORRADE_COMPARE(a.invertedNormalized(), DualComplex()); - CORRADE_COMPARE(o.str(), "Math::DualComplex::invertedNormalized(): dual complex number must be normalized\n"); - - DualComplex normalized = a.normalized(); - DualComplex inverted = normalized.invertedNormalized(); - CORRADE_COMPARE(normalized*inverted, DualComplex()); - CORRADE_COMPARE(inverted*normalized, DualComplex()); - CORRADE_COMPARE(inverted, b/Math::sqrt(Dual(7.25f, -43.5f))); + DualComplex notInverted = DualComplex({-1.0f, -2.5f}, {}).invertedNormalized(); + CORRADE_VERIFY(notInverted != notInverted); + CORRADE_COMPARE(o.str(), "Math::Complex::invertedNormalized(): complex number must be normalized\n"); + + DualComplex inverted = a.invertedNormalized(); + CORRADE_COMPARE(a*inverted, DualComplex()); + CORRADE_COMPARE(inverted*a, DualComplex()); + CORRADE_COMPARE(inverted, b); } void DualComplexTest::rotation() { From 7aac5bd70bfb56086f45ab59fe9ba91ecdc09549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:48:04 +0100 Subject: [PATCH 451/567] Math: no need for Complex::transformVectorNormalized(). Unlike quaternions it doesn't need inversion or normalization for transforming vectors. --- src/Math/Complex.h | 23 +++-------------------- src/Math/Quaternion.h | 3 +-- src/Math/Test/ComplexTest.cpp | 18 ------------------ src/MeshTools/Transform.h | 10 +++++----- 4 files changed, 9 insertions(+), 45 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 665523e1c..528ec3c12 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -102,7 +102,7 @@ template class Complex { * To be used in transformations later. @f[ * c = v_x + iv_y * @f] - * @see operator Vector2(), transformVector(), transformVectorNormalized() + * @see operator Vector2(), transformVector() */ inline constexpr explicit Complex(const Vector2& vector): _real(vector.x()), _imaginary(vector.y()) {} @@ -345,29 +345,12 @@ template class Complex { /** * @brief Rotate vector with complex number * - * See transformVectorNormalized(), which is faster for normalized - * complex numbers. @f[ - * v' = \frac c {|c|} v = \frac c {|c|} (v_x + iv_y) + * @f[ + * v' = c v = c (v_x + iv_y) * @f] * @see Complex(const Vector2&), operator Vector2(), Matrix3::transformVector() */ inline Vector2 transformVector(const Vector2& vector) const { - return Vector2(normalized()*Complex(vector)); - } - - /** - * @brief Rotate vector with normalized complex number - * - * Faster alternative to transformVector(), expects that the complex - * number is normalized. @f[ - * v' = \frac c {|c|} v = cv = c(v_x + iv_y) - * @f] - * @see Complex(const Vector2&), operator Vector2(), Matrix3::transformVector() - */ - inline Vector2 transformVectorNormalized(const Vector2& vector) const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), - "Math::Complex::transformVectorNormalized(): complex number must be normalized", - Vector2(std::numeric_limits::quiet_NaN())); return Vector2((*this)*Complex(vector)); } diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 8592e26f9..5eef4346f 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -423,8 +423,7 @@ template class Quaternion { * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] * @see Quaternion(const Vector3&), vector(), Matrix4::transformVector(), - * DualQuaternion::transformPointNormalized(), - * Complex::transformVectorNormalized() + * DualQuaternion::transformPointNormalized(), Complex::transformVector() */ inline Vector3 transformVectorNormalized(const Vector3& vector) const { CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 76136dbbf..aa909989c 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -50,7 +50,6 @@ class ComplexTest: public Corrade::TestSuite::Tester { void rotation(); void matrix(); void transformVector(); - void transformVectorNormalized(); void debug(); }; @@ -81,7 +80,6 @@ ComplexTest::ComplexTest() { &ComplexTest::rotation, &ComplexTest::matrix, &ComplexTest::transformVector, - &ComplexTest::transformVectorNormalized, &ComplexTest::debug); } @@ -285,22 +283,6 @@ void ComplexTest::transformVector() { CORRADE_COMPARE(rotated, Vector2(-3.58733f, -0.762279f)); } -void ComplexTest::transformVectorNormalized() { - Complex a = Complex::rotation(Deg(23.0f)); - Matrix3 m = Matrix3::rotation(Deg(23.0f)); - Vector2 v(-3.6f, 0.7f); - - std::ostringstream o; - Error::setOutput(&o); - Vector2 notRotated = (a*2).transformVectorNormalized(v); - CORRADE_VERIFY(notRotated != notRotated); - CORRADE_COMPARE(o.str(), "Math::Complex::transformVectorNormalized(): complex number must be normalized\n"); - - Vector2 rotated = a.transformVectorNormalized(v); - CORRADE_COMPARE(rotated, m.transformVector(v)); - CORRADE_COMPARE(rotated, a.transformVector(v)); -} - void ComplexTest::debug() { std::ostringstream o; diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h index 9ce7b07ae..2f654ab18 100644 --- a/src/MeshTools/Transform.h +++ b/src/MeshTools/Transform.h @@ -31,8 +31,8 @@ namespace Magnum { namespace MeshTools { Usable for one-time mesh transformations that would otherwise negatively affect dependent objects, such as (uneven) scaling. Accepts any forward-iterable type with compatible vector type as @p vectors. Expects that @ref Math::Quaternion "Quaternion" -or @ref Math::Complex "Complex" is normalized, no further requirements are for -transformation matrices. +is normalized, no further requirements are for other transformation +representations. Unlike in transformPointsInPlace(), the transformation does not involve translation. @@ -53,8 +53,8 @@ template void transformVectorsInPlace(const Math::Quaternion void transformVectorsInPlace(const Math::Complex& normalizedComplex, U& vectors) { - for(auto& vector: vectors) vector = normalizedComplex.transformVectorNormalized(vector); +template void transformVectorsInPlace(const Math::Complex& complex, U& vectors) { + for(auto& vector: vectors) vector = complex.transformVector(vector); } /** @overload */ @@ -86,7 +86,7 @@ Usable for one-time mesh transformations that would otherwise negatively affect dependent objects, such as (uneven) scaling. Accepts any forward-iterable type with compatible vector type as @p vectors. Expects that @ref Math::DualQuaternion "DualQuaternion" is normalized, no further -requirements are for transformation matrices. +requirements are for other transformation representations. Unlike in transformVectorsInPlace(), the transformation also involves translation. From 8e562316e8ff9b232231f5f00cf42e5ff03be414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 10:53:24 +0100 Subject: [PATCH 452/567] Math: creating DualComplex from Vector2. --- src/Math/DualComplex.h | 14 ++++++++++++++ src/Math/Test/DualComplexTest.cpp | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 4cc1deea2..c150f378d 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -88,6 +88,20 @@ template class DualComplex: public Dual> { */ inline constexpr /*implicit*/ DualComplex(const Complex& real, const Complex& dual): Dual>(real, dual) {} + /** + * @brief Construct dual complex number from vector + * + * To be used in transformations later. @f[ + * \hat c = (0 + i1) + \epsilon(v_x + iv_y) + * @f] + * @todoc Remove workaround when Doxygen is predictable + */ + #ifdef DOXYGEN_GENERATING_OUTPUT + inline constexpr explicit DualComplex(const Vector2& vector); + #else + inline constexpr explicit DualComplex(const Vector2& vector): Dual>({}, Complex(vector)) {} + #endif + /** * @brief Rotation angle of dual complex number * diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 2a37f25c1..4922e4ecb 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -27,6 +27,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); + void constructFromVector(); void constExpressions(); @@ -59,6 +60,7 @@ typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { addTests(&DualComplexTest::construct, &DualComplexTest::constructDefault, + &DualComplexTest::constructFromVector, &DualComplexTest::constExpressions, @@ -92,6 +94,10 @@ void DualComplexTest::constructDefault() { CORRADE_COMPARE(DualComplex().length(), 1.0f); } +void DualComplexTest::constructFromVector() { + CORRADE_COMPARE(DualComplex(Vector2(1.5f, -3.0f)), DualComplex({1.0f, 0.0f}, {1.5f, -3.0f})); +} + void DualComplexTest::constExpressions() { /* Default constructor */ constexpr DualComplex a; @@ -101,6 +107,10 @@ void DualComplexTest::constExpressions() { constexpr DualComplex b({-1.0f, 2.5f}, {3.0f, -7.5f}); CORRADE_COMPARE(b, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); + /* Vector constructor */ + constexpr DualComplex c(Vector2(-3.0f, 7.5f)); + CORRADE_COMPARE(c, DualComplex({}, {-3.0f, 7.5f})); + /* Copy constructor */ constexpr DualComplex d(b); CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); From 268c07acc5034984dc02b388dfdb4bd637edcf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:23:56 +0100 Subject: [PATCH 453/567] Math: converting DualComplex to matrix. --- src/Math/Complex.h | 2 +- src/Math/DualComplex.h | 10 ++++++++++ src/Math/Test/DualComplexTest.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 528ec3c12..b88d8e4d0 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -155,7 +155,7 @@ template class Complex { * b & a * \end{pmatrix} * @f] - * @see Matrix3::from(const Matrix<2, T>&, const Vector2&) + * @see DualComplex::matrix(), Matrix3::from(const Matrix<2, T>&, const Vector2&) */ Matrix<2, T> matrix() const { return {Vector<2, T>(_real, _imaginary), diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index c150f378d..d4484727a 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -21,6 +21,7 @@ #include "Math/Dual.h" #include "Math/Complex.h" +#include "Math/Matrix3.h" namespace Magnum { namespace Math { @@ -126,6 +127,15 @@ template class DualComplex: public Dual> { return Vector2(this->dual()); } + /** + * @brief Convert dual complex number to transformation matrix + * + * @see Complex::matrix() + */ + inline Matrix3 matrix() const { + return Matrix3::from(this->real().matrix(), translation()); + } + /** * @brief Multipy with dual complex number * diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 4922e4ecb..acc5bd03e 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -46,6 +46,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void rotation(); void translation(); void combinedTransformParts(); + void matrix(); void debug(); }; @@ -55,6 +56,7 @@ typedef Math::Rad Rad; typedef Math::Complex Complex; typedef Math::Dual Dual; typedef Math::DualComplex DualComplex; +typedef Math::Matrix3 Matrix3; typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { @@ -79,6 +81,7 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::rotation, &DualComplexTest::translation, &DualComplexTest::combinedTransformParts, + &DualComplexTest::matrix, &DualComplexTest::debug); } @@ -206,6 +209,13 @@ void DualComplexTest::combinedTransformParts() { CORRADE_COMPARE(b.translation(), Complex::rotation(Deg(23.0f)).transformVector(translation)); } +void DualComplexTest::matrix() { + DualComplex a = DualComplex::rotation(Deg(23.0f))*DualComplex::translation({2.0f, 3.0f}); + Matrix3 m = Matrix3::rotation(Deg(23.0f))*Matrix3::translation({2.0f, 3.0f}); + + CORRADE_COMPARE(a.matrix(), m); +} + void DualComplexTest::debug() { std::ostringstream o; From a0af6856c771de62524587dc821557cfec481726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:25:43 +0100 Subject: [PATCH 454/567] Math: transforming points with DualComplex. --- src/Math/DualComplex.h | 14 ++++++++++++++ src/Math/DualQuaternion.h | 4 ++-- src/Math/Matrix3.h | 5 +++-- src/Math/Test/DualComplexTest.cpp | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index d4484727a..acb3154a0 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -249,6 +249,20 @@ template class DualComplex: public Dual> { return DualComplex(this->real().invertedNormalized(), {{}, {}})*DualComplex({}, -this->dual()); } + /** + * @brief Rotate and translate point with dual complex number + * + * See transformPointNormalized(), which is faster for normalized dual + * complex number. @f[ + * v' = \hat c v = \hat c ((0 + i) + \epsilon(v_x + iv_y)) + * @f] + * @see DualComplex(const Vector2&), dual(), Matrix3::transformPoint(), + * Complex::transformVector(), DualQuaternion::transformPoint() + */ + inline Vector2 transformPoint(const Vector2& vector) const { + return Vector2(((*this)*DualComplex(vector)).dual()); + } + /* Verbatim copy of DUAL_SUBCLASS_IMPLEMENTATION(), as we need to hide Dual's operator*() and operator/() */ #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index b9a9f67ad..9e10be0aa 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -253,7 +253,7 @@ template class DualQuaternion: public Dual> { * v' = \hat q v \overline{\hat q^{-1}} = \hat q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^{-1}} * @f] * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), - * Quaternion::transformVector() + * Quaternion::transformVector(), DualComplex::transformPoint() */ inline Vector3 transformPoint(const Vector3& vector) const { return ((*this)*DualQuaternion(vector)*inverted().dualConjugated()).dual().vector(); @@ -267,7 +267,7 @@ template class DualQuaternion: public Dual> { * v' = \hat q v \overline{\hat q^{-1}} = \hat q v \overline{\hat q^*} = \hat q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), - * Quaternion::transformVectorNormalized() + * Quaternion::transformVectorNormalized(), DualComplex::transformPointNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { CORRADE_ASSERT(lengthSquared() == Dual(1), diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index e36b9a7ef..4bd73a8ec 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -29,7 +29,8 @@ namespace Magnum { namespace Math { @tparam T Underlying data type Represents 2D transformation. See @ref matrix-vector for brief introduction. -@see Magnum::Matrix3, Magnum::Matrix3d, SceneGraph::MatrixTransformation2D +@see Magnum::Matrix3, Magnum::Matrix3d, DualComplex, + SceneGraph::MatrixTransformation2D @configurationvalueref{Magnum::Math::Matrix3} */ template class Matrix3: public Matrix<3, T> { @@ -234,7 +235,7 @@ template class Matrix3: public Matrix<3, T> { * transformation. @f[ * \boldsymbol v' = \boldsymbol M \begin{pmatrix} v_x \\ v_y \\ 1 \end{pmatrix} * @f] - * @see Matrix4::transformPoint() + * @see DualComplex::transformPoint(), Matrix4::transformPoint() */ inline Vector2 transformPoint(const Vector2& vector) const { return ((*this)*Vector3(vector, T(1))).xy(); diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index acc5bd03e..242688540 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -47,6 +47,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void translation(); void combinedTransformParts(); void matrix(); + void transformPoint(); void debug(); }; @@ -82,6 +83,7 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::translation, &DualComplexTest::combinedTransformParts, &DualComplexTest::matrix, + &DualComplexTest::transformPoint, &DualComplexTest::debug); } @@ -216,6 +218,22 @@ void DualComplexTest::matrix() { CORRADE_COMPARE(a.matrix(), m); } +void DualComplexTest::transformPoint() { + DualComplex a = DualComplex::translation({2.0f, 3.0f})*DualComplex::rotation(Deg(23.0f)); + DualComplex b = DualComplex::rotation(Deg(23.0f))*DualComplex::translation({2.0f, 3.0f}); + Matrix3 m = Matrix3::translation({2.0f, 3.0f})*Matrix3::rotation(Deg(23.0f)); + Matrix3 n = Matrix3::rotation(Deg(23.0f))*Matrix3::translation({2.0f, 3.0f}); + Vector2 v(-3.6f, 0.7f); + + Vector2 transformedA = a.transformPoint(v); + CORRADE_COMPARE(transformedA, m.transformPoint(v)); + CORRADE_COMPARE(transformedA, Vector2(-1.58733f, 2.237721f)); + + Vector2 transformedB = b.transformPoint(v); + CORRADE_COMPARE(transformedB, n.transformPoint(v)); + CORRADE_COMPARE(transformedB, Vector2(-2.918512f, 2.780698f)); +} + void DualComplexTest::debug() { std::ostringstream o; From e204dbc109ee060eda95605d43914ae362546202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:31:31 +0100 Subject: [PATCH 455/567] Brought DualComplex into Magnum namespace. --- src/Magnum.h | 3 +++ src/Math/DualComplex.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Magnum.h b/src/Magnum.h index 05b6b5c17..0fdb9e711 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -120,6 +120,9 @@ typedef Math::Matrix4 Matrix4d; /** @brief %Complex number */ typedef Math::Complex Complex; +/** @brief %Dual complex number */ +typedef Math::DualComplex DualComplex; + /** @brief %Quaternion */ typedef Math::Quaternion Quaternion; diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index acb3154a0..b96bbce88 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Math { @tparam T Underlying data type Represents 2D rotation and translation. -@see Dual, Complex, Matrix3 +@see Magnum::DualComplex, Dual, Complex, Matrix3 @todo Can this be done similarly as in dual quaternions? It sort of works, but the math beneath is weird. */ From e8e8e674836ec54d5d2b0ffe48478ff02c5d1367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 11:26:04 +0100 Subject: [PATCH 456/567] MeshTools: ability to call transformPoints*() also with DualComplex. --- src/MeshTools/Test/TransformTest.cpp | 11 +++++++---- src/MeshTools/Transform.h | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/MeshTools/Test/TransformTest.cpp b/src/MeshTools/Test/TransformTest.cpp index b6f3e16c4..1cfe3b934 100644 --- a/src/MeshTools/Test/TransformTest.cpp +++ b/src/MeshTools/Test/TransformTest.cpp @@ -81,27 +81,30 @@ void TransformTest::transformVectors2D() { void TransformTest::transformVectors3D() { auto matrix = MeshTools::transformVectors(Matrix4::rotationZ(Deg(90.0f)), points3D); - auto complex = MeshTools::transformVectors(Quaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); + auto quaternion = MeshTools::transformVectors(Quaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); CORRADE_COMPARE(matrix, points3DRotated); - CORRADE_COMPARE(complex, points3DRotated); + CORRADE_COMPARE(quaternion, points3DRotated); } void TransformTest::transformPoints2D() { auto matrix = MeshTools::transformPoints( Matrix3::translation(Vector2::yAxis(-1.0f))*Matrix3::rotation(Deg(90.0f)), points2D); + auto complex = MeshTools::transformPoints( + DualComplex::translation(Vector2::yAxis(-1.0f))*DualComplex::rotation(Deg(90.0f)), points2D); CORRADE_COMPARE(matrix, points2DRotatedTranslated); + CORRADE_COMPARE(complex, points2DRotatedTranslated); } void TransformTest::transformPoints3D() { auto matrix = MeshTools::transformPoints( Matrix4::translation(Vector3::yAxis(-1.0f))*Matrix4::rotationZ(Deg(90.0f)), points3D); - auto complex = MeshTools::transformPoints( + auto quaternion = MeshTools::transformPoints( DualQuaternion::translation(Vector3::yAxis(-1.0f))*DualQuaternion::rotation(Deg(90.0f), Vector3::zAxis()), points3D); CORRADE_COMPARE(matrix, points3DRotatedTranslated); - CORRADE_COMPARE(complex, points3DRotatedTranslated); + CORRADE_COMPARE(quaternion, points3DRotatedTranslated); } }}} diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h index 2f654ab18..7ecd1e8f4 100644 --- a/src/MeshTools/Transform.h +++ b/src/MeshTools/Transform.h @@ -19,9 +19,8 @@ * @brief Function Magnum::MeshTools::transformVectorsInPlace(), Magnum::MeshTools::transformVectors(), Magnum::MeshTools::transformPointsInPlace(), Magnum::MeshTools::transformPoints() */ -#include "Math/Complex.h" #include "Math/DualQuaternion.h" -#include "Math/Matrix3.h" +#include "Math/DualComplex.h" namespace Magnum { namespace MeshTools { @@ -106,6 +105,11 @@ template void transformPointsInPlace(const Math::DualQuaternio for(auto& point: points) point = normalizedDualQuaternion.transformPointNormalized(point); } +/** @overload */ +template void transformPointsInPlace(const Math::DualComplex& dualComplex, U& points) { + for(auto& point: points) point = dualComplex.transformPoint(point); +} + /** @overload */ template void transformPointsInPlace(const Math::Matrix3& matrix, U& points) { for(auto& point: points) point = matrix.transformPoint(point); From 14460cf0f4dde064f520bbae759dd15362bbab7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 12:01:23 +0100 Subject: [PATCH 457/567] Math: renamed *::matrix() to ::toMatrix(). It better visualizes the fact that neither (Dual)Complex nor (Dual)Quaternion contains the matrix inside them, but performs (possibly costly) conversion. --- src/Math/Complex.h | 4 ++-- src/Math/DualComplex.h | 6 +++--- src/Math/DualQuaternion.h | 6 +++--- src/Math/Quaternion.h | 4 ++-- src/Math/Test/ComplexTest.cpp | 2 +- src/Math/Test/DualComplexTest.cpp | 2 +- src/Math/Test/DualQuaternionTest.cpp | 4 ++-- src/Math/Test/QuaternionTest.cpp | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index b88d8e4d0..8bd7486ac 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -155,9 +155,9 @@ template class Complex { * b & a * \end{pmatrix} * @f] - * @see DualComplex::matrix(), Matrix3::from(const Matrix<2, T>&, const Vector2&) + * @see DualComplex::toMatrix(), Matrix3::from(const Matrix<2, T>&, const Vector2&) */ - Matrix<2, T> matrix() const { + Matrix<2, T> toMatrix() const { return {Vector<2, T>(_real, _imaginary), Vector<2, T>(-_imaginary, _real)}; } diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index b96bbce88..a17198d8d 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -130,10 +130,10 @@ template class DualComplex: public Dual> { /** * @brief Convert dual complex number to transformation matrix * - * @see Complex::matrix() + * @see Complex::toMatrix() */ - inline Matrix3 matrix() const { - return Matrix3::from(this->real().matrix(), translation()); + inline Matrix3 toMatrix() const { + return Matrix3::from(this->real().toMatrix(), translation()); } /** diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 9e10be0aa..6a305e0b5 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -146,10 +146,10 @@ template class DualQuaternion: public Dual> { /** * @brief Convert dual quaternion to transformation matrix * - * @see Quaternion::matrix() + * @see Quaternion::toMatrix() */ - Matrix4 matrix() const { - return Matrix4::from(this->real().matrix(), translation()); + Matrix4 toMatrix() const { + return Matrix4::from(this->real().toMatrix(), translation()); } /** diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 5eef4346f..e92397145 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -204,9 +204,9 @@ template class Quaternion { /** * @brief Convert quaternion to rotation matrix * - * @see DualQuaternion::matrix(), Matrix4::from(const Matrix<3, T>&, const Vector3&) + * @see DualQuaternion::toMatrix(), Matrix4::from(const Matrix<3, T>&, const Vector3&) */ - Matrix<3, T> matrix() const { + Matrix<3, T> toMatrix() const { return { Vector<3, T>(T(1) - 2*pow2(_vector.y()) - 2*pow2(_vector.z()), 2*_vector.x()*_vector.y() + 2*_vector.z()*_scalar, diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index aa909989c..8b49bacbb 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -270,7 +270,7 @@ void ComplexTest::matrix() { Complex a = Complex::rotation(Deg(37.0f)); Matrix2 m = Matrix3::rotation(Deg(37.0f)).rotationScaling(); - CORRADE_COMPARE(a.matrix(), m); + CORRADE_COMPARE(a.toMatrix(), m); } void ComplexTest::transformVector() { diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 242688540..758088379 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -215,7 +215,7 @@ void DualComplexTest::matrix() { DualComplex a = DualComplex::rotation(Deg(23.0f))*DualComplex::translation({2.0f, 3.0f}); Matrix3 m = Matrix3::rotation(Deg(23.0f))*Matrix3::translation({2.0f, 3.0f}); - CORRADE_COMPARE(a.matrix(), m); + CORRADE_COMPARE(a.toMatrix(), m); } void DualComplexTest::transformPoint() { diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 7e64be636..72d8acb06 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -223,8 +223,8 @@ void DualQuaternionTest::matrix() { Matrix4 m = Matrix4::rotationX(Deg(23.0f))*Matrix4::translation({-1.0f, 2.0f, 3.0f}); /* Verify that negated dual quaternion gives the same transformation */ - CORRADE_COMPARE(q.matrix(), m); - CORRADE_COMPARE((-q).matrix(), m); + CORRADE_COMPARE(q.toMatrix(), m); + CORRADE_COMPARE((-q).toMatrix(), m); } void DualQuaternionTest::transformPoint() { diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 11b28527b..de71e044a 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -277,8 +277,8 @@ void QuaternionTest::matrix() { Matrix3 m = Matrix4::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); /* Verify that negated quaternion gives the same rotation */ - CORRADE_COMPARE(q.matrix(), m); - CORRADE_COMPARE((-q).matrix(), m); + CORRADE_COMPARE(q.toMatrix(), m); + CORRADE_COMPARE((-q).toMatrix(), m); } void QuaternionTest::lerp() { From 8913e38432ffa0ab1d18f65d1396f8105ddcaf72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 25 Feb 2013 21:24:30 +0100 Subject: [PATCH 458/567] Math: documented this whole transformation thingy. --- doc/features.dox | 1 + doc/matrix-vector.dox | 20 --- doc/transformations.dox | 290 ++++++++++++++++++++++++++++++++++++++ src/Math/Complex.h | 2 +- src/Math/DualComplex.h | 3 +- src/Math/DualQuaternion.h | 3 +- src/Math/Matrix3.h | 3 +- src/Math/Matrix4.h | 3 +- src/Math/Quaternion.h | 2 +- 9 files changed, 301 insertions(+), 26 deletions(-) create mode 100644 doc/transformations.dox diff --git a/doc/features.dox b/doc/features.dox index 3a0084de2..0a084a3bc 100644 --- a/doc/features.dox +++ b/doc/features.dox @@ -3,6 +3,7 @@ namespace Magnum { @brief Fundamental principles and design goals - @subpage matrix-vector - @copybrief matrix-vector +- @subpage transformations - @copybrief transformations - @subpage scenegraph - @copybrief scenegraph - @subpage collision-detection - @copybrief collision-detection - @subpage debug-tools - @copybrief debug-tools diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index c12adb0b6..a5addb366 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -65,15 +65,6 @@ Matrix3 diag(Matrix3::Identity, 2); // diagonal set to 2, zeros elsewh Vector3 fill(10); // {10, 10, 10} @endcode -Vectors are commonly used to specify various axes and scaling coefficients in -transformations, you can use convenience functions instead of typing out all -other elements: -@code -Matrix4::rotation(5.0_degf, Vector3::xAxis()); // {1.0f, 0.0f, 0.0f} -Matrix3::translation(Vector2::yAxis(2.0f)); // {0.0f, 2.0f} -Matrix4::scaling(Vector3::zScale(-10.0f)); // {1.0f, 1.0f, -10.0f} -@endcode - It is possible to create matrices from other matrices and vectors with the same row count; vectors from vector and scalar: @code @@ -133,17 +124,6 @@ Vector<4, int> bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } Vector<6, int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } @endcode -Matrix3 and Matrix4 have functions for accessing properties of given 2D/3D -transformation: -@code -Matrix4 a = Matrix4::translation(Vector3::yAxis(4.0f)); -Vector3 translation = a.translation(); - -Matrix3 b = Matrix3::rotation(15.0_degf)); -Matrix<2, float> rotationScaling = b.rotationScaling(); -Vector2 up = b.up(); -@endcode - @section matrix-vector-column-major Matrices are column-major and vectors are columns OpenGL matrices are column-major, thus it is reasonable to have matrices in diff --git a/doc/transformations.dox b/doc/transformations.dox new file mode 100644 index 000000000..43bba0457 --- /dev/null +++ b/doc/transformations.dox @@ -0,0 +1,290 @@ +namespace Magnum { namespace Math { +/** @page transformations 2D and 3D transformations + +@brief Introduction to essential operations on vectors and points. + +@tableofcontents + +Transformations are essential operations involved in scene management -- object +relations, hierarchies, animations etc. %Magnum provides classes for +transformations in both 2D and 3D. Each class is suited for different purposes, +but their usage is nearly the same to make your life simpler. This page will +explain the basic operation and differences between various representations. + +@section transformations-representation Representing transformations + +The first and most straightforward way to represent transformations is to use +homogeneous transformation matrix, i.e. Matrix3 for 2D and Matrix4 for 3D. The +matrices are able to represent all possible types of transformations -- rotation, +translation, scaling, reflection etc. and also projective transformation, thus +they are used at the very core of graphics pipeline and are supported natively +in OpenGL. + +On the other hand, matrices need 9 or 16 floats to represent the transformation, +which has implications on both memory usage and performance (relatively slow +matrix multiplication). It is also relatively hard to extract transformation +properties (such as rotation angle/axis) from them, interpolate between them or +compute inverse transformation. They suffer badly from so-called floating-point +drift -- e.g. after a few combined rotations the transformation won't be pure +rotation anymore, but will involve also a bit of scaling, shearing and whatnot. + +However, you can trade some transformation features for improved performance and +better behavior -- for just a rotation you can use Complex in 2D and Quaternion +in 3D, or DualComplex and DualQuaternion if you want also translation. It is not +possible to represent scaling, reflection or other transformations with them, +but they occupy only 2 or 4 floats (4 or 8 floats in dual versions), can be +easily inverted and interpolated and have many other awesome properties. However, +they are not magic so they also suffer slightly from floating-point drift, but +not too much and the drift can be accounted for more easily than with matrices. + +@section transformations-types Transformation types + +Transformation matrices and (dual) complex numbers or quaternions have completely +different internals, but they share the same API to achieve the same things, +greatly simplifying their usage. In many cases it is even possible to hot-swap +the transformation class type without changing any function calls. + +@subsection transformations-default Default (identity) transformation + +Default-constructed Matrix3, Matrix4, Complex, Quaternion, DualComplex and +DualQuaternion represent identity transformation, so you don't need to worry +about them in initialization. + +@subsection transformations-rotation Rotation + +2D rotation is represented solely by its angle in counterclockwise direction and +rotation transformation can be created by calling Matrix3::rotation(), +Complex::rotation() or DualComplex::rotation(), for example: +@code +auto a = Matrix3::rotation(23.0_degf); +auto b = Complex::rotation(Rad(Constants::pi()/2)); +auto c = DualComplex::rotation(-1.57_radf); +@endcode + +3D rotation is represented by angle and (three-dimensional) axis. The rotation +can be created by calling Matrix4::rotation(), Quaternion::rotation() or +DualQuaternion::rotation(). The axis must be always of unit length to avoid +redundant normalization. Shortcuts Vector3::xAxis(), Vector3::yAxis() and +Vector3::zAxis() are provided for convenience. %Matrix representation has also +Matrix4::rotationX(), Matrix4::rotationY() and Matrix4::rotationZ() which are +faster than using the generic function for rotation around primary axes. +Examples: +@code +auto a = Quaternion::rotation(60.0_degf, Vector3::xAxis()); +auto b = DualQuaternion::rotation(-1.0_degf, Vector3(1.0f, 0.5f, 3.0f).normalized()); +auto c = Matrix4::rotationZ(angle); +@endcode + +Rotations are always around origin. Rotation about arbitrary point can be done +by applying translation to have the point at origin, performing the rotation and +then translating back. Read below for more information. +@todo DualQuaternion and rotation around arbitrary axis + +@subsection transformations-translation Translation + +2D translation is defined by two-dimensional vector and can be created with +Matrix3::translation() or DualComplex::translation(). You can use Vector2::xAxis() +or Vector2::yAxis() to translate only along given axis. Examples: +@code +auto a = Matrix3::translation(Vector2::xAxis(-5.0f)); +auto b = DualComplex::translation({-1.0f, 0.5f}); +@endcode + +3D translation is defined by three-dimensional vector and can be created with +Matrix4::translation() or DualQuaternion::translation(). You can use +Vector3::xAxis() and friends also here. Examples: +@code +auto a = Matrix4::translation(vector); +auto b = DualQuaternion::translation(Vector3::zAxis(1.3f)); +@endcode + +@subsection transformations-scaling Scaling and reflection + +Scaling is defined by two- or three-dimensional vector and is represented by +matrices. You can create it with Matrix3::scaling() or Matrix4::scaling(). You +can use Vector3::xScale(), Vector3::yScale(), Vector3::zScale() or their 2D +counterparts to scale along one axis and leave the rest unchanged or call +explicit one-parameter vector constructor to scale uniformly on all axes. +Examples: +@code +auto a = Matrix3::scaling(Vector2::xScale(2.0f)); +auto b = Matrix4::scaling({2.0f, -2.0f, 1.5f}); +auto c = Matrix4::scaling(Vector3(10.0f)); +@endcode + +Reflections are defined by normal along which to reflect (i.e., two- or +three-dimensional vector of unit length) and they are also represented by +matrices. Reflection is created with Matrix3::reflection() or Matrix4::reflection(). +You can use Vector3::xAxis() and friends also here. Examples: +@code +auto a = Matrix3::reflection(Vector2::yAxis()); +auto b = Matrix4::reflection(axis.normalized()); +@endcode + +Scaling and reflection is also done relative to origin, you can use method +mentioned above to scale or reflect around arbitrary point. + +Sscaling and reflection can be (to some extent) also represented by complex +numbers and quaternions, but it has some bad properties and would make some +operations more expensive, so it's not implemented. + +@subsection transformations-projective Projective transformations + +Projective transformations eploit the full potential of transformation matrices. +In 2D there is only one projection type, which can be created with Matrix3::projection() +and it is defined by area which will be projected into unit rectangle. In 3D +there is orthographic projection, created with Matrix4::orthographicProjection() +and defined by volume to project into unit cube, and perspective projection. +Perspective projection is created with Matrix4::perspectiveProjection() and is +defined either by field-of-view, aspect ratio and distance to near and far plane +of view frustum or by size of near plane, its distance and distance to far +plane. Some examples: +@code +auto a = Matrix3::projection({4.0f, 3.0f}); +auto b = Matrix4::orthographicProjection({4.0f, 3.0f, 100.0f}); +auto c = Matrix4::perspectiveProjection(35.0_degf, 1.333f, 0.001f, 100.0f); +@endcode + +@section transformations-composing Composing and inverting transformations + +Transformations (of the same representation) can be composed simply by +multiplying them, it works the same for matrices, complex numbers, quaternions +and their dual counterparts. Order of multiplication matters -- the +transformation on the right-hand side of multiplication is applied first, the +transformation on the left-hand side is applied second. For example, rotation +followed by translation is done like this: +@code +auto a = DualComplex::translation(Vector2::yAxis(2.0f))* + DualComplex::rotation(25.0_degf); +auto b = Matrix4::translation(Vector3::yAxis(5.0f))* + Matrix4::rotationY(25.0_degf); +@endcode + +Inverse transformation can be computed using Matrix3::inverted(), Matrix4::inverted(), +Complex::inverted(), Quaternion::inverted(), DualComplex::inverted() or +DualQuaternion::inverted(). %Matrix inversion is quite costly, so if your +transformation involves only translation and rotation, you can use faster +alternatives Matrix3::invertedEuclidean() and Matrix4::invertedEuclidean(). If +you are sure that the (dual) complex number or (dual) quaternion is of unit +length, you can use Complex::invertedNormalized(), Quaternion::invertedNormalized(), +DualComplex::invertedNormalized() or DualQuaternion::invertedNormalized() which +is a little bit faster, because it doesn't need to renormalize the result. + +@section transformations-transforming Transforming vectors and points + +Transformations can be used directly for transforming vectors and points. %Vector +transformation does not involve translation, in 2D can be done using +Matrix3::transformVector() and Complex::transformVector(), in 3D using +Matrix4::transformVector() and Quaternion::transformVector(). For transformation +with normalized quaternion you can use faster alternative Quaternion::transformVectorNormalized(). +Example: +@code +auto transformation = Matrix3::rotation(-30.0_degf)*Matrix3::scaling(Vector2(3.0f)); +Vector2 transformed = transformation.transformVector({1.5f, -7.9f}); +@endcode + +Point transformation involves also translation, in 2D is done with +Matrix3::transformPoint() and DualComplex::transformPoint(), in 3D with +Matrix4::transformPoint() and DualQuaternion::transformPoint(). Also here you +can use faster alternative Quaternion::transformPointNormalized(): +@code +auto transformation = DualQuaternion::rotation(-30.0_degf, Vector3::xAxis())* + DualQuaternion::translation(Vector3::yAxis(3.0f)); +Vector3 transformed = transformation.transformPointNormalized({1.5f, 3.0f, -7.9f}); +@endcode + +@section transformations-properties Transformation properties and conversion + +It is possible to extract some transformation properties from transformation +matrices, particularly translation vector, rotation/scaling part of the matrix +(or pure rotation if the matrix has uniform scaling) and also base vectors: +@code +Matrix4 a; +auto rotationScaling = transformation.rotationScaling(); +Vector3 up = transformation.up(); +Vector3 right = transformation.right(); + +Matrix3 b; +auto rotation = b.rotation(); +Float xTranslation = b.translation().x(); +@endcode +Extracting scaling and rotation from arbitrary transformation matrices is harder +and can be done using Algorithms::svd(). Extracting rotation angle (and axis in +3D) from rotation part is possible using by converting it to complex number or +quaternion, see below. + +You can also recreate transformation matrix from rotation and translation parts: +@code +Matrix3 c = Matrix3::from(rotation, {1.0f, 3.0f}); +@endcode + +%Complex numbers and quaternions are far better in this regard and they allow +you to extract rotation angle using Complex::rotationAngle(), Quaternion::rotationAngle(), +DualComplex::rotationAngle() or DualQuaternion::rotationAngle(), and rotation +axis in 3D using Quaternion::rotationAxis() or DualQuaternion::rotationAxis(). +It is also possible to extract translation from their dual versions using +DualComplex::translation() const and DualQuaternion::translation() const. +@code +DualComplex a; +Rad rotation = a.rotationAngle(); +Vector2 translation = a.translation(); + +Quaternion b; +Vector3 rotationAxis = b.rotationAxis(); +@endcode + +You can convert Complex and Quaternion to rotation matrix using Complex::toMatrix() +and Quaternion::toMatrix() or their dual version to rotation and translation +matrix using DualComplex::toMatrix() and DualQuaternion::toMatrix(): +@code +Quaternion a; +auto rotation = Matrix4::from(a.toMatrix(), {}); + +DualComplex b; +Matrix3 transformation = b.toMatrix(); +@endcode + +Conversion the other way around is possible only from rotation matrices using +Complex::fromMatrix() or Quaternion::fromMatrix() and from rotation and +translation matrices using DualComplex::fromMatrix() and +DualQuaternion::fromMatrix(): +@code +Matrix3 rotation; +auto a = Complex::fromMatrix(rotation.rotationScaling()); + +Matrix4 transformation; +auto b = DualQuaternion::fromMatrix(transformation); +@endcode + +@section transformations-interpolation Transformation interpolation + +@todoc Write this when interpolation is done also for (dual) complex numbers and + dual quaternions + +@section transformations-normalization Normalizing transformations + +When doing multiplicative transformations, e.g. adding rotating to an +transformation many times during an animation, the resulting transformation will +accumulate rounding errors and behave strangely. For transformation matrices +this can't always be fixed, because they can represent any transformation (and +thus no algorithm can't tell if the transformation is in expected form or not). +If you restrict yourselves (e.g. only uniform scaling and no skew), the matrix +can be reorthogonalized using Algorithms::gramSchmidtOrthogonalize() (or +Algorithms::gramSchmidtOrthonormalize(), if you don't have any scaling). You can +also use Algorithms::svd() to more precisely (but way more slowly) account for +the drift. Example: +@code +Matrix4 transformation; +Math::Algorithms::gramSchmidtOrthonormalizeInPlace(transformation); +@endcode + +For quaternions and complex number this problem can be solved far more easily +using Complex::normalized(), Quaternion::normalized(), DualComplex::normalized() +and DualQuaternion::normalized(). Transformation quaternions and complex numbers +are always of unit length, thus normalizing them reduces the drift. +@code +DualQuaternion transformation; +transformation = transformation.normalized(); +@endcode +*/ +}} diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 8bd7486ac..5a363b08b 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Math { @brief %Complex number @tparam T Data type -Represents 2D rotation. +Represents 2D rotation. See @ref transformations for brief introduction. @see Magnum::Complex, Matrix3 */ template class Complex { diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index a17198d8d..d455d72e6 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -29,7 +29,8 @@ namespace Magnum { namespace Math { @brief %Dual complex number @tparam T Underlying data type -Represents 2D rotation and translation. +Represents 2D rotation and translation. See @ref transformations for brief +introduction. @see Magnum::DualComplex, Dual, Complex, Matrix3 @todo Can this be done similarly as in dual quaternions? It sort of works, but the math beneath is weird. diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 6a305e0b5..7bc3d70d7 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -29,7 +29,8 @@ namespace Magnum { namespace Math { @brief %Dual quaternion @tparam T Underlying data type -Represents 3D rotation and translation. +Represents 3D rotation and translation. See @ref transformations for brief +introduction. @see Magnum::DualQuaternion, Dual, Quaternion, Matrix4 */ template class DualQuaternion: public Dual> { diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 4bd73a8ec..81d930e7b 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -28,7 +28,8 @@ namespace Magnum { namespace Math { @brief 3x3 matrix @tparam T Underlying data type -Represents 2D transformation. See @ref matrix-vector for brief introduction. +Represents 2D transformation. See @ref matrix-vector and @ref transformations +for brief introduction. @see Magnum::Matrix3, Magnum::Matrix3d, DualComplex, SceneGraph::MatrixTransformation2D @configurationvalueref{Magnum::Math::Matrix3} diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 8333b2271..8ba2e4f7a 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -33,7 +33,8 @@ namespace Magnum { namespace Math { @brief 4x4 matrix @tparam T Underlying data type -Represents 3D transformation. See @ref matrix-vector for brief introduction. +Represents 3D transformation. See @ref matrix-vector and @ref transformations +for brief introduction. @see Magnum::Matrix4, Magnum::Matrix4d, DualQuaternion, SceneGraph::MatrixTransformation3D @configurationvalueref{Magnum::Math::Matrix4} diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index e92397145..f50904fdc 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Math { @brief %Quaternion @tparam T Underlying data type -Represents 3D rotation. +Represents 3D rotation. See @ref transformations for brief introduction. @see Magnum::Quaternion, DualQuaternion, Matrix4 */ template class Quaternion { From 5ff0e29950c0f9c37799b8515a3ec163906e67c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 12:32:44 +0100 Subject: [PATCH 459/567] Math: fix warning about literal types in normalize(). C++11 changed type of character literal (i.e. '\x7F') from int to char, thus the documentation is wrong (also mistakenly used octal literal). Added test to properly test the behavior. --- src/Math/Functions.h | 6 +++--- src/Math/Test/FunctionsTest.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index e1b5582e7..dc2ff22e6 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -231,11 +231,11 @@ value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$ literals, this function should be called with both template parameters explicit, e.g.: @code -// Even if this is character literal, integral type is 32bit, thus a != 1.0f -float a = normalize('\127'); +// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f +float a = normalize('\xFF'); // b = 1.0f -float b = normalize('\127'); +float b = normalize('\xFF'); @endcode @see denormalize() diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index c0d8e2809..e0858e566 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -37,6 +37,8 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void renormalizeUnsinged(); void renormalizeSinged(); + void normalizeTypeDeduction(); + void pow(); void log(); void log2(); @@ -65,6 +67,8 @@ FunctionsTest::FunctionsTest() { &FunctionsTest::renormalizeUnsinged, &FunctionsTest::renormalizeSinged, + &FunctionsTest::normalizeTypeDeduction, + &FunctionsTest::pow, &FunctionsTest::log, &FunctionsTest::log2, @@ -233,6 +237,11 @@ void FunctionsTest::renormalizeSinged() { CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); } +void FunctionsTest::normalizeTypeDeduction() { + CORRADE_COMPARE(Math::normalize('\x7F'), 1.0f); + CORRADE_COMPARE((Math::normalize('\x7F')), 1.0f); +} + void FunctionsTest::pow() { CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); From baeda307c121812cf7501caefeb5c287c327f242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 13:13:23 +0100 Subject: [PATCH 460/567] Math: do Matrix::trace() using diagonal() and Vector::sum(). Use (future) SIMD optimizations in Vector::sum() instead of doing it all over again. --- src/Math/Matrix.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index b4f482391..6334038cc 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -100,12 +100,7 @@ template class Matrix: public RectangularMatrixdiagonal().sum(); } /** @brief %Matrix without given column and row */ From 792198ae897ba9b0143b62eb3a8f3d00c5b5dd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 01:00:24 +0100 Subject: [PATCH 461/567] Platform: undefine another conflicting macro. --- src/Platform/GlxContextHandler.h | 1 + src/Platform/WindowlessGlxApplication.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Platform/GlxContextHandler.h b/src/Platform/GlxContextHandler.h index 1a8f7b85f..e78df00ba 100644 --- a/src/Platform/GlxContextHandler.h +++ b/src/Platform/GlxContextHandler.h @@ -22,6 +22,7 @@ #include "Magnum.h" #include /* undef Xlib nonsense to avoid conflicts */ +#undef Complex #undef None #undef Always diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 1722e82e3..541b0a9f4 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -24,6 +24,7 @@ #include #include /* undef Xlib nonsense to avoid conflicts */ +#undef Complex #undef None #undef Always From 6220f24f0b2bacae73d512954be59c96e4e2ecdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 16:35:24 +0100 Subject: [PATCH 462/567] Our own aliases for builtin types. It seems like a bad idea, but it will: * Improve portability, as `Int` will be always 32bit. * Improve readability, as `std::int32_t` is just plain ugly and too complicated to write. * Improve consistency and reduce confusion, as it's not good to mix `int`, `std::int32_t`, `GLint`, `khronos_int_t` and whatnot in one codebase. * Possibly reduce compilation time, because including all ~35k lines worth of GL headers just for one GLfloat typedef is even worse than now forbidden #include in headers. --- doc/features.dox | 11 +- doc/types.dox | 72 +++++++++++++ src/AbstractShaderProgram.h | 66 ++++-------- src/CMakeLists.txt | 1 + src/Magnum.h | 206 +++++++++++++++++++++++++++--------- src/Types.h | 45 ++++++++ 6 files changed, 302 insertions(+), 99 deletions(-) create mode 100644 doc/types.dox create mode 100644 src/Types.h diff --git a/doc/features.dox b/doc/features.dox index 0a084a3bc..137c52c9a 100644 --- a/doc/features.dox +++ b/doc/features.dox @@ -2,10 +2,11 @@ namespace Magnum { /** @page features Feature overview @brief Fundamental principles and design goals -- @subpage matrix-vector - @copybrief matrix-vector -- @subpage transformations - @copybrief transformations -- @subpage scenegraph - @copybrief scenegraph -- @subpage collision-detection - @copybrief collision-detection -- @subpage debug-tools - @copybrief debug-tools +- @subpage types -- @copybrief types +- @subpage matrix-vector -- @copybrief matrix-vector +- @subpage transformations -- @copybrief transformations +- @subpage scenegraph -- @copybrief scenegraph +- @subpage collision-detection -- @copybrief collision-detection +- @subpage debug-tools -- @copybrief debug-tools */ } diff --git a/doc/types.dox b/doc/types.dox new file mode 100644 index 000000000..bce7c53ef --- /dev/null +++ b/doc/types.dox @@ -0,0 +1,72 @@ +namespace Magnum { +/** @page types Type system + +@brief Type aliases, naming and compatibility with OpenGL and GLSL types + +@section types-builtin Builtin types + +%Magnum provides typedefs for builtin integral and floating-point arithmetic +types to ensure portability (e.g. Int is *always* 32bit), maintain consistency +and reduce confusion (e.g. `std::int32_t`, `int` and `GLint` all refer to the +same type). + +| %Magnum type | Size | Equivalent GLSL type | +| ------------------ | -------------- | -------------------- | +| @ref UnsignedByte | 8bit unsigned | | +| @ref Byte | 8bit signed | | +| @ref UnsignedShort | 16bit unsigned | | +| @ref Short | 16bit signed | | +| @ref UnsignedInt | 32bit unsigned | `uint` | +| @ref Int | 32bit signed | `int` | +| @ref UnsignedLong | 64bit unsigned | | +| @ref Long | 64bit signed | | +| @ref Float | 32bit | `float` | +| @ref Double | 64bit | `double` | + +Types not meant to be used in arithmetic (such as `bool` or `std::size_t`) or +types which cannot be directly passed to GLSL shaders (such as `long double`) +have no typedefs. + +Types from the above table are then used to define other types. All following +types are aliases of corresponding types in Math namespace. No suffix after type +name means @ref Float underlying type, `ui` means @ref UnsignedInt underlying +type, `i` is @ref Int underlying type and `d` is for @ref Double underlying type. + +@section types-matrix Matrix/vector types + +| %Magnum vector type | Equivalent GLSL type | +| ---------------------------------------------- | ------------------------- | +| @ref Vector2, @ref Vector3, @ref Vector4 | `vec2`, `vec3`, `vec4` | +| @ref Vector2ui, @ref Vector3ui, @ref Vector4ui | `uvec2`, `uvec3`, `uvec4` | +| @ref Vector2i, @ref Vector3i, @ref Vector4i | `ivec2`, `ivec3`, `ivec4` | +| @ref Vector2d, @ref Vector3d, @ref Vector4d | `dvec2`, `dvec3`, `dvec4` | + +| %Magnum matrix type | Equivalent GLSL type | +| --------------------------------- | ------------------------------------ | +| @ref Matrix2 or @ref Matrix2d | `mat2`/`mat2x2` or `dmat2`/`dmat2x2` | +| @ref Matrix3 or @ref Matrix3d | `mat3`/`mat3x3` or `dmat3`/`dmat3x3` | +| @ref Matrix4 or @ref Matrix4d | `mat4`/`mat4x4` or `dmat3`/`dmat4x4` | +| @ref Matrix2x3 or @ref Matrix2x3d | `mat2x3` or `dmat2x3` | +| @ref Matrix3x2 or @ref Matrix3x2d | `mat3x2` or `dmat3x2` | +| @ref Matrix2x4 or @ref Matrix2x4d | `mat2x4` or `dmat2x4` | +| @ref Matrix4x2 or @ref Matrix4x2d | `mat4x2` or `dmat4x2` | +| @ref Matrix3x4 or @ref Matrix3x4d | `mat3x4` or `dmat3x4` | +| @ref Matrix4x3 or @ref Matrix4x3d | `mat4x3` or `dmat4x3` | + +Any super- or sub-class of the same size and underlying type can be used +equivalently (e.g. Math::Vector or Color3 instead of @ref Vector3). + +@section types-other Other types + +Other types, which don't have their GLSL equivalent, are: + + - @ref Rectangle or @ref Rectanglei + - @ref Complex or @ref Complexd, @ref DualComplex or @ref DualComplexd + - @ref Quaternion or @ref Quaterniond, @ref DualQuaternion or @ref DualQuaterniond + +These types can be used in GLSL either by extracting values from their +underlying structure or converting them to types supported by GLSL (e.g. +quaternion to matrix). + +*/ +} diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 53b69ce6c..c38b7de4a 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -219,53 +219,29 @@ mesh.draw(); @section AbstractShaderProgram-types Mapping between GLSL and Magnum types -- `vec2`, `vec3` and `vec4` is @ref Math::Vector "Math::Vector<2, GLfloat>", - @ref Math::Vector "Math::Vector<3, GLfloat>" and - @ref Math::Vector "Math::Vector<4, GLfloat>". - -- `mat2`, `mat3` and `mat4` is @ref Math::Matrix "Math::Matrix<2, GLfloat>", - @ref Math::Matrix "Math::Matrix<3, GLfloat>" and - @ref Math::Matrix "Math::Matrix<4, GLfloat>". - -- `mat2x3`, `mat3x2`, `mat2x4`, `mat4x2`, `mat3x4`, `mat4x3` is - @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 3, GLfloat>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 2, GLfloat>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 4, GLfloat>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 2, GLfloat>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 4, GLfloat>" and - @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 3, GLfloat>". - -- `ivec2`, `ivec3` and `ivec4` is @ref Math::Vector "Math::Vector<2, GLint>", - @ref Math::Vector "Math::Vector<3, GLint>" and - @ref Math::Vector "Math::Vector<4, GLint>", `uvec2`, `uvec3` and `uvec4` is - @ref Math::Vector "Math::Vector<2, GLuint>", - @ref Math::Vector "Math::Vector<3, GLuint>" and - @ref Math::Vector "Math::Vector<4, GLuint>". - @requires_gl30 %Extension @extension{EXT,gpu_shader4} (for integer attributes - and unsigned integer uniforms) - @requires_gles30 Integer attributes and unsigned integer uniforms are not +See @ref types for more information, only types with GLSL equivalent can be used +(and their super- or subclasses with the same size and underlying type). + +@requires_gl30 %Extension @extension{EXT,gpu_shader4} is required when using + integer attributes (i.e. UnsignedInt, Int, Vector2ui, Vector2i, Vector3ui, + Vector3i, Vector4ui and Vector4i) or unsigned integer uniforms. (i.e. + UnsignedInt, Vector2ui, Vector3ui and Vector4ui). +@requires_gles30 Integer attributes and unsigned integer uniforms are not available in OpenGL ES 2.0. -- `dvec2`, `dvec3` and `dvec4` is @ref Math::Vector "Math::Vector<2, GLdouble>", - @ref Math::Vector "Math::Vector<3, GLdouble>" and - @ref Math::Vector "Math::Vector<4, GLdouble>", `dmat2`, `dmat3` and `dmat4` - is @ref Math::Matrix "Math::Matrix<2, GLdouble>", - @ref Math::Matrix "Math::Matrix<3, GLdouble>" and - @ref Math::Matrix "Math::Matrix<4, GLdouble>", `dmat2x3`, `dmat3x2`, - `dmat2x4`, `dmat4x2`, `dmat3x4`, `dmat4x3` is - @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 3, GLdouble>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 2, GLdouble>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<2, 4, GLdouble>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 2, GLdouble>", - @ref Math::RectangularMatrix "Math::RectangularMatrix<3, 4, GLdouble>" and - @ref Math::RectangularMatrix "Math::RectangularMatrix<4, 3, GLdouble>". - @requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} (for double - attributes) - @requires_gl Double attributes are not available in OpenGL ES. - -Only types listed here (and their subclasses and specializations, such as -@ref Matrix3 or Color4) can be used for setting uniforms and specifying -vertex attributes. +@requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} is required when + using double uniforms (i.e. Double, Vector2d, Vector3d, Vector4d, Matrix2d, + Matrix3d, Matrix4d, Matrix2x3d, Matrix3x2d, Matrix2x4d, Matrix4x2d, + Matrix3x4d and Matrix4x3d). +@requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} is required when + using double attributes (i.e. Double, Vector2d, Vector3d, Vector4d, Matrix2d, + Matrix3d, Matrix4d, Matrix2x3d, Matrix3x2d, Matrix2x4d, Matrix4x2d, + Matrix3x4d and Matrix4x3d). +@requires_gl Double attributes and uniforms are not available in OpenGL ES. + +@requires_gles30 Non-square matrix attributes and uniforms (i.e. Matrix2x3, + Matrix3x2, Matrix2x4, Matrix4x2, Matrix3x4 and Matrix4x3) are not available + in OpenGL ES 2.0. @section AbstractShaderProgram-performance-optimization Performance optimizations diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56b94d28d..136a082dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,6 +78,7 @@ set(Magnum_HEADERS Swizzle.h Texture.h Timeline.h + Types.h magnumVisibility.h) diff --git a/src/Magnum.h b/src/Magnum.h index 0fdb9e711..862b2b14d 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -19,10 +19,10 @@ * @brief Basic definitions and forward declarations for Magnum namespace */ -#include #include #include "Math/Math.h" +#include "Types.h" #include "magnumConfigure.h" @@ -53,10 +53,10 @@ namespace Magnum { namespace Math { template struct Constants; - constexpr Rad operator "" _rad(long double); - constexpr Rad operator "" _radf(long double); - constexpr Deg operator "" _deg(long double); - constexpr Deg operator "" _degf(long double); + constexpr Rad operator "" _rad(long double); + constexpr Rad operator "" _radf(long double); + constexpr Deg operator "" _deg(long double); + constexpr Deg operator "" _degf(long double); } /* Bring debugging facility from Corrade::Utility namespace */ @@ -65,85 +65,193 @@ using Corrade::Utility::Warning; using Corrade::Utility::Error; #endif +/** @{ @name Basic type definitions + +See @ref types for more information. +*/ + +/** @brief Unsigned byte (8bit) */ +typedef std::uint8_t UnsignedByte; + +/** @brief Signed byte (8bit) */ +typedef std::int8_t Byte; + +/** @brief Unsigned short (16bit) */ +typedef std::uint16_t UnsignedShort; + +/** @brief Signed short (16bit) */ +typedef std::int16_t Short; + +/** @brief Unsigned int (32bit) */ +typedef std::uint32_t UnsignedInt; + +/** @brief Signed int (32bit) */ +typedef std::int32_t Int; + +/** @brief Unsigned long (64bit) */ +typedef std::uint64_t UnsignedLong; + +/** @brief Signed long (64bit) */ +typedef std::int64_t Long; + +/** @brief Float (32bit) */ +typedef float Float; + /** @brief Two-component float vector */ -typedef Math::Vector2 Vector2; +typedef Math::Vector2 Vector2; /** @brief Three-component float vector */ -typedef Math::Vector3 Vector3; +typedef Math::Vector3 Vector3; /** @brief Four-component float vector */ -typedef Math::Vector4 Vector4; +typedef Math::Vector4 Vector4; + +/** @brief Two-component unsigned integer vector */ +typedef Math::Vector2 Vector2ui; + +/** @brief Three-component unsigned integer vector */ +typedef Math::Vector3 Vector3ui; + +/** @brief Four-component unsigned integer vector */ +typedef Math::Vector4 Vector4ui; /** @brief Two-component signed integer vector */ -typedef Math::Vector2 Vector2i; +typedef Math::Vector2 Vector2i; /** @brief Three-component signed integer vector */ -typedef Math::Vector3 Vector3i; +typedef Math::Vector3 Vector3i; /** @brief Four-component signed integer vector */ -typedef Math::Vector4 Vector4i; +typedef Math::Vector4 Vector4i; -/** @brief Two-component unsigned integer vector */ -typedef Math::Vector2 Vector2ui; +/** @brief 2x2 float matrix */ +typedef Math::Matrix<2, Float> Matrix2; -/** @brief Three-component unsigned integer vector */ -typedef Math::Vector3 Vector3ui; +/** @brief 3x3 float matrix */ +typedef Math::Matrix3 Matrix3; -/** @brief Four-component unsigned integer vector */ -typedef Math::Vector4 Vector4ui; +/** @brief 4x4 float matrix */ +typedef Math::Matrix4 Matrix4; + +/** @brief Float matrix with 2 columns and 3 rows */ +typedef Math::RectangularMatrix<2, 3, Float> Matrix2x3; + +/** @brief Float matrix with 3 columns and 2 rows */ +typedef Math::RectangularMatrix<3, 2, Float> Matrix3x2; + +/** @brief Float matrix with 2 columns and 4 rows */ +typedef Math::RectangularMatrix<2, 4, Float> Matrix2x4; + +/** @brief Float matrix with 4 columns and 2 rows */ +typedef Math::RectangularMatrix<4, 2, Float> Matrix4x2; + +/** @brief Float matrix with 3 columns and 4 rows */ +typedef Math::RectangularMatrix<3, 4, Float> Matrix3x4; + +/** @brief Float matrix with 4 columns and 3 rows */ +typedef Math::RectangularMatrix<4, 3, Float> Matrix4x3; + +/** @brief Float complex number */ +typedef Math::Complex Complex; + +/** @brief Float dual complex number */ +typedef Math::DualComplex DualComplex; + +/** @brief Float quaternion */ +typedef Math::Quaternion Quaternion; + +/** @brief Float dual quaternion */ +typedef Math::DualQuaternion DualQuaternion; + +/** @brief Float constants */ +typedef Math::Constants Constants; + +/** @brief Angle in float degrees */ +typedef Math::Deg Deg; + +/** @brief Angle in float radians */ +typedef Math::Rad Rad; + +/** @brief Float rectangle */ +typedef Math::Geometry::Rectangle Rectangle; + +/** @brief Signed integer rectangle */ +typedef Math::Geometry::Rectangle Rectanglei; + +/*@}*/ #ifndef MAGNUM_TARGET_GLES +/** @{ @name Double-precision types + +See @ref types for more information. +@requires_gl Only single-precision types are available in OpenGL ES. +*/ + +/** @brief Double (64bit) */ +typedef double Double; + /** @brief Two-component double vector */ -typedef Math::Vector2 Vector2d; +typedef Math::Vector2 Vector2d; /** @brief Three-component double vector */ -typedef Math::Vector3 Vector3d; +typedef Math::Vector3 Vector3d; /** @brief Four-component double vector */ -typedef Math::Vector4 Vector4d; -#endif +typedef Math::Vector4 Vector4d; -/** @brief 3x3 float matrix */ -typedef Math::Matrix3 Matrix3; +/** @brief 2x2 double matrix */ +typedef Math::Matrix<2, Double> Matrix2d; -/** @brief 4x4 float matrix */ -typedef Math::Matrix4 Matrix4; - -#ifndef MAGNUM_TARGET_GLES /** @brief 3x3 double matrix */ -typedef Math::Matrix3 Matrix3d; +typedef Math::Matrix3 Matrix3d; /** @brief 4x4 double matrix */ -typedef Math::Matrix4 Matrix4d; -#endif +typedef Math::Matrix4 Matrix4d; -/** @brief %Complex number */ -typedef Math::Complex Complex; +/** @brief Double matrix with 2 columns and 3 rows */ +typedef Math::RectangularMatrix<2, 3, Double> Matrix2x3d; -/** @brief %Dual complex number */ -typedef Math::DualComplex DualComplex; +/** @brief Double matrix with 3 columns and 2 rows */ +typedef Math::RectangularMatrix<3, 2, Double> Matrix3x2d; -/** @brief %Quaternion */ -typedef Math::Quaternion Quaternion; +/** @brief Double matrix with 2 columns and 4 rows */ +typedef Math::RectangularMatrix<2, 4, Double> Matrix2x4d; -/** @brief %Dual quaternion */ -typedef Math::DualQuaternion DualQuaternion; +/** @brief Double matrix with 4 columns and 2 rows */ +typedef Math::RectangularMatrix<4, 2, Double> Matrix4x2d; -/** @brief Floating-point constants */ -/* Using float instead of GLfloat to not break KDevelop autocompletion */ -typedef Math::Constants Constants; +/** @brief Double matrix with 3 columns and 4 rows */ +typedef Math::RectangularMatrix<3, 4, Double> Matrix3x4d; -/** @brief Angle in single-precision degrees */ -typedef Math::Deg Deg; +/** @brief Double matrix with 4 columns and 3 rows */ +typedef Math::RectangularMatrix<4, 3, Double> Matrix4x3d; -/** @brief Angle in single-precision radians */ -typedef Math::Rad Rad; +/** @brief Double complex number */ +typedef Math::Complex Complexd; -/** @brief Floating-point rectangle */ -typedef Math::Geometry::Rectangle Rectangle; +/** @brief Double dual complex number */ +typedef Math::DualComplex DualComplexd; -/** @brief Integer rectangle */ -typedef Math::Geometry::Rectangle Rectanglei; +/** @brief Double quaternion */ +typedef Math::Quaternion Quaterniond; + +/** @brief Double dual quaternion */ +typedef Math::DualQuaternion DualQuaterniond; + +/** @brief Double constants */ +typedef Math::Constants Constantsd; + +/** @brief Angle in double degrees */ +typedef Math::Deg Degd; + +/** @brief Angle in double radians */ +typedef Math::Rad Radd; + +/** @brief Double rectangle */ +typedef Math::Geometry::Rectangle Rectangled; + +/*@}*/ +#endif /* Using angle literals from Math namespace */ using Math::operator "" _deg; diff --git a/src/Types.h b/src/Types.h new file mode 100644 index 000000000..ee76b421f --- /dev/null +++ b/src/Types.h @@ -0,0 +1,45 @@ +#ifndef Magnum_Types_h +#define Magnum_Types_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Declarations of built-in types + */ + +#include + +#include "magnumConfigure.h" + +namespace Magnum { + +/* Documented in Magnum.h */ +typedef std::uint8_t UnsignedByte; +typedef std::int8_t Byte; +typedef std::uint16_t UnsignedShort; +typedef std::int16_t Short; +typedef std::uint32_t UnsignedInt; +typedef std::int32_t Int; +typedef std::uint64_t UnsignedLong; +typedef std::int64_t Long; +typedef float Float; + +#ifndef MAGNUM_TARGET_GLES +typedef double Double; +#endif + +} + +#endif From 6a90b0231bc1c43fb4b28b6f0ab3dfdb89360a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 16:42:54 +0100 Subject: [PATCH 463/567] Math: using new aliases for builtin types in whole Math namespace. --- doc/matrix-vector.dox | 54 +++---- src/Math/Algorithms/Svd.h | 18 +-- src/Math/Algorithms/Test/GaussJordanTest.cpp | 6 +- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 4 +- src/Math/Algorithms/Test/SvdTest.cpp | 22 +-- src/Math/Angle.cpp | 8 +- src/Math/Angle.h | 58 +++---- src/Math/BoolVector.h | 17 +- src/Math/Complex.cpp | 4 +- src/Math/Complex.h | 4 +- src/Math/Constants.h | 18 ++- src/Math/DualComplex.cpp | 4 +- src/Math/DualComplex.h | 4 +- src/Math/DualQuaternion.cpp | 4 +- src/Math/DualQuaternion.h | 4 +- src/Math/Functions.cpp | 8 +- src/Math/Functions.h | 20 +-- src/Math/Geometry/Rectangle.h | 4 +- src/Math/Geometry/Test/DistanceTest.cpp | 41 ++--- src/Math/Geometry/Test/IntersectionTest.cpp | 6 +- src/Math/Geometry/Test/RectangleTest.cpp | 6 +- src/Math/MathTypeTraits.h | 43 ++--- src/Math/Matrix.h | 4 +- src/Math/Quaternion.cpp | 4 +- src/Math/Quaternion.h | 4 +- src/Math/RectangularMatrix.cpp | 72 ++++----- src/Math/RectangularMatrix.h | 80 +++++----- src/Math/Swizzle.h | 2 +- src/Math/Test/AngleTest.cpp | 32 ++-- src/Math/Test/BoolVectorTest.cpp | 2 +- src/Math/Test/ComplexTest.cpp | 24 +-- src/Math/Test/ConstantsTest.cpp | 8 +- src/Math/Test/DualComplexTest.cpp | 14 +- src/Math/Test/DualQuaternionTest.cpp | 16 +- src/Math/Test/DualTest.cpp | 14 +- src/Math/Test/FunctionsTest.cpp | 156 +++++++++---------- src/Math/Test/MathTypeTraitsTest.cpp | 20 +-- src/Math/Test/Matrix3Test.cpp | 8 +- src/Math/Test/Matrix4Test.cpp | 22 +-- src/Math/Test/MatrixTest.cpp | 34 ++-- src/Math/Test/QuaternionTest.cpp | 44 +++--- src/Math/Test/RectangularMatrixTest.cpp | 78 +++++----- src/Math/Test/SwizzleTest.cpp | 10 +- src/Math/Test/UnitTest.cpp | 14 +- src/Math/Test/Vector2Test.cpp | 4 +- src/Math/Test/Vector3Test.cpp | 8 +- src/Math/Test/Vector4Test.cpp | 10 +- src/Math/Test/VectorTest.cpp | 32 ++-- src/Math/Vector.cpp | 48 +++--- src/Math/Vector.h | 52 +++---- 50 files changed, 585 insertions(+), 588 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index a5addb366..b601cb5a8 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -35,13 +35,13 @@ Default constructors of RectangularMatrix and Vector (and Vector2, Vector3, Vector4, Color3) create zero-filled objects. Matrix (and Matrix3, Matrix4) is by default constructed as identity matrix. Color4 has alpha value set to opaque. @code -RectangularMatrix<2, 3, int> a; // zero-filled -Vector<3, int> b; // zero-filled +RectangularMatrix<2, 3, Int> a; // zero-filled +Vector<3, Int> b; // zero-filled -Matrix<3, int> identity; // diagonal set to 1 -Matrix<3, int> zero(Matrix<3, int>::Zero); // zero-filled +Matrix<3, Int> identity; // diagonal set to 1 +Matrix<3, Int> zero(Matrix<3, Int>::Zero); // zero-filled -Color4 black1; // {0.0f, 0.0f, 0.0f, 1.0f} +Color4 black1; // {0.0f, 0.0f, 0.0f, 1.0f} Color4 black2; // {0, 0, 0, 255} @endcode @@ -49,9 +49,9 @@ Most common and most efficient way to create vector is to pass all values to constructor, matrix is created by passing all column vectors to the constructor. @code -Vector3 vec(0, 1, 2); +Vector3 vec(0, 1, 2); -Matrix3 mat({0, 1, 2}, +Matrix3 mat({0, 1, 2}, {3, 4, 5}, {6, 7, 8}); @endcode @@ -61,34 +61,34 @@ at compile time. You can specify all components of vector or whole diagonal of square matrix at once: @code -Matrix3 diag(Matrix3::Identity, 2); // diagonal set to 2, zeros elsewhere -Vector3 fill(10); // {10, 10, 10} +Matrix3 diag(Matrix3::Identity, 2); // diagonal set to 2, zeros elsewhere +Vector3 fill(10); // {10, 10, 10} @endcode It is possible to create matrices from other matrices and vectors with the same row count; vectors from vector and scalar: @code -RectangularMatrix<2, 3, int> a; -Vector3 b, c; -Matrix3 mat(a, b); -Vector<8, int> vec(1, b, 2, c); +RectangularMatrix<2, 3, Int> a; +Vector3 b, c; +Matrix3 mat(a, b); +Vector<8, Int> vec(1, b, 2, c); @endcode It is also possible to create them from an C-style array. The function does simple type cast without any copying, so it's possible to conveniently operate on the array itself: @code -int[] mat = { 2, 4, 6, +Int[] mat = { 2, 4, 6, 1, 3, 5 }; -RectangularMatrix<2, 3, int>::from(mat) *= 2; // mat == { 4, 8, 12, 2, 6, 10 } +RectangularMatrix<2, 3, Int>::from(mat) *= 2; // mat == { 4, 8, 12, 2, 6, 10 } @endcode Note that unlike constructors, this function has no way to check whether the array is long enough to contain all elements, so use with caution. You can also *explicitly* convert between data types: @code -Vector4 floating(1.3f, 2.7f, -15.0f, 7.0f); -Vector4 integral(floating); // {1, 2, -15, 7} +Vector4 floating(1.3f, 2.7f, -15.0f, 7.0f); +Vector4 integral(floating); // {1, 2, -15, 7} @endcode @section matrix-vector-component-access Accessing matrix and vector components @@ -97,31 +97,31 @@ Column vectors of matrices and vector components can be accessed using square brackets, there is also round bracket operator for accessing matrix components directly: @code -RectangularMatrix<3, 2, int> a; +RectangularMatrix<3, 2, Int> a; a[2] /= 2; // third column (column major indexing, see explanation below) a[0][1] = 5; // first column, second element -Vector<3, int> b; +Vector<3, Int> b; b[1] = 1; // second element @endcode Fixed-size vector subclasses have functions for accessing named components and subparts: @code -Vector4 a; -int x = a.x(); +Vector4 a; +Int x = a.x(); a.y() += 5; -Vector3 xyz = a.xyz(); +Vector3 xyz = a.xyz(); xyz.xy() *= 5; @endcode Color3 and Color4 name their components `rgba` instead of `xyzw`. For more involved operations with components there is the swizzle() function: @code -Vector<4, int> original(-1, 2, 3, 4); -Vector<4, int> bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } -Vector<6, int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } +Vector<4, Int> original(-1, 2, 3, 4); +Vector<4, Int> bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } +Vector<6, Int> w10xyz = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // { 4, 1, 0, -1, 2, 3 } @endcode @section matrix-vector-column-major Matrices are column-major and vectors are columns @@ -133,12 +133,12 @@ implications and it may differ from what is common in mathematics: - Order of template arguments in specification of RectangularMatrix is also column-major: @code -RectangularMatrix<2, 3, int> mat; // two columns, three rows +RectangularMatrix<2, 3, Int> mat; // two columns, three rows @endcode - Order of components in matrix constructors is also column-major, further emphasized by requirement that you have to pass directly column vectors: @code -Matrix3 mat({0, 1, 2}, +Matrix3 mat({0, 1, 2}, {3, 4, 5}, {6, 7, 8}); // first column is {0, 1, 2} @endcode diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h index 7320c513c..ebdc7591e 100644 --- a/src/Math/Algorithms/Svd.h +++ b/src/Math/Algorithms/Svd.h @@ -41,8 +41,8 @@ template T pythagoras(T a, T b) { } template T smallestDelta(); -template<> inline constexpr float smallestDelta() { return 1.0e-32; } -template<> inline constexpr double smallestDelta() { return 1.0e-64; } +template<> inline constexpr Float smallestDelta() { return 1.0e-32; } +template<> inline constexpr Double smallestDelta() { return 1.0e-64; } } #endif @@ -61,22 +61,22 @@ zero matrices. Full @f$ U @f$, @f$ \Sigma @f$ matrices and original @f$ M @f$ matrix can be reconstructed from the values as following: @code -RectangularMatrix m; +RectangularMatrix m; -RectangularMatrix uPart; -Vector wDiagonal; -Matrix v; +RectangularMatrix uPart; +Vector wDiagonal; +Matrix v; std::tie(uPart, wDiagonal, v) = Math::Algorithms::svd(m); // Extend U -Matrix u(Matrix::Zero); +Matrix u(Matrix::Zero); for(std::size_t i = 0; i != rows; ++i) u[i] = uPart[i]; // Diagonal W -RectangularMatrix w = - RectangularMatrix::fromDiagonal(wDiagonal); +RectangularMatrix w = + RectangularMatrix::fromDiagonal(wDiagonal); // u*w*v.transposed() == m @endcode diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index 155144f84..c2ef7c925 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -27,8 +27,8 @@ class GaussJordanTest: public Corrade::TestSuite::Tester { void invert(); }; -typedef RectangularMatrix<4, 4, float> Matrix4; -typedef Vector<4, float> Vector4; +typedef RectangularMatrix<4, 4, Float> Matrix4; +typedef Vector<4, Float> Vector4; GaussJordanTest::GaussJordanTest() { addTests(&GaussJordanTest::singular, @@ -40,7 +40,7 @@ void GaussJordanTest::singular() { Vector4(2.0f, 3.0f, -7.0f, 11.0f), Vector4(2.0f, 4.0f, 6.0f, 8.0f), Vector4(1.0f, 2.0f, 7.0f, 40.0f)); - RectangularMatrix<4, 1, float> t; + RectangularMatrix<4, 1, Float> t; CORRADE_VERIFY(!gaussJordanInPlaceTransposed(a, t)); } diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 67e1e7595..6af54d4e6 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -27,8 +27,8 @@ class GramSchmidtTest: public Corrade::TestSuite::Tester { void orthonormalize(); }; -typedef RectangularMatrix<3, 3, float> Matrix3; -typedef Vector<3, float> Vector3; +typedef RectangularMatrix<3, 3, Float> Matrix3; +typedef Vector<3, Float> Vector3; GramSchmidtTest::GramSchmidtTest() { addTests(&GramSchmidtTest::orthogonalize, diff --git a/src/Math/Algorithms/Test/SvdTest.cpp b/src/Math/Algorithms/Test/SvdTest.cpp index 9c0a55560..b0ccade4d 100644 --- a/src/Math/Algorithms/Test/SvdTest.cpp +++ b/src/Math/Algorithms/Test/SvdTest.cpp @@ -27,17 +27,17 @@ class SvdTest: public Corrade::TestSuite::Tester { void testFloat(); }; -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; - -typedef RectangularMatrix<5, 8, float> Matrix5x8f; -typedef Matrix<8, float> Matrix8f; -typedef Matrix<5, float> Matrix5f; -typedef Vector<8, float> Vector8f; -typedef Vector<5, float> Vector5f; +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; + +typedef RectangularMatrix<5, 8, Float> Matrix5x8f; +typedef Matrix<8, Float> Matrix8f; +typedef Matrix<5, Float> Matrix5f; +typedef Vector<8, Float> Vector8f; +typedef Vector<5, Float> Vector5f; constexpr static Matrix5x8d a( Vector8d(22.0, 14.0, -1.0, -3.0, 9.0, 9.0, 2.0, 4.0), diff --git a/src/Math/Angle.cpp b/src/Math/Angle.cpp index bbf6ed37c..07f77b4e6 100644 --- a/src/Math/Angle.cpp +++ b/src/Math/Angle.cpp @@ -18,11 +18,11 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit&); #endif #endif diff --git a/src/Math/Angle.h b/src/Math/Angle.h index a692572fc..3d6e6a319 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -39,17 +39,17 @@ conversion less error-prone. You can enter the value either by using literal: @code -auto degrees = 60.0_degf; // type is Deg -auto radians = 1.047_rad; // type is Rad +auto degrees = 60.0_degf; // type is Deg +auto radians = 1.047_rad; // type is Rad @endcode Or explicitly convert unitless value (such as output from some function) to either degrees or radians: @code -double foo(); +Double foo(); -Deg degrees(35.0f); -Rad radians(foo()); +Deg degrees(35.0f); +Rad radians(foo()); //degrees = 60.0f; // error, no implicit conversion @endcode @@ -65,9 +65,9 @@ It is also possible to compare angles with all comparison operators, but comparison of degrees and radians is not possible without explicit conversion to common type: @code -Rad angle(); +Rad angle(); -Deg x = angle(); // convert to degrees for easier comparison +Deg x = angle(); // convert to degrees for easier comparison if(x < 30.0_degf) foo(); //if(x > 1.57_radf) bar(); // error, both need to be of the same type @endcode @@ -75,11 +75,11 @@ if(x < 30.0_degf) foo(); It is possible to seamlessly convert between degrees and radians and explicitly convert the value back to underlying type: @code -float sine(Rad angle); -float a = sine(60.0_degf); // the same as sine(1.047_radf) -Deg b = 1.047_rad; // the same as 60.0_deg -float d = double(b); // 60.0 -//float e = b; // error, no implicit conversion +Float sine(Rad angle); +Float a = sine(60.0_degf); // the same as sine(1.047_radf) +Deg b = 1.047_rad; // the same as 60.0_deg +Float d = Double(b); // 60.0 +//Float e = b; // error, no implicit conversion @endcode @section Rad-conversions Requirement of explicit conversion @@ -88,10 +88,10 @@ The requirement of explicit conversions from and to unitless types helps to reduce unit-based errors. Consider following example with implicit conversions allowed: @code -float std::sin(float angle); -float sine(Rad angle); +Float std::sin(Float angle); +Float sine(Rad angle); -float a = 60.0f; // degrees +Float a = 60.0f; // degrees sine(a); // silent error, sine() expected radians auto b = 60.0_degf; // degrees @@ -101,10 +101,10 @@ std::sin(b); // silent error, std::sin() expected radians These silent errors are easily avoided by requiring explicit conversions: @code //sine(angleInDegrees); // compilation error -sine(Deg(angleInDegrees)); // explicitly specifying unit +sine(Deg(angleInDegrees)); // explicitly specifying unit //std::sin(angleInDegrees); // compilation error -std::sin(float(Rad(angleInDegrees)); // required explicit conversion hints +std::sin(Float(Rad(angleInDegrees)); // required explicit conversion hints // to user that this case needs special // attention (i.e., conversion to radians) @endcode @@ -142,26 +142,26 @@ template class Deg: public Unit { Example usage: @code -double cosine = Math::cos(60.0_deg); // cosine = 0.5 -double cosine = Math::cos(1.047_rad); // cosine = 0.5 +Double cosine = Math::cos(60.0_deg); // cosine = 0.5 +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. */ -inline constexpr Deg operator "" _deg(long double value) { return Deg(value); } +inline constexpr Deg operator "" _deg(long double value) { return Deg(value); } /** @relates Deg @brief Single-precision degree value literal Example usage: @code -float tangent = Math::tan(60.0_degf); // tangent = 1.732f -float tangent = Math::tan(1.047_radf); // tangent = 1.732f +Float tangent = Math::tan(60.0_degf); // tangent = 1.732f +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. */ -inline constexpr Deg operator "" _degf(long double value) { return Deg(value); } +inline constexpr Deg operator "" _degf(long double value) { return Deg(value); } #endif /** @@ -203,7 +203,7 @@ See operator""_rad() for more information. @see Magnum::operator""_rad(), operator""_radf(), operator""_deg() @note Not available on GCC < 4.7. Use Rad::Rad(T) instead. */ -inline constexpr Rad operator "" _rad(long double value) { return Rad(value); } +inline constexpr Rad operator "" _rad(long double value) { return Rad(value); } /** @relates Rad @brief Single-precision radian value literal @@ -212,7 +212,7 @@ See operator""_degf() for more information. @see Magnum::operator""_radf(), operator""_rad(), operator""_degf() @note Not available on GCC < 4.7. Use Rad::Rad(T) instead. */ -inline constexpr Rad operator "" _radf(long double value) { return Rad(value); } +inline constexpr Rad operator "" _radf(long double value) { return Rad(value); } #endif template inline constexpr Deg::Deg(Unit value): Unit(T(180)*T(value)/Math::Constants::pi()) {} @@ -238,11 +238,11 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb /* Explicit instantiation for commonly used types */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit&); #endif #endif diff --git a/src/Math/BoolVector.h b/src/Math/BoolVector.h index a5ac589d4..14166de15 100644 --- a/src/Math/BoolVector.h +++ b/src/Math/BoolVector.h @@ -19,9 +19,10 @@ * @brief Class Magnum::Math::BoolVector */ -#include #include +#include "Types.h" + namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -65,9 +66,9 @@ template class BoolVector { * @param next Values for next Bbit segments */ #ifdef DOXYGEN_GENERATING_OUTPUT - template inline constexpr /*implicit*/ BoolVector(std::uint8_t first, T... next); + template inline constexpr /*implicit*/ BoolVector(UnsignedByte first, T... next); #else - template::type> inline constexpr /*implicit*/ BoolVector(std::uint8_t first, T... next): _data{first, std::uint8_t(next)...} {} + template::type> inline constexpr /*implicit*/ BoolVector(UnsignedByte first, T... next): _data{first, UnsignedByte(next)...} {} #endif /** @brief Construct boolean vector with one value for all fields */ @@ -89,8 +90,8 @@ template class BoolVector { * * @see operator[](), set() */ - inline std::uint8_t* data() { return _data; } - inline constexpr const std::uint8_t* data() const { return _data; } /**< @overload */ + inline UnsignedByte* data() { return _data; } + inline constexpr const UnsignedByte* data() const { return _data; } /**< @overload */ /** @brief Bit at given position */ inline constexpr bool operator[](std::size_t i) const { @@ -225,15 +226,15 @@ template class BoolVector { } private: - enum: std::uint8_t { + enum: UnsignedByte { FullSegmentMask = 0xFF, LastSegmentMask = (1 << size%8) - 1 }; /* Implementation for Vector::Vector(U) */ - template inline constexpr explicit BoolVector(Implementation::Sequence, std::uint8_t value): _data{Implementation::repeat(value, sequence)...} {} + template inline constexpr explicit BoolVector(Implementation::Sequence, UnsignedByte value): _data{Implementation::repeat(value, sequence)...} {} - std::uint8_t _data[(size-1)/8+1]; + UnsignedByte _data[(size-1)/8+1]; }; /** @debugoperator{Magnum::Math::BoolVector} */ diff --git a/src/Math/Complex.cpp b/src/Math/Complex.cpp index 0a6c5bd39..84cdf2c3e 100644 --- a/src/Math/Complex.cpp +++ b/src/Math/Complex.cpp @@ -18,9 +18,9 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Complex&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Complex&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Complex&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Complex&); #endif #endif diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 5a363b08b..cd3139a0b 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -390,9 +390,9 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb /* Explicit instantiation for commonly used types */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Complex&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Complex&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Complex&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Complex&); #endif #endif diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 7f4e3aa6b..bbc8b047c 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -19,6 +19,8 @@ * @brief Class Magnum::Math::Constants */ +#include "Types.h" + namespace Magnum { namespace Math { /** @@ -44,19 +46,19 @@ template struct Constants { }; #ifndef DOXYGEN_GENERATING_OUTPUT -template<> struct Constants { +template<> struct Constants { Constants() = delete; - static inline constexpr double pi() { return 3.141592653589793; } - static inline constexpr double sqrt2() { return 1.414213562373095; } - static inline constexpr double sqrt3() { return 1.732050807568877; } + static inline constexpr Double pi() { return 3.141592653589793; } + static inline constexpr Double sqrt2() { return 1.414213562373095; } + static inline constexpr Double sqrt3() { return 1.732050807568877; } }; -template<> struct Constants { +template<> struct Constants { Constants() = delete; - static inline constexpr float pi() { return 3.141592654f; } - static inline constexpr float sqrt2() { return 1.414213562f; } - static inline constexpr float sqrt3() { return 1.732050808f; } + static inline constexpr Float pi() { return 3.141592654f; } + static inline constexpr Float sqrt2() { return 1.414213562f; } + static inline constexpr Float sqrt3() { return 1.732050808f; } }; #endif diff --git a/src/Math/DualComplex.cpp b/src/Math/DualComplex.cpp index 128f2f767..e0e83ca08 100644 --- a/src/Math/DualComplex.cpp +++ b/src/Math/DualComplex.cpp @@ -18,9 +18,9 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualComplex&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualComplex&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualComplex&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualComplex&); #endif #endif diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index d455d72e6..8c47152f4 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -308,9 +308,9 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb /* Explicit instantiation for commonly used types */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualComplex&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualComplex&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualComplex&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualComplex&); #endif #endif diff --git a/src/Math/DualQuaternion.cpp b/src/Math/DualQuaternion.cpp index 7a5d2448c..fe330c6b6 100644 --- a/src/Math/DualQuaternion.cpp +++ b/src/Math/DualQuaternion.cpp @@ -18,9 +18,9 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualQuaternion&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualQuaternion&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualQuaternion&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const DualQuaternion&); #endif #endif diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 7bc3d70d7..0cb8bd6d0 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -298,9 +298,9 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb /* Explicit instantiation for commonly used types */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualQuaternion&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualQuaternion&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualQuaternion&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const DualQuaternion&); #endif #endif diff --git a/src/Math/Functions.cpp b/src/Math/Functions.cpp index 286f5d632..afcb2ad76 100644 --- a/src/Math/Functions.cpp +++ b/src/Math/Functions.cpp @@ -17,15 +17,15 @@ namespace Magnum { namespace Math { -std::uint32_t log2(std::uint32_t number) { - std::uint32_t log = 0; +UnsignedInt log2(UnsignedInt number) { + UnsignedInt log = 0; while(number >>= 1) ++log; return log; } -std::uint32_t log(std::uint32_t base, std::uint32_t number) { - std::uint32_t log = 0; +UnsignedInt log(UnsignedInt base, UnsignedInt number) { + UnsignedInt log = 0; while(number /= base) ++log; return log; diff --git a/src/Math/Functions.h b/src/Math/Functions.h index dc2ff22e6..d123fdfad 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct Pow { + template struct Pow { Pow() = delete; template inline constexpr static T pow(T base) { @@ -51,7 +51,7 @@ namespace Implementation { * * Returns integral power of base to the exponent. */ -template inline constexpr T pow(T base) { +template inline constexpr T pow(T base) { return Implementation::Pow::pow(base); } @@ -61,7 +61,7 @@ template inline constexpr T pow(T base) { * Returns integral logarithm of given number with base `2`. * @see log() */ -std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number); +UnsignedInt MAGNUM_EXPORT log2(UnsignedInt number); /** * @brief Integral logarithm @@ -69,7 +69,7 @@ std::uint32_t MAGNUM_EXPORT log2(std::uint32_t number); * Returns integral logarithm of given number with given base. * @see log2() */ -std::uint32_t MAGNUM_EXPORT log(std::uint32_t base, std::uint32_t number); +UnsignedInt MAGNUM_EXPORT log(UnsignedInt base, UnsignedInt number); /** @brief Sine */ template inline T sin(Rad angle) { return std::sin(T(angle)); } @@ -224,18 +224,18 @@ Converts integral value from full range of given *unsigned* integral type to value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$. @note For best precision, resulting `FloatingPoint` type should be always - larger that `Integral` type (e.g. `double` from `std::int32_t`, `long double` - from `std::int64_t` and similarly for vector types). + larger that `Integral` type (e.g. Double from Int, LongDouble from Long and + similarly for vector types). @attention To ensure the integral type is correctly detected when using literals, this function should be called with both template parameters explicit, e.g.: @code // Literal type is (signed) char, but we assumed unsigned char, a != 1.0f -float a = normalize('\xFF'); +Float a = normalize('\xFF'); // b = 1.0f -float b = normalize('\xFF'); +Float b = normalize('\xFF'); @endcode @see denormalize() @@ -273,8 +273,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 `std::int32_t`, `long double` - to `std::int64_t` and similarly for vector types). + resulting `Integral` type (e.g. Double to Int, LongDouble to Long and + similarly for vector types). @attention Return value for floating point numbers outside the normalized range is undefined. diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 1ca5275e7..c2601383f 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -60,8 +60,8 @@ template class Rectangle { * Performs only default casting on the values, no rounding or * anything else. Example usage: * @code - * Rectangle floatingPoint({1.3f, 2.7f}, {-15.0f, 7.0f}); - * Rectangle integral(floatingPoint); // {{1, 2}, {-15, 7}} + * Rectangle floatingPoint({1.3f, 2.7f}, {-15.0f, 7.0f}); + * Rectangle integral(floatingPoint); // {{1, 2}, {-15, 7}} * @endcode */ template inline constexpr explicit Rectangle(const Rectangle& other): _bottomLeft(other._bottomLeft), _topRight(other._topRight) {} diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index 069ad493d..2ddf630d2 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -31,8 +31,9 @@ class DistanceTest: public Corrade::TestSuite::Tester { void lineSegmentPoint3D(); }; -typedef Magnum::Math::Vector2 Vector2; -typedef Magnum::Math::Vector3 Vector3; +typedef Math::Vector2 Vector2; +typedef Math::Vector3 Vector3; +typedef Math::Constants Constants; DistanceTest::DistanceTest() { addTests(&DistanceTest::linePoint2D, @@ -49,14 +50,11 @@ void DistanceTest::linePoint2D() { CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(0.25f))), 0.0f); /* The distance should be the same for all equidistant points */ - CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(1.0f, 0.0f))), - 1.0f/Constants::sqrt2()); - CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(1.0f, 0.0f)+Vector2(100.0f))), - 1.0f/Constants::sqrt2()); + CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(1.0f, 0.0f))), 1.0f/Constants::sqrt2()); + CORRADE_COMPARE((Distance::linePoint(a, b, Vector2(1.0f, 0.0f)+Vector2(100.0f))), 1.0f/Constants::sqrt2()); /* Be sure that *Squared() works the same, as it has slightly different implementation */ - CORRADE_COMPARE((Distance::linePointSquared(a, b, Vector2(1.0f, 0.0f))), - 0.5f); + CORRADE_COMPARE((Distance::linePointSquared(a, b, Vector2(1.0f, 0.0f))), 0.5f); } void DistanceTest::linePoint3D() { @@ -67,10 +65,8 @@ void DistanceTest::linePoint3D() { CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(0.25f))), 0.0f); /* The distance should be the same for all equidistant points */ - CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f))), - Constants::sqrt2()/Constants::sqrt3()); - CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(100.0f))), - Constants::sqrt2()/Constants::sqrt3()); + CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f))), Constants::sqrt2()/Constants::sqrt3()); + CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(100.0f))), Constants::sqrt2()/Constants::sqrt3()); } void DistanceTest::lineSegmentPoint2D() { @@ -81,19 +77,17 @@ void DistanceTest::lineSegmentPoint2D() { CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(0.25f))), 0.0f); /* Point on the line, outside the segment, closer to A */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(-1.0f))), Constants::sqrt2()); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(-1.0f))), Constants::sqrt2()); /* Be sure that *Squared() works the same, as it has slightly different implementation */ CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(-1.0f))), 2.0f); /* Point on the line, outside the segment, closer to B */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f+1.0f/Constants::sqrt2()))), 1.0f); - CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f+1.0f/Constants::sqrt2()))), 1.0f); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f+1.0f/Constants::sqrt2()))), 1.0f); + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f+1.0f/Constants::sqrt2()))), 1.0f); /* Point next to the line segment */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f, 0.0f))), - 1.0f/Constants::sqrt2()); - CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f, 0.0f))), - 0.5f); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f, 0.0f))), 1.0f/Constants::sqrt2()); + CORRADE_COMPARE((Distance::lineSegmentPointSquared(a, b, Vector2(1.0f, 0.0f))), 0.5f); /* Point outside the line segment, closer to A */ CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector2(1.0f, 0.0f)-Vector2(1.0f, 0.5f))), 0.5f); @@ -112,20 +106,19 @@ void DistanceTest::lineSegmentPoint3D() { CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(0.25f))), 0.0f); /* Point on the line, outside the segment, closer to A */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(-1.0f))), +Constants::sqrt3()); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(-1.0f))), Constants::sqrt3()); /* Point on the line, outside the segment, closer to B */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f+1.0f/Constants::sqrt3()))), 1.0f); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f+1.0f/Constants::sqrt3()))), 1.0f); /* Point next to the line segment */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f))), - Constants::sqrt2()/Constants::sqrt3()); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f))), Constants::sqrt2()/Constants::sqrt3()); /* Point outside the line segment, closer to A */ CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)-Vector3(1.0f))), 1.0f); /* Point outside the line segment, closer to B */ - CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(1.0f))), +Constants::sqrt2()); + CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(1.0f))), Constants::sqrt2()); } }}}} diff --git a/src/Math/Geometry/Test/IntersectionTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp index 3e1f27d08..c9cb17fdb 100644 --- a/src/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -27,7 +27,7 @@ class IntersectionTest: public Corrade::TestSuite::Tester { void planeLine(); }; -typedef Magnum::Math::Vector3 Vector3; +typedef Math::Vector3 Vector3; IntersectionTest::IntersectionTest() { addTests(&IntersectionTest::planeLine); @@ -47,11 +47,11 @@ void IntersectionTest::planeLine() { /* Line lies on the plane */ CORRADE_COMPARE(Intersection::planeLine(planePosition, planeNormal, - Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)), std::numeric_limits::quiet_NaN()); + Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)), std::numeric_limits::quiet_NaN()); /* Line is parallell to the plane */ CORRADE_COMPARE((Intersection::planeLine(planePosition, planeNormal, - Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), -std::numeric_limits::infinity()); + Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), -std::numeric_limits::infinity()); } }}}} diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 84c8b2567..99eb5e309 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -32,9 +32,9 @@ class RectangleTest: public Corrade::TestSuite::Tester { void debug(); }; -typedef Geometry::Rectangle Rectangle; -typedef Geometry::Rectangle Rectanglei; -typedef Vector2 Vector2i; +typedef Geometry::Rectangle Rectangle; +typedef Geometry::Rectangle Rectanglei; +typedef Vector2 Vector2i; RectangleTest::RectangleTest() { addTests(&RectangleTest::access, diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index d60a1eb80..a8f72e114 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -19,9 +19,10 @@ * @brief Class Magnum::Math::MathTypeTraits */ -#include #include +#include "Types.h" + /** @brief Precision when testing floats for equality */ #ifndef FLOAT_EQUALITY_PRECISION #define FLOAT_EQUALITY_PRECISION 1.0e-6 @@ -113,28 +114,28 @@ namespace Implementation { }; } -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef float FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { + typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef float FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { + typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef float FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { + typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef float FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { + typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef double FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { + typedef Double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { - typedef double FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { + typedef Double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { typedef long double FloatingPointType; }; @@ -149,15 +150,15 @@ namespace Implementation { }; } -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { - typedef float FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { + typedef Float FloatingPointType; - inline constexpr static float epsilon() { return FLOAT_EQUALITY_PRECISION; } + inline constexpr static Float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { - typedef double FloatingPointType; +template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { + typedef Double FloatingPointType; - inline constexpr static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } + inline constexpr static Double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { typedef long double FloatingPointType; diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 6334038cc..89e070f57 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -81,9 +81,9 @@ template class Matrix: public RectangularMatrix floatingPoint({1.3f, 2.7f}, + * Matrix<2, Float> floatingPoint({1.3f, 2.7f}, * {-15.0f, 7.0f}); - * Matrix<2, std::int8_t> integral(floatingPoint); + * Matrix<2, Byte> integral(floatingPoint); * // integral == {{1, 2}, {-15, 7}} * @endcode */ diff --git a/src/Math/Quaternion.cpp b/src/Math/Quaternion.cpp index c736cbfbf..9939dc854 100644 --- a/src/Math/Quaternion.cpp +++ b/src/Math/Quaternion.cpp @@ -18,9 +18,9 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Quaternion&); #endif #endif diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index f50904fdc..97024a248 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -479,9 +479,9 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb /* Explicit instantiation for commonly used types */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Quaternion&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Quaternion&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Quaternion&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Quaternion&); #endif #endif diff --git a/src/Math/RectangularMatrix.cpp b/src/Math/RectangularMatrix.cpp index 1716c3a14..76d8e9cdf 100644 --- a/src/Math/RectangularMatrix.cpp +++ b/src/Math/RectangularMatrix.cpp @@ -18,28 +18,28 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 2, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 3, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 4, float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 2, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 3, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 4, Float>&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 2, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 3, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 4, double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 2, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 3, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 4, Double>&); #endif -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 3, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 2, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 4, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 2, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 4, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 3, float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 3, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 2, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 4, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 2, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 4, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 3, Float>&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 3, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 2, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 4, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 2, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 4, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 3, double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 3, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 2, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<2, 4, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 2, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<3, 4, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::RectangularMatrix<4, 3, Double>&); #endif #endif @@ -48,28 +48,28 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnu namespace Corrade { namespace Utility { #ifndef DOXYGEN_GENERATING_OUTPUT -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; #ifndef MAGNUM_TARGET_GLES -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; #endif -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; #ifndef MAGNUM_TARGET_GLES -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; #endif #endif diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 29189eab9..0702ff57d 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -104,8 +104,8 @@ template class RectangularMatrix { * Performs only default casting on the values, no rounding or * anything else. Example usage: * @code - * RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * RectangularMatrix<4, 1, std::int8_t> integral(floatingPoint); + * RectangularMatrix<4, 1, Float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + * RectangularMatrix<4, 1, Byte> integral(floatingPoint); * // integral == {1, 2, -15, 7} * @endcode */ @@ -132,8 +132,8 @@ template class RectangularMatrix { * * Particular elements can be accessed using Vector::operator[], e.g.: * @code - * RectangularMatrix<4, 3, float> m; - * float a = m[2][1]; + * RectangularMatrix<4, 3, Float> m; + * Float a = m[2][1]; * @endcode * * @see data() @@ -475,29 +475,29 @@ template Corrade::Utility::Debug op #ifndef DOXYGEN_GENERATING_OUTPUT /* Explicit instantiation for types used in OpenGL */ /* Square matrices */ -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 2, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 3, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 4, float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 2, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 3, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 4, Float>&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 2, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 3, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 4, double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 2, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 3, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 4, Double>&); #endif /* Rectangular matrices */ -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 3, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 2, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 4, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 2, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 4, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 3, float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 3, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 2, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 4, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 2, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 4, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 3, Float>&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 3, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 2, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 4, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 2, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 4, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 3, double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 3, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 2, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<2, 4, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 2, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<3, 4, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const RectangularMatrix<4, 3, Double>&); #endif #define MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(cols, rows, ...) \ @@ -591,29 +591,29 @@ template struct ConfigurationValue< #ifndef DOXYGEN_GENERATING_OUTPUT /* Square matrices */ -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; #ifndef MAGNUM_TARGET_GLES -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; #endif /* Rectangular matrices */ -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; #ifndef MAGNUM_TARGET_GLES -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; #endif #endif diff --git a/src/Math/Swizzle.h b/src/Math/Swizzle.h index 482236d29..b0010fab0 100644 --- a/src/Math/Swizzle.h +++ b/src/Math/Swizzle.h @@ -50,7 +50,7 @@ namespace Implementation { Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); auto vec = swizzle<'w', '1', '0', 'x', 'y', 'z'>(original); // vec == { 4, 1, 0, -1, 2, 3 } diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp index fbd71685c..7ac2f7e6b 100644 --- a/src/Math/Test/AngleTest.cpp +++ b/src/Math/Test/AngleTest.cpp @@ -32,10 +32,10 @@ class AngleTest: public Corrade::TestSuite::Tester { void debugRad(); }; -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Deg Degd; -typedef Math::Rad Radd; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Deg Degd; +typedef Math::Rad Radd; AngleTest::AngleTest() { addTests(&AngleTest::construct, @@ -50,14 +50,14 @@ void AngleTest::construct() { /* Default constructor */ constexpr Degd a; constexpr Deg m; - CORRADE_COMPARE(double(a), 0.0f); - CORRADE_COMPARE(float(m), 0.0f); + CORRADE_COMPARE(Double(a), 0.0f); + CORRADE_COMPARE(Float(m), 0.0f); /* Value constructor */ constexpr Deg b(25.0); constexpr Radd n(3.14); - CORRADE_COMPARE(float(b), 25.0); - CORRADE_COMPARE(double(n), 3.14); + CORRADE_COMPARE(Float(b), 25.0); + CORRADE_COMPARE(Double(n), 3.14); /* Copy constructor */ constexpr Deg c(b); @@ -68,8 +68,8 @@ void AngleTest::construct() { /* Conversion operator */ constexpr Degd d(b); constexpr Rad p(n); - CORRADE_COMPARE(double(d), 25.0); - CORRADE_COMPARE(float(p), 3.14f); + CORRADE_COMPARE(Double(d), 25.0); + CORRADE_COMPARE(Float(p), 3.14f); } void AngleTest::literals() { @@ -77,23 +77,23 @@ void AngleTest::literals() { constexpr auto b = 25.0_degf; CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same::value)); - CORRADE_COMPARE(double(a), 25.0); - CORRADE_COMPARE(float(b), 25.0f); + CORRADE_COMPARE(Double(a), 25.0); + CORRADE_COMPARE(Float(b), 25.0f); 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); - CORRADE_COMPARE(float(n), 3.14f); + CORRADE_COMPARE(Double(m), 3.14); + CORRADE_COMPARE(Float(n), 3.14f); } void AngleTest::conversion() { constexpr Deg a(Rad(1.57079633f)); - CORRADE_COMPARE(float(a), 90.0f); + CORRADE_COMPARE(Float(a), 90.0f); constexpr Rad b(Deg(90.0f)); - CORRADE_COMPARE(float(b), 1.57079633f); + CORRADE_COMPARE(Float(b), 1.57079633f); } void AngleTest::debugDeg() { diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp index 5729c9415..c0328348f 100644 --- a/src/Math/Test/BoolVectorTest.cpp +++ b/src/Math/Test/BoolVectorTest.cpp @@ -121,7 +121,7 @@ void BoolVectorTest::constExpressions() { /* Data access, pointer chasings, i.e. *(b.data()[3]), are not possible */ constexpr bool e = b[2]; - constexpr std::uint8_t f = *b.data(); + constexpr UnsignedByte f = *b.data(); CORRADE_COMPARE(e, true); CORRADE_COMPARE(f, 0xa5); } diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 8b49bacbb..ec407d53b 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -84,12 +84,12 @@ ComplexTest::ComplexTest() { &ComplexTest::debug); } -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Complex Complex; -typedef Math::Vector2 Vector2; -typedef Math::Matrix3 Matrix3; -typedef Math::Matrix<2, float> Matrix2; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Complex Complex; +typedef Math::Vector2 Vector2; +typedef Math::Matrix3 Matrix3; +typedef Math::Matrix<2, Float> Matrix2; void ComplexTest::construct() { Complex c(0.5f, -3.7f); @@ -111,10 +111,10 @@ void ComplexTest::constructFromVector() { } void ComplexTest::compare() { - CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); - CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); - CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); - CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); } void ComplexTest::constExpressions() { @@ -135,8 +135,8 @@ void ComplexTest::constExpressions() { CORRADE_COMPARE(d, Complex(2.5f, -5.0f)); /* Data access */ - constexpr float e = b.real(); - constexpr float f = b.imaginary(); + constexpr Float e = b.real(); + constexpr Float f = b.imaginary(); constexpr Vector2 g(b); CORRADE_COMPARE(e, 2.5f); CORRADE_COMPARE(f, -5.0f); diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index 1354beacf..7192b2db7 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -32,11 +32,11 @@ ConstantsTest::ConstantsTest() { } void ConstantsTest::constants() { - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0f); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0f); + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0f); + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0f); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0); + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0); + CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0); } }}} diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 758088379..ee292a6ba 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -52,13 +52,13 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void debug(); }; -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Complex Complex; -typedef Math::Dual Dual; -typedef Math::DualComplex DualComplex; -typedef Math::Matrix3 Matrix3; -typedef Math::Vector2 Vector2; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Complex Complex; +typedef Math::Dual Dual; +typedef Math::DualComplex DualComplex; +typedef Math::Matrix3 Matrix3; +typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { addTests(&DualComplexTest::construct, diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 72d8acb06..7bcbcbccd 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -50,13 +50,13 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void debug(); }; -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Dual Dual; -typedef Math::Matrix4 Matrix4; -typedef Math::DualQuaternion DualQuaternion; -typedef Math::Quaternion Quaternion; -typedef Math::Vector3 Vector3; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Dual Dual; +typedef Math::Matrix4 Matrix4; +typedef Math::DualQuaternion DualQuaternion; +typedef Math::Quaternion Quaternion; +typedef Math::Vector3 Vector3; DualQuaternionTest::DualQuaternionTest() { addTests(&DualQuaternionTest::construct, @@ -184,7 +184,7 @@ void DualQuaternionTest::rotation() { std::ostringstream o; Error::setOutput(&o); - Vector3 axis(1.0f/Constants::sqrt3()); + Vector3 axis(1.0f/Constants::sqrt3()); CORRADE_COMPARE(DualQuaternion::rotation(Deg(120.0f), axis*2.0f), DualQuaternion()); CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index 5b2987075..e1be57922 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -40,7 +40,7 @@ class DualTest: public Corrade::TestSuite::Tester { void debug(); }; -typedef Math::Dual Dual; +typedef Math::Dual Dual; DualTest::DualTest() { addTests(&DualTest::construct, @@ -74,10 +74,10 @@ void DualTest::constructDefault() { } void DualTest::compare() { - CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); /* Compare to real part only */ CORRADE_VERIFY(Dual(1.0f, 0.0f) == 1.0f); @@ -98,8 +98,8 @@ void DualTest::constExpressions() { CORRADE_COMPARE(c, Dual(2.0f, 3.0f)); /* Data access */ - constexpr float e = b.real(); - constexpr float f = b.dual(); + constexpr Float e = b.real(); + constexpr Float f = b.dual(); CORRADE_COMPARE(e, 2.0f); CORRADE_COMPARE(f, 3.0f); } diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index e0858e566..cfe7b64d4 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -45,13 +45,13 @@ class FunctionsTest: public Corrade::TestSuite::Tester { void trigonometric(); }; -typedef Math::Constants Constants; -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Vector3 Vector3; -typedef Math::Vector3 Vector3ub; -typedef Math::Vector3 Vector3b; -typedef Math::Vector3 Vector3i; +typedef Math::Constants Constants; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Vector3 Vector3; +typedef Math::Vector3 Vector3ub; +typedef Math::Vector3 Vector3b; +typedef Math::Vector3 Vector3i; FunctionsTest::FunctionsTest() { addTests(&FunctionsTest::min, @@ -115,131 +115,131 @@ void FunctionsTest::lerp() { CORRADE_COMPARE(Math::lerp(a, b, 0.25f), Vector3(0.0f, 1.0f, 5.0f)); /* Integer vector */ - typedef Math::Vector<3, std::int32_t> Vector3ub; + typedef Math::Vector<3, Int> Vector3ub; Vector3ub c(0, 128, 64); Vector3ub d(16, 0, 32); CORRADE_COMPARE(Math::lerp(c, d, 0.25f), Vector3ub(4, 96, 56)); } void FunctionsTest::normalizeUnsigned() { - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(255)), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(255)), 1.0f); - 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); - 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); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); - CORRADE_COMPARE((Math::normalize(8192)), 0.125002f); - CORRADE_COMPARE((Math::normalize(49152)), 0.750011f); + CORRADE_COMPARE((Math::normalize(8192)), 0.125002f); + CORRADE_COMPARE((Math::normalize(49152)), 0.750011f); CORRADE_COMPARE(Math::normalize(Vector3ub(0, 127, 255)), Vector3(0.0f, 0.498039f, 1.0f)); } void FunctionsTest::normalizeSigned() { - CORRADE_COMPARE((Math::normalize(127)), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(-128)), -1.0f); + CORRADE_COMPARE((Math::normalize(127)), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(-128)), -1.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); - 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); + 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); - 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); + 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); - CORRADE_COMPARE((Math::normalize(16384)), 0.500015f); - CORRADE_COMPARE((Math::normalize(-16384)), -0.500015f); + CORRADE_COMPARE((Math::normalize(16384)), 0.500015f); + CORRADE_COMPARE((Math::normalize(-16384)), -0.500015f); CORRADE_COMPARE(Math::normalize(Vector3b(0, -127, 64)), Vector3(0.0f, -1.0f, 0.503937f)); } void FunctionsTest::denormalizeUnsigned() { - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 255); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), 255); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); - 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_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - 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_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - CORRADE_COMPARE(Math::denormalize(0.33f), 21626); - CORRADE_COMPARE(Math::denormalize(0.66f), 43253); + CORRADE_COMPARE(Math::denormalize(0.33f), 21626); + CORRADE_COMPARE(Math::denormalize(0.66f), 43253); CORRADE_COMPARE(Math::denormalize(Vector3(0.0f, 0.5f, 1.0f)), Vector3ub(0, 127, 255)); } void FunctionsTest::denormalizeSigned() { - CORRADE_COMPARE(Math::denormalize(-1.0f), -127); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 127); + CORRADE_COMPARE(Math::denormalize(-1.0f), -127); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), 127); - CORRADE_COMPARE(Math::denormalize(-1.0f), std::numeric_limits::min()+1); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(-1.0f), std::numeric_limits::min()+1); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); - 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()); + 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()); - 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()); + 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()); - CORRADE_COMPARE(Math::denormalize(-0.33f), -10813); - CORRADE_COMPARE(Math::denormalize(0.66f), 21626); + CORRADE_COMPARE(Math::denormalize(-0.33f), -10813); + CORRADE_COMPARE(Math::denormalize(0.66f), 21626); CORRADE_COMPARE(Math::denormalize(Vector3(0.0f, -1.0f, 0.5f)), Vector3b(0, -127, 63)); } void FunctionsTest::renormalizeUnsinged() { - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - 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.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); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0l)), 0.0l); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); } void FunctionsTest::renormalizeSinged() { - CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); + CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - 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); + 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); - 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); + 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); } void FunctionsTest::normalizeTypeDeduction() { - CORRADE_COMPARE(Math::normalize('\x7F'), 1.0f); - CORRADE_COMPARE((Math::normalize('\x7F')), 1.0f); + CORRADE_COMPARE(Math::normalize('\x7F'), 1.0f); + CORRADE_COMPARE((Math::normalize('\x7F')), 1.0f); } void FunctionsTest::pow() { diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index 74e50d286..1f276b3a5 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -38,19 +38,19 @@ MathTypeTraitsTest::MathTypeTraitsTest() { } void MathTypeTraitsTest::equalsIntegral() { - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); } void MathTypeTraitsTest::equalsFloatingPoint() { - _equalsFloatingPoint(); - _equalsFloatingPoint(); + _equalsFloatingPoint(); + _equalsFloatingPoint(); } template void MathTypeTraitsTest::_equalsIntegral() { diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 5cf07abb9..6df37ed9f 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -43,10 +43,10 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Math::Deg Deg; -typedef Math::Matrix3 Matrix3; -typedef Math::Matrix<2, float> Matrix2; -typedef Math::Vector2 Vector2; +typedef Math::Deg Deg; +typedef Math::Matrix3 Matrix3; +typedef Math::Matrix<2, Float> Matrix2; +typedef Math::Vector2 Vector2; Matrix3Test::Matrix3Test() { addTests(&Matrix3Test::constructIdentity, diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index da5f96e57..9258c9ff8 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -48,11 +48,11 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Matrix4 Matrix4; -typedef Math::Matrix<3, float> Matrix3; -typedef Math::Vector3 Vector3; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Matrix4 Matrix4; +typedef Math::Matrix<3, Float> Matrix3; +typedef Math::Vector3 Vector3; Matrix4Test::Matrix4Test() { addTests(&Matrix4Test::constructIdentity, @@ -135,8 +135,8 @@ void Matrix4Test::rotationX() { {0.0f, 0.90096887f, 0.43388374f, 0.0f}, {0.0f, -0.43388374f, 0.90096887f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::xAxis()), matrix); - CORRADE_COMPARE(Matrix4::rotationX(Rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::xAxis()), matrix); + CORRADE_COMPARE(Matrix4::rotationX(Rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationY() { @@ -144,8 +144,8 @@ void Matrix4Test::rotationY() { { 0.0f, 1.0f, 0.0f, 0.0f}, {0.43388374f, 0.0f, 0.90096887f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); - CORRADE_COMPARE(Matrix4::rotationY(Rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::yAxis()), matrix); + CORRADE_COMPARE(Matrix4::rotationY(Rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::rotationZ() { @@ -153,8 +153,8 @@ void Matrix4Test::rotationZ() { {-0.43388374f, 0.90096887f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); - CORRADE_COMPARE(Matrix4::rotationZ(Rad(Math::Constants::pi()/7)), matrix); + CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants::pi()/7), Vector3::zAxis()), matrix); + CORRADE_COMPARE(Matrix4::rotationZ(Rad(Math::Constants::pi()/7)), matrix); } void Matrix4Test::reflection() { diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 1cd499397..a862326be 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -37,10 +37,10 @@ class MatrixTest: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Matrix<4, float> Matrix4; -typedef Matrix<3, float> Matrix3; -typedef Vector<4, float> Vector4; -typedef Vector<3, float> Vector3; +typedef Matrix<4, Float> Matrix4; +typedef Matrix<3, Float> Matrix3; +typedef Vector<4, Float> Vector4; +typedef Vector<3, Float> Vector3; MatrixTest::MatrixTest() { addTests(&MatrixTest::construct, @@ -55,7 +55,7 @@ MatrixTest::MatrixTest() { } void MatrixTest::construct() { - float m[] = { + Float m[] = { 3.0f, 5.0f, 8.0f, 4.0f, 4.0f, 4.0f, 7.0f, 3.0f, 7.0f, -1.0f, 8.0f, 0.0f, @@ -102,12 +102,12 @@ void MatrixTest::constructZero() { } void MatrixTest::trace() { - Matrix<5, std::int32_t> m( - Vector<5, std::int32_t>(1, 2, 3, 0, 0), - Vector<5, std::int32_t>(2, 3, 2, 1, -2), - Vector<5, std::int32_t>(1, 1, -20, 1, 0), - Vector<5, std::int32_t>(2, 0, 0, 10, 2), - Vector<5, std::int32_t>(3, 1, 0, 1, -2) + Matrix<5, Int> m( + Vector<5, Int>(1, 2, 3, 0, 0), + Vector<5, Int>(2, 3, 2, 1, -2), + Vector<5, Int>(1, 1, -20, 1, 0), + Vector<5, Int>(2, 0, 0, 10, 2), + Vector<5, Int>(3, 1, 0, 1, -2) ); CORRADE_COMPARE(m.trace(), -8); @@ -127,12 +127,12 @@ void MatrixTest::ij() { } void MatrixTest::determinant() { - Matrix<5, std::int32_t> m( - Vector<5, std::int32_t>(1, 2, 2, 1, 0), - Vector<5, std::int32_t>(2, 3, 2, 1, -2), - Vector<5, std::int32_t>(1, 1, 1, 1, 0), - Vector<5, std::int32_t>(2, 0, 0, 1, 2), - Vector<5, std::int32_t>(3, 1, 0, 1, -2) + Matrix<5, Int> m( + Vector<5, Int>(1, 2, 2, 1, 0), + Vector<5, Int>(2, 3, 2, 1, -2), + Vector<5, Int>(1, 1, 1, 1, 0), + Vector<5, Int>(2, 0, 0, 1, 2), + Vector<5, Int>(3, 1, 0, 1, -2) ); CORRADE_COMPARE(m.determinant(), -2); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index de71e044a..2d4be8a32 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -57,13 +57,13 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void debug(); }; -typedef Math::Deg Deg; -typedef Math::Rad Rad; -typedef Math::Matrix<3, float> Matrix3; -typedef Math::Matrix4 Matrix4; -typedef Math::Quaternion Quaternion; -typedef Math::Vector3 Vector3; -typedef Math::Vector4 Vector4; +typedef Math::Deg Deg; +typedef Math::Rad Rad; +typedef Math::Matrix<3, Float> Matrix3; +typedef Math::Matrix4 Matrix4; +typedef Math::Quaternion Quaternion; +typedef Math::Vector3 Vector3; +typedef Math::Vector4 Vector4; QuaternionTest::QuaternionTest() { addTests(&QuaternionTest::construct, @@ -114,10 +114,10 @@ void QuaternionTest::constructFromVector() { } void QuaternionTest::compare() { - CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); - CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); } void QuaternionTest::constExpressions() { @@ -139,7 +139,7 @@ void QuaternionTest::constExpressions() { /* Data access */ constexpr Vector3 e = b.vector(); - constexpr float f = b.scalar(); + constexpr Float f = b.scalar(); CORRADE_COMPARE(e, Vector3(1.0f, -3.0f, 7.0f)); CORRADE_COMPARE(f, 2.5f); } @@ -215,7 +215,7 @@ void QuaternionTest::invertedNormalized() { Error::setOutput(&o); Quaternion notInverted = a.invertedNormalized(); CORRADE_COMPARE(notInverted.vector(), Vector3()); - CORRADE_COMPARE(notInverted.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(notInverted.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::invertedNormalized(): quaternion must be normalized\n"); Quaternion aNormalized = a.normalized(); @@ -229,7 +229,7 @@ void QuaternionTest::rotation() { std::ostringstream o; Error::setOutput(&o); - Vector3 axis(1.0f/Constants::sqrt3()); + Vector3 axis(1.0f/Constants::sqrt3()); CORRADE_COMPARE(Quaternion::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion()); CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); @@ -273,8 +273,8 @@ void QuaternionTest::angle() { } void QuaternionTest::matrix() { - Quaternion q = Quaternion::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())); - Matrix3 m = Matrix4::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); + Quaternion q = Quaternion::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())); + Matrix3 m = Matrix4::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); /* Verify that negated quaternion gives the same rotation */ CORRADE_COMPARE(q.toMatrix(), m); @@ -282,7 +282,7 @@ void QuaternionTest::matrix() { } void QuaternionTest::lerp() { - Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); std::ostringstream o; @@ -290,13 +290,13 @@ void QuaternionTest::lerp() { Quaternion notLerpA = Quaternion::lerp(a*3.0f, b, 0.35f); CORRADE_COMPARE(notLerpA.vector(), Vector3()); - CORRADE_COMPARE(notLerpA.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(notLerpA.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::lerp(): quaternions must be normalized\n"); o.str({}); Quaternion notLerpB = Quaternion::lerp(a, b*-3.0f, 0.35f); CORRADE_COMPARE(notLerpB.vector(), Vector3()); - CORRADE_COMPARE(notLerpB.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(notLerpB.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::lerp(): quaternions must be normalized\n"); Quaternion lerp = Quaternion::lerp(a, b, 0.35f); @@ -304,7 +304,7 @@ void QuaternionTest::lerp() { } void QuaternionTest::slerp() { - Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); + Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); std::ostringstream o; @@ -312,13 +312,13 @@ void QuaternionTest::slerp() { Quaternion notSlerpA = Quaternion::slerp(a*3.0f, b, 0.35f); CORRADE_COMPARE(notSlerpA.vector(), Vector3()); - CORRADE_COMPARE(notSlerpA.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(notSlerpA.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::slerp(): quaternions must be normalized\n"); o.str({}); Quaternion notSlerpB = Quaternion::slerp(a, b*-3.0f, 0.35f); CORRADE_COMPARE(notSlerpB.vector(), Vector3()); - CORRADE_COMPARE(notSlerpB.scalar(), std::numeric_limits::quiet_NaN()); + CORRADE_COMPARE(notSlerpB.scalar(), std::numeric_limits::quiet_NaN()); CORRADE_COMPARE(o.str(), "Math::Quaternion::slerp(): quaternions must be normalized\n"); Quaternion slerp = Quaternion::slerp(a, b, 0.35f); diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 5f3e8867f..2e1cf095d 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -55,14 +55,14 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void configuration(); }; -typedef RectangularMatrix<4, 3, float> Matrix4x3; -typedef RectangularMatrix<3, 4, float> Matrix3x4; -typedef RectangularMatrix<2, 2, float> Matrix2; -typedef RectangularMatrix<2, 2, std::int32_t> Matrix2i; -typedef Vector<4, float> Vector4; -typedef Vector<3, float> Vector3; -typedef Vector<2, float> Vector2; -typedef Vector<2, std::int32_t> Vector2i; +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 Vector<4, Float> Vector4; +typedef Vector<3, Float> Vector3; +typedef Vector<2, Float> Vector2; +typedef Vector<2, Int> Vector2i; RectangularMatrixTest::RectangularMatrixTest() { addTests(&RectangularMatrixTest::constructFromData, @@ -96,7 +96,7 @@ RectangularMatrixTest::RectangularMatrixTest() { } void RectangularMatrixTest::constructFromData() { - float m[] = { + Float m[] = { 3.0f, 5.0f, 8.0f, 4.0f, 4.0f, 4.0f, 7.0f, 3.0f, 7.0f, -1.0f, 8.0f, 0.0f @@ -121,15 +121,15 @@ void RectangularMatrixTest::constructDefault() { } void RectangularMatrixTest::constructConversion() { - Matrix2 floatingPoint(Vector2( 1.3f, 2.7f), + Matrix2 FloatingPoint(Vector2( 1.3f, 2.7f), Vector2(-15.0f, 7.0f)); - Matrix2 floatingPointRounded(Vector2(1.0f, 2.0f), + Matrix2 FloatingPointRounded(Vector2(1.0f, 2.0f), Vector2(-15.0f, 7.0f)); Matrix2i integral(Vector2i( 1, 2), Vector2i(-15, 7)); - CORRADE_COMPARE(Matrix2i(floatingPoint), integral); - CORRADE_COMPARE(Matrix2(integral), floatingPointRounded); + CORRADE_COMPARE(Matrix2i(FloatingPoint), integral); + CORRADE_COMPARE(Matrix2(integral), FloatingPointRounded); } void RectangularMatrixTest::constructFromVectors() { @@ -194,8 +194,8 @@ void RectangularMatrixTest::constExpressions() { Vector4(7.0f, -1.7f, 8.0f, 0.0f))); /* Conversion constructor */ - typedef RectangularMatrix<3, 4, std::int32_t> Matrix3x4i; - typedef Vector<4, std::int32_t> Vector4i; + typedef RectangularMatrix<3, 4, Int> Matrix3x4i; + typedef Vector<4, Int> Vector4i; constexpr Matrix3x4i c(b); CORRADE_COMPARE(c, Matrix3x4i(Vector4i(3, 5, 8, 4), Vector4i(4, 4, 7, 3), @@ -209,8 +209,8 @@ void RectangularMatrixTest::constExpressions() { /* Data access, pointer chasings, i.e. *(b.data()[1]), are not possible */ constexpr Vector4 e = b[2]; - constexpr float f = b[1][2]; - constexpr float g = *b.data(); + constexpr Float f = b[1][2]; + constexpr Float g = *b.data(); CORRADE_COMPARE(e, Vector4(7.0f, -1.7f, 8.0f, 0.0f)); CORRADE_COMPARE(f, 7.0f); CORRADE_COMPARE(g, 3.0f); @@ -219,9 +219,9 @@ void RectangularMatrixTest::constExpressions() { void RectangularMatrixTest::compare() { Matrix2 a(Vector2(1.0f, -3.0f), Vector2(5.0f, -10.0f)); - Matrix2 b(Vector2(1.0f + MathTypeTraits::epsilon()/2, -3.0f), + Matrix2 b(Vector2(1.0f + MathTypeTraits::epsilon()/2, -3.0f), Vector2(5.0f, -10.0f)); - Matrix2 c(Vector2(1.0f, -1.0f + MathTypeTraits::epsilon()*2), + Matrix2 c(Vector2(1.0f, -1.0f + MathTypeTraits::epsilon()*2), Vector2(5.0f, -10.0f)); CORRADE_VERIFY(a == b); CORRADE_VERIFY(a != c); @@ -270,8 +270,8 @@ void RectangularMatrixTest::multiplyDivide() { CORRADE_COMPARE(-1.5f*matrix, multiplied); CORRADE_COMPARE(multiplied/-1.5f, matrix); - Math::RectangularMatrix<1, 1, std::int8_t> matrixChar(32); - Math::RectangularMatrix<1, 1, std::int8_t> multipliedChar(-48); + Math::RectangularMatrix<1, 1, Byte> matrixChar(32); + Math::RectangularMatrix<1, 1, Byte> multipliedChar(-48); CORRADE_COMPARE(matrixChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, matrixChar); CORRADE_COMPARE(-1.5f*matrixChar, multipliedChar); @@ -286,27 +286,27 @@ void RectangularMatrixTest::multiplyDivide() { } void RectangularMatrixTest::multiply() { - RectangularMatrix<4, 6, std::int32_t> left( - Vector<6, std::int32_t>(-5, 27, 10, 33, 0, -15), - Vector<6, std::int32_t>( 7, 56, 66, 1, 0, -24), - Vector<6, std::int32_t>( 4, 41, 4, 0, 1, -4), - Vector<6, std::int32_t>( 9, -100, 19, -49, 1, 9) + RectangularMatrix<4, 6, Int> left( + Vector<6, Int>(-5, 27, 10, 33, 0, -15), + Vector<6, Int>( 7, 56, 66, 1, 0, -24), + Vector<6, Int>( 4, 41, 4, 0, 1, -4), + Vector<6, Int>( 9, -100, 19, -49, 1, 9) ); - RectangularMatrix<5, 4, std::int32_t> right( - Vector<4, std::int32_t>(1, -7, 0, 158), - Vector<4, std::int32_t>(2, 24, -3, 40), - Vector<4, std::int32_t>(3, -15, -2, -50), - Vector<4, std::int32_t>(4, 17, -1, -284), - Vector<4, std::int32_t>(5, 30, 4, 18) + RectangularMatrix<5, 4, Int> right( + Vector<4, Int>(1, -7, 0, 158), + Vector<4, Int>(2, 24, -3, 40), + Vector<4, Int>(3, -15, -2, -50), + Vector<4, Int>(4, 17, -1, -284), + Vector<4, Int>(5, 30, 4, 18) ); - RectangularMatrix<5, 6, std::int32_t> expected( - Vector<6, std::int32_t>( 1368, -16165, 2550, -7716, 158, 1575), - Vector<6, std::int32_t>( 506, -2725, 2352, -1870, 37, -234), - Vector<6, std::int32_t>( -578, 4159, -1918, 2534, -52, -127), - Vector<6, std::int32_t>(-2461, 29419, -4238, 14065, -285, -3020), - Vector<6, std::int32_t>( 363, 179, 2388, -687, 22, -649) + RectangularMatrix<5, 6, Int> expected( + Vector<6, Int>( 1368, -16165, 2550, -7716, 158, 1575), + Vector<6, Int>( 506, -2725, 2352, -1870, 37, -234), + Vector<6, Int>( -578, 4159, -1918, 2534, -52, -127), + Vector<6, Int>(-2461, 29419, -4238, 14065, -285, -3020), + Vector<6, Int>( 363, 179, 2388, -687, 22, -649) ); CORRADE_COMPARE(left*right, expected); @@ -399,7 +399,7 @@ void RectangularMatrixTest::debug() { " 4, 3, 0)\n"); o.str({}); - Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, std::int8_t>(); + Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, Byte>(); CORRADE_COMPARE(o.str(), "a Matrix(0, 0, 0,\n" " 0, 0, 0,\n" " 0, 0, 0,\n" diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp index 795d4297a..fd51bdc38 100644 --- a/src/Math/Test/SwizzleTest.cpp +++ b/src/Math/Test/SwizzleTest.cpp @@ -29,7 +29,7 @@ class SwizzleTest: public Corrade::TestSuite::Tester { void constExpressions(); }; -typedef Vector<4, std::int32_t> Vector4i; +typedef Vector<4, Int> Vector4i; SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::components, @@ -47,12 +47,12 @@ void SwizzleTest::constants() { } void SwizzleTest::sizes() { - CORRADE_COMPARE((swizzle<'y', 'x', 'x'>(Math::Vector<2, std::int32_t>(1, 2))), - (Math::Vector<3, std::int32_t>(2, 1, 1))); + CORRADE_COMPARE((swizzle<'y', 'x', 'x'>(Math::Vector<2, Int>(1, 2))), + (Math::Vector<3, Int>(2, 1, 1))); CORRADE_COMPARE(swizzle<'z'>(Vector4i(1, 2, 3, 4)), - (Math::Vector<1, std::int32_t>(3))); + (Math::Vector<1, Int>(3))); CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y', 'z', 'y', 'x'>(Vector4i(1, 2, 3, 4))), - (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); + (Math::Vector<7, Int>(3, 1, 4, 2, 3, 2, 1))); } void SwizzleTest::constExpressions() { diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index a0a57978b..347474d53 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -45,16 +45,16 @@ UnitTest::UnitTest() { } template struct Sec_; -typedef Unit Sec; -typedef Unit Secd; +typedef Unit Sec; +typedef Unit Secd; inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, Sec value) { - return debug << float(value); + return debug << Float(value); } void UnitTest::construct() { constexpr Sec a(25.0f); - CORRADE_COMPARE(float(a), 25.0f); + CORRADE_COMPARE(Float(a), 25.0f); } void UnitTest::constructDefault() { @@ -69,8 +69,8 @@ void UnitTest::constructConversion() { } void UnitTest::compare() { - CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()/2) == Sec(25.0f)); - CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()*2) != Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()/2) == Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()*2) != Sec(25.0f)); constexpr bool c = Sec(3.0f) < Sec(3.0f); constexpr bool d = Sec(3.0f) <= Sec(3.0f); @@ -129,7 +129,7 @@ void UnitTest::multiplyDivide() { CORRADE_COMPARE(e, b); CORRADE_COMPARE(f, a); - constexpr float g = b/a; + constexpr Float g = b/a; CORRADE_COMPARE(g, -1.5f); } diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 4314ee219..31d017b6f 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -34,7 +34,7 @@ class Vector2Test: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Math::Vector2 Vector2; +typedef Math::Vector2 Vector2; Vector2Test::Vector2Test() { addTests(&Vector2Test::construct, @@ -46,7 +46,7 @@ Vector2Test::Vector2Test() { } void Vector2Test::construct() { - CORRADE_COMPARE(Vector2(1, 2), (Vector<2, float>(1.0f, 2.0f))); + CORRADE_COMPARE(Vector2(1, 2), (Vector<2, Float>(1.0f, 2.0f))); } void Vector2Test::access() { diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 36204c764..4c25b28c6 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -36,8 +36,8 @@ class Vector3Test: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Math::Vector3 Vector3; -typedef Math::Vector2 Vector2; +typedef Math::Vector3 Vector3; +typedef Math::Vector2 Vector2; Vector3Test::Vector3Test() { addTests(&Vector3Test::construct, @@ -52,8 +52,8 @@ Vector3Test::Vector3Test() { void Vector3Test::construct() { CORRADE_COMPARE(Vector3(), Vector3(0.0f, 0.0f, 0.0f)); - CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); - CORRADE_COMPARE(Vector3(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f))); + CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, Float>(1.0f, 2.0f, 3.0f))); + CORRADE_COMPARE(Vector3(Vector<2, Float>(1.0f, 2.0f), 3), (Vector<3, Float>(1.0f, 2.0f, 3.0f))); } void Vector3Test::access() { diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index a5d5953ae..a52063e65 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -34,9 +34,9 @@ class Vector4Test: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Math::Vector4 Vector4; -typedef Math::Vector3 Vector3; -typedef Math::Vector2 Vector2; +typedef Math::Vector4 Vector4; +typedef Math::Vector3 Vector3; +typedef Math::Vector2 Vector2; Vector4Test::Vector4Test() { addTests(&Vector4Test::construct, @@ -49,8 +49,8 @@ Vector4Test::Vector4Test() { void Vector4Test::construct() { CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); - CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); - CORRADE_COMPARE(Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); + CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, Float>(1.0f, 2.0f, 3.0f, 4.0f))); + CORRADE_COMPARE(Vector4(Vector<3, Float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, Float>(1.0f, 2.0f, 3.0f, 4.0f))); } void Vector4Test::access() { diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index d334430a3..24a1003ca 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -62,10 +62,10 @@ class VectorTest: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Math::Rad Rad; -typedef Vector<3, float> Vector3; -typedef Vector<4, float> Vector4; -typedef Vector<4, std::int32_t> Vector4i; +typedef Math::Rad Rad; +typedef Vector<3, Float> Vector3; +typedef Vector<4, Float> Vector4; +typedef Vector<4, Int> Vector4i; VectorTest::VectorTest() { addTests(&VectorTest::constructFromData, @@ -106,7 +106,7 @@ VectorTest::VectorTest() { } void VectorTest::constructFromData() { - float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; + Float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; CORRADE_COMPARE(Vector4::from(data), Vector4(1.0f, 2.0f, 3.0f, 4.0f)); } @@ -119,7 +119,7 @@ void VectorTest::constructOneValue() { } void VectorTest::constructOneComponent() { - typedef Vector<1, float> Vector1; + typedef Vector<1, Float> Vector1; /* Implicit constructor must work */ Vector1 vec = 1; @@ -127,12 +127,12 @@ void VectorTest::constructOneComponent() { } void VectorTest::constructConversion() { - Vector4 floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - Vector4 floatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); + Vector4 FloatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + Vector4 FloatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); Vector4i integral(1, 2, -15, 7); - CORRADE_COMPARE(Vector4i(floatingPoint), integral); - CORRADE_COMPARE(Vector4(integral), floatingPointRounded); + CORRADE_COMPARE(Vector4i(FloatingPoint), integral); + CORRADE_COMPARE(Vector4(integral), FloatingPointRounded); } void VectorTest::data() { @@ -167,15 +167,15 @@ void VectorTest::constExpressions() { CORRADE_COMPARE(e, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); /* Data access, pointer chasings, i.e. *(b.data()[3]), are not possible */ - constexpr float f = b[3]; - constexpr float g = *b.data(); + constexpr Float f = b[3]; + constexpr Float g = *b.data(); CORRADE_COMPARE(f, -2.7f); CORRADE_COMPARE(g, 1.0f); } void VectorTest::compare() { - CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + MathTypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); - CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + MathTypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); CORRADE_VERIFY(Vector4i(1, -3, 5, -10) == Vector4i(1, -3, 5, -10)); CORRADE_VERIFY(Vector4i(1, -3, 5, -10) != Vector4i(1, -2, 5, -10)); @@ -210,8 +210,8 @@ void VectorTest::multiplyDivide() { CORRADE_COMPARE(-1.5f*vector, multiplied); CORRADE_COMPARE(multiplied/-1.5f, vector); - Math::Vector<1, std::int8_t> vectorChar(32); - Math::Vector<1, std::int8_t> multipliedChar(-48); + Math::Vector<1, Byte> vectorChar(32); + Math::Vector<1, Byte> multipliedChar(-48); CORRADE_COMPARE(vectorChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, vectorChar); CORRADE_COMPARE(-1.5f*vectorChar, multipliedChar); diff --git a/src/Math/Vector.cpp b/src/Math/Vector.cpp index 3e54dedd8..c01650c88 100644 --- a/src/Math/Vector.cpp +++ b/src/Math/Vector.cpp @@ -18,19 +18,19 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, float>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, unsigned int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, unsigned int>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, unsigned int>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, Float>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, Int>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, Int>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, Int>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, UnsignedInt>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, UnsignedInt>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, UnsignedInt>&); #ifndef MAGNUM_TARGET_GLES -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, double>&); -template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<2, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<3, Double>&); +template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnum::Math::Vector<4, Double>&); #endif #endif @@ -39,19 +39,19 @@ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Magnu namespace Corrade { namespace Utility { #ifndef DOXYGEN_GENERATING_OUTPUT -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; #ifndef MAGNUM_TARGET_GLES -template struct ConfigurationValue>; -template struct ConfigurationValue>; -template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; +template struct ConfigurationValue>; #endif #endif diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 8630cca78..833554cb8 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -127,8 +127,8 @@ template class Vector { * Performs only default casting on the values, no rounding or * anything else. Example usage: * @code - * Vector<4, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * Vector<4, std::int8_t> integral(floatingPoint); + * Vector<4, Float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); + * Vector<4, Byte> integral(floatingPoint); * // integral == {1, 2, -15, 7} * @endcode */ @@ -556,19 +556,19 @@ template Corrade::Utility::Debug operator<<(Corrade:: /* Explicit instantiation for types used in OpenGL */ #ifndef DOXYGEN_GENERATING_OUTPUT -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, float>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, unsigned int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, unsigned int>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, unsigned int>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, Float>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, Int>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, Int>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, Int>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, UnsignedInt>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, UnsignedInt>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, UnsignedInt>&); #ifndef MAGNUM_TARGET_GLES -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, double>&); -extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<2, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<3, Double>&); +extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Vector<4, Double>&); #endif #endif @@ -689,19 +689,19 @@ template struct ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; #ifndef MAGNUM_TARGET_GLES -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; -extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; +extern template struct MAGNUM_EXPORT ConfigurationValue>; #endif #endif From 2d2d1c07f403a82895f491dc44d3afe02633eb25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 22:49:26 +0100 Subject: [PATCH 464/567] Using new type aliases in whole root Magnum namespace. --- src/AbstractShaderProgram.cpp | 46 ++--- src/AbstractShaderProgram.h | 232 ++++++++++++------------- src/AbstractTexture.cpp | 8 +- src/AbstractTexture.h | 16 +- src/Array.h | 16 +- src/BufferImage.cpp | 2 +- src/BufferImage.h | 10 +- src/BufferTexture.h | 2 +- src/Color.h | 4 +- src/Context.h | 10 +- src/CubeMapTexture.h | 12 +- src/CubeMapTextureArray.h | 18 +- src/DefaultFramebuffer.cpp | 2 +- src/DefaultFramebuffer.h | 2 +- src/DimensionTraits.h | 26 +-- src/Framebuffer.cpp | 4 +- src/Framebuffer.h | 12 +- src/Image.cpp | 2 +- src/Image.h | 12 +- src/ImageWrapper.h | 12 +- src/Magnum.h | 22 +-- src/Mesh.cpp | 2 +- src/Mesh.h | 48 ++--- src/Query.cpp | 16 +- src/Query.h | 32 ++-- src/Renderer.h | 28 +-- src/Resource.h | 2 +- src/ResourceManager.h | 12 +- src/Test/AbstractShaderProgramTest.cpp | 8 +- src/Test/ColorTest.cpp | 10 +- src/Test/ResourceManagerTest.cpp | 24 +-- src/Test/SwizzleTest.cpp | 16 +- src/Texture.h | 16 +- src/Timeline.cpp | 4 +- src/Timeline.h | 14 +- 35 files changed, 351 insertions(+), 351 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index b8a3c03f1..b5f09a957 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -29,16 +29,16 @@ namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(std::is_same::value, "GLubyte is not the same as std::uint8_t"); -static_assert(std::is_same::value, "GLbyte is not the same as std::int8_t"); -static_assert(std::is_same::value, "GLushort is not the same as std::uint16_t"); -static_assert(std::is_same::value, "GLshort is not the same as std::int16_t"); -static_assert(std::is_same::value, "GLuint is not the same as std::uint32_t"); -static_assert(std::is_same::value, "GLint is not the same as std::int32_t"); -static_assert(std::is_same::value, "GLsizei is not the same as std::int32_t"); -static_assert(std::is_same::value, "GLfloat is not the same as float"); +static_assert(std::is_same::value, "GLubyte is not the same as UnsignedByte"); +static_assert(std::is_same::value, "GLbyte is not the same as Byte"); +static_assert(std::is_same::value, "GLushort is not the same as UnsignedShort"); +static_assert(std::is_same::value, "GLshort is not the same as Short"); +static_assert(std::is_same::value, "GLuint is not the same as UnsignedInt"); +static_assert(std::is_same::value, "GLint is not the same as Int"); +static_assert(std::is_same::value, "GLsizei is not the same as Int"); +static_assert(std::is_same::value, "GLfloat is not the same as Float"); #ifndef MAGNUM_TARGET_GLES -static_assert(std::is_same::value, "GLdouble is not the same as double"); +static_assert(std::is_same::value, "GLdouble is not the same as Double"); #endif #endif @@ -86,7 +86,7 @@ AbstractShaderProgram::UniformMatrix3x4dvImplementation AbstractShaderProgram::u AbstractShaderProgram::UniformMatrix4x3dvImplementation AbstractShaderProgram::uniformMatrix4x3dvImplementation = &AbstractShaderProgram::uniformImplementationDefault; #endif -GLint AbstractShaderProgram::maxSupportedVertexAttributeCount() { +Int AbstractShaderProgram::maxSupportedVertexAttributeCount() { GLint& value = Context::current()->state()->shaderProgram->maxSupportedVertexAttributeCount; /* Get the value, if not already cached */ @@ -121,19 +121,19 @@ bool AbstractShaderProgram::attachShader(Shader& shader) { return true; } -void AbstractShaderProgram::bindAttributeLocation(GLuint location, const std::string& name) { +void AbstractShaderProgram::bindAttributeLocation(UnsignedInt location, const std::string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: attribute cannot be bound after linking.", ); glBindAttribLocation(_id, location, name.c_str()); } #ifndef MAGNUM_TARGET_GLES -void AbstractShaderProgram::bindFragmentDataLocation(GLuint location, const std::string& name) { +void AbstractShaderProgram::bindFragmentDataLocation(UnsignedInt location, const std::string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: fragment data location cannot be bound after linking.", ); glBindFragDataLocation(_id, location, name.c_str()); } -void AbstractShaderProgram::bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name) { +void AbstractShaderProgram::bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name) { CORRADE_ASSERT(state == Initialized, "AbstractShaderProgram: fragment data location cannot be bound after linking.", ); glBindFragDataLocationIndexed(_id, location, index, name.c_str()); @@ -169,7 +169,7 @@ void AbstractShaderProgram::link() { state = status == GL_FALSE ? Failed : Linked; } -GLint AbstractShaderProgram::uniformLocation(const std::string& name) { +Int AbstractShaderProgram::uniformLocation(const std::string& name) { /** @todo What if linking just failed (not programmer error?) */ CORRADE_ASSERT(state == Linked, "AbstractShaderProgram: uniform location cannot be retrieved before linking.", -1); @@ -640,7 +640,7 @@ std::size_t DoubleAttribute::size(GLint components, DataType dataType) { } #endif -std::size_t Attribute>::size(GLint components, DataType dataType) { +std::size_t Attribute>::size(GLint components, DataType dataType) { #ifndef MAGNUM_TARGET_GLES if(components == GL_BGRA) components = 4; #endif @@ -749,18 +749,18 @@ Debug operator<<(Debug debug, SizedMatrixAttribute<4>::Components value) { return debug << "AbstractShaderProgram::Attribute::Components::(invalid)"; } -Debug operator<<(Debug debug, Attribute>::Components value) { +Debug operator<<(Debug debug, Attribute>::Components value) { switch(value) { - case Attribute>::Components::One: + case Attribute>::Components::One: return debug << "AbstractShaderProgram::Attribute::Components::One"; - case Attribute>::Components::Two: + case Attribute>::Components::Two: return debug << "AbstractShaderProgram::Attribute::Components::Two"; - case Attribute>::Components::Three: + case Attribute>::Components::Three: return debug << "AbstractShaderProgram::Attribute::Components::Three"; - case Attribute>::Components::Four: + case Attribute>::Components::Four: return debug << "AbstractShaderProgram::Attribute::Components::Four"; #ifndef MAGNUM_TARGET_GLES - case Attribute>::Components::BGRA: + case Attribute>::Components::BGRA: return debug << "AbstractShaderProgram::Attribute::Components::BGRA"; #endif } @@ -817,9 +817,9 @@ Debug operator<<(Debug debug, DoubleAttribute::DataType value) { } #endif -Debug operator<<(Debug debug, Attribute>::DataType value) { +Debug operator<<(Debug debug, Attribute>::DataType value) { switch(value) { - #define _c(value) case Attribute>::DataType::value: return debug << "AbstractShaderProgram::Attribute::DataType::" #value; + #define _c(value) case Attribute>::DataType::value: return debug << "AbstractShaderProgram::Attribute::DataType::" #value; _c(UnsignedByte) _c(Byte) _c(UnsignedShort) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index c38b7de4a..658281fa6 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -52,7 +52,7 @@ typedef Attribute<2, Vector2> TextureCoordinates; @endcode - **Output attribute locations**, if desired, for example: @code -enum: GLuint { +enum: UnsignedInt { ColorOutput = 0, NormalOutput = 1 }; @@ -60,7 +60,7 @@ enum: GLuint { - **Layers for texture uniforms** to which the textures will be bound before rendering, for example: @code -enum: GLint { +enum: Int { DiffuseTextureLayer = 0, SpecularTextureLayer = 1 }; @@ -68,7 +68,7 @@ enum: GLint { - **Uniform locations** for setting uniform data (see below) (private variables), for example: @code -GLint TransformationUniform = 0, +Int TransformationUniform = 0, ProjectionUniform = 1, DiffuseTextureUniform = 2, SpecularTextureUniform = 3; @@ -164,8 +164,8 @@ layout(location = 1) uniform mat4 projection; If you don't have the required extension, you can get uniform location using uniformLocation() after linking stage: @code -GLint transformationUniform = uniformLocation("transformation"); -GLint projectionUniform = uniformLocation("projection"); +Int transformationUniform = uniformLocation("transformation"); +Int projectionUniform = uniformLocation("projection"); @endcode @requires_gl43 %Extension @extension{ARB,explicit_uniform_location} for @@ -185,16 +185,16 @@ layout(binding = 1) uniform sampler2D specularTexture; @endcode If you don't have the required extension (or if you want to change the layer -later), you can set the texture layer uniform using setUniform(GLint, GLint): +later), you can set the texture layer uniform using setUniform(Int, Int): @code setUniform(DiffuseTextureUniform, DiffuseTextureLayer); setUniform(SpecularTextureUniform, SpecularTextureLayer); @endcode @requires_gl42 %Extension @extension{ARB,shading_language_420pack} for explicit - texture layer binding instead of using setUniform(GLint, GLint). + texture layer binding instead of using setUniform(Int, Int). @requires_gl Explicit texture layer binding is not supported in OpenGL ES. Use - setUniform(GLint, GLint) instead. + setUniform(Int, Int) instead. @section AbstractShaderProgram-rendering-workflow Rendering workflow @@ -204,7 +204,7 @@ for more information) and map shader outputs to framebuffer attachments if needed (see @ref Framebuffer-usage "Framebuffer documentation" for more information). In each draw event set uniforms, mark the shader for use, bind specific framebuffer (if needed) and bind required textures to their -respective layers using AbstractTexture::bind(GLint). Then call Mesh::draw(). +respective layers using AbstractTexture::bind(Int). Then call Mesh::draw(). Example: @code shader->setTransformation(transformation) @@ -252,7 +252,7 @@ are cached, so repeated queries don't result in repeated @fn_gl{Get} calls. If extension @extension{ARB,separate_shader_objects} or @extension{EXT,direct_state_access} is available, uniform setting functions use DSA functions to avoid unnecessary calls to @fn_gl{UseProgram}. See -setUniform(GLint, GLfloat) documentation for more information. +setUniform() documentation for more information. To achieve least state changes, set all uniforms in one run -- method chaining comes in handy. @@ -293,9 +293,9 @@ class MAGNUM_EXPORT AbstractShaderProgram { * shaders and @ref Mesh-configuration for example usage when adding * vertex buffers to mesh. */ - template class Attribute { + template class Attribute { public: - enum: GLuint { + enum: UnsignedInt { Location = location /**< Location to which the attribute is bound */ }; @@ -424,7 +424,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @see DataOptions, Attribute() */ #ifdef DOXYGEN_GENERATING_OUTPUT - enum class DataOption: std::uint8_t { + enum class DataOption: UnsignedByte { /** * Normalize integer components. Only for float attribute * types. Default is to not normalize. @@ -440,7 +440,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @see Attribute() */ #ifdef DOXYGEN_GENERATING_OUTPUT - typedef typename Corrade::Containers::EnumSet DataOptions; + typedef typename Corrade::Containers::EnumSet DataOptions; #else typedef typename Implementation::Attribute::DataOptions DataOptions; #endif @@ -494,7 +494,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * OpenGL calls. * @see Attribute, @fn_gl{Get} with @def_gl{MAX_VERTEX_ATTRIBS} */ - static GLint maxSupportedVertexAttributeCount(); + static Int maxSupportedVertexAttributeCount(); /** * @brief Constructor @@ -590,7 +590,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * for more information. * @see @fn_gl{BindAttribLocation} */ - void bindAttributeLocation(GLuint location, const std::string& name); + void bindAttributeLocation(UnsignedInt location, const std::string& name); #ifndef MAGNUM_TARGET_GLES /** @@ -613,7 +613,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Multiple blend function inputs are not available in * OpenGL ES. */ - void bindFragmentDataLocationIndexed(GLuint location, GLuint index, const std::string& name); + void bindFragmentDataLocationIndexed(UnsignedInt location, UnsignedInt index, const std::string& name); /** * @brief Bind fragment data to given location and first color input index @@ -627,7 +627,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @requires_gl Use explicit location specification in OpenGL ES 3.0 * instead. */ - void bindFragmentDataLocation(GLuint location, const std::string& name); + void bindFragmentDataLocation(UnsignedInt location, const std::string& name); #endif /** @@ -651,7 +651,7 @@ class MAGNUM_EXPORT AbstractShaderProgram { * for more information. * @see @fn_gl{GetUniformLocation} */ - GLint uniformLocation(const std::string& name); + Int uniformLocation(const std::string& name); /** * @brief Set uniform value @@ -664,265 +664,265 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @see @fn_gl{UseProgram}, @fn_gl{Uniform} or `glProgramUniform()` * from @extension{ARB,separate_shader_objects}/@extension{EXT,direct_state_access}. */ - inline void setUniform(GLint location, GLfloat value) { + inline void setUniform(Int location, Float value) { (this->*uniform1fImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Vector<2, GLfloat>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Vector<2, Float>& value) { (this->*uniform2fvImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Vector<3, GLfloat>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Vector<3, Float>& value) { (this->*uniform3fvImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Vector<4, GLfloat>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Vector<4, Float>& value) { (this->*uniform4fvImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, GLint value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, Int value) { (this->*uniform1iImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Vector<2, GLint>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Vector<2, Int>& value) { (this->*uniform2ivImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Vector<3, GLint>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Vector<3, Int>& value) { (this->*uniform3ivImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Vector<4, GLint>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Vector<4, Int>& value) { (this->*uniform4ivImplementation)(location, value); } #ifndef MAGNUM_TARGET_GLES2 /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, GLuint value) { + inline void setUniform(Int location, UnsignedInt value) { (this->*uniform1uiImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::Vector<2, GLuint>& value) { + inline void setUniform(Int location, const Math::Vector<2, UnsignedInt>& value) { (this->*uniform2uivImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::Vector<3, GLuint>& value) { + inline void setUniform(Int location, const Math::Vector<3, UnsignedInt>& value) { (this->*uniform3uivImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl30 %Extension @extension{EXT,gpu_shader4} * @requires_gles30 Only signed integers are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::Vector<4, GLuint>& value) { + inline void setUniform(Int location, const Math::Vector<4, UnsignedInt>& value) { (this->*uniform4uivImplementation)(location, value); } #endif #ifndef MAGNUM_TARGET_GLES /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, GLdouble value) { + inline void setUniform(Int location, Double value) { (this->*uniform1dImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::Vector<2, GLdouble>& value) { + inline void setUniform(Int location, const Math::Vector<2, Double>& value) { (this->*uniform2dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::Vector<3, GLdouble>& value) { + inline void setUniform(Int location, const Math::Vector<3, Double>& value) { (this->*uniform3dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::Vector<4, GLdouble>& value) { + inline void setUniform(Int location, const Math::Vector<4, Double>& value) { (this->*uniform4dvImplementation)(location, value); } #endif - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Matrix<2, GLfloat>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Matrix<2, Float>& value) { (this->*uniformMatrix2fvImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Matrix<3, GLfloat>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Matrix<3, Float>& value) { (this->*uniformMatrix3fvImplementation)(location, value); } - /** @copydoc setUniform(GLint, GLfloat) */ - inline void setUniform(GLint location, const Math::Matrix<4, GLfloat>& value) { + /** @copydoc setUniform(Int, Float) */ + inline void setUniform(Int location, const Math::Matrix<4, Float>& value) { (this->*uniformMatrix4fvImplementation)(location, value); } #ifndef MAGNUM_TARGET_GLES2 /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLfloat>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<2, 3, Float>& value) { (this->*uniformMatrix2x3fvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLfloat>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<3, 2, Float>& value) { (this->*uniformMatrix3x2fvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLfloat>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<2, 4, Float>& value) { (this->*uniformMatrix2x4fvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLfloat>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<4, 2, Float>& value) { (this->*uniformMatrix4x2fvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLfloat>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<3, 4, Float>& value) { (this->*uniformMatrix3x4fvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gles30 Only square matrices are available in OpenGL ES 2.0. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLfloat>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<4, 3, Float>& value) { (this->*uniformMatrix4x3fvImplementation)(location, value); } #endif #ifndef MAGNUM_TARGET_GLES /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::Matrix<2, GLdouble>& value) { + inline void setUniform(Int location, const Math::Matrix<2, Double>& value) { (this->*uniformMatrix2dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::Matrix<3, GLdouble>& value) { + inline void setUniform(Int location, const Math::Matrix<3, Double>& value) { (this->*uniformMatrix3dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::Matrix<4, GLdouble>& value) { + inline void setUniform(Int location, const Math::Matrix<4, Double>& value) { (this->*uniformMatrix4dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<2, 3, GLdouble>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<2, 3, Double>& value) { (this->*uniformMatrix2x3dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<3, 2, GLdouble>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<3, 2, Double>& value) { (this->*uniformMatrix3x2dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<2, 4, GLdouble>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<2, 4, Double>& value) { (this->*uniformMatrix2x4dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<4, 2, GLdouble>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<4, 2, Double>& value) { (this->*uniformMatrix4x2dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<3, 4, GLdouble>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<3, 4, Double>& value) { (this->*uniformMatrix3x4dvImplementation)(location, value); } /** - * @copydoc setUniform(GLint, GLfloat) + * @copydoc setUniform(Int, Float) * @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} * @requires_gl Only floats are available in OpenGL ES. */ - inline void setUniform(GLint location, const Math::RectangularMatrix<4, 3, GLdouble>& value) { + inline void setUniform(Int location, const Math::RectangularMatrix<4, 3, Double>& value) { (this->*uniformMatrix4x3dvImplementation)(location, value); } #endif @@ -1175,7 +1175,7 @@ template struct Attribute; /* Base for float attributes */ struct FloatAttribute { - typedef GLfloat Type; + typedef Float Type; enum class DataType: GLenum { UnsignedByte = GL_UNSIGNED_BYTE, @@ -1198,10 +1198,10 @@ struct FloatAttribute { }; constexpr static DataType DefaultDataType = DataType::Float; - enum class DataOption: std::uint8_t { + enum class DataOption: UnsignedByte { Normalized = 1 << 0 }; - typedef Corrade::Containers::EnumSet DataOptions; + typedef Corrade::Containers::EnumSet DataOptions; static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; @@ -1213,7 +1213,7 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, FloatAttribute::DataType value); #ifndef MAGNUM_TARGET_GLES2 /* Base for int attributes */ struct IntAttribute { - typedef GLint Type; + typedef Int Type; enum class DataType: GLenum { UnsignedByte = GL_UNSIGNED_BYTE, @@ -1225,8 +1225,8 @@ struct IntAttribute { }; constexpr static DataType DefaultDataType = DataType::Int; - enum class DataOption: std::uint8_t {}; - typedef Corrade::Containers::EnumSet DataOptions; + enum class DataOption: UnsignedByte {}; + typedef Corrade::Containers::EnumSet DataOptions; static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; @@ -1235,13 +1235,13 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, IntAttribute::DataType value); /* Base for unsigned int attributes */ struct UnsignedIntAttribute { - typedef GLuint Type; + typedef UnsignedInt Type; typedef IntAttribute::DataType DataType; constexpr static DataType DefaultDataType = DataType::UnsignedInt; typedef IntAttribute::DataOption DataOption; - typedef Corrade::Containers::EnumSet DataOptions; + typedef Corrade::Containers::EnumSet DataOptions; inline static std::size_t size(GLint components, DataType dataType) { return IntAttribute::size(components, dataType); @@ -1252,15 +1252,15 @@ struct UnsignedIntAttribute { #ifndef MAGNUM_TARGET_GLES /* Base for double attributes */ struct DoubleAttribute { - typedef GLdouble Type; + typedef Double Type; enum class DataType: GLenum { Double = GL_DOUBLE }; constexpr static DataType DefaultDataType = DataType::Double; - enum class DataOption: std::uint8_t {}; - typedef Corrade::Containers::EnumSet DataOptions; + enum class DataOption: UnsignedByte {}; + typedef Corrade::Containers::EnumSet DataOptions; static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; @@ -1269,8 +1269,8 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, DoubleAttribute::DataType value); #endif /* Floating-point four-component vector is absolutely special case */ -template<> struct Attribute> { - typedef GLfloat Type; +template<> struct Attribute> { + typedef Float Type; enum class Components: GLint { One = 1, @@ -1309,39 +1309,39 @@ template<> struct Attribute> { }; constexpr static DataType DefaultDataType = DataType::Float; - enum class DataOption: std::uint8_t { + enum class DataOption: UnsignedByte { Normalized = 1 << 0 }; - typedef Corrade::Containers::EnumSet DataOptions; + typedef Corrade::Containers::EnumSet DataOptions; inline constexpr static std::size_t vectorCount() { return 1; } static std::size_t MAGNUM_EXPORT size(GLint components, DataType dataType); }; -typedef Math::Vector<4, GLfloat> _Vector4; +typedef Math::Vector<4, Float> _Vector4; CORRADE_ENUMSET_OPERATORS(Attribute<_Vector4>::DataOptions) -Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute>::Components value); -Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute>::DataType value); +Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute>::Components value); +Debug MAGNUM_EXPORT operator<<(Debug debug, Attribute>::DataType value); /* Common float, int, unsigned int and double scalar attributes */ -template<> struct Attribute: FloatAttribute, SizedAttribute<1, 1> {}; +template<> struct Attribute: FloatAttribute, SizedAttribute<1, 1> {}; #ifndef MAGNUM_TARGET_GLES2 -template<> struct Attribute: IntAttribute, SizedAttribute<1, 1> {}; -template<> struct Attribute: UnsignedIntAttribute, SizedAttribute<1, 1> {}; +template<> struct Attribute: IntAttribute, SizedAttribute<1, 1> {}; +template<> struct Attribute: UnsignedIntAttribute, SizedAttribute<1, 1> {}; #ifndef MAGNUM_TARGET_GLES -template<> struct Attribute: DoubleAttribute, SizedAttribute<1, 1> {}; +template<> struct Attribute: DoubleAttribute, SizedAttribute<1, 1> {}; #endif #endif /* Common float, int, unsigned int and double vector attributes */ -template struct Attribute>: FloatAttribute, SizedAttribute<1, size_> {}; +template struct Attribute>: FloatAttribute, SizedAttribute<1, size_> {}; #ifndef MAGNUM_TARGET_GLES2 -template struct Attribute>: IntAttribute, SizedAttribute<1, size_> {}; -template struct Attribute>: UnsignedIntAttribute, SizedAttribute<1, size_> {}; +template struct Attribute>: IntAttribute, SizedAttribute<1, size_> {}; +template struct Attribute>: UnsignedIntAttribute, SizedAttribute<1, size_> {}; #ifndef MAGNUM_TARGET_GLES -template struct Attribute>: DoubleAttribute, SizedAttribute<1, size_> {}; +template struct Attribute>: DoubleAttribute, SizedAttribute<1, size_> {}; #endif #endif template struct Attribute>: Attribute> {}; @@ -1351,15 +1351,15 @@ template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; /* Common float and double rectangular matrix attributes */ -template struct Attribute>: FloatAttribute, SizedAttribute {}; +template struct Attribute>: FloatAttribute, SizedAttribute {}; #ifndef MAGNUM_TARGET_GLES -template struct Attribute>: DoubleAttribute, SizedAttribute {}; +template struct Attribute>: DoubleAttribute, SizedAttribute {}; #endif /* Common float and double square matrix attributes */ -template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; #ifndef MAGNUM_TARGET_GLES -template struct Attribute>: Attribute> {}; +template struct Attribute>: Attribute> {}; #endif template struct Attribute>: Attribute> {}; template struct Attribute>: Attribute> {}; diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 7fe72dca1..440b3820d 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -83,11 +83,11 @@ static_assert((filter_or(NearestNeighbor, BaseLevel) == GL_NEAREST) && #undef filter_or #endif -GLint AbstractTexture::maxSupportedLayerCount() { +Int AbstractTexture::maxSupportedLayerCount() { return Context::current()->state()->texture->maxSupportedLayerCount; } -GLfloat AbstractTexture::maxSupportedAnisotropy() { +Float AbstractTexture::maxSupportedAnisotropy() { GLfloat& value = Context::current()->state()->texture->maxSupportedAnisotropy; /** @todo Re-enable when extension header is available */ @@ -131,7 +131,7 @@ AbstractTexture& AbstractTexture::operator=(AbstractTexture&& other) { return *this; } -void AbstractTexture::bind(GLint layer) { +void AbstractTexture::bind(Int layer) { Implementation::TextureState* const textureState = Context::current()->state()->texture; /* If already bound in given layer, nothing to do */ @@ -453,7 +453,7 @@ void AbstractTexture::invalidateSubImplementationARB(GLint level, const Vector3i #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_TARGET_GLES2 namespace Implementation { - template const GLvoid* ImageHelper>::dataOrPixelUnpackBuffer(BufferImage* image) { + template const GLvoid* ImageHelper>::dataOrPixelUnpackBuffer(BufferImage* image) { image->buffer()->bind(Buffer::Target::PixelUnpack); return nullptr; } diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 2ec6975dc..b1a6095ed 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -979,11 +979,11 @@ class MAGNUM_EXPORT AbstractTexture { * * The result is cached, repeated queries don't result in repeated * OpenGL calls. - * @see @ref AbstractShaderProgram-subclassing, bind(GLint), + * @see @ref AbstractShaderProgram-subclassing, bind(Int), * @fn_gl{Get} with @def_gl{MAX_COMBINED_TEXTURE_IMAGE_UNITS}, * @fn_gl{ActiveTexture} */ - static GLint maxSupportedLayerCount(); + static Int maxSupportedLayerCount(); /** * @brief Max supported anisotropy @@ -994,7 +994,7 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ - static GLfloat maxSupportedAnisotropy(); + static Float maxSupportedAnisotropy(); #ifndef DOXYGEN_GENERATING_OUTPUT inline explicit AbstractTexture(GLenum target): _target(target) { @@ -1030,7 +1030,7 @@ class MAGNUM_EXPORT AbstractTexture { * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} or * @fn_gl_extension{BindMultiTexture,EXT,direct_state_access} */ - void bind(GLint layer); + void bind(Int layer); /** * @brief Set minification filter @@ -1108,7 +1108,7 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ - inline AbstractTexture* setMaxAnisotropy(GLfloat anisotropy) { + inline AbstractTexture* setMaxAnisotropy(Float anisotropy) { (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); return this; } @@ -1122,7 +1122,7 @@ class MAGNUM_EXPORT AbstractTexture { * @see @ref Texture::invalidateSubImage() "invalidateSubImage()", * @fn_gl{InvalidateTexImage} */ - inline void invalidateImage(GLint level) { + inline void invalidateImage(Int level) { (this->*invalidateImplementation)(level); } @@ -1142,7 +1142,7 @@ class MAGNUM_EXPORT AbstractTexture { protected: #ifndef DOXYGEN_GENERATING_OUTPUT - template struct DataHelper {}; + template struct DataHelper {}; /* Unlike bind() this also sets the binding layer as active */ void MAGNUM_LOCAL bindInternal(); @@ -1290,7 +1290,7 @@ namespace Implementation { }; #ifndef MAGNUM_TARGET_GLES2 - template struct MAGNUM_EXPORT ImageHelper> { + template struct MAGNUM_EXPORT ImageHelper> { static const GLvoid* dataOrPixelUnpackBuffer(BufferImage* image); }; #endif diff --git a/src/Array.h b/src/Array.h index 2788fcfc3..cfe5dfb28 100644 --- a/src/Array.h +++ b/src/Array.h @@ -37,10 +37,10 @@ need any math operations and fuzzy comparison (e.g. enum values). Unlike Math::Vector this class has non-explicit constructor from one value. @see Array1D, Array2D, Array3D */ -template class Array { +template class Array { public: typedef T Type; /**< @brief Data type */ - const static std::uint8_t Dimensions = dimensions; /**< @brief Dimension count */ + const static UnsignedInt Dimensions = dimensions; /**< @brief Dimension count */ /** * @brief Default constructor @@ -68,13 +68,13 @@ template class Array { * @param value Value for all fields */ template::value && dimensions != 1, U>::type> inline /*implicit*/ Array(U value) { - for(std::uint8_t i = 0; i != dimensions; ++i) + for(UnsignedInt i = 0; i != dimensions; ++i) _data[i] = value; } /** @brief Equality */ inline bool operator==(const Array& other) const { - for(std::uint8_t i = 0; i != dimensions; ++i) + for(UnsignedInt i = 0; i != dimensions; ++i) if(_data[i] != other._data[i]) return false; return true; } @@ -85,8 +85,8 @@ template class Array { } /** @brief Value at given position */ - inline T& operator[](std::uint8_t pos) { return _data[pos]; } - inline constexpr T operator[](std::uint8_t pos) const { return _data[pos]; } /**< @overload */ + inline T& operator[](UnsignedInt pos) { return _data[pos]; } + inline constexpr T operator[](UnsignedInt pos) const { return _data[pos]; } /**< @overload */ /** * @brief Raw data @@ -181,10 +181,10 @@ template class Array3D: public Array<3, T> { }; /** @debugoperator{Magnum::Array} */ -template Debug operator<<(Debug debug, const Array& value) { +template Debug operator<<(Debug debug, const Array& value) { debug << "Array("; debug.setFlag(Debug::SpaceAfterEachValue, false); - for(std::uint8_t i = 0; i != dimensions; ++i) { + for(UnsignedInt i = 0; i != dimensions; ++i) { if(i != 0) debug << ", "; debug << value[i]; } diff --git a/src/BufferImage.cpp b/src/BufferImage.cpp index 377b28e8b..ff2b8f5d9 100644 --- a/src/BufferImage.cpp +++ b/src/BufferImage.cpp @@ -18,7 +18,7 @@ namespace Magnum { #ifndef MAGNUM_TARGET_GLES2 -template void BufferImage::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) { +template void BufferImage::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) { _format = format; _type = type; _size = size; diff --git a/src/BufferImage.h b/src/BufferImage.h index 743f31dac..1e5998c07 100644 --- a/src/BufferImage.h +++ b/src/BufferImage.h @@ -37,9 +37,9 @@ Trade::ImageData. @see BufferImage1D, BufferImage2D, BufferImage3D, Buffer @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. */ -template class MAGNUM_EXPORT BufferImage: public AbstractImage { +template class MAGNUM_EXPORT BufferImage: public AbstractImage { public: - const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ + const static UnsignedInt Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor @@ -54,7 +54,7 @@ template class MAGNUM_EXPORT BufferImage: public Abstra } /** @brief %Image size */ - inline typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief %Image buffer */ inline Buffer* buffer() { return &_buffer; } @@ -72,10 +72,10 @@ template class MAGNUM_EXPORT BufferImage: public Abstra * * @see Buffer::setData() */ - void setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage); + void setData(const typename DimensionTraits::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage); private: - Math::Vector _size; + Math::Vector _size; Buffer _buffer; }; diff --git a/src/BufferTexture.h b/src/BufferTexture.h index 4a6130fb1..cf697b094 100644 --- a/src/BufferTexture.h +++ b/src/BufferTexture.h @@ -197,7 +197,7 @@ class MAGNUM_EXPORT BufferTexture: private AbstractTexture { inline explicit BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} /** @copydoc AbstractTexture::bind() */ - inline void bind(GLint layer) { AbstractTexture::bind(layer); } + inline void bind(Int layer) { AbstractTexture::bind(layer); } /** * @brief Set texture buffer diff --git a/src/Color.h b/src/Color.h index bb256994d..041b4be22 100644 --- a/src/Color.h +++ b/src/Color.h @@ -144,7 +144,7 @@ range @f$ [0.0, 1.0] @f$. #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class Color3: public Math::Vector3 { public: @@ -267,7 +267,7 @@ See Color3 for more information. #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class Color4: public Math::Vector4 { public: diff --git a/src/Context.h b/src/Context.h index 569ac877f..86cc209b6 100644 --- a/src/Context.h +++ b/src/Context.h @@ -39,7 +39,7 @@ namespace Implementation { @see Context, MAGNUM_ASSERT_VERSION_SUPPORTED() */ -enum class Version: GLint { +enum class Version: Int { None = 0xFFFF, /**< @brief Unspecified */ #ifndef MAGNUM_TARGET_GLES GL210 = 210, /**< @brief OpenGL 2.1 / GLSL 1.20 */ @@ -166,7 +166,7 @@ class MAGNUM_EXPORT Context { * @see minorVersion(), version(), versionString(), * shadingLanguageVersionString() */ - inline GLint majorVersion() const { return _majorVersion; } + inline Int majorVersion() const { return _majorVersion; } /** * @brief Minor OpenGL version (e.g. `3`) @@ -174,7 +174,7 @@ class MAGNUM_EXPORT Context { * @see majorVersion(), version(), versionString(), * shadingLanguageVersionString() */ - inline GLint minorVersion() const { return _minorVersion; } + inline Int minorVersion() const { return _minorVersion; } /** * @brief Vendor string @@ -293,8 +293,8 @@ class MAGNUM_EXPORT Context { static Context* _current; Version _version; - GLint _majorVersion; - GLint _minorVersion; + Int _majorVersion; + Int _minorVersion; std::bitset<128> extensionStatus; std::vector _supportedExtensions; diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index ed3a2c9d3..59c3d68c8 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -119,7 +119,7 @@ class CubeMapTexture: public AbstractTexture { * See Texture::imageSize() for more information. * @requires_gl %Texture image queries are not available in OpenGL ES. */ - inline Vector2i imageSize(Coordinate coordinate, GLint level) { + inline Vector2i imageSize(Coordinate coordinate, Int level) { return DataHelper<2>::imageSize(this, static_cast(coordinate), level); } #endif @@ -129,7 +129,7 @@ class CubeMapTexture: public AbstractTexture { * * See Texture::setStorage() for more information. */ - inline CubeMapTexture* setStorage(GLsizei levels, InternalFormat internalFormat, const Vector2i& size) { + inline CubeMapTexture* setStorage(Int levels, InternalFormat internalFormat, const Vector2i& size) { DataHelper<2>::setStorage(this, _target, levels, internalFormat, size); return this; } @@ -145,7 +145,7 @@ class CubeMapTexture: public AbstractTexture { * * See Texture::setImage() for more information. */ - template inline CubeMapTexture* setImage(Coordinate coordinate, GLint level, InternalFormat internalFormat, Image* image) { + template inline CubeMapTexture* setImage(Coordinate coordinate, Int level, InternalFormat internalFormat, Image* image) { DataHelper<2>::set(this, static_cast(coordinate), level, internalFormat, image); return this; } @@ -161,7 +161,7 @@ class CubeMapTexture: public AbstractTexture { * * See Texture::setSubImage() for more information. */ - template inline CubeMapTexture* setSubImage(Coordinate coordinate, GLint level, const Vector2i& offset, const Image* image) { + template inline CubeMapTexture* setSubImage(Coordinate coordinate, Int level, const Vector2i& offset, const Image* image) { DataHelper<2>::setSub(this, static_cast(coordinate), level, offset, image); return this; } @@ -178,7 +178,7 @@ class CubeMapTexture: public AbstractTexture { * * See Texture::invalidateSubImage() for more information. */ - inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { + inline void invalidateSubImage(Int level, const Vector3i& offset, const Vector3i& size) { DataHelper<3>::invalidateSub(this, level, offset, size); } @@ -198,7 +198,7 @@ class CubeMapTexture: public AbstractTexture { return this; } #endif - inline CubeMapTexture* setMaxAnisotropy(GLfloat anisotropy) { + inline CubeMapTexture* setMaxAnisotropy(Float anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index d6b25f3af..2a6ffb35c 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -106,7 +106,7 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::imageSize() for more information. */ - inline Vector3i imageSize(Coordinate coordinate, GLint level) { + inline Vector3i imageSize(Coordinate coordinate, Int level) { return DataHelper<3>::imageSize(this, GL_TEXTURE_CUBE_MAP_POSITIVE_X + static_cast(coordinate), level); } @@ -115,7 +115,7 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setStorage() for more information. */ - inline CubeMapTextureArray* setStorage(GLsizei levels, InternalFormat internalFormat, const Vector3i& size) { + inline CubeMapTextureArray* setStorage(Int levels, InternalFormat internalFormat, const Vector3i& size) { DataHelper<3>::setStorage(this, _target, levels, internalFormat, size); return this; } @@ -134,7 +134,7 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setImage() for more information. */ - template inline CubeMapTextureArray* setImage(GLint level, InternalFormat internalFormat, T* image) { + template inline CubeMapTextureArray* setImage(Int level, InternalFormat internalFormat, T* image) { DataHelper<3>::set(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, internalFormat, image); return this; } @@ -156,9 +156,9 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setSubImage() for more information. * - * @see setSubImage(GLsizei, Coordinate, GLint, const Math::Vector<2, GLint>&, const Image*) + * @see setSubImage(Int, Coordinate, Int, const Math::Vector<2, Int>&, const Image*) */ - template inline CubeMapTextureArray* setSubImage(GLint level, const Vector3i& offset, const Image* image) { + template inline CubeMapTextureArray* setSubImage(Int level, const Vector3i& offset, const Image* image) { DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, offset, image, Vector3i(Math::Vector())); return this; } @@ -175,9 +175,9 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setSubImage() for more information. * - * @see setSubImage(GLint, const Math::Vector<3, GLint>&, const Image*) + * @see setSubImage(Int, const Math::Vector<3, Int>&, const Image*) */ - template inline CubeMapTextureArray* setSubImage(GLsizei layer, Coordinate coordinate, GLint level, const Vector2i& offset, const Image* image) { + template inline CubeMapTextureArray* setSubImage(Int layer, Coordinate coordinate, Int level, const Vector2i& offset, const Image* image) { DataHelper<3>::setSub(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, Vector3i(offset, layer*6+static_cast(coordinate)), image, Vector2i(Math::Vector())); return this; } @@ -194,7 +194,7 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::invalidateSubImage() for more information. */ - inline void invalidateSubImage(GLint level, const Vector3i& offset, const Vector3i& size) { + inline void invalidateSubImage(Int level, const Vector3i& offset, const Vector3i& size) { DataHelper<3>::invalidateSub(this, level, offset, size); } @@ -212,7 +212,7 @@ class CubeMapTextureArray: public AbstractTexture { AbstractTexture::setBorderColor(color); return this; } - inline CubeMapTextureArray* setMaxAnisotropy(GLfloat anisotropy) { + inline CubeMapTextureArray* setMaxAnisotropy(Float anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); return this; } diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index dac3e572a..6a0d40899 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -28,7 +28,7 @@ DefaultFramebuffer defaultFramebuffer; DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } #ifndef MAGNUM_TARGET_GLES2 -void DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { +void DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 8548809df..6bbb736bd 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -282,7 +282,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - void mapForDraw(std::initializer_list> attachments); + void mapForDraw(std::initializer_list> attachments); /** * @brief Map shader output to buffer attachment diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index 71785aa3e..eb790dbe0 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -24,7 +24,7 @@ namespace Magnum { /** @brief Matrix, point and vector specializations for given dimension count */ -template struct DimensionTraits { +template struct DimensionTraits { DimensionTraits() = delete; #ifdef DOXYGEN_GENERATING_OUTPUT @@ -61,17 +61,17 @@ template struct DimensionTraits<2, T> { }; /* Two dimensions - floating-point */ -template<> struct DimensionTraits<2, float> { +template<> struct DimensionTraits<2, Float> { DimensionTraits() = delete; - typedef Math::Vector2 VectorType; - typedef Math::Matrix3 MatrixType; + typedef Math::Vector2 VectorType; + typedef Math::Matrix3 MatrixType; }; -template<> struct DimensionTraits<2, double> { +template<> struct DimensionTraits<2, Double> { DimensionTraits() = delete; - typedef Math::Vector2 VectorType; - typedef Math::Matrix3 MatrixType; + typedef Math::Vector2 VectorType; + typedef Math::Matrix3 MatrixType; }; /* Three dimensions - integral */ @@ -82,17 +82,17 @@ template struct DimensionTraits<3, T> { }; /* Three dimensions - floating-point */ -template<> struct DimensionTraits<3, float> { +template<> struct DimensionTraits<3, Float> { DimensionTraits() = delete; - typedef Math::Vector3 VectorType; - typedef Math::Matrix4 MatrixType; + typedef Math::Vector3 VectorType; + typedef Math::Matrix4 MatrixType; }; -template<> struct DimensionTraits<3, double> { +template<> struct DimensionTraits<3, Double> { DimensionTraits() = delete; - typedef Math::Vector3 VectorType; - typedef Math::Matrix4 MatrixType; + typedef Math::Vector3 VectorType; + typedef Math::Matrix4 MatrixType; }; #endif diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 056a08cd9..629a24c9d 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -58,7 +58,7 @@ Framebuffer::~Framebuffer() { glDeleteFramebuffers(1, &_id); } -void Framebuffer::mapForDraw(std::initializer_list> attachments) { +void Framebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) @@ -94,7 +94,7 @@ void Framebuffer::invalidate(std::initializer_list attac delete _attachments; } -void Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, GLint mipLevel) { +void Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int mipLevel) { /** @todo Check for texture target compatibility */ (this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel); } diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 8c4713876..706374210 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -105,7 +105,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @brief Constructor * @param id Color attachment id */ - inline constexpr explicit ColorAttachment(std::uint8_t id): attachment(GL_COLOR_ATTACHMENT0 + id) {} + inline constexpr explicit ColorAttachment(UnsignedInt id): attachment(GL_COLOR_ATTACHMENT0 + id) {} #ifndef DOXYGEN_GENERATING_OUTPUT inline constexpr explicit operator GLenum() const { return attachment; } @@ -238,7 +238,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - void mapForDraw(std::initializer_list> attachments); + void mapForDraw(std::initializer_list> attachments); /** * @brief Map shader output to attachment @@ -333,7 +333,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - inline void attachTexture1D(BufferAttachment attachment, Texture1D* texture, GLint level) { + inline void attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { (this->*texture1DImplementation)(attachment, texture, level); } #endif @@ -350,7 +350,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachTexture2D(BufferAttachment attachment, Texture2D* texture, GLint level); + void attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); /** * @brief Attach cube map texture to given buffer @@ -365,7 +365,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - inline void attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, GLint level) { + inline void attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { (this->*texture2DImplementation)(attachment, GLenum(coordinate), texture->id(), level); } @@ -383,7 +383,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - inline void attachTexture3D(BufferAttachment attachment, Texture3D* texture, GLint level, GLint layer) { + inline void attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { /** @todo Check for texture target compatibility */ (this->*texture3DImplementation)(attachment, texture, level, layer); } diff --git a/src/Image.cpp b/src/Image.cpp index 2e04ce74f..b6c6921e2 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void Image::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data) { +template void Image::setData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data) { delete[] _data; _format = format; _type = type; diff --git a/src/Image.h b/src/Image.h index 111a748f7..20c30cd13 100644 --- a/src/Image.h +++ b/src/Image.h @@ -32,9 +32,9 @@ Stores image data on client memory. Interchangeable with ImageWrapper, BufferImage or Trade::ImageData. @see Image1D, Image2D, Image3D */ -template class Image: public AbstractImage { +template class Image: public AbstractImage { public: - const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ + const static UnsignedInt Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor @@ -46,7 +46,7 @@ template class Image: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline explicit Image(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} + inline explicit Image(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -62,7 +62,7 @@ template class Image: public AbstractImage { inline ~Image() { delete[] _data; } /** @brief %Image size */ - inline typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -78,10 +78,10 @@ template class Image: public AbstractImage { * Deletes previous data and replaces them with new. Note that the * data are not copied, but they are deleted on destruction. */ - void setData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data); + void setData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data); private: - Math::Vector _size; + Math::Vector _size; char* _data; }; diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index c3a5046b5..739bb810a 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -40,9 +40,9 @@ to change image properties, only data pointer. Interchangeable with Image, BufferImage or Trade::ImageData. @see ImageWrapper1D, ImageWrapper2D, ImageWrapper3D */ -template class ImageWrapper: public AbstractImage { +template class ImageWrapper: public AbstractImage { public: - const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ + const static UnsignedInt Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor * @param size %Image size @@ -53,7 +53,7 @@ template class ImageWrapper: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline explicit ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} + inline explicit ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** * @brief Constructor @@ -64,10 +64,10 @@ template class ImageWrapper: public AbstractImage { * Dimensions and data pointer are set to zero, call setData() to fill * the image with data. */ - inline explicit ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type): AbstractImage(format, type), _size(size), _data(nullptr) {} + inline explicit ImageWrapper(const typename DimensionTraits::VectorType& size, Format format, Type type): AbstractImage(format, type), _size(size), _data(nullptr) {} /** @brief %Image size */ - inline typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } @@ -86,7 +86,7 @@ template class ImageWrapper: public AbstractImage { } private: - Math::Vector _size; + Math::Vector _size; char* _data; }; diff --git a/src/Magnum.h b/src/Magnum.h index 862b2b14d..782d97a0c 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -267,7 +267,7 @@ class AbstractImage; class AbstractShaderProgram; class AbstractTexture; -template class Array; +template class Array; template class Array1D; template class Array2D; template class Array3D; @@ -275,7 +275,7 @@ template class Array3D; class Buffer; #ifndef MAGNUM_TARGET_GLES2 -template class BufferImage; +template class BufferImage; typedef BufferImage<1> BufferImage1D; typedef BufferImage<2> BufferImage2D; typedef BufferImage<3> BufferImage3D; @@ -285,10 +285,10 @@ typedef BufferImage<3> BufferImage3D; class BufferTexture; #endif -template class Color3; -template class Color4; +template class Color3; +template class Color4; -enum class Version: GLint; +enum class Version: Int; class Context; class CubeMapTexture; @@ -303,12 +303,12 @@ class CubeMapTextureArray; class Extension; class Framebuffer; -template class Image; +template class Image; typedef Image<1> Image1D; typedef Image<2> Image2D; typedef Image<3> Image3D; -template class ImageWrapper; +template class ImageWrapper; typedef ImageWrapper<1> ImageWrapper1D; typedef ImageWrapper<2> ImageWrapper2D; typedef ImageWrapper<3> ImageWrapper3D; @@ -317,16 +317,16 @@ class Mesh; class Query; class Renderbuffer; -enum class ResourceState: std::uint8_t; -enum class ResourceDataState: std::uint8_t; -enum class ResourcePolicy: std::uint8_t; +enum class ResourceState: UnsignedByte; +enum class ResourceDataState: UnsignedByte; +enum class ResourcePolicy: UnsignedByte; template class Resource; class ResourceKey; template class ResourceManager; class Shader; -template class Texture; +template class Texture; #ifndef MAGNUM_TARGET_GLES typedef Texture<1> Texture1D; #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index f78cd89de..566f3dee2 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -108,7 +108,7 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } -Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, GLuint start, GLuint end) { +Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { indexOffset = offset; indexType = type; #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/Mesh.h b/src/Mesh.h index 3f2c554f2..4b0641879 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -381,7 +381,7 @@ class MAGNUM_EXPORT Mesh { * polygon offset for desired polygon modes. * @see @fn_gl{PolygonOffset} */ - inline static void setPolygonOffset(GLfloat factor, GLfloat units) { + inline static void setPolygonOffset(Float factor, Float units) { glPolygonOffset(factor, units); } @@ -391,7 +391,7 @@ class MAGNUM_EXPORT Mesh { * Initial value is `1.0f`. * @see @fn_gl{LineWidth} */ - inline static void setLineWidth(GLfloat width) { + inline static void setLineWidth(Float width) { glLineWidth(width); } @@ -404,7 +404,7 @@ class MAGNUM_EXPORT Mesh { * @requires_gl Set directly in vertex shader using @c gl_PointSize * builtin variable. */ - inline static void setPointSize(GLfloat size) { + inline static void setPointSize(Float size) { glPointSize(size); } @@ -528,7 +528,7 @@ class MAGNUM_EXPORT Mesh { } /** @brief Vertex count */ - inline GLsizei vertexCount() const { return _vertexCount; } + inline Int vertexCount() const { return _vertexCount; } /** * @brief Set vertex count @@ -538,13 +538,13 @@ class MAGNUM_EXPORT Mesh { * @see setPrimitive(), addVertexBuffer(), addInterleavedVertexBuffer(), * addVertexBufferStride(), MeshTools::interleave() */ - inline Mesh* setVertexCount(GLsizei vertexCount) { + inline Mesh* setVertexCount(Int vertexCount) { _vertexCount = vertexCount; return this; } /** @brief Index count */ - inline GLsizei indexCount() const { return _indexCount; } + inline Int indexCount() const { return _indexCount; } /** * @brief Set index count @@ -553,7 +553,7 @@ class MAGNUM_EXPORT Mesh { * Default is zero. * @see setIndexBuffer(), MeshTools::compressIndices() */ - inline Mesh* setIndexCount(GLsizei count) { + inline Mesh* setIndexCount(Int count) { _indexCount = count; return this; } @@ -637,7 +637,7 @@ class MAGNUM_EXPORT Mesh { * Buffer* buffer; * mesh->addInterleavedVertexBuffer(buffer, * 35, // skip other data - * sizeof(GLfloat), // skip vertex weight + * sizeof(Float), // skip vertex weight * Shaders::PhongShader::Position(), // vertex position * sizeof(Vector2), // skip texture coordinates * Shaders::PhongShader::Normal()); // vertex normal @@ -648,14 +648,14 @@ class MAGNUM_EXPORT Mesh { * between vertex attributes: * @code * GLsizei stride = // size of one vertex - * sizeof(GLfloat) + + * sizeof(Float) + * sizeof(Shaders::PhongShader::Position::Type) + * sizeof(Vector2) + * sizeof(Shaders::PhongShader::Normal::Type); * - * mesh->addVertexBufferStride(buffer, 35 + sizeof(GLfloat), + * mesh->addVertexBufferStride(buffer, 35 + sizeof(Float), * stride, Shaders::PhongShader::Position()); - * ->addVertexBufferStride(buffer, 35 + sizeof(GLfloat) + + * ->addVertexBufferStride(buffer, 35 + sizeof(Float) + * sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2), * stride, Shaders::PhongShader::Normal()); * @endcode @@ -683,7 +683,7 @@ class MAGNUM_EXPORT Mesh { * * See addInterleavedVertexBuffer() for more information. */ - template inline Mesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { + template inline Mesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { addInterleavedVertexBufferInternal(buffer, offset, stride, attribute); return this; } @@ -708,7 +708,7 @@ class MAGNUM_EXPORT Mesh { * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, GLuint start, GLuint end); + Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end); /** * @brief Set index buffer @@ -717,7 +717,7 @@ class MAGNUM_EXPORT Mesh { * @param type Index data type * @return Pointer to self (for method chaining) * - * Prefer to use setIndexBuffer(Buffer*, GLintptr, IndexType, GLuint, GLuint) + * Prefer to use setIndexBuffer(Buffer*, GLintptr, IndexType, UnsignedInt, UnsignedInt) * for better performance. * @see setIndexCount(), MeshTools::compressIndices(), * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if @@ -778,7 +778,7 @@ class MAGNUM_EXPORT Mesh { static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); /* Adding non-interleaved vertex attributes */ - template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { + template inline void addVertexBufferInternal(Buffer* buffer, GLintptr offset, const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { addVertexAttribute(buffer, attribute, offset, 0); /* Add size of this attribute array to offset for next attribute */ @@ -791,7 +791,7 @@ class MAGNUM_EXPORT Mesh { inline void addVertexBufferInternal(Buffer*, GLintptr) {} /* Computing stride of interleaved vertex attributes */ - template inline static GLsizei strideOfInterleaved(const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { + template inline static GLsizei strideOfInterleaved(const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { return attribute.dataSize() + strideOfInterleaved(attributes...); } template inline static GLsizei strideOfInterleaved(GLintptr gap, const T&... attributes) { @@ -800,7 +800,7 @@ class MAGNUM_EXPORT Mesh { inline static GLsizei strideOfInterleaved() { return 0; } /* Adding interleaved vertex attributes */ - template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { + template inline void addInterleavedVertexBufferInternal(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute, const U&... attributes) { addVertexAttribute(buffer, attribute, offset, stride); /* Add size of this attribute to offset for next attribute */ @@ -812,8 +812,8 @@ class MAGNUM_EXPORT Mesh { } inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} - template inline void addVertexAttribute(typename std::enable_if::Type, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { - for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) + template inline void addVertexAttribute(typename std::enable_if::Type, Float>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + for(UnsignedInt i = 0; i != Implementation::Attribute::vectorCount(); ++i) (this->*attributePointerImplementation)(Attribute{ buffer, location+i, @@ -826,7 +826,7 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES2 - template inline void addVertexAttribute(typename std::enable_if::Type>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + template inline void addVertexAttribute(typename std::enable_if::Type>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { (this->*attributeIPointerImplementation)(IntegerAttribute{ buffer, location, @@ -838,8 +838,8 @@ class MAGNUM_EXPORT Mesh { } #ifndef MAGNUM_TARGET_GLES - template inline void addVertexAttribute(typename std::enable_if::Type, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { - for(GLuint i = 0; i != Implementation::Attribute::vectorCount(); ++i) + template inline void addVertexAttribute(typename std::enable_if::Type, Double>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute& attribute, GLintptr offset, GLsizei stride) { + for(UnsignedInt i = 0; i != Implementation::Attribute::vectorCount(); ++i) (this->*attributeLPointerImplementation)(LongAttribute{ buffer, location+i, @@ -915,9 +915,9 @@ class MAGNUM_EXPORT Mesh { GLuint vao; Primitive _primitive; - GLsizei _vertexCount, _indexCount; + Int _vertexCount, _indexCount; #ifndef MAGNUM_TARGET_GLES2 - GLuint indexStart, indexEnd; + UnsignedInt indexStart, indexEnd; #endif GLintptr indexOffset; IndexType indexType; diff --git a/src/Query.cpp b/src/Query.cpp index 1b9fc86bc..12cf4e527 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -39,10 +39,10 @@ template<> bool AbstractQuery::result() { #endif } -template<> GLuint AbstractQuery::result() { +template<> UnsignedInt AbstractQuery::result() { /** @todo Re-enable when extension wrangler is available for ES */ #ifndef MAGNUM_TARGET_GLES2 - GLuint result; + UnsignedInt result; glGetQueryObjectuiv(_id, GL_QUERY_RESULT, &result); return result; #else @@ -51,20 +51,20 @@ template<> GLuint AbstractQuery::result() { } #ifndef MAGNUM_TARGET_GLES -template<> GLint AbstractQuery::result() { - GLint result; +template<> Int AbstractQuery::result() { + Int result; glGetQueryObjectiv(_id, GL_QUERY_RESULT, &result); return result; } -template<> GLuint64 AbstractQuery::result() { - GLuint64 result; +template<> UnsignedLong AbstractQuery::result() { + UnsignedLong result; glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result); return result; } -template<> GLint64 AbstractQuery::result() { - GLint64 result; +template<> Long AbstractQuery::result() { + Long result; glGetQueryObjecti64v(_id, GL_QUERY_RESULT, &result); return result; } diff --git a/src/Query.h b/src/Query.h index f768c8ca7..22aace60f 100644 --- a/src/Query.h +++ b/src/Query.h @@ -72,16 +72,16 @@ class MAGNUM_EXPORT AbstractQuery { /** * @brief Result - * @tparam T Result type. Can be either `bool`, `GLuint`, - * `GLint`, `GLuint64` or `GLint64`. + * @tparam T Result type. Can be either `bool`, @ref UnsignedInt, + * @ref Int, @ref UnsignedLong or @ref Long. * * Note that this function is blocking until the result is available. * See resultAvailable(). * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} - * @requires_gl33 %Extension @extension{ARB,timer_query} (result - * type `GLuint64` and `GLint64`) - * @requires_gl Result types @c GLint, @c GLuint64 and @c GLint64 are - * not available in OpenGL ES. + * @requires_gl33 %Extension @extension{ARB,timer_query} (result type + * UnsignedInt and Long) + * @requires_gl Result types Int, UnsignedLong and Long are not + * available in OpenGL ES. */ template T result(); @@ -92,11 +92,11 @@ class MAGNUM_EXPORT AbstractQuery { #ifndef DOXYGEN_GENERATING_OUTPUT template<> bool MAGNUM_EXPORT AbstractQuery::result(); -template<> GLuint MAGNUM_EXPORT AbstractQuery::result(); +template<> UnsignedInt MAGNUM_EXPORT AbstractQuery::result(); #ifndef MAGNUM_TARGET_GLES -template<> GLint MAGNUM_EXPORT AbstractQuery::result(); -template<> GLuint64 MAGNUM_EXPORT AbstractQuery::result(); -template<> GLint64 MAGNUM_EXPORT AbstractQuery::result(); +template<> Int MAGNUM_EXPORT AbstractQuery::result(); +template<> UnsignedLong MAGNUM_EXPORT AbstractQuery::result(); +template<> Long MAGNUM_EXPORT AbstractQuery::result(); #endif #endif @@ -118,7 +118,7 @@ if(!q.resultAvailable()) { } // ...or block until the result is available -GLuint primitiveCount = q.result(); +UnsignedInt primitiveCount = q.result(); @endcode @requires_gl30 %Extension @extension{EXT,transform_feedback} @requires_gles30 Only sample queries are available on OpenGL ES 2.0. @@ -338,8 +338,8 @@ q1.end(); q2.begin(Query::Target::TimeElapsed); // another rendering... q2.end(); -GLuint timeElapsed1 = q1.result(); -GLuint timeElapsed2 = q2.result(); +UnsignedInt timeElapsed1 = q1.result(); +UnsignedInt timeElapsed2 = q2.result(); @endcode @code TimeQuery q1, q2, q3; @@ -348,9 +348,9 @@ q1.timestamp(); q2.timestamp(); // another rendering... q3.timestamp(); -GLuint tmp = q2.result(); -GLuint timeElapsed1 = tmp-q1.result(); -GLuint timeElapsed2 = q3.result()-tmp; +UnsignedInt tmp = q2.result(); +UnsignedInt timeElapsed1 = tmp-q1.result(); +UnsignedInt timeElapsed2 = q3.result()-tmp; @endcode Using this query results in fewer OpenGL calls when doing more measures. @requires_gl33 %Extension @extension{ARB,timer_query} diff --git a/src/Renderer.h b/src/Renderer.h index e2274fc61..f91144556 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -43,9 +43,9 @@ class MAGNUM_EXPORT Renderer { * @brief Affected polygon facing for culling, stencil operations and masks * * @see setFaceCullingMode(), - * setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint), + * setStencilFunction(PolygonFacing, StencilFunction, Int, UnsignedInt), * setStencilOperation(PolygonFacing, StencilOperation, StencilOperation, StencilOperation), - * setStencilMask(PolygonFacing, GLuint) + * setStencilMask(PolygonFacing, UnsignedInt) */ enum class PolygonFacing: GLenum { Front = GL_FRONT, /**< Front-facing polygons */ @@ -137,9 +137,9 @@ class MAGNUM_EXPORT Renderer { * * Initial value is `1.0`. * @see @fn_gl{ClearDepth} - * @requires_gl See setClearDepth(GLfloat), which is available in OpenGL ES. + * @requires_gl See setClearDepth(Float), which is available in OpenGL ES. */ - inline static void setClearDepth(GLdouble depth) { glClearDepth(depth); } + inline static void setClearDepth(Double depth) { glClearDepth(depth); } #endif /** @@ -149,7 +149,7 @@ class MAGNUM_EXPORT Renderer { * @requires_gl41 %Extension @extension{ARB,ES2_compatibility} * @todo Call double version if the extension is not available */ - inline static void setClearDepth(GLfloat depth) { glClearDepthf(depth); } + inline static void setClearDepth(Float depth) { glClearDepthf(depth); } /** * @brief Set clear stencil @@ -157,7 +157,7 @@ class MAGNUM_EXPORT Renderer { * Initial value is `0`. * @see @fn_gl{ClearStencil} */ - inline static void setClearStencil(GLint stencil) { glClearStencil(stencil); } + inline static void setClearStencil(Int stencil) { glClearStencil(stencil); } /*@}*/ @@ -252,21 +252,21 @@ class MAGNUM_EXPORT Renderer { * Initial value is all `1`s. * * @attention You have to enable stencil test with setFeature() first. - * @see setStencilFunction(StencilFunction, GLint, GLuint), + * @see setStencilFunction(StencilFunction, Int, UnsignedInt), * @fn_gl{StencilFuncSeparate} */ - inline static void setStencilFunction(PolygonFacing facing, StencilFunction function, GLint referenceValue, GLuint mask) { + inline static void setStencilFunction(PolygonFacing facing, StencilFunction function, Int referenceValue, UnsignedInt mask) { glStencilFuncSeparate(static_cast(facing), static_cast(function), referenceValue, mask); } /** * @brief Set stencil function * - * The same as setStencilFunction(PolygonFacing, StencilFunction, GLint, GLuint) + * The same as setStencilFunction(PolygonFacing, StencilFunction, Int, UnsignedInt) * with `facing` set to `PolygonFacing::FrontAndBack`. * @see @fn_gl{StencilFunc} */ - inline static void setStencilFunction(StencilFunction function, GLint referenceValue, GLuint mask) { + inline static void setStencilFunction(StencilFunction function, Int referenceValue, UnsignedInt mask) { glStencilFunc(static_cast(function), referenceValue, mask); } @@ -353,20 +353,20 @@ class MAGNUM_EXPORT Renderer { * * Set given bit to `0` to disallow writing stencil value for given * faces to it. Initial value is all `1`s. - * @see setStencilMask(GLuint), @fn_gl{StencilMaskSeparate} + * @see setStencilMask(UnsignedInt), @fn_gl{StencilMaskSeparate} */ - inline static void setStencilMask(PolygonFacing facing, GLuint allowBits) { + inline static void setStencilMask(PolygonFacing facing, UnsignedInt allowBits) { glStencilMaskSeparate(static_cast(facing), allowBits); } /** * @brief Mask stencil writes * - * The same as setStencilMask(PolygonFacing, GLuint) with `facing` set + * The same as setStencilMask(PolygonFacing, UnsignedInt) with `facing` set * to `PolygonFacing::FrontAndBack`. * @see @fn_gl{StencilMask} */ - inline static void setStencilMask(GLuint allowBits) { + inline static void setStencilMask(UnsignedInt allowBits) { glStencilMask(allowBits); } diff --git a/src/Resource.h b/src/Resource.h index 88dbb415b..71e00d856 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -33,7 +33,7 @@ namespace Magnum { * * @see Resource::state(), ResourceManager::state() */ -enum class ResourceState: std::uint8_t { +enum class ResourceState: UnsignedByte { /** The resource is not yet loaded (and no fallback is available). */ NotLoaded, diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 1c0128e85..2ae2d5075 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -30,18 +30,18 @@ namespace Magnum { * * @see ResourceManager::set(), ResourceState */ -enum class ResourceDataState: std::uint8_t { +enum class ResourceDataState: UnsignedByte { /** * The resource is currently loading. Parameter @p data in ResourceManager::set() * should be set to `null`. */ - Loading = int(ResourceState::Loading), + Loading = UnsignedByte(ResourceState::Loading), /** * The resource was not found. Parameter @p data in ResourceManager::set() * should be set to `null`. */ - NotFound = int(ResourceState::NotFound), + NotFound = UnsignedByte(ResourceState::NotFound), /** * The resource can be changed by the manager in the future. This is @@ -49,14 +49,14 @@ enum class ResourceDataState: std::uint8_t { * the data are accessed, but allows changing the data for e.g. debugging * purposes. */ - Mutable = std::uint8_t(ResourceState::Mutable), + Mutable = UnsignedByte(ResourceState::Mutable), /** * The resource cannot be changed by the manager in the future. This is * faster, as Resource instances will ask for the data only one time, thus * suitable for production code. */ - Final = std::uint8_t(ResourceState::Final) + Final = UnsignedByte(ResourceState::Final) }; /** @relates ResourceManager @@ -64,7 +64,7 @@ enum class ResourceDataState: std::uint8_t { @see ResourceManager::set(), ResourceManager::free() */ -enum class ResourcePolicy: std::uint8_t { +enum class ResourcePolicy: UnsignedByte { /** The resource will stay resident for whole lifetime of resource manager. */ Resident, diff --git a/src/Test/AbstractShaderProgramTest.cpp b/src/Test/AbstractShaderProgramTest.cpp index 7a3de5032..1f8738b55 100644 --- a/src/Test/AbstractShaderProgramTest.cpp +++ b/src/Test/AbstractShaderProgramTest.cpp @@ -57,7 +57,7 @@ AbstractShaderProgramTest::AbstractShaderProgramTest() { } void AbstractShaderProgramTest::attributeScalar() { - typedef AbstractShaderProgram::Attribute<3, GLfloat> Attribute; + typedef AbstractShaderProgram::Attribute<3, Float> Attribute; CORRADE_COMPARE(Attribute::Location, 3); /* Default constructor */ @@ -74,7 +74,7 @@ void AbstractShaderProgramTest::attributeScalar() { } void AbstractShaderProgramTest::attributeScalarInt() { - typedef AbstractShaderProgram::Attribute<3, GLint> Attribute; + typedef AbstractShaderProgram::Attribute<3, Int> Attribute; /* Default constructor */ Attribute a; @@ -86,7 +86,7 @@ void AbstractShaderProgramTest::attributeScalarInt() { } void AbstractShaderProgramTest::attributeScalarUnsignedInt() { - typedef AbstractShaderProgram::Attribute<3, GLuint> Attribute; + typedef AbstractShaderProgram::Attribute<3, UnsignedInt> Attribute; /* Default constructor */ Attribute a; @@ -99,7 +99,7 @@ void AbstractShaderProgramTest::attributeScalarUnsignedInt() { void AbstractShaderProgramTest::attributeScalarDouble() { #ifndef MAGNUM_TARGET_GLES - typedef AbstractShaderProgram::Attribute<3, GLdouble> Attribute; + typedef AbstractShaderProgram::Attribute<3, Double> Attribute; /* Default constructor */ Attribute a; diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index b7af66ad9..d171637d4 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -43,10 +43,10 @@ class ColorTest: public Corrade::TestSuite::Tester { void configuration(); }; -typedef Magnum::Color3 Color3; -typedef Magnum::Color4 Color4; -typedef Magnum::Color3 Color3f; -typedef Magnum::Color4 Color4f; +typedef Magnum::Color3 Color3; +typedef Magnum::Color4 Color4; +typedef Magnum::Color3 Color3f; +typedef Magnum::Color4 Color4f; ColorTest::ColorTest() { addTests(&ColorTest::access, @@ -130,7 +130,7 @@ void ColorTest::hsv() { CORRADE_COMPARE(Color3::fromHSV(Deg(230.0f), 0.749f, 0.427f), Color3(27, 40, 108)); Deg hue; - float saturation, value; + Float saturation, value; std::tie(hue, saturation, value) = Color3(27, 41, 109).toHSV(); CORRADE_COMPARE(hue, Deg(229.756106f)); CORRADE_COMPARE(saturation, 0.752294f); diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 6028555d8..18f4ed22f 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -45,16 +45,16 @@ class Data { inline ~Data() { --count; } }; -typedef Magnum::ResourceManager ResourceManager; +typedef Magnum::ResourceManager ResourceManager; -class IntResourceLoader: public AbstractResourceLoader { +class IntResourceLoader: public AbstractResourceLoader { public: void load(ResourceKey key) override { AbstractResourceLoader::load(key); } void load() { - set("hello", new std::int32_t(773), ResourceDataState::Final, ResourcePolicy::Resident); + set("hello", new Int(773), ResourceDataState::Final, ResourcePolicy::Resident); setNotFound("world"); } }; @@ -143,27 +143,27 @@ void ResourceManagerTest::basic() { /* One mutable, one final */ ResourceKey questionKey("the-question"); ResourceKey answerKey("the-answer"); - rm.set(questionKey, new std::int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); - rm.set(answerKey, new std::int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); - Resource theQuestion = rm.get(questionKey); - Resource theAnswer = rm.get(answerKey); + rm.set(questionKey, new Int(10), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm.set(answerKey, new Int(42), ResourceDataState::Final, ResourcePolicy::Resident); + Resource theQuestion = rm.get(questionKey); + Resource theAnswer = rm.get(answerKey); /* Check basic functionality */ CORRADE_COMPARE(theQuestion.state(), ResourceState::Mutable); CORRADE_COMPARE(theAnswer.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 10); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(rm.count(), 2); + CORRADE_COMPARE(rm.count(), 2); /* Cannot change already final resource */ std::ostringstream out; Error::setOutput(&out); - rm.set(answerKey, new std::int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm.set(answerKey, new Int(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource " + answerKey.hexString() + '\n'); /* But non-final can be changed */ - rm.set(questionKey, new std::int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); + rm.set(questionKey, new Int(20), ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_COMPARE(theQuestion.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } @@ -235,8 +235,8 @@ void ResourceManagerTest::loader() { rm.setLoader(&loader); Resource data = rm.get("data"); - Resource hello = rm.get("hello"); - Resource world = rm.get("world"); + Resource hello = rm.get("hello"); + Resource world = rm.get("world"); CORRADE_COMPARE(data.state(), ResourceState::NotLoaded); CORRADE_COMPARE(hello.state(), ResourceState::Loading); CORRADE_COMPARE(world.state(), ResourceState::Loading); diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index d3f500333..5a50565a4 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -44,18 +44,18 @@ void SwizzleTest::type() { CORRADE_VERIFY((std::is_same(orig)), Vector3i>::value)); CORRADE_VERIFY((std::is_same(orig)), Vector4i>::value)); - Color3 origColor3; - Color4 origColor4; - CORRADE_VERIFY((std::is_same(origColor3)), Color3<>>::value)); - CORRADE_VERIFY((std::is_same(origColor4)), Color3>::value)); - CORRADE_VERIFY((std::is_same(origColor3)), Color4<>>::value)); - CORRADE_VERIFY((std::is_same(origColor4)), Color4>::value)); + Color3 origColor3; + Color4 origColor4; + CORRADE_VERIFY((std::is_same(origColor3)), Color3>::value)); + CORRADE_VERIFY((std::is_same(origColor4)), Color3>::value)); + CORRADE_VERIFY((std::is_same(origColor3)), Color4>::value)); + CORRADE_VERIFY((std::is_same(origColor4)), Color4>::value)); } void SwizzleTest::defaultType() { Vector4i orig(1, 2, 3, 4); - CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, std::int32_t>(3))); - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, std::int32_t>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle<'b'>(orig), (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))); } }} diff --git a/src/Texture.h b/src/Texture.h index 80cf12063..6e946227c 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -107,9 +107,9 @@ generateMipmap() documentation for more information. @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @todo @extension{AMD,sparse_texture} */ -template class Texture: public AbstractTexture { +template class Texture: public AbstractTexture { public: - static const std::uint8_t Dimensions = dimensions; /**< @brief %Texture dimension count */ + static const UnsignedInt Dimensions = dimensions; /**< @brief %Texture dimension count */ #ifdef DOXYGEN_GENERATING_OUTPUT /** @@ -186,7 +186,7 @@ template class Texture: public AbstractTexture { * with @def_gl{TEXTURE_WIDTH}, @def_gl{TEXTURE_HEIGHT} or @def_gl{TEXTURE_DEPTH}. * @requires_gl %Texture image queries are not available in OpenGL ES. */ - inline typename DimensionTraits::VectorType imageSize(GLint level) { + inline typename DimensionTraits::VectorType imageSize(Int level) { return DataHelper::imageSize(this, _target, level); } #endif @@ -236,7 +236,7 @@ template class Texture: public AbstractTexture { * @requires_gl42 %Extension @extension{ARB,texture_storage} * @requires_gles30 %Extension @es_extension{EXT,texture_storage} */ - inline Texture* setStorage(GLsizei levels, InternalFormat internalFormat, const typename DimensionTraits::VectorType& size) { + inline Texture* setStorage(Int levels, InternalFormat internalFormat, const typename DimensionTraits::VectorType& size) { DataHelper::setStorage(this, _target, levels, internalFormat, size); return this; } @@ -263,7 +263,7 @@ template class Texture: public AbstractTexture { * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access} */ - template inline Texture* setImage(GLint level, InternalFormat internalFormat, Image* image) { + template inline Texture* setImage(Int level, InternalFormat internalFormat, Image* image) { DataHelper::set(this, _target, level, internalFormat, image); return this; } @@ -293,7 +293,7 @@ template class Texture: public AbstractTexture { * @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} */ - template inline Texture* setSubImage(GLint level, const typename DimensionTraits::VectorType& offset, Image* image) { + template inline Texture* setSubImage(Int level, const typename DimensionTraits::VectorType& offset, Image* image) { DataHelper::setSub(this, _target, level, offset, image); return this; } @@ -308,7 +308,7 @@ template class Texture: public AbstractTexture { * is not available, this function does nothing. * @see invalidateImage(), @fn_gl{InvalidateTexSubImage} */ - inline void invalidateSubImage(GLint level, const typename DimensionTraits::VectorType& offset, const typename DimensionTraits::VectorType& size) { + inline void invalidateSubImage(Int level, const typename DimensionTraits::VectorType& offset, const typename DimensionTraits::VectorType& size) { DataHelper::invalidateSub(this, level, offset, size); } @@ -327,7 +327,7 @@ template class Texture: public AbstractTexture { AbstractTexture::setBorderColor(color); return this; } - inline Texture* setMaxAnisotropy(GLfloat anisotropy) { + inline Texture* setMaxAnisotropy(Float anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); return this; } diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 3a4419464..a94d19376 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -39,7 +39,7 @@ void Timeline::nextFrame() { if(!running) return; auto now = high_resolution_clock::now(); - std::uint32_t duration = duration_cast(now-_previousFrameTime).count(); + UnsignedInt duration = duration_cast(now-_previousFrameTime).count(); _previousFrameDuration = duration/1e6f; if(_previousFrameDuration < _minimalFrameTime) { @@ -51,7 +51,7 @@ void Timeline::nextFrame() { _previousFrameTime = now; } -GLfloat Timeline::previousFrameTime() const { +Float Timeline::previousFrameTime() const { return duration_cast(_previousFrameTime-_startTime).count()/1e6f; } diff --git a/src/Timeline.h b/src/Timeline.h index 581f2ba2b..91908937e 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -60,7 +60,7 @@ MyApplication::MyApplication(...): Platform::GlutApplication(...) { void MyApplication::drawEvent() { // Distance of object travelling at speed of 15 units per second - GLfloat distance = 15.0f*timeline.previousFrameDuration(); + Float distance = 15.0f*timeline.previousFrameDuration(); // Move object, draw ... @@ -81,7 +81,7 @@ class MAGNUM_EXPORT Timeline { inline constexpr explicit Timeline(): _minimalFrameTime(0), _previousFrameDuration(0), running(false) {} /** @brief Minimal frame time (in seconds) */ - inline constexpr GLfloat minimalFrameTime() const { + inline constexpr Float minimalFrameTime() const { return _minimalFrameTime; } @@ -91,7 +91,7 @@ class MAGNUM_EXPORT Timeline { * Default value is 0. * @see nextFrame() */ - inline void setMinimalFrameTime(GLfloat seconds) { + inline void setMinimalFrameTime(Float seconds) { _minimalFrameTime = seconds; } @@ -126,22 +126,22 @@ class MAGNUM_EXPORT Timeline { * Returns time elapsed since start() was called. If the timeline is * stopped, the function returns `0.0f`. */ - GLfloat previousFrameTime() const; + Float previousFrameTime() const; /** * @brief Duration of previous frame (in seconds) * * If the timeline is stopped, the function returns `0.0f`. */ - inline constexpr GLfloat previousFrameDuration() const { + inline constexpr Float previousFrameDuration() const { return _previousFrameDuration; } private: std::chrono::high_resolution_clock::time_point _startTime; std::chrono::high_resolution_clock::time_point _previousFrameTime; - GLfloat _minimalFrameTime; - GLfloat _previousFrameDuration; + Float _minimalFrameTime; + Float _previousFrameDuration; bool running; }; From 7af5ff17b6901c80680a6c665799672dc6760cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 22:51:38 +0100 Subject: [PATCH 465/567] Trade: using new type aliases in whole Trade namespace. --- src/Trade/AbstractImporter.h | 170 +++++++++++++++++----------------- src/Trade/ImageData.h | 10 +- src/Trade/MeshData2D.h | 20 ++-- src/Trade/MeshData3D.h | 26 +++--- src/Trade/MeshObjectData2D.h | 6 +- src/Trade/MeshObjectData3D.h | 6 +- src/Trade/ObjectData2D.h | 12 +-- src/Trade/ObjectData3D.h | 12 +-- src/Trade/PhongMaterialData.h | 6 +- src/Trade/SceneData.h | 8 +- src/Trade/Trade.h | 4 +- 11 files changed, 140 insertions(+), 140 deletions(-) diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 8bc77668f..b2c78dea5 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -105,10 +105,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * @note The function is not const, because the value will probably * be lazy-populated. */ - virtual inline std::int32_t defaultScene() { return -1; } + virtual inline Int defaultScene() { return -1; } /** @brief %Scene count */ - virtual inline std::uint32_t sceneCount() const { return 0; } + virtual inline UnsignedInt sceneCount() const { return 0; } /** * @brief %Scene ID for given name @@ -116,7 +116,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no scene for given name exists, returns -1. * @see sceneName() */ - virtual std::int32_t sceneForName(const std::string& name); + virtual Int sceneForName(const std::string& name); /** * @brief %Scene name @@ -124,7 +124,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see sceneForName() */ - virtual std::string sceneName(std::uint32_t id); + virtual std::string sceneName(UnsignedInt id); /** * @brief %Scene @@ -132,10 +132,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given scene or nullptr, if no such scene exists. */ - virtual SceneData* scene(std::uint32_t id); + virtual SceneData* scene(UnsignedInt id); /** @brief %Light count */ - virtual inline std::uint32_t lightCount() const { return 0; } + virtual inline UnsignedInt lightCount() const { return 0; } /** * @brief %Light ID for given name @@ -143,7 +143,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no light for given name exists, returns -1. * @see lightName() */ - virtual std::int32_t lightForName(const std::string& name); + virtual Int lightForName(const std::string& name); /** * @brief %Light name @@ -151,7 +151,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see lightForName() */ - virtual std::string lightName(std::uint32_t id); + virtual std::string lightName(UnsignedInt id); /** * @brief %Light @@ -159,10 +159,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given light or nullptr, if no such light exists. */ - virtual LightData* light(std::uint32_t id); + virtual LightData* light(UnsignedInt id); /** @brief Camera count */ - virtual inline std::uint32_t cameraCount() const { return 0; } + virtual inline UnsignedInt cameraCount() const { return 0; } /** * @brief Camera ID for given name @@ -170,7 +170,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no camera for given name exists, returns -1. * @see cameraName() */ - virtual std::int32_t cameraForName(const std::string& name); + virtual Int cameraForName(const std::string& name); /** * @brief Camera name @@ -178,7 +178,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see cameraForName() */ - virtual std::string cameraName(std::uint32_t id); + virtual std::string cameraName(UnsignedInt id); /** * @brief Camera @@ -187,10 +187,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given camera or nullptr, if no such camera * exists. */ - virtual CameraData* camera(std::uint32_t id); + virtual CameraData* camera(UnsignedInt id); /** @brief Two-dimensional object count */ - virtual inline std::uint32_t object2DCount() const { return 0; } + virtual inline UnsignedInt object2DCount() const { return 0; } /** * @brief Two-dimensional object ID for given name @@ -198,7 +198,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no scene for given name exists, returns -1. * @see object2DName() */ - virtual std::int32_t object2DForName(const std::string& name); + virtual Int object2DForName(const std::string& name); /** * @brief Two-dimensional object name @@ -206,7 +206,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see object2DForName() */ - virtual std::string object2DName(std::uint32_t id); + virtual std::string object2DName(UnsignedInt id); /** * @brief Two-dimensional object @@ -215,10 +215,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given object or nullptr, if no such object * exists. */ - virtual ObjectData2D* object2D(std::uint32_t id); + virtual ObjectData2D* object2D(UnsignedInt id); /** @brief Three-dimensional object count */ - virtual inline std::uint32_t object3DCount() const { return 0; } + virtual inline UnsignedInt object3DCount() const { return 0; } /** * @brief Three-dimensional object ID for given name @@ -226,7 +226,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no scene for given name exists, returns -1. * @see object3DName() */ - virtual std::int32_t object3DForName(const std::string& name); + virtual Int object3DForName(const std::string& name); /** * @brief Three-dimensional object name @@ -234,7 +234,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see object3DForName() */ - virtual std::string object3DName(std::uint32_t id); + virtual std::string object3DName(UnsignedInt id); /** * @brief Three-dimensional object @@ -243,10 +243,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given object or nullptr, if no such object * exists. */ - virtual ObjectData3D* object3D(std::uint32_t id); + virtual ObjectData3D* object3D(UnsignedInt id); /** @brief Two-dimensional mesh count */ - virtual inline std::uint32_t mesh2DCount() const { return 0; } + virtual inline UnsignedInt mesh2DCount() const { return 0; } /** * @brief Two-dimensional mesh ID for given name @@ -254,7 +254,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no mesh for given name exists, returns -1. * @see mesh2DName() */ - virtual std::int32_t mesh2DForName(const std::string& name); + virtual Int mesh2DForName(const std::string& name); /** * @brief Two-dimensional mesh name @@ -262,7 +262,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see mesh2DForName() */ - virtual std::string mesh2DName(std::uint32_t id); + virtual std::string mesh2DName(UnsignedInt id); /** * @brief Two-dimensional mesh @@ -270,10 +270,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ - virtual MeshData2D* mesh2D(std::uint32_t id); + virtual MeshData2D* mesh2D(UnsignedInt id); /** @brief Three-dimensional mesh count */ - virtual inline std::uint32_t mesh3DCount() const { return 0; } + virtual inline UnsignedInt mesh3DCount() const { return 0; } /** * @brief Three-dimensional mesh ID for given name @@ -281,7 +281,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no mesh for given name exists, returns -1. * @see mesh3DName() */ - virtual std::int32_t mesh3DForName(const std::string& name); + virtual Int mesh3DForName(const std::string& name); /** * @brief Three-dimensional mesh name @@ -289,7 +289,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see mesh3DForName() */ - virtual std::string mesh3DName(std::uint32_t id); + virtual std::string mesh3DName(UnsignedInt id); /** * @brief Three-dimensional mesh @@ -297,10 +297,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given mesh or nullptr, if no such mesh exists. */ - virtual MeshData3D* mesh3D(std::uint32_t id); + virtual MeshData3D* mesh3D(UnsignedInt id); /** @brief Material count */ - virtual inline std::uint32_t materialCount() const { return 0; } + virtual inline UnsignedInt materialCount() const { return 0; } /** * @brief Material ID for given name @@ -308,7 +308,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no material for given name exists, returns -1. * @see materialName() */ - virtual std::int32_t materialForName(const std::string& name); + virtual Int materialForName(const std::string& name); /** * @brief Material name @@ -316,7 +316,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see materialForName() */ - virtual std::string materialName(std::uint32_t id); + virtual std::string materialName(UnsignedInt id); /** * @brief Material @@ -325,10 +325,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given material or nullptr, if no such material * exists. */ - virtual AbstractMaterialData* material(std::uint32_t id); + virtual AbstractMaterialData* material(UnsignedInt id); /** @brief %Texture count */ - virtual inline std::uint32_t textureCount() const { return 0; } + virtual inline UnsignedInt textureCount() const { return 0; } /** * @brief %Texture ID for given name @@ -336,7 +336,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no texture for given name exists, returns -1. * @see textureName() */ - virtual std::int32_t textureForName(const std::string& name); + virtual Int textureForName(const std::string& name); /** * @brief %Texture name @@ -344,7 +344,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see textureForName() */ - virtual std::string textureName(std::uint32_t id); + virtual std::string textureName(UnsignedInt id); /** * @brief %Texture @@ -353,10 +353,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * Returns pointer to given texture or nullptr, if no such texture * exists. */ - virtual TextureData* texture(std::uint32_t id); + virtual TextureData* texture(UnsignedInt id); /** @brief One-dimensional image count */ - virtual inline std::uint32_t image1DCount() const { return 0; } + virtual inline UnsignedInt image1DCount() const { return 0; } /** * @brief One-dimensional image ID for given name @@ -364,7 +364,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no image for given name exists, returns -1. * @see image1Dname() */ - virtual std::int32_t image1DForName(const std::string& name); + virtual Int image1DForName(const std::string& name); /** * @brief One-dimensional image name @@ -372,7 +372,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see image1DForName() */ - virtual std::string image1DName(std::uint32_t id); + virtual std::string image1DName(UnsignedInt id); /** * @brief One-dimensional image @@ -380,10 +380,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given image or nullptr, if no such image exists. */ - virtual ImageData1D* image1D(std::uint32_t id); + virtual ImageData1D* image1D(UnsignedInt id); /** @brief Two-dimensional image count */ - virtual inline std::uint32_t image2DCount() const { return 0; } + virtual inline UnsignedInt image2DCount() const { return 0; } /** * @brief Two-dimensional image ID for given name @@ -391,7 +391,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no image for given name exists, returns -1. * @see image2DName() */ - virtual std::int32_t image2DForName(const std::string& name); + virtual Int image2DForName(const std::string& name); /** * @brief Two-dimensional image name @@ -399,7 +399,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see image2DForName() */ - virtual std::string image2DName(std::uint32_t id); + virtual std::string image2DName(UnsignedInt id); /** * @brief Two-dimensional image @@ -407,10 +407,10 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given image or nullptr, if no such image exists. */ - virtual ImageData2D* image2D(std::uint32_t id); + virtual ImageData2D* image2D(UnsignedInt id); /** @brief Three-dimensional image count */ - virtual inline std::uint32_t image3DCount() const { return 0; } + virtual inline UnsignedInt image3DCount() const { return 0; } /** * @brief Three-dimensional image ID for given name @@ -418,7 +418,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * If no image for given name exists, returns -1. * @see image3DName() */ - virtual std::int32_t image3DForName(const std::string& name); + virtual Int image3DForName(const std::string& name); /** * @brief Three-dimensional image name @@ -426,7 +426,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * @see image3DForName() */ - virtual std::string image3DName(std::uint32_t id); + virtual std::string image3DName(UnsignedInt id); /** * @brief Three-dimensional image @@ -434,7 +434,7 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { * * Returns pointer to given image or nullptr, if no such image exists. */ - virtual ImageData3D* image3D(std::uint32_t id); + virtual ImageData3D* image3D(UnsignedInt id); /*@}*/ }; @@ -442,42 +442,42 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { CORRADE_ENUMSET_OPERATORS(AbstractImporter::Features) /* Implementations for inline functions with unused parameters */ -inline std::int32_t AbstractImporter::sceneForName(const std::string&) { return -1; } -inline std::string AbstractImporter::sceneName(std::uint32_t) { return {}; } -inline SceneData* AbstractImporter::scene(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::lightForName(const std::string&) { return -1; } -inline std::string AbstractImporter::lightName(std::uint32_t) { return {}; } -inline LightData* AbstractImporter::light(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::cameraForName(const std::string&) { return -1; } -inline std::string AbstractImporter::cameraName(std::uint32_t) { return {}; } -inline CameraData* AbstractImporter::camera(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::object2DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::object2DName(std::uint32_t) { return {}; } -inline ObjectData2D* AbstractImporter::object2D(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::object3DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::object3DName(std::uint32_t) { return {}; } -inline ObjectData3D* AbstractImporter::object3D(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::mesh2DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::mesh2DName(std::uint32_t) { return {}; } -inline MeshData2D* AbstractImporter::mesh2D(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::mesh3DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::mesh3DName(std::uint32_t) { return {}; } -inline MeshData3D* AbstractImporter::mesh3D(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::materialForName(const std::string&) { return -1; } -inline std::string AbstractImporter::materialName(std::uint32_t) { return {}; } -inline AbstractMaterialData* AbstractImporter::material(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::textureForName(const std::string&) { return -1; } -inline std::string AbstractImporter::textureName(std::uint32_t) { return {}; } -inline TextureData* AbstractImporter::texture(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::image1DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::image1DName(std::uint32_t) { return {}; } -inline ImageData1D* AbstractImporter::image1D(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::image2DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::image2DName(std::uint32_t) { return {}; } -inline ImageData2D* AbstractImporter::image2D(std::uint32_t) { return nullptr; } -inline std::int32_t AbstractImporter::image3DForName(const std::string&) { return -1; } -inline std::string AbstractImporter::image3DName(std::uint32_t) { return {}; } -inline ImageData3D* AbstractImporter::image3D(std::uint32_t) { return nullptr; } +inline Int AbstractImporter::sceneForName(const std::string&) { return -1; } +inline std::string AbstractImporter::sceneName(UnsignedInt) { return {}; } +inline SceneData* AbstractImporter::scene(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::lightForName(const std::string&) { return -1; } +inline std::string AbstractImporter::lightName(UnsignedInt) { return {}; } +inline LightData* AbstractImporter::light(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::cameraForName(const std::string&) { return -1; } +inline std::string AbstractImporter::cameraName(UnsignedInt) { return {}; } +inline CameraData* AbstractImporter::camera(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::object2DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::object2DName(UnsignedInt) { return {}; } +inline ObjectData2D* AbstractImporter::object2D(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::object3DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::object3DName(UnsignedInt) { return {}; } +inline ObjectData3D* AbstractImporter::object3D(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::mesh2DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::mesh2DName(UnsignedInt) { return {}; } +inline MeshData2D* AbstractImporter::mesh2D(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::mesh3DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::mesh3DName(UnsignedInt) { return {}; } +inline MeshData3D* AbstractImporter::mesh3D(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::materialForName(const std::string&) { return -1; } +inline std::string AbstractImporter::materialName(UnsignedInt) { return {}; } +inline AbstractMaterialData* AbstractImporter::material(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::textureForName(const std::string&) { return -1; } +inline std::string AbstractImporter::textureName(UnsignedInt) { return {}; } +inline TextureData* AbstractImporter::texture(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::image1DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::image1DName(UnsignedInt) { return {}; } +inline ImageData1D* AbstractImporter::image1D(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::image2DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::image2DName(UnsignedInt) { return {}; } +inline ImageData2D* AbstractImporter::image2D(UnsignedInt) { return nullptr; } +inline Int AbstractImporter::image3DForName(const std::string&) { return -1; } +inline std::string AbstractImporter::image3DName(UnsignedInt) { return {}; } +inline ImageData3D* AbstractImporter::image3D(UnsignedInt) { return nullptr; } }} diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index bd41ecf74..d1c4d9094 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -32,9 +32,9 @@ Access to image data provided by AbstractImporter subclasses. Interchangeable with Image, ImageWrapper or BufferImage. @see ImageData1D, ImageData2D, ImageData3D */ -template class ImageData: public AbstractImage { +template class ImageData: public AbstractImage { public: - const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ + const static UnsignedInt Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor @@ -46,20 +46,20 @@ template class ImageData: public AbstractImage { * Note that the image data are not copied on construction, but they * are deleted on class destruction. */ - inline ImageData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} + inline ImageData(const typename DimensionTraits::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast(data)) {} /** @brief Destructor */ inline ~ImageData() { delete[] _data; } /** @brief %Image size */ - inline typename DimensionTraits::VectorType size() const { return _size; } + inline typename DimensionTraits::VectorType size() const { return _size; } /** @brief Pointer to raw data */ inline void* data() { return _data; } inline const void* data() const { return _data; } /**< @overload */ private: - Math::Vector _size; + Math::Vector _size; char* _data; }; diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index 85f6ea7d3..08dbc9911 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -47,7 +47,7 @@ class MAGNUM_EXPORT MeshData2D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} + inline MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _textureCoords2D(textureCoords2D) {} /** @brief Move constructor */ MeshData2D(MeshData2D&&) = default; @@ -65,11 +65,11 @@ class MAGNUM_EXPORT MeshData2D { * @brief Indices * @return Indices or nullptr if the mesh is not indexed. */ - inline std::vector* indices() { return _indices; } - inline const std::vector* indices() const { return _indices; } /**< @overload */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ - inline std::uint32_t positionArrayCount() const { return _positions.size(); } + inline UnsignedInt positionArrayCount() const { return _positions.size(); } /** * @brief Positions @@ -77,11 +77,11 @@ class MAGNUM_EXPORT MeshData2D { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(std::uint32_t id) { return _positions[id]; } - inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(UnsignedInt id) { return _positions[id]; } + inline const std::vector* positions(UnsignedInt id) const { return _positions[id]; } /**< @overload */ /** @brief Count of 2D texture coordinate arrays */ - inline std::uint32_t textureCoords2DArrayCount() const { return _textureCoords2D.size(); } + inline UnsignedInt textureCoords2DArrayCount() const { return _textureCoords2D.size(); } /** * @brief 2D texture coordinates @@ -89,12 +89,12 @@ class MAGNUM_EXPORT MeshData2D { * @return %Texture coordinates or nullptr if there is no texture * coordinates array with given ID. */ - inline std::vector* textureCoords2D(std::uint32_t id) { return _textureCoords2D[id]; } - inline const std::vector* textureCoords2D(std::uint32_t id) const { return _textureCoords2D[id]; } /**< @overload */ + inline std::vector* textureCoords2D(UnsignedInt id) { return _textureCoords2D[id]; } + inline const std::vector* textureCoords2D(UnsignedInt id) const { return _textureCoords2D[id]; } /**< @overload */ private: Mesh::Primitive _primitive; - std::vector* _indices; + std::vector* _indices; std::vector*> _positions; std::vector*> _textureCoords2D; }; diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 17a1ac802..94c60def4 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -48,7 +48,7 @@ class MAGNUM_EXPORT MeshData3D { * @param textureCoords2D Array with two-dimensional texture * coordinate arrays or empty array */ - inline MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} + inline MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(positions), _normals(normals), _textureCoords2D(textureCoords2D) {} /** @brief Move constructor */ MeshData3D(MeshData3D&&) = default; @@ -66,11 +66,11 @@ class MAGNUM_EXPORT MeshData3D { * @brief Indices * @return Indices or nullptr if the mesh is not indexed. */ - inline std::vector* indices() { return _indices; } - inline const std::vector* indices() const { return _indices; } /**< @overload */ + inline std::vector* indices() { return _indices; } + inline const std::vector* indices() const { return _indices; } /**< @overload */ /** @brief Count of vertex position arrays */ - inline std::uint32_t positionArrayCount() const { return _positions.size(); } + inline UnsignedInt positionArrayCount() const { return _positions.size(); } /** * @brief Positions @@ -78,11 +78,11 @@ class MAGNUM_EXPORT MeshData3D { * @return Positions or nullptr if there is no vertex array with given * ID. */ - inline std::vector* positions(std::uint32_t id) { return _positions[id]; } - inline const std::vector* positions(std::uint32_t id) const { return _positions[id]; } /**< @overload */ + inline std::vector* positions(UnsignedInt id) { return _positions[id]; } + inline const std::vector* positions(UnsignedInt id) const { return _positions[id]; } /**< @overload */ /** @brief Count of normal arrays */ - inline std::uint32_t normalArrayCount() const { return _normals.size(); } + inline UnsignedInt normalArrayCount() const { return _normals.size(); } /** * @brief Normals @@ -90,11 +90,11 @@ class MAGNUM_EXPORT MeshData3D { * @return Normals or nullptr if there is no normal array with given * ID. */ - inline std::vector* normals(std::uint32_t id) { return _normals[id]; } - inline const std::vector* normals(std::uint32_t id) const { return _normals[id]; } /**< @overload */ + inline std::vector* normals(UnsignedInt id) { return _normals[id]; } + inline const std::vector* normals(UnsignedInt id) const { return _normals[id]; } /**< @overload */ /** @brief Count of 2D texture coordinate arrays */ - inline std::uint32_t textureCoords2DArrayCount() const { return _textureCoords2D.size(); } + inline UnsignedInt textureCoords2DArrayCount() const { return _textureCoords2D.size(); } /** * @brief 2D texture coordinates @@ -102,12 +102,12 @@ class MAGNUM_EXPORT MeshData3D { * @return %Texture coordinates or nullptr if there is no texture * coordinates array with given ID. */ - inline std::vector* textureCoords2D(std::uint32_t id) { return _textureCoords2D[id]; } - inline const std::vector* textureCoords2D(std::uint32_t id) const { return _textureCoords2D[id]; } /**< @overload */ + inline std::vector* textureCoords2D(UnsignedInt id) { return _textureCoords2D[id]; } + inline const std::vector* textureCoords2D(UnsignedInt id) const { return _textureCoords2D[id]; } /**< @overload */ private: Mesh::Primitive _primitive; - std::vector* _indices; + std::vector* _indices; std::vector*> _positions; std::vector*> _normals; std::vector*> _textureCoords2D; diff --git a/src/Trade/MeshObjectData2D.h b/src/Trade/MeshObjectData2D.h index ac99eb223..14dabdd4e 100644 --- a/src/Trade/MeshObjectData2D.h +++ b/src/Trade/MeshObjectData2D.h @@ -45,13 +45,13 @@ class MeshObjectData2D: public ObjectData2D { * * Creates object with mesh instance type. */ - inline MeshObjectData2D(const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData2D(children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData2D(const std::vector& children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material): ObjectData2D(children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ - inline std::uint32_t material() const { return _material; } + inline UnsignedInt material() const { return _material; } private: - std::uint32_t _material; + UnsignedInt _material; }; }} diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h index 8c1f381a1..05dbf10e2 100644 --- a/src/Trade/MeshObjectData3D.h +++ b/src/Trade/MeshObjectData3D.h @@ -45,13 +45,13 @@ class MeshObjectData3D: public ObjectData3D { * * Creates object with mesh instance type. */ - inline MeshObjectData3D(const std::vector& children, const Matrix4& transformation, std::uint32_t instance, std::uint32_t material): ObjectData3D(children, transformation, InstanceType::Mesh, instance), _material(material) {} + inline MeshObjectData3D(const std::vector& children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material): ObjectData3D(children, transformation, InstanceType::Mesh, instance), _material(material) {} /** @brief Material ID */ - inline std::uint32_t material() const { return _material; } + inline UnsignedInt material() const { return _material; } private: - std::uint32_t _material; + UnsignedInt _material; }; }} diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h index 40ae13a97..a40f305ce 100644 --- a/src/Trade/ObjectData2D.h +++ b/src/Trade/ObjectData2D.h @@ -54,20 +54,20 @@ class ObjectData2D { * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData2D(const std::vector& children, const Matrix3& transformation, InstanceType instanceType, std::uint32_t instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData2D(const std::vector& children, const Matrix3& transformation, InstanceType instanceType, UnsignedInt instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData2D(const std::vector& children, const Matrix3& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData2D(const std::vector& children, const Matrix3& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ inline virtual ~ObjectData2D() {} /** @brief Child objects */ - inline std::vector& children() { return _children; } + inline std::vector& children() { return _children; } /** @brief Transformation (relative to parent) */ inline Matrix3 transformation() const { return _transformation; } @@ -86,13 +86,13 @@ class ObjectData2D { * @return ID of given camera / light / mesh etc., specified by * instanceType() */ - inline std::int32_t instanceId() const { return _instanceId; } + inline Int instanceId() const { return _instanceId; } private: - std::vector _children; + std::vector _children; Matrix3 _transformation; InstanceType _instanceType; - std::int32_t _instanceId; + Int _instanceId; }; /** @debugoperator{Magnum::Trade::ObjectData2D} */ diff --git a/src/Trade/ObjectData3D.h b/src/Trade/ObjectData3D.h index e6862cb52..3884c2a12 100644 --- a/src/Trade/ObjectData3D.h +++ b/src/Trade/ObjectData3D.h @@ -55,20 +55,20 @@ class ObjectData3D { * @param instanceType Instance type * @param instanceId Instance ID */ - inline ObjectData3D(const std::vector& children, const Matrix4& transformation, InstanceType instanceType, std::uint32_t instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} + inline ObjectData3D(const std::vector& children, const Matrix4& transformation, InstanceType instanceType, UnsignedInt instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {} /** * @brief Constructor for empty instance * @param children Child objects * @param transformation Transformation (relative to parent) */ - inline ObjectData3D(const std::vector& children, const Matrix4& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} + inline ObjectData3D(const std::vector& children, const Matrix4& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {} /** @brief Destructor */ inline virtual ~ObjectData3D() {} /** @brief Child objects */ - inline std::vector& children() { return _children; } + inline std::vector& children() { return _children; } /** @brief Transformation (relative to parent) */ inline Matrix4 transformation() const { return _transformation; } @@ -87,13 +87,13 @@ class ObjectData3D { * @return ID of given camera / light / mesh etc., specified by * instanceType() */ - inline std::int32_t instanceId() const { return _instanceId; } + inline Int instanceId() const { return _instanceId; } private: - std::vector _children; + std::vector _children; Matrix4 _transformation; InstanceType _instanceType; - std::int32_t _instanceId; + Int _instanceId; }; /** @debugoperator{Magnum::Trade::ObjectData3D} */ diff --git a/src/Trade/PhongMaterialData.h b/src/Trade/PhongMaterialData.h index f726f1c3b..3d80f83e1 100644 --- a/src/Trade/PhongMaterialData.h +++ b/src/Trade/PhongMaterialData.h @@ -37,7 +37,7 @@ class PhongMaterialData: public AbstractMaterialData { * @param specularColor Specular color * @param shininess Shininess */ - PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, GLfloat shininess): AbstractMaterialData(Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {} + PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, Float shininess): AbstractMaterialData(Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {} /** @brief Ambient color */ inline Vector3 ambientColor() const { return _ambientColor; } @@ -49,13 +49,13 @@ class PhongMaterialData: public AbstractMaterialData { inline Vector3 specularColor() const { return _specularColor; } /** @brief Shininess */ - inline GLfloat shininess() const { return _shininess; } + inline Float shininess() const { return _shininess; } private: Vector3 _ambientColor, _diffuseColor, _specularColor; - GLfloat _shininess; + Float _shininess; }; }} diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index 17ad448eb..acc962870 100644 --- a/src/Trade/SceneData.h +++ b/src/Trade/SceneData.h @@ -39,16 +39,16 @@ class MAGNUM_EXPORT SceneData { * @param children2D Two-dimensional child objects * @param children3D Three-dimensional child objects */ - inline SceneData(const std::vector& children2D, const std::vector& children3D): _children2D(children2D), _children3D(children3D) {} + inline SceneData(const std::vector& children2D, const std::vector& children3D): _children2D(children2D), _children3D(children3D) {} /** @brief Two-dimensional child objects */ - inline const std::vector& children2D() const { return _children2D; } + inline const std::vector& children2D() const { return _children2D; } /** @brief Three-dimensional child objects */ - inline const std::vector& children3D() const { return _children3D; } + inline const std::vector& children3D() const { return _children3D; } private: - std::vector _children2D, + std::vector _children2D, _children3D; }; diff --git a/src/Trade/Trade.h b/src/Trade/Trade.h index b629b96d8..5ac365db3 100644 --- a/src/Trade/Trade.h +++ b/src/Trade/Trade.h @@ -19,7 +19,7 @@ * @brief Forward declarations for Magnum::Trade namespace */ -#include +#include "Types.h" namespace Magnum { namespace Trade { @@ -29,7 +29,7 @@ class AbstractImporter; class AbstractMaterialData; class CameraData; -template class ImageData; +template class ImageData; typedef ImageData<1> ImageData1D; typedef ImageData<2> ImageData2D; typedef ImageData<3> ImageData3D; From e4f6a531859db54b67cf24548b73695d8929a22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 22:52:40 +0100 Subject: [PATCH 466/567] Primitives: using new type aliases in whole Primitives namespace. --- src/Primitives/Capsule.cpp | 46 ++++++++++++++-------------- src/Primitives/Capsule.h | 14 ++++----- src/Primitives/Cube.cpp | 4 +-- src/Primitives/Cylinder.cpp | 10 +++--- src/Primitives/Cylinder.h | 4 +-- src/Primitives/Icosphere.cpp | 2 +- src/Primitives/Test/CapsuleTest.cpp | 4 +-- src/Primitives/Test/CylinderTest.cpp | 4 +-- src/Primitives/Test/UVSphereTest.cpp | 4 +-- src/Primitives/UVSphere.cpp | 4 +-- src/Primitives/UVSphere.h | 2 +- 11 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 94b6b8e5d..6ac9a6317 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -20,11 +20,11 @@ namespace Magnum { namespace Primitives { -Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float length, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), 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; - GLfloat hemisphereTextureCoordsVIncrement = 1.0f/(hemisphereRings*height); + Float height = 2.0f+length; + Float hemisphereTextureCoordsVIncrement = 1.0f/(hemisphereRings*height); Rad hemisphereRingAngleIncrement = Rad(Constants::pi())/(2*hemisphereRings); /* Bottom cap vertex */ @@ -48,9 +48,9 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std topFaceRing(); } -Capsule::Capsule(std::uint32_t segments, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(UnsignedInt segments, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} -void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { +void Capsule::capVertex(Float y, Float normalY, Float textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); normals(0)->push_back({0.0f, normalY, 0.0f}); @@ -58,15 +58,15 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { textureCoords2D(0)->push_back({0.5, textureCoordsV}); } -void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, Rad startRingAngle, Rad ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::hemisphereVertexRings(UnsignedInt count, Float centerY, Rad startRingAngle, Rad ringAngleIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement) { Rad segmentAngleIncrement = 2*Rad(Constants::pi())/segments; - GLfloat x, y, z; - for(std::uint32_t i = 0; i != count; ++i) { + Float x, y, z; + for(UnsignedInt i = 0; i != count; ++i) { Rad ringAngle = startRingAngle + i*ringAngleIncrement; x = z = Math::cos(ringAngle); y = Math::sin(ringAngle); - for(std::uint32_t j = 0; j != segments; ++j) { + for(UnsignedInt j = 0; j != segments; ++j) { Rad segmentAngle = j*segmentAngleIncrement; positions(0)->push_back({x*Math::sin(segmentAngle), centerY+y, z*Math::cos(segmentAngle)}); normals(0)->push_back({x*Math::sin(segmentAngle), y, z*Math::cos(segmentAngle)}); @@ -84,10 +84,10 @@ void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, Rad st } } -void Capsule::cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::cylinderVertexRings(UnsignedInt count, Float startY, Float yIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement) { Rad segmentAngleIncrement = 2*Rad(Constants::pi())/segments; - for(std::uint32_t i = 0; i != count; ++i) { - for(std::uint32_t j = 0; j != segments; ++j) { + for(UnsignedInt i = 0; i != count; ++i) { + for(UnsignedInt j = 0; j != segments; ++j) { Rad segmentAngle = j*segmentAngleIncrement; positions(0)->push_back({Math::sin(segmentAngle), startY, Math::cos(segmentAngle)}); normals(0)->push_back({Math::sin(segmentAngle), 0.0f, Math::cos(segmentAngle)}); @@ -108,7 +108,7 @@ void Capsule::cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat y } void Capsule::bottomFaceRing() { - for(std::uint32_t j = 0; j != segments; ++j) { + for(UnsignedInt j = 0; j != segments; ++j) { /* Bottom vertex */ indices()->push_back(0); @@ -121,16 +121,16 @@ void Capsule::bottomFaceRing() { } } -void Capsule::faceRings(std::uint32_t count, std::uint32_t offset) { - std::uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); +void Capsule::faceRings(UnsignedInt count, UnsignedInt offset) { + UnsignedInt vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(std::uint32_t i = 0; i != count; ++i) { - for(std::uint32_t j = 0; j != segments; ++j) { - std::uint32_t bottomLeft = i*vertexSegments+j+offset; - std::uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? + for(UnsignedInt i = 0; i != count; ++i) { + for(UnsignedInt j = 0; j != segments; ++j) { + UnsignedInt bottomLeft = i*vertexSegments+j+offset; + UnsignedInt bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? i*vertexSegments+j+1+offset : i*segments+offset); - std::uint32_t topLeft = bottomLeft+vertexSegments; - std::uint32_t topRight = bottomRight+vertexSegments; + UnsignedInt topLeft = bottomLeft+vertexSegments; + UnsignedInt topRight = bottomRight+vertexSegments; indices()->push_back(bottomLeft); indices()->push_back(bottomRight); @@ -143,9 +143,9 @@ void Capsule::faceRings(std::uint32_t count, std::uint32_t offset) { } void Capsule::topFaceRing() { - std::uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); + UnsignedInt vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(std::uint32_t j = 0; j != segments; ++j) { + for(UnsignedInt j = 0; j != segments; ++j) { /* Bottom left vertex */ indices()->push_back(normals(0)->size()-vertexSegments+j-1); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 1ae25f78b..461478796 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -55,19 +55,19 @@ class Capsule: public Trade::MeshData3D { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - explicit MAGNUM_PRIMITIVES_EXPORT Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); + explicit MAGNUM_PRIMITIVES_EXPORT Capsule(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: - Capsule(std::uint32_t segments, TextureCoords textureCoords); + Capsule(UnsignedInt segments, TextureCoords textureCoords); - void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV); - void hemisphereVertexRings(std::uint32_t count, GLfloat centerY, Rad startRingAngle, Rad ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); - void cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void capVertex(Float y, Float normalY, Float textureCoordsV); + void hemisphereVertexRings(UnsignedInt count, Float centerY, Rad startRingAngle, Rad ringAngleIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement); + void cylinderVertexRings(UnsignedInt count, Float startY, Float yIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement); void bottomFaceRing(); - void faceRings(std::uint32_t count, std::uint32_t offset = 1); + void faceRings(UnsignedInt count, UnsignedInt offset = 1); void topFaceRing(); - std::uint32_t segments; + UnsignedInt segments; TextureCoords textureCoords; }; diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 6c63afdc6..9319d341c 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ namespace Magnum { namespace Primitives { Trade::MeshData3D Cube::solid() { - return Trade::MeshData3D(Mesh::Primitive::Triangles, new std::vector{ + return Trade::MeshData3D(Mesh::Primitive::Triangles, new std::vector{ 0, 1, 2, 0, 2, 3, /* +Z */ 4, 5, 6, 4, 6, 7, /* +X */ 8, 9, 10, 8, 10, 11, /* +Y */ @@ -92,7 +92,7 @@ Trade::MeshData3D Cube::solid() { } Trade::MeshData3D Cube::wireframe() { - return Trade::MeshData3D(Mesh::Primitive::Lines, new std::vector{ + return Trade::MeshData3D(Mesh::Primitive::Lines, new std::vector{ 0, 1, 1, 2, 2, 3, 3, 0, /* +Z */ 4, 5, 5, 6, 6, 7, 7, 4, /* -Z */ 1, 5, 2, 6, /* +X */ diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 8b47b67f4..b51e991f5 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -20,11 +20,11 @@ namespace Magnum { namespace Primitives { -Cylinder::Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { +Cylinder::Cylinder(UnsignedInt rings, UnsignedInt segments, Float 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; - GLfloat textureCoordsV = flags & Flag::CapEnds ? 1.0f/(length+2.0f) : 0.0f; + Float y = length*0.5f; + Float textureCoordsV = flags & Flag::CapEnds ? 1.0f/(length+2.0f) : 0.0f; /* Bottom cap */ if(flags & Flag::CapEnds) { @@ -47,10 +47,10 @@ Cylinder::Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, if(flags & Flag::CapEnds) topFaceRing(); } -void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { +void Cylinder::capVertexRing(Float y, Float textureCoordsV, const Vector3& normal) { Rad segmentAngleIncrement = 2*Rad(Constants::pi())/segments; - for(std::uint32_t i = 0; i != segments; ++i) { + for(UnsignedInt i = 0; i != segments; ++i) { Rad segmentAngle = i*segmentAngleIncrement; positions(0)->push_back({Math::sin(segmentAngle), y, Math::cos(segmentAngle)}); normals(0)->push_back(normal); diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index a5b35beb8..1e8be915c 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -60,10 +60,10 @@ class Cylinder: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - explicit MAGNUM_PRIMITIVES_EXPORT Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); + explicit MAGNUM_PRIMITIVES_EXPORT Cylinder(UnsignedInt rings, UnsignedInt segments, Float length, Flags flags = Flags()); private: - void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal); + void capVertexRing(Float y, Float textureCoordsV, const Vector3& normal); }; CORRADE_ENUMSET_OPERATORS(Cylinder::Flags) diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index f7e003ba3..0dbd56845 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vector{ +Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vector{ 1, 2, 6, 1, 7, 2, 3, 4, 5, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 84177dc4a..d37ae82d9 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -94,7 +94,7 @@ void CapsuleTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (std::vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, @@ -169,7 +169,7 @@ void CapsuleTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*capsule.indices(), (std::vector{ + CORRADE_COMPARE_AS(*capsule.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 5e847a984..76cc5562e 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -67,7 +67,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 0.0f, -0.5f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5, 3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8 }), Container); @@ -169,7 +169,7 @@ void CylinderTest::withTextureCoordsAndCaps() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ + CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 494a6f4d0..3ede74162 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -67,7 +67,7 @@ void UVSphereTest::withoutTextureCoords() { {0.0f, 1.0f, 0.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (std::vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 7, 5, 6, 7, 6, 4, 7 @@ -109,7 +109,7 @@ void UVSphereTest::withTextureCoords() { {0.5f, 1.0f} }), Container); - CORRADE_COMPARE_AS(*sphere.indices(), (std::vector{ + CORRADE_COMPARE_AS(*sphere.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 9, 6, 7, 9, 7, 8, 9 diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 0746be437..5e898d9ce 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -19,10 +19,10 @@ namespace Magnum { namespace Primitives { -UVSphere::UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords): Capsule(segments, textureCoords) { +UVSphere::UVSphere(UnsignedInt rings, UnsignedInt 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; + Float textureCoordsVIncrement = 1.0f/rings; Rad ringAngleIncrement = Rad(Constants::pi())/rings; /* Bottom cap vertex */ diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index d2cd6400e..b23c6f702 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -42,7 +42,7 @@ class UVSphere: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - explicit MAGNUM_PRIMITIVES_EXPORT UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); + explicit MAGNUM_PRIMITIVES_EXPORT UVSphere(UnsignedInt rings, UnsignedInt segments, TextureCoords textureCoords = TextureCoords::DontGenerate); }; }} From 32b783505fe6fc31dcc50e7870a74e72145a67bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 22:53:59 +0100 Subject: [PATCH 467/567] MeshTools: using new type aliases in whole MeshTools namespace. --- src/MeshTools/Clean.h | 10 +++--- src/MeshTools/CombineIndexedArrays.h | 24 ++++++------- src/MeshTools/CompressIndices.cpp | 20 +++++------ src/MeshTools/CompressIndices.h | 8 ++--- src/MeshTools/FlipNormals.cpp | 2 +- src/MeshTools/FlipNormals.h | 8 ++--- src/MeshTools/GenerateFlatNormals.cpp | 6 ++-- src/MeshTools/GenerateFlatNormals.h | 6 ++-- src/MeshTools/Subdivide.h | 12 +++---- src/MeshTools/Test/CleanTest.cpp | 6 ++-- .../Test/CombineIndexedArraysTest.cpp | 34 +++++++++---------- src/MeshTools/Test/CompressIndicesTest.cpp | 6 ++-- src/MeshTools/Test/FlipNormalsTest.cpp | 6 ++-- .../Test/GenerateFlatNormalsTest.cpp | 6 ++-- src/MeshTools/Test/InterleaveTest.cpp | 32 ++++++++--------- src/MeshTools/Test/SubdivideTest.cpp | 8 ++--- src/MeshTools/Test/TipsifyTest.cpp | 12 +++---- src/MeshTools/Tipsify.cpp | 30 ++++++++-------- src/MeshTools/Tipsify.h | 12 +++---- 19 files changed, 124 insertions(+), 124 deletions(-) diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 60c940282..df6f1f5c2 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -32,7 +32,7 @@ namespace Implementation { template class Clean { public: - inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { if(indices.empty()) return; @@ -107,12 +107,12 @@ template class Clean { }; struct HashedVertex { - std::uint32_t oldIndex, newIndex; + UnsignedInt oldIndex, newIndex; - HashedVertex(std::uint32_t oldIndex, std::uint32_t newIndex): oldIndex(oldIndex), newIndex(newIndex) {} + HashedVertex(UnsignedInt oldIndex, UnsignedInt newIndex): oldIndex(oldIndex), newIndex(newIndex) {} }; - std::vector& indices; + std::vector& indices; std::vector& vertices; }; @@ -136,7 +136,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 07cef4980..528d3cd43 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -33,17 +33,17 @@ namespace Implementation { class CombineIndexedArrays { public: - template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { + template std::vector operator()(const std::tuple&, std::vector&>&... indexedArrays) { /* Compute index count */ std::size_t _indexCount = indexCount(std::get<0>(indexedArrays)...); /* Resulting index array */ - std::vector result; + std::vector result; result.resize(_indexCount); std::iota(result.begin(), result.end(), 0); /* All index combinations */ - std::vector > indexCombinations(_indexCount); + std::vector > indexCombinations(_indexCount); writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...); /* Make the combinations unique */ @@ -56,13 +56,13 @@ class CombineIndexedArrays { } private: - template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { + template inline static std::size_t indexCount(const std::vector& first, const std::vector&... next) { CORRADE_ASSERT(sizeof...(next) == 0 || indexCount(next...) == first.size(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.", 0); return first.size(); } - template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { + template static void writeCombinedIndices(std::vector>& output, const std::vector& first, const std::vector&... next) { /* Copy the data to output */ for(std::size_t i = 0; i != output.size(); ++i) output[i][size-sizeof...(next)-1] = first[i]; @@ -70,7 +70,7 @@ class CombineIndexedArrays { writeCombinedIndices(output, next...); } - template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { + template static void writeCombinedArrays(const std::vector>& combinedIndices, std::vector& first, std::vector&... next) { /* Rewrite output array */ std::vector output; for(std::size_t i = 0; i != combinedIndices.size(); ++i) @@ -82,8 +82,8 @@ class CombineIndexedArrays { /* Terminator functions for recursive calls */ inline static std::size_t indexCount() { return 0; } - template inline static void writeCombinedIndices(std::vector>&) {} - template inline static void writeCombinedArrays(const std::vector>&) {} + template inline static void writeCombinedIndices(std::vector>&) {} + template inline static void writeCombinedArrays(const std::vector>&) {} }; } @@ -105,13 +105,13 @@ avoid explicit verbose specification of tuple type, you can write it with help of some STL functions like shown below. Also if one index array is shader by more than one attribute array, just pass the index array more times. Example: @code -std::vector vertexIndices; +std::vector vertexIndices; std::vector positions; -std::vector normalTextureIndices; +std::vector normalTextureIndices; std::vector normals; std::vector textureCoordinates; -std::vector indices = MeshTools::combineIndexedArrays( +std::vector indices = MeshTools::combineIndexedArrays( std::make_tuple(std::cref(vertexIndices), std::ref(positions)), std::make_tuple(std::cref(normalTextureIndices), std::ref(normals)), std::make_tuple(std::cref(normalTextureIndices), std::ref(textureCoordinates)) @@ -125,7 +125,7 @@ attributes indexed with `indices`. /* Implementation note: It's done using tuples because it is more clear which parameter is index array and which is attribute array, mainly when both are of the same type. */ -template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { +template std::vector combineIndexedArrays(const std::tuple&, std::vector&>&... indexedArrays) { return Implementation::CombineIndexedArrays()(indexedArrays...); } diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index b76c5af3e..e100078c3 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -26,11 +26,11 @@ namespace Magnum { namespace MeshTools { namespace { template constexpr Mesh::IndexType indexType(); -template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedByte; } -template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedShort; } -template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedInt; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedByte; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedShort; } +template<> inline constexpr Mesh::IndexType indexType() { return Mesh::IndexType::UnsignedInt; } -template inline std::tuple compress(const std::vector& indices) { +template inline std::tuple compress(const std::vector& indices) { char* buffer = new char[indices.size()*sizeof(T)]; for(std::size_t i = 0; i != indices.size(); ++i) { T index = static_cast(indices[i]); @@ -40,15 +40,15 @@ template inline std::tuple compres return std::make_tuple(indices.size(), indexType(), buffer); } -std::tuple compressIndicesInternal(const std::vector& indices, std::uint32_t max) { +std::tuple compressIndicesInternal(const std::vector& indices, UnsignedInt max) { switch(Math::log(256, max)) { case 0: - return compress(indices); + return compress(indices); case 1: - return compress(indices); + return compress(indices); case 2: case 3: - return compress(indices); + return compress(indices); default: CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << max << "elements.", {}); @@ -58,11 +58,11 @@ std::tuple compressIndicesInternal(const st } #endif -std::tuple compressIndices(const std::vector& indices) { +std::tuple compressIndices(const std::vector& indices) { return compressIndicesInternal(indices, *std::max_element(indices.begin(), indices.end())); } -void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { +void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices) { auto minmax = std::minmax_element(indices.begin(), indices.end()); /** @todo Performance hint when range can be represented by smaller value? */ diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index ac67d5849..2b5d029ad 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -49,10 +49,10 @@ std::size_t dataSize = indexCount*Mesh::indexSize(indexType); delete[] data; @endcode -See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector&), +See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector&), which writes the compressed data directly into index buffer of given mesh. */ -std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); +std::tuple MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector& indices); /** @brief Compress vertex indices and write them to index buffer @@ -61,14 +61,14 @@ std::tuple MAGNUM_MESHTOOLS_EXPORT compress @param usage Index buffer usage @param indices Index array -The same as compressIndices(const std::vector&), but this +The same as compressIndices(const std::vector&), but this function writes the output to given buffer, updates index count and specifies index buffer with proper index range in the mesh, so you don't have to call Mesh::setIndexCount() and Mesh::setIndexBuffer() on your own. @see MeshTools::interleave() */ -void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector& indices); }} diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index 596dfb4a3..5dda1adc2 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace MeshTools { -void flipFaceWinding(std::vector& indices) { +void flipFaceWinding(std::vector& indices) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); for(std::size_t i = 0; i != indices.size(); i += 3) diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index 98d71eb08..c0f6f5519 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -31,15 +31,15 @@ namespace Magnum { namespace MeshTools { /** @brief Flip face winding -The same as flipNormals(std::vector&, std::vector&), +The same as flipNormals(std::vector&, std::vector&), but flips only face winding. */ -void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); /** @brief Flip mesh normals -The same as flipNormals(std::vector&, std::vector&), +The same as flipNormals(std::vector&, std::vector&), but flips only normals, not face winding. */ void MAGNUM_MESHTOOLS_EXPORT flipNormals(std::vector& normals); @@ -56,7 +56,7 @@ flipFaceWinding(), which flip normals or face winding only. @attention The function requires the mesh to have triangle faces, thus index count must be divisible by 3. */ -inline void flipNormals(std::vector& indices, std::vector& normals) { +inline void flipNormals(std::vector& indices, std::vector& normals) { flipFaceWinding(indices); flipNormals(normals); } diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index 2c5195728..dcc00bc5f 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -20,11 +20,11 @@ namespace Magnum { namespace MeshTools { -std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { - CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple, std::vector>())); +std::tuple, std::vector> generateFlatNormals(const std::vector& indices, const std::vector& positions) { + CORRADE_ASSERT(!(indices.size()%3), "MeshTools::generateFlatNormals(): index count is not divisible by 3!", (std::tuple, std::vector>())); /* Create normal for every triangle (assuming counterclockwise winding) */ - std::vector normalIndices; + std::vector normalIndices; normalIndices.reserve(indices.size()); std::vector normals; normals.reserve(indices.size()/3); diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index cdccb6d7e..b9060b292 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -38,10 +38,10 @@ namespace Magnum { namespace MeshTools { For each face generates one normal vector, removes duplicates before returning. Example usage: @code -std::vector vertexIndices; +std::vector vertexIndices; std::vector positions; -std::vector normalIndices; +std::vector normalIndices; std::vector normals; std::tie(normalIndices, normals) = MeshTools::generateFlatNormals(vertexIndices, positions); @endcode @@ -51,7 +51,7 @@ use the same indices. @attention Index count must be divisible by 3, otherwise zero length result is generated. */ -std::tuple, std::vector> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); +std::tuple, std::vector> MAGNUM_MESHTOOLS_EXPORT generateFlatNormals(const std::vector& indices, const std::vector& positions); }} diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index 8993bb4da..d98823267 100644 --- a/src/MeshTools/Subdivide.h +++ b/src/MeshTools/Subdivide.h @@ -29,7 +29,7 @@ namespace Implementation { template class Subdivide { public: - inline Subdivide(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} + inline Subdivide(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} void operator()(Interpolator interpolator) { CORRADE_ASSERT(!(indices.size()%3), "MeshTools::subdivide(): index count is not divisible by 3!", ); @@ -40,7 +40,7 @@ template class Subdivide { /* Subdivide each face to four new */ for(std::size_t i = 0; i != indexCount; i += 3) { /* Interpolate each side */ - std::uint32_t newVertices[3]; + UnsignedInt newVertices[3]; for(int j = 0; j != 3; ++j) newVertices[j] = addVertex(interpolator(vertices[indices[i+j]], vertices[indices[i+(j+1)%3]])); @@ -66,15 +66,15 @@ template class Subdivide { } private: - std::vector& indices; + std::vector& indices; std::vector& vertices; - std::uint32_t addVertex(const Vertex& v) { + UnsignedInt addVertex(const Vertex& v) { vertices.push_back(v); return vertices.size()-1; } - void addFace(std::uint32_t first, std::uint32_t second, std::uint32_t third) { + void addFace(UnsignedInt first, UnsignedInt second, UnsignedInt third) { indices.push_back(first); indices.push_back(second); indices.push_back(third); @@ -96,7 +96,7 @@ template class Subdivide { Goes through all triangle faces and subdivides them into four new. Cleaning duplicate vertices in the mesh is up to user. */ -template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { +template inline void subdivide(std::vector& indices, std::vector& vertices, Interpolator interpolator) { Implementation::Subdivide(indices, vertices)(interpolator); } diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index c26413082..658c1296f 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -29,7 +29,7 @@ class CleanTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef std::int32_t Type; + typedef Int Type; Vector1(): data(0) {} Vector1(Type i): data(i) {} @@ -49,12 +49,12 @@ CleanTest::CleanTest() { void CleanTest::cleanMesh() { std::vector positions{1, 2, 1, 4}; - std::vector indices{0, 1, 2, 1, 2, 3}; + std::vector indices{0, 1, 2, 1, 2, 3}; MeshTools::clean(indices, positions); /* Verify cleanup */ CORRADE_VERIFY(positions == (std::vector{1, 2, 4})); - CORRADE_COMPARE(indices, (std::vector{0, 1, 0, 1, 0, 2})); + CORRADE_COMPARE(indices, (std::vector{0, 1, 0, 1, 0, 2})); } }}} diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index ade28f47c..edd14e225 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -37,29 +37,29 @@ CombineIndexedArraysTest::CombineIndexedArraysTest() { void CombineIndexedArraysTest::wrongIndexCount() { std::stringstream ss; Error::setOutput(&ss); - std::vector array; - std::vector result = MeshTools::combineIndexedArrays( - std::tuple&, std::vector&>(std::vector{0, 1, 0}, array), - std::tuple&, std::vector&>(std::vector{3, 4}, array)); + std::vector array; + std::vector result = MeshTools::combineIndexedArrays( + std::tuple&, std::vector&>(std::vector{0, 1, 0}, array), + std::tuple&, std::vector&>(std::vector{3, 4}, array)); CORRADE_COMPARE(result.size(), 0); CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n"); } void CombineIndexedArraysTest::combine() { - std::vector array1{ 0, 1 }; - std::vector array2{ 0, 1, 2, 3, 4 }; - std::vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; - - std::vector result = MeshTools::combineIndexedArrays( - std::tuple&, std::vector&>(std::vector{0, 1, 0}, array1), - std::tuple&, std::vector&>(std::vector{3, 4, 3}, array2), - std::tuple&, std::vector&>(std::vector{6, 7, 6}, array3)); - - CORRADE_COMPARE(result, (std::vector{0, 1, 0})); - CORRADE_COMPARE(array1, (std::vector{0, 1})); - CORRADE_COMPARE(array2, (std::vector{3, 4})); - CORRADE_COMPARE(array3, (std::vector{6, 7})); + std::vector array1{ 0, 1 }; + std::vector array2{ 0, 1, 2, 3, 4 }; + std::vector array3{ 0, 1, 2, 3, 4, 5, 6, 7 }; + + std::vector result = MeshTools::combineIndexedArrays( + std::tuple&, std::vector&>(std::vector{0, 1, 0}, array1), + std::tuple&, std::vector&>(std::vector{3, 4, 3}, array2), + std::tuple&, std::vector&>(std::vector{6, 7, 6}, array3)); + + CORRADE_COMPARE(result, (std::vector{0, 1, 0})); + CORRADE_COMPARE(array1, (std::vector{0, 1})); + CORRADE_COMPARE(array2, (std::vector{3, 4})); + CORRADE_COMPARE(array3, (std::vector{6, 7})); } }}} diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index da0459b2c..417f7dda2 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -42,7 +42,7 @@ void CompressIndicesTest::compressChar() { Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( - std::vector{1, 2, 3, 0, 4}); + std::vector{1, 2, 3, 0, 4}); CORRADE_COMPARE(indexCount, 5); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte); @@ -57,7 +57,7 @@ void CompressIndicesTest::compressShort() { Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( - std::vector{1, 256, 0, 5}); + std::vector{1, 256, 0, 5}); CORRADE_COMPARE(indexCount, 4); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort); @@ -83,7 +83,7 @@ void CompressIndicesTest::compressInt() { Mesh::IndexType indexType; char* data; std::tie(indexCount, indexType, data) = MeshTools::compressIndices( - std::vector{65536, 3, 2}); + std::vector{65536, 3, 2}); CORRADE_COMPARE(indexCount, 3); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt); diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index 6fc61d1ca..a38a832e7 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -40,18 +40,18 @@ void FlipNormalsTest::wrongIndexCount() { std::stringstream ss; Error::setOutput(&ss); - std::vector indices{0, 1}; + std::vector indices{0, 1}; MeshTools::flipFaceWinding(indices); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); } void FlipNormalsTest::flipFaceWinding() { - std::vector indices{0, 1, 2, + std::vector indices{0, 1, 2, 3, 4, 5}; MeshTools::flipFaceWinding(indices); - CORRADE_COMPARE(indices, (std::vector{0, 2, 1, + CORRADE_COMPARE(indices, (std::vector{0, 2, 1, 3, 5, 4})); } diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 25a867e82..f476452a1 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -37,7 +37,7 @@ GenerateFlatNormalsTest::GenerateFlatNormalsTest() { void GenerateFlatNormalsTest::wrongIndexCount() { std::stringstream ss; Error::setOutput(&ss); - std::vector indices; + std::vector indices; std::vector normals; std::tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1 @@ -50,7 +50,7 @@ void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::generate() { /* Two vertices connected by one edge, each winded in another direction */ - std::vector indices; + std::vector indices; std::vector normals; std::tie(indices, normals) = MeshTools::generateFlatNormals({ 0, 1, 2, @@ -62,7 +62,7 @@ void GenerateFlatNormalsTest::generate() { {1.0f, 0.0f, 0.0f} }); - CORRADE_COMPARE(indices, (std::vector{ + CORRADE_COMPARE(indices, (std::vector{ 0, 0, 0, 1, 1, 1 })); diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index 6939fb96a..fde0b5bd6 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -48,30 +48,30 @@ InterleaveTest::InterleaveTest() { void InterleaveTest::attributeCount() { std::stringstream ss; Error::setOutput(&ss); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, - std::vector{0, 1, 2, 3, 4, 5})), std::size_t(0)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, + std::vector{0, 1, 2, 3, 4, 5})), std::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(std::vector{0, 1, 2}, - std::vector{3, 4, 5})), std::size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, + std::vector{3, 4, 5})), std::size_t(3)); } void InterleaveTest::attributeCountGaps() { - CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, 3, - std::vector{3, 4, 5}, 5)), std::size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(std::vector{0, 1, 2}, 3, + std::vector{3, 4, 5}, 5)), std::size_t(3)); /* No arrays from which to get size */ CORRADE_COMPARE(Implementation::Interleave::attributeCount(3, 5), ~std::size_t(0)); } void InterleaveTest::stride() { - CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(1)); - CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(4)); - CORRADE_COMPARE((Implementation::Interleave::stride(std::vector(), std::vector())), std::size_t(5)); + CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(1)); + CORRADE_COMPARE(Implementation::Interleave::stride(std::vector()), std::size_t(4)); + CORRADE_COMPARE((Implementation::Interleave::stride(std::vector(), std::vector())), std::size_t(5)); } void InterleaveTest::strideGaps() { - CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector(), 1, std::vector(), 12)), std::size_t(20)); + CORRADE_COMPARE((Implementation::Interleave::stride(2, std::vector(), 1, std::vector(), 12)), std::size_t(20)); } void InterleaveTest::write() { @@ -79,9 +79,9 @@ void InterleaveTest::write() { std::size_t stride; char* data; std::tie(attributeCount, stride, data) = MeshTools::interleave( - std::vector{0, 1, 2}, - std::vector{3, 4, 5}, - std::vector{6, 7, 8}); + std::vector{0, 1, 2}, + std::vector{3, 4, 5}, + std::vector{6, 7, 8}); CORRADE_COMPARE(attributeCount, std::size_t(3)); CORRADE_COMPARE(stride, std::size_t(7)); @@ -108,9 +108,9 @@ void InterleaveTest::writeGaps() { std::size_t stride; char* data; std::tie(attributeCount, stride, data) = MeshTools::interleave( - std::vector{0, 1, 2}, 3, - std::vector{3, 4, 5}, - std::vector{6, 7, 8}, 2); + std::vector{0, 1, 2}, 3, + std::vector{3, 4, 5}, + std::vector{6, 7, 8}, 2); CORRADE_COMPARE(attributeCount, std::size_t(3)); CORRADE_COMPARE(stride, std::size_t(12)); diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 8409f2a59..bbbab9e79 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -33,7 +33,7 @@ class SubdivideTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef std::int32_t Type; + typedef Int Type; Vector1(): data(0) {} Vector1(Type i): data(i) {} @@ -59,20 +59,20 @@ void SubdivideTest::wrongIndexCount() { Error::setOutput(&ss); std::vector positions; - std::vector indices{0, 1}; + std::vector indices{0, 1}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n"); } void SubdivideTest::subdivide() { std::vector positions{0, 2, 6, 8}; - std::vector indices{0, 1, 2, 1, 2, 3}; + std::vector indices{0, 1, 2, 1, 2, 3}; MeshTools::subdivide(indices, positions, interpolator); CORRADE_COMPARE(indices.size(), 24); CORRADE_VERIFY(positions == (std::vector{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); - CORRADE_COMPARE(indices, (std::vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); + CORRADE_COMPARE(indices, (std::vector{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); MeshTools::clean(indices, positions); diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index a62159947..38177e80e 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -27,7 +27,7 @@ class TipsifyTest: public Corrade::TestSuite::Tester { void tipsify(); private: - std::vector indices; + std::vector indices; std::size_t vertexCount; }; @@ -75,10 +75,10 @@ TipsifyTest::TipsifyTest(): indices{ } void TipsifyTest::buildAdjacency() { - std::vector liveTriangleCount, neighborOffset, neighbors; + std::vector liveTriangleCount, neighborOffset, neighbors; Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); - CORRADE_COMPARE(liveTriangleCount, (std::vector{ + CORRADE_COMPARE(liveTriangleCount, (std::vector{ 1, 3, 3, 2, 4, 6, 6, 2, 2, 6, 6, 4, @@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() { 1, 1, 1 })); - CORRADE_COMPARE(neighborOffset, (std::vector{ + CORRADE_COMPARE(neighborOffset, (std::vector{ 0, 1, 4, 7, 9, 13, 19, 25, 27, 29, 35, 41, @@ -94,7 +94,7 @@ void TipsifyTest::buildAdjacency() { 54, 55, 56, 57 })); - CORRADE_COMPARE(neighbors, (std::vector{ + CORRADE_COMPARE(neighbors, (std::vector{ 0, 0, 7, 11, 2, 7, 13, @@ -122,7 +122,7 @@ void TipsifyTest::buildAdjacency() { void TipsifyTest::tipsify() { MeshTools::tipsify(indices, vertexCount, 3); - CORRADE_COMPARE(indices, (std::vector{ + CORRADE_COMPARE(indices, (std::vector{ 4, 1, 0, 9, 5, 4, 1, 4, 5, diff --git a/src/MeshTools/Tipsify.cpp b/src/MeshTools/Tipsify.cpp index 803304daf..497f74890 100644 --- a/src/MeshTools/Tipsify.cpp +++ b/src/MeshTools/Tipsify.cpp @@ -22,37 +22,37 @@ namespace Magnum { namespace MeshTools { namespace Implementation { void Tipsify::operator()(std::size_t cacheSize) { /* Neighboring triangles for each vertex, per-vertex live triangle count */ - std::vector liveTriangleCount, neighborPosition, neighbors; + std::vector liveTriangleCount, neighborPosition, neighbors; buildAdjacency(liveTriangleCount, neighborPosition, neighbors); /* Global time, per-vertex caching timestamps, per-triangle emmited flag */ - std::uint32_t time = cacheSize+1; - std::vector timestamp(vertexCount); + UnsignedInt time = cacheSize+1; + std::vector timestamp(vertexCount); std::vector emitted(indices.size()/3); /* Dead-end vertex stack */ - std::stack deadEndStack; + std::stack deadEndStack; /* Output index buffer */ - std::vector outputIndices; + std::vector outputIndices; outputIndices.reserve(indices.size()); /* Starting vertex for fanning, cursor */ - std::uint32_t fanningVertex = 0; - std::uint32_t i = 0; + UnsignedInt fanningVertex = 0; + UnsignedInt i = 0; while(fanningVertex != 0xFFFFFFFFu) { /* Array with candidates for next fanning vertex (in 1-ring around fanning vertex) */ - std::vector candidates; + std::vector candidates; /* For all neighbors of fanning vertex */ - for(std::uint32_t ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { + for(UnsignedInt ti = neighborPosition[fanningVertex], t = neighbors[ti]; ti != neighborPosition[fanningVertex+1]; t = neighbors[++ti]) { /* Continue if already emitted */ if(emitted[t]) continue; emitted[t] = true; /* Write all vertices of the triangle to output buffer */ - for(std::uint32_t vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { + for(UnsignedInt vi = 0, v = indices[t*3]; vi != 3; v = indices[++vi+t*3]) { outputIndices.push_back(v); /* Add to dead end stack and candidates array */ @@ -73,15 +73,15 @@ void Tipsify::operator()(std::size_t cacheSize) { fanningVertex = 0xFFFFFFFFu; /* Go through candidates in 1-ring around fanning vertex */ - std::int32_t candidatePriority = -1; - for(std::uint32_t v: candidates) { + Int candidatePriority = -1; + for(UnsignedInt v: candidates) { /* Skip if it doesn't have any live triangles */ if(!liveTriangleCount[v]) continue; /* Get most fresh candidate which will still be in cache even after fanning. Every fanned triangle will generate at most two cache misses, thus 2*liveTriangleCount */ - std::int32_t priority = 0; + Int priority = 0; if(time-timestamp[v]+2*liveTriangleCount[v] <= cacheSize) priority = time-timestamp[v]; if(priority > candidatePriority) { @@ -117,7 +117,7 @@ void Tipsify::operator()(std::size_t cacheSize) { std::swap(indices, outputIndices); } -void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { +void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const { /* How many times is each vertex referenced == count of neighboring triangles for each vertex */ liveTriangleCount.clear(); @@ -132,7 +132,7 @@ void Tipsify::buildAdjacency(std::vector& liveTriangleCount, std: neighborOffset.clear(); neighborOffset.reserve(vertexCount+1); neighborOffset.push_back(0); - std::uint32_t sum = 0; + UnsignedInt sum = 0; for(std::size_t i = 0; i != vertexCount; ++i) { neighborOffset.push_back(sum); sum += liveTriangleCount[i]; diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index 69d65082e..30ef00526 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -19,9 +19,9 @@ * @brief Function Magnum::MeshTools::tipsify() */ -#include #include +#include "Types.h" #include "magnumMeshToolsVisibility.h" namespace Magnum { namespace MeshTools { @@ -31,7 +31,7 @@ namespace Implementation { class MAGNUM_MESHTOOLS_EXPORT Tipsify { public: - inline Tipsify(std::vector& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {} + inline Tipsify(std::vector& indices, UnsignedInt vertexCount): indices(indices), vertexCount(vertexCount) {} void operator()(std::size_t cacheSize); @@ -42,11 +42,11 @@ class MAGNUM_MESHTOOLS_EXPORT Tipsify { * (used internally). * @todo Export only for unit test, hide otherwise */ - void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; + void buildAdjacency(std::vector& liveTriangleCount, std::vector& neighborOffset, std::vector& neighbors) const; private: - std::vector& indices; - const std::uint32_t vertexCount; + std::vector& indices; + const UnsignedInt vertexCount; }; } @@ -64,7 +64,7 @@ array for beter usage of post-transform vertex cache. Algorithm used: for Vertex Locality and Reduced Overdraw, SIGGRAPH 2007, http://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/index.php*. */ -inline void tipsify(std::vector& indices, std::uint32_t vertexCount, std::size_t cacheSize) { +inline void tipsify(std::vector& indices, UnsignedInt vertexCount, std::size_t cacheSize) { Implementation::Tipsify(indices, vertexCount)(cacheSize); } From 003e524a26d625bbfdcdced17209d68314eb85e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 22:54:51 +0100 Subject: [PATCH 468/567] Shaders: using new type aliases in whole Shaders namespace. --- src/Shaders/AbstractTextShader.h | 4 ++-- src/Shaders/FlatShader.cpp | 4 ++-- src/Shaders/FlatShader.h | 4 ++-- src/Shaders/PhongShader.h | 4 ++-- src/Shaders/Shaders.h | 10 +++++----- src/Shaders/TextShader.cpp | 4 ++-- src/Shaders/TextShader.h | 4 ++-- src/Shaders/VertexColorShader.cpp | 4 ++-- src/Shaders/VertexColorShader.h | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractTextShader.h index 8f391c1f5..e1fe529af 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractTextShader.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Shaders { @see AbstractTextShader2D, AbstractTextShader3D */ -template class AbstractTextShader: public AbstractShaderProgram { +template class AbstractTextShader: public AbstractShaderProgram { public: /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::VectorType> Position; @@ -45,7 +45,7 @@ template class AbstractTextShader: public AbstractShade ~AbstractTextShader() = 0; }; -template inline AbstractTextShader::~AbstractTextShader() {} +template inline AbstractTextShader::~AbstractTextShader() {} /** @brief Base for two-dimensional text shaders */ typedef AbstractTextShader<2> AbstractTextShader2D; diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index 70b32361f..d8ea1b039 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -23,12 +23,12 @@ namespace Magnum { namespace Shaders { namespace { - template constexpr const char* vertexShaderName(); + template constexpr const char* vertexShaderName(); template<> constexpr const char* vertexShaderName<2>() { return "FlatShader2D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "FlatShader3D.vert"; } } -template FlatShader::FlatShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { +template FlatShader::FlatShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index 6eb110a3c..ea0922816 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -35,7 +35,7 @@ namespace Magnum { namespace Shaders { Draws whole mesh with one color. @see FlatShader2D, FlatShader3D */ -template class MAGNUM_SHADERS_EXPORT FlatShader: public AbstractShaderProgram { +template class MAGNUM_SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::VectorType> Position; @@ -61,7 +61,7 @@ template class MAGNUM_SHADERS_EXPORT FlatShader: public } private: - GLint transformationProjectionMatrixUniform, + Int transformationProjectionMatrixUniform, colorUniform; }; diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index a82f4c93b..3e7f84bc3 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -78,7 +78,7 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * The larger value, the harder surface (smaller specular highlight). * If not set, default value is `80.0f`. */ - inline PhongShader* setShininess(GLfloat shininess) { + inline PhongShader* setShininess(Float shininess) { setUniform(shininessUniform, shininess); return this; } @@ -123,7 +123,7 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } private: - GLint transformationMatrixUniform, + Int transformationMatrixUniform, projectionMatrixUniform, normalMatrixUniform, lightUniform, diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index fba4ef929..b4733ffd5 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -19,27 +19,27 @@ * @brief Forward declarations for Magnum::Shaders namespace */ -#include +#include "Types.h" namespace Magnum { namespace Shaders { /** @todoc remove when doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractTextShader; +template class AbstractTextShader; typedef AbstractTextShader<2> AbstractTextShader2D; typedef AbstractTextShader<3> AbstractTextShader3D; -template class FlatShader; +template class FlatShader; typedef FlatShader<2> FlatShader2D; typedef FlatShader<3> FlatShader3D; class PhongShader; -template class TextShader; +template class TextShader; typedef TextShader<2> TextShader2D; typedef TextShader<3> TextShader3D; -template class VertexColorShader; +template class VertexColorShader; typedef VertexColorShader<2> VertexColorShader2D; typedef VertexColorShader<3> VertexColorShader3D; #endif diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/TextShader.cpp index e1265e784..37519d7ae 100644 --- a/src/Shaders/TextShader.cpp +++ b/src/Shaders/TextShader.cpp @@ -24,12 +24,12 @@ namespace Magnum { namespace Shaders { namespace { - template constexpr const char* vertexShaderName(); + template constexpr const char* vertexShaderName(); template<> constexpr const char* vertexShaderName<2>() { return "TextShader2D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "TextShader3D.vert"; } } -template TextShader::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { +template TextShader::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/TextShader.h b/src/Shaders/TextShader.h index 4b1819dbb..564581506 100644 --- a/src/Shaders/TextShader.h +++ b/src/Shaders/TextShader.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Shaders { @see TextShader2D, TextShader3D */ -template class MAGNUM_SHADERS_EXPORT TextShader: public AbstractTextShader { +template class MAGNUM_SHADERS_EXPORT TextShader: public AbstractTextShader { public: TextShader(); @@ -49,7 +49,7 @@ template class MAGNUM_SHADERS_EXPORT TextShader: public } private: - GLint transformationProjectionMatrixUniform, + Int transformationProjectionMatrixUniform, colorUniform; }; diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index e872a9fba..e73c2335e 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -23,12 +23,12 @@ namespace Magnum { namespace Shaders { namespace { - template constexpr const char* vertexShaderName(); + template constexpr const char* vertexShaderName(); template<> constexpr const char* vertexShaderName<2>() { return "VertexColorShader2D.vert"; } template<> constexpr const char* vertexShaderName<3>() { return "VertexColorShader3D.vert"; } } -template VertexColorShader::VertexColorShader(): transformationProjectionMatrixUniform(0) { +template VertexColorShader::VertexColorShader(): transformationProjectionMatrixUniform(0) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 4f0275d3f..6e97d4fe5 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -35,7 +35,7 @@ namespace Magnum { namespace Shaders { Draws vertex-colored mesh. @see VertexColorShader2D, VertexColorShader3D */ -template class MAGNUM_SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { +template class MAGNUM_SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { public: /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::VectorType> Position; @@ -55,7 +55,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: } private: - GLint transformationProjectionMatrixUniform; + Int transformationProjectionMatrixUniform; }; /** @brief 2D vertex color shader */ From 4e5a6f76eb96bbace748ee311a9d3e03c2e2611d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 23:37:05 +0100 Subject: [PATCH 469/567] SceneGraph: using new type aliases in whole SceneGraph namespace. --- doc/compilation-speedup.dox | 8 +- doc/scenegraph.dox | 10 +- src/SceneGraph/AbstractCamera.h | 18 ++-- src/SceneGraph/AbstractCamera.hpp | 14 +-- src/SceneGraph/AbstractFeature.h | 22 ++--- src/SceneGraph/AbstractGroupedFeature.h | 8 +- src/SceneGraph/AbstractObject.h | 8 +- src/SceneGraph/AbstractTransformation.h | 12 +-- .../AbstractTranslationRotation2D.h | 2 +- .../AbstractTranslationRotation3D.h | 2 +- .../AbstractTranslationRotationScaling2D.h | 2 +- .../AbstractTranslationRotationScaling3D.h | 2 +- src/SceneGraph/Animable.h | 36 ++++---- src/SceneGraph/Animable.hpp | 12 +-- src/SceneGraph/AnimableGroup.h | 10 +- src/SceneGraph/Camera.cpp | 8 +- src/SceneGraph/Camera2D.h | 6 +- src/SceneGraph/Camera3D.h | 6 +- src/SceneGraph/Drawable.h | 20 ++-- .../EuclideanMatrixTransformation2D.h | 2 +- .../EuclideanMatrixTransformation3D.h | 2 +- src/SceneGraph/FeatureGroup.h | 8 +- src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/MatrixTransformation3D.h | 2 +- src/SceneGraph/Object.h | 16 ++-- src/SceneGraph/Object.hpp | 8 +- src/SceneGraph/SceneGraph.h | 92 +++++++++---------- src/SceneGraph/Test/AnimableTest.cpp | 14 +-- src/SceneGraph/Test/CameraTest.cpp | 18 ++-- src/SceneGraph/Test/SceneTest.cpp | 4 +- src/Trade/SceneData.h | 2 + 31 files changed, 188 insertions(+), 188 deletions(-) diff --git a/doc/compilation-speedup.dox b/doc/compilation-speedup.dox index 99abac95e..8d86d3bb3 100644 --- a/doc/compilation-speedup.dox +++ b/doc/compilation-speedup.dox @@ -31,8 +31,8 @@ available, each namespace has its own: @section compilation-speedup-templates Templates Many things in %Magnum are templated to allow handling of various types and -sizes of data, for example whole Scene graph can operate either with `float`s -or with `double`s. However, having templated classes and function usually +sizes of data, for example whole Scene graph can operate either with @ref Float +or @ref Double data type. However, having templated classes and function usually means that the compiler compiles the whole templated code again in each compilation unit (i.e. source file). In linking stage of the application or library the duplicates are just thrown out, which is a waste of compilation @@ -64,7 +64,7 @@ Sometimes you however need to use your own specialization and that's why template implementation files are included in the library. For example we want to use @ref SceneGraph::Object "Object" from SceneGraph with @ref SceneGraph::MatrixTransformation3D "MatrixTransformation3D" with -`GLdouble` as underlying type, because our scene will span the whole universe. +@ref Double as underlying type, because our scene will span the whole universe. We include the implementation file in dedicated source file and explicitly instantiate the template: @code @@ -73,7 +73,7 @@ instantiate the template: using namespace Magnum::SceneGraph; -template class Object>; +template class Object>; @endcode All other files using the same object specialization now need to include only SceneGraph/Object.h header. Thus the Object specialization will be compiled diff --git a/doc/scenegraph.dox b/doc/scenegraph.dox index 28fec624d..857f9c4d9 100644 --- a/doc/scenegraph.dox +++ b/doc/scenegraph.dox @@ -22,12 +22,12 @@ main components: Transformation handles object position, rotation etc. and its basic property is dimension count (2D or 3D) and underlying floating-point type (by default -`float`s are used everywhere, but you can use `double`s too). +@ref Float type is used everywhere, but you can use @ref Double too). -@note All classes in SceneGraph have `GLfloat` as default underlying - floating-point type, which means that you can omit that template parameter - and write just %AbstractObject<2> or %MatrixTransformation3D<> - instead of %AbstractObject<2, GLfloat> and %MatrixTransformation3D<GLfloat>. +@note All classes in SceneGraph have Float as default underlying floating-point + type, which means that you can omit that template parameter and write just + %AbstractObject<2> or %MatrixTransformation3D<> instead of + %AbstractObject<2, Float> and %MatrixTransformation3D<Float>. %Scene graph has implementation of transformations in both 2D and 3D, using either matrices or combination of position and rotation. Each implementation diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 4f2c24076..fff05d28d 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -32,7 +32,7 @@ namespace Magnum { namespace SceneGraph { @see AbstractCamera::setAspectRatioPolicy() */ -enum class AspectRatioPolicy: std::uint8_t { +enum class AspectRatioPolicy: UnsignedByte { NotPreserved, /**< Don't preserve aspect ratio (default) */ Extend, /**< Extend on larger side of view */ Clip /**< Clip on smaller side of view */ @@ -40,7 +40,7 @@ enum class AspectRatioPolicy: std::uint8_t { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Vector2i& viewport); + template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Vector2i& viewport); } #endif @@ -53,22 +53,22 @@ instantiatable, use Camera2D or Camera3D subclasses instead. @section AbstractCamera-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations (e.g. using `double` type) you have to use +For other specializations (e.g. using Double type) you have to use AbstractCamera.hpp implementation file to avoid linker errors. See also relevant sections in @ref Camera2D-explicit-specializations "Camera2D" and @ref Camera3D-explicit-specializations "Camera3D" class documentation or @ref compilation-speedup-hpp for more information. - - @ref AbstractCamera "AbstractCamera<2, GLfloat>" - - @ref AbstractCamera "AbstractCamera<3, GLfloat>" + - @ref AbstractCamera "AbstractCamera<2, Float>" + - @ref AbstractCamera "AbstractCamera<3, Float>" @see @ref scenegraph, Drawable, DrawableGroup, AbstractCamera2D, AbstractCamera3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature { public: @@ -170,7 +170,7 @@ for more information. @see AbstractCamera3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -185,7 +185,7 @@ for more information. @see AbstractCamera2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/AbstractCamera.hpp b/src/SceneGraph/AbstractCamera.hpp index a39f85ab9..89840d11d 100644 --- a/src/SceneGraph/AbstractCamera.hpp +++ b/src/SceneGraph/AbstractCamera.hpp @@ -30,7 +30,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -template class Camera {}; +template class Camera {}; template class Camera<2, T> { public: @@ -45,7 +45,7 @@ template class Camera<3, T> { } }; -template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Math::Vector2& viewport) { +template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Vector2i& viewport) { /* Don't divide by zero / don't preserve anything */ if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved) return {}; @@ -63,24 +63,24 @@ template typename DimensionTraits AbstractCamera::AbstractCamera(AbstractObject* object): AbstractFeature(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) { +template AbstractCamera::AbstractCamera(AbstractObject* object): AbstractFeature(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) { AbstractFeature::setCachedTransformations(AbstractFeature::CachedTransformation::InvertedAbsolute); } -template AbstractCamera::~AbstractCamera() {} +template AbstractCamera::~AbstractCamera() {} -template AbstractCamera* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template AbstractCamera* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); return this; } -template void AbstractCamera::setViewport(const Math::Vector2& size) { +template void AbstractCamera::setViewport(const Vector2i& size) { _viewport = size; fixAspectRatio(); } -template void AbstractCamera::draw(DrawableGroup& group) { +template void AbstractCamera::draw(DrawableGroup& group) { AbstractObject* scene = AbstractFeature::object()->sceneObject(); CORRADE_ASSERT(scene, "Camera::draw(): cannot draw when camera is not part of any scene", ); diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 3b8d344dc..c8b81f45e 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -28,12 +28,12 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - enum class FeatureCachedTransformation: std::uint8_t { + enum class FeatureCachedTransformation: UnsignedByte { Absolute = 1 << 0, InvertedAbsolute = 1 << 1 }; - typedef Corrade::Containers::EnumSet FeatureCachedTransformations; + typedef Corrade::Containers::EnumSet FeatureCachedTransformations; CORRADE_ENUMSET_OPERATORS(FeatureCachedTransformations) } @@ -118,9 +118,9 @@ which is automatically extracted from the pointer in our constructor. @see AbstractFeature2D, AbstractFeature3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractFeature: private Corrade::Containers::LinkedListItem, AbstractObject> +template class AbstractFeature: private Corrade::Containers::LinkedListItem, AbstractObject> #else -template class AbstractFeature +template class AbstractFeature #endif { friend class Corrade::Containers::LinkedList>; @@ -186,7 +186,7 @@ template class AbstractFeature #ifndef DOXYGEN_GENERATING_OUTPUT typedef Implementation::FeatureCachedTransformation CachedTransformation; #else - enum class CachedTransformation: std::uint8_t { + enum class CachedTransformation: UnsignedByte { /** * Absolute transformation is cached. * @@ -212,7 +212,7 @@ template class AbstractFeature #ifndef DOXYGEN_GENERATING_OUTPUT typedef Implementation::FeatureCachedTransformations CachedTransformations; #else - typedef Corrade::Containers::EnumSet CachedTransformations; + typedef Corrade::Containers::EnumSet CachedTransformations; #endif /** @@ -280,9 +280,9 @@ template class AbstractFeature CachedTransformations _cachedTransformations; }; -template inline AbstractFeature::~AbstractFeature() {} -template inline void AbstractFeature::clean(const typename DimensionTraits::MatrixType&) {} -template inline void AbstractFeature::cleanInverted(const typename DimensionTraits::MatrixType&) {} +template inline AbstractFeature::~AbstractFeature() {} +template inline void AbstractFeature::clean(const typename DimensionTraits::MatrixType&) {} +template inline void AbstractFeature::cleanInverted(const typename DimensionTraits::MatrixType&) {} #ifndef CORRADE_GCC46_COMPATIBILITY /** @@ -294,7 +294,7 @@ for more information. @see AbstractFeature3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -309,7 +309,7 @@ for more information. @see AbstractFeature2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index e1dbfd58b..2672e5d73 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -48,9 +48,9 @@ typedef SceneGraph::FeatureGroup3D DrawableGroup; FeatureGroup, FeatureGroup2D, FeatureGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class AbstractGroupedFeature: public AbstractFeature { friend class FeatureGroup; @@ -103,7 +103,7 @@ AbstractGroupedFeature for more information. @see AbstractGroupedFeature3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -119,7 +119,7 @@ AbstractGroupedFeature for more information. @see AbstractGroupedFeature2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 3278ed29c..90ad22a96 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -48,9 +48,9 @@ for(AbstractFeature* feature = o->firstFeature(); feature; feature = feature->ne @see AbstractObject2D, AbstractObject3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class MAGNUM_SCENEGRAPH_EXPORT AbstractObject: private Corrade::Containers::LinkedList> +template class MAGNUM_SCENEGRAPH_EXPORT AbstractObject: private Corrade::Containers::LinkedList> #else -template class AbstractObject +template class AbstractObject #endif { friend class Corrade::Containers::LinkedList>; @@ -198,7 +198,7 @@ for more information. @see AbstractObject3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -213,7 +213,7 @@ for more information. @see AbstractObject2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 92c2ea62d..10b26f9ee 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -44,9 +44,9 @@ When subclassing, you have to: @see @ref scenegraph, AbstractTransformation2D, AbstractTransformation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class MAGNUM_SCENEGRAPH_EXPORT AbstractTransformation { public: @@ -54,7 +54,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractTransformation { typedef T Type; /** @brief Dimension count */ - static const std::uint8_t Dimensions = dimensions; + static const UnsignedInt Dimensions = dimensions; explicit AbstractTransformation(); virtual ~AbstractTransformation() = 0; @@ -131,7 +131,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractTransformation { }; /** @brief Transformation type */ -enum class TransformationType: std::uint8_t { +enum class TransformationType: UnsignedByte { /** Global transformation, applied after all other transformations. */ Global = 0x00, @@ -150,7 +150,7 @@ AbstractTransformation for more information. @see AbstractTransformation3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -166,7 +166,7 @@ AbstractTransformation for more information. @see AbstractTransformation2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index 33b178d47..c3d17321c 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -31,7 +31,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class AbstractTranslationRotation2D: public AbstractTransformation<2, T> { public: diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index d0f49b47b..c9cca2ecc 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -32,7 +32,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class AbstractTranslationRotation3D: public AbstractTransformation<3, T> { public: diff --git a/src/SceneGraph/AbstractTranslationRotationScaling2D.h b/src/SceneGraph/AbstractTranslationRotationScaling2D.h index 45476a17d..e0318157b 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling2D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling2D.h @@ -31,7 +31,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class AbstractTranslationRotationScaling2D: public AbstractTranslationRotation2D { public: diff --git a/src/SceneGraph/AbstractTranslationRotationScaling3D.h b/src/SceneGraph/AbstractTranslationRotationScaling3D.h index a2a1fb3de..21be3a012 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling3D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling3D.h @@ -31,7 +31,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class AbstractTranslationRotationScaling3D: public AbstractTranslationRotation3D { public: diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index a58dbfea3..ef0c9c323 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -30,7 +30,7 @@ namespace Magnum { namespace SceneGraph { @see Animable::setState() */ -enum class AnimationState: std::uint8_t { +enum class AnimationState: UnsignedByte { /** * The animation is stopped. The animation will be started from the * beginning when state is changed to @ref AnimationState "AnimationState::Running". @@ -74,7 +74,7 @@ class AnimableObject: public Object3D, SceneGraph::Animable3D<> { // ... } - void animationStep(GLfloat time, GLfloat delta) override { + void animationStep(Float time, Float delta) override { rotateX(15.0_degf*delta); // rotate at 15 degrees per second } } @@ -121,19 +121,19 @@ traversed when calling AnimableGroup::step(), saving precious frame time. @section Animable-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into %SceneGraph library. -For other specializations (e.g. using `double` type) you have to use +For other specializations (e.g. using Double type) you have to use Animable.hpp implementation file to avoid linker errors. See also @ref compilation-speedup-hpp for more information. - - @ref Animable "Animable<2, GLfloat>", @ref AnimableGroup "AnimableGroup<2, GLfloat>" - - @ref Animable "Animable<3, GLfloat>", @ref AnimableGroup "AnimableGroup<3, GLfloat>" + - @ref Animable "Animable<2, Float>", @ref AnimableGroup "AnimableGroup<2, Float>" + - @ref Animable "Animable<3, Float>", @ref AnimableGroup "AnimableGroup<3, Float>" @see @ref scenegraph, Animable2D, Animable3D, AnimableGroup2D, AnimableGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature, T> { friend class AnimableGroup; @@ -153,7 +153,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* setRepeatCount(std::uint16_t count) { + inline Animable* setRepeatCount(UnsignedShort count) { _repeatCount = count; return this; } @@ -227,7 +227,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature* setDuration(GLfloat duration) { + inline Animable* setDuration(Float duration) { _duration = duration; return this; } @@ -251,7 +251,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Animable: public AbstractGroupedFeature +template #else template #endif @@ -347,7 +347,7 @@ information. @see Animable2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp index 619e556c2..4b2789cee 100644 --- a/src/SceneGraph/Animable.hpp +++ b/src/SceneGraph/Animable.hpp @@ -26,11 +26,11 @@ namespace Magnum { namespace SceneGraph { -template Animable::Animable(AbstractObject* object, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(0.0f), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} +template Animable::Animable(AbstractObject* object, AnimableGroup* group): AbstractGroupedFeature, T>(object, group), _duration(0.0f), startTime(std::numeric_limits::infinity()), pauseTime(-std::numeric_limits::infinity()), previousState(AnimationState::Stopped), currentState(AnimationState::Stopped), _repeated(false), _repeatCount(0), repeats(0) {} -template Animable::~Animable() {} +template Animable::~Animable() {} -template Animable* Animable::setState(AnimationState state) { +template Animable* Animable::setState(AnimationState state) { if(currentState == state) return this; /* Not allowed (for sanity) */ @@ -43,15 +43,15 @@ template Animable* Animable AnimableGroup* Animable::group() { +template AnimableGroup* Animable::group() { return static_cast*>(AbstractGroupedFeature, T>::group()); } -template const AnimableGroup* Animable::group() const { +template const AnimableGroup* Animable::group() const { return static_cast*>(AbstractGroupedFeature, T>::group()); } -template void AnimableGroup::step(const GLfloat time, const GLfloat delta) { +template void AnimableGroup::step(const Float time, const Float delta) { if(!_runningCount && !wakeUp) return; wakeUp = false; diff --git a/src/SceneGraph/AnimableGroup.h b/src/SceneGraph/AnimableGroup.h index 5b6a1780b..3b7081867 100644 --- a/src/SceneGraph/AnimableGroup.h +++ b/src/SceneGraph/AnimableGroup.h @@ -32,9 +32,9 @@ See Animable for more information. @see @ref scenegraph, AnimableGroup2D, AnimableGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup: public FeatureGroup, T> { friend class Animable; @@ -60,7 +60,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AnimableGroup: public FeatureGroup +template #else template #endif @@ -92,7 +92,7 @@ more information. @see AnimableGroup2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 6d46a42c7..a62f75548 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -19,10 +19,10 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractCamera<2, GLfloat>; -template class AbstractCamera<3, GLfloat>; -template class Camera2D; -template class Camera3D; +template class AbstractCamera<2, Float>; +template class AbstractCamera<3, Float>; +template class Camera2D; +template class Camera3D; #endif }} diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 6674703e1..1e3ee9400 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -38,18 +38,18 @@ camera->setProjection({4.0f/3.0f, 1.0f}) @section Camera2D-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations (e.g. using `double` type) you have to use +For other specializations (e.g. using Double type) you have to use Camera2D.hpp implementation file to avoid linker errors. See @ref compilation-speedup-hpp for more information. - - @ref Camera2D "Camera2D" + - @ref Camera2D "Camera2D" @see @ref scenegraph, Camera3D, Drawable, DrawableGroup */ #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { public: diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 70a7258fe..6c62a893f 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -43,18 +43,18 @@ camera->setPerspective({}, 0.001f, 100.0f) @section Camera3D-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations (e.g. using `double` type) you have to use +For other specializations (e.g. using Double type) you have to use Camera3D.hpp implementation file to avoid linker errors. See @ref compilation-speedup-hpp for more information. - - @ref Camera3D "Camera3D" + - @ref Camera3D "Camera3D" @see @ref scenegraph, Camera2D, Drawable, DrawableGroup */ #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { public: diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index daad699c9..27e49f13b 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -108,9 +108,9 @@ void MyApplication::drawEvent() { @see @ref scenegraph, Drawable2D, Drawable3D, DrawableGroup2D, DrawableGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class Drawable: public AbstractGroupedFeature, T> { public: @@ -145,7 +145,7 @@ information. @see Drawable3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -160,7 +160,7 @@ information. @see Drawable2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -175,16 +175,16 @@ See Drawable for more information. */ #ifndef CORRADE_GCC46_COMPATIBILITY #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif using DrawableGroup = FeatureGroup, T>; #else #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class DrawableGroup: public FeatureGroup, T> {}; #endif @@ -199,7 +199,7 @@ more information. @see DrawableGroup3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -214,7 +214,7 @@ more information. @see DrawableGroup2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index 12fe4749c..2ea810c5c 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -38,7 +38,7 @@ transformations. #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { public: diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index 35cda398e..4a94b9fe4 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -38,7 +38,7 @@ transformations. #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { public: diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 229f719c9..2f1856942 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -34,9 +34,9 @@ See AbstractGroupedFeature for more information. @see @ref scenegraph, FeatureGroup2D, FeatureGroup3D */ #ifndef DOXYGEN_GENERATING_OUTPUT -template +template #else -template +template #endif class FeatureGroup { friend class AbstractGroupedFeature; @@ -119,7 +119,7 @@ AbstractGroupedFeature for more information. @see FeatureGroup3D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif @@ -135,7 +135,7 @@ AbstractGroupedFeature for more information. @see FeatureGroup2D */ #ifdef DOXYGEN_GENERATING_OUTPUT -template +template #else template #endif diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index 87cb449fc..032246a74 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -34,7 +34,7 @@ Uses Math::Matrix3 as underlying type. #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { public: diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 0c613cacb..1e98d447d 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -34,7 +34,7 @@ Uses Math::Matrix4 as underlying type. #ifndef DOXYGEN_GENERATING_OUTPUT template #else -template +template #endif class MatrixTransformation3D: public AbstractTranslationRotationScaling3D { public: diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 0b6fb50be..e2d0f8694 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -30,13 +30,13 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - enum class ObjectFlag: std::uint8_t { + enum class ObjectFlag: UnsignedByte { Dirty = 1 << 0, Visited = 1 << 1, Joint = 1 << 2 }; - typedef Corrade::Containers::EnumSet ObjectFlags; + typedef Corrade::Containers::EnumSet ObjectFlags; CORRADE_ENUMSET_OPERATORS(ObjectFlags) } @@ -68,14 +68,14 @@ for(Object* child = o->firstChild(); child; child = child->nextSibling()) { @section Object-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations (e.g. using `double` type or special transformation +For other specializations (e.g. using Double type or special transformation class) you have to use Object.hpp implementation file to avoid linker errors. See @ref compilation-speedup-hpp for more information. - - @ref MatrixTransformation2D "Object>" - - @ref MatrixTransformation3D "Object>" - - @ref EuclideanMatrixTransformation2D "Object>" - - @ref EuclideanMatrixTransformation3D "Object>" + - @ref MatrixTransformation2D "Object>" + - @ref MatrixTransformation3D "Object>" + - @ref EuclideanMatrixTransformation2D "Object>" + - @ref EuclideanMatrixTransformation3D "Object>" @see Scene, AbstractFeature, AbstractTransformation, DebugTools::ObjectRenderer */ @@ -249,7 +249,7 @@ template class MAGNUM_SCENEGRAPH_EXPORT Object: public Abs typedef Implementation::ObjectFlag Flag; typedef Implementation::ObjectFlags Flags; - std::uint16_t counter; + UnsignedShort counter; Flags flags; }; diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index 708384def..88141f3f0 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -29,11 +29,11 @@ namespace Magnum { namespace SceneGraph { -template AbstractObject::AbstractObject() {} -template AbstractObject::~AbstractObject() {} +template AbstractObject::AbstractObject() {} +template AbstractObject::~AbstractObject() {} -template inline AbstractTransformation::AbstractTransformation() {} -template inline AbstractTransformation::~AbstractTransformation() {} +template inline AbstractTransformation::AbstractTransformation() {} +template inline AbstractTransformation::~AbstractTransformation() {} template Scene* Object::scene() { return static_cast*>(sceneObject()); diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index 014c74383..4b9a3aeb8 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -19,9 +19,7 @@ * @brief Forward declarations for Magnum::SceneGraph namespace */ -#include - -#include "Magnum.h" +#include "Types.h" #include "corradeCompatibility.h" @@ -29,87 +27,87 @@ namespace Magnum { namespace SceneGraph { /** @todoc remove when doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -enum class AspectRatioPolicy: std::uint8_t; +enum class AspectRatioPolicy: UnsignedByte; -template class AbstractCamera; +template class AbstractCamera; #ifndef CORRADE_GCC46_COMPATIBILITY -template using AbstractCamera2D = AbstractCamera<2, T>; -template using AbstractCamera3D = AbstractCamera<3, T>; +template using AbstractCamera2D = AbstractCamera<2, T>; +template using AbstractCamera3D = AbstractCamera<3, T>; #endif -template class AbstractFeature; +template class AbstractFeature; #ifndef CORRADE_GCC46_COMPATIBILITY -template using AbstractFeature2D = AbstractFeature<2, T>; -template using AbstractFeature3D = AbstractFeature<3, T>; +template using AbstractFeature2D = AbstractFeature<2, T>; +template using AbstractFeature3D = AbstractFeature<3, T>; #endif -template class AbstractGroupedFeature; +template class AbstractGroupedFeature; #ifndef CORRADE_GCC46_COMPATIBILITY -template using AbstractGroupedFeature2D = AbstractGroupedFeature<2, Derived, T>; -template using AbstractGroupedFeature3D = AbstractGroupedFeature<3, Derived, T>; +template using AbstractGroupedFeature2D = AbstractGroupedFeature<2, Derived, T>; +template using AbstractGroupedFeature3D = AbstractGroupedFeature<3, Derived, T>; #endif -template class AbstractObject; +template class AbstractObject; #ifndef CORRADE_GCC46_COMPATIBILITY -template using AbstractObject2D = AbstractObject<2, T>; -template using AbstractObject3D = AbstractObject<3, T>; +template using AbstractObject2D = AbstractObject<2, T>; +template using AbstractObject3D = AbstractObject<3, T>; #endif -enum class TransformationType: std::uint8_t; +enum class TransformationType: UnsignedByte; -template class AbstractTransformation; +template class AbstractTransformation; #ifndef CORRADE_GCC46_COMPATIBILITY -template using AbstractTransformation2D = AbstractTransformation<2, T>; -template using AbstractTransformation3D = AbstractTransformation<3, T>; +template using AbstractTransformation2D = AbstractTransformation<2, T>; +template using AbstractTransformation3D = AbstractTransformation<3, T>; #endif -template class AbstractTranslationRotation2D; -template class AbstractTranslationRotation3D; -template class AbstractTranslationRotationScaling2D; -template class AbstractTranslationRotationScaling3D; +template class AbstractTranslationRotation2D; +template class AbstractTranslationRotation3D; +template class AbstractTranslationRotationScaling2D; +template class AbstractTranslationRotationScaling3D; -template class Animable; +template class Animable; #ifndef CORRADE_GCC46_COMPATIBILITY -template using Animable2D = Animable<2, T>; -template using Animable3D = Animable<3, T>; +template using Animable2D = Animable<2, T>; +template using Animable3D = Animable<3, T>; #endif -enum class AnimationState: std::uint8_t; +enum class AnimationState: UnsignedByte; -template class AnimableGroup; +template class AnimableGroup; #ifndef CORRADE_GCC46_COMPATIBILITY -template using AnimableGroup2D = AnimableGroup<2, T>; -template using AnimableGroup3D = AnimableGroup<3, T>; +template using AnimableGroup2D = AnimableGroup<2, T>; +template using AnimableGroup3D = AnimableGroup<3, T>; #endif -template class Camera2D; -template class Camera3D; +template class Camera2D; +template class Camera3D; -template class Drawable; +template class Drawable; #ifndef CORRADE_GCC46_COMPATIBILITY -template using Drawable2D = Drawable<2, T>; -template using Drawable3D = Drawable<3, T>; +template using Drawable2D = Drawable<2, T>; +template using Drawable3D = Drawable<3, T>; #endif -template class EuclideanMatrixTransformation2D; -template class EuclideanMatrixTransformation3D; +template class EuclideanMatrixTransformation2D; +template class EuclideanMatrixTransformation3D; -template class FeatureGroup; +template class FeatureGroup; #ifndef CORRADE_GCC46_COMPATIBILITY -template using FeatureGroup2D = FeatureGroup<2, Feature, T>; -template using FeatureGroup3D = FeatureGroup<3, Feature, T>; +template using FeatureGroup2D = FeatureGroup<2, Feature, T>; +template using FeatureGroup3D = FeatureGroup<3, Feature, T>; #endif #ifndef CORRADE_GCC46_COMPATIBILITY -template using DrawableGroup = FeatureGroup, T>; -template using DrawableGroup2D = DrawableGroup<2, T>; -template using DrawableGroup3D = DrawableGroup<3, T>; +template using DrawableGroup = FeatureGroup, T>; +template using DrawableGroup2D = DrawableGroup<2, T>; +template using DrawableGroup3D = DrawableGroup<3, T>; #else -template class DrawableGroup; +template class DrawableGroup; #endif -template class MatrixTransformation2D; -template class MatrixTransformation3D; +template class MatrixTransformation2D; +template class MatrixTransformation3D; template class Object; template class Scene; diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index 1be3a1fd4..b7984c849 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -58,7 +58,7 @@ void AnimableTest::state() { std::string trackedState; protected: - void animationStep(GLfloat, GLfloat) override {} + void animationStep(Float, Float) override {} void animationStarted() override { trackedState += "started"; } void animationPaused() override { trackedState += "paused"; } @@ -146,11 +146,11 @@ class OneShotAnimable: public SceneGraph::Animable<3> { setState(AnimationState::Running); } - GLfloat time; + Float time; std::string stateChanges; protected: - void animationStep(GLfloat time, GLfloat) override { + void animationStep(Float time, Float) override { this->time = time; } @@ -168,10 +168,10 @@ void AnimableTest::step() { public: InifiniteAnimable(AbstractObject<3>* object, AnimableGroup<3>* group = nullptr): SceneGraph::Animable<3>(object, group), time(-1.0f), delta(0.0f) {} - GLfloat time, delta; + Float time, delta; protected: - void animationStep(GLfloat time, GLfloat delta) override { + void animationStep(Float time, Float delta) override { this->time = time; this->delta = delta; } @@ -231,10 +231,10 @@ void AnimableTest::repeat() { setRepeated(true); } - GLfloat time; + Float time; protected: - void animationStep(GLfloat time, GLfloat) override { + void animationStep(Float time, Float) override { this->time = time; } }; diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index a5d504365..82e47eb8e 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -65,37 +65,37 @@ void CameraTest::fixAspectRatio() { Vector2 projectionScaleZeroX(0.0f, 0.5f); Vector2i sizeZeroY(400, 0); Vector2i sizeZeroX(0, 300); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, projectionScale, sizeZeroX)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Extend, projectionScale, sizeZeroX)), Matrix4()); /* Not preserved */ - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::NotPreserved, projectionScale, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::NotPreserved, projectionScale, size)), Matrix4()); /* Clip */ Matrix4 expectedClip({1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 4.0f/3.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, Vector2(0.5f), size)), expectedClip); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, Vector2(0.5f), size)), expectedClip); Matrix4 expectedClipRectangle({1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 2.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScale, size)), expectedClipRectangle); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScale, size)), expectedClipRectangle); /* Extend */ Matrix4 expectedExtend({3.0f/4.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, Vector2(0.5f), size)), expectedExtend); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Extend, Vector2(0.5f), size)), expectedExtend); Matrix4 expectedExtendRectangle({0.5f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, projectionScale, size)), expectedExtendRectangle); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Extend, projectionScale, size)), expectedExtendRectangle); } void CameraTest::defaultProjection2D() { diff --git a/src/SceneGraph/Test/SceneTest.cpp b/src/SceneGraph/Test/SceneTest.cpp index a8c7b177e..1baebacb5 100644 --- a/src/SceneGraph/Test/SceneTest.cpp +++ b/src/SceneGraph/Test/SceneTest.cpp @@ -28,8 +28,8 @@ class SceneTest: public Corrade::TestSuite::Tester { void parent(); }; -typedef SceneGraph::Scene> Scene3D; -typedef SceneGraph::Object> Object3D; +typedef SceneGraph::Scene> Scene3D; +typedef SceneGraph::Object> Object3D; SceneTest::SceneTest() { addTests(&SceneTest::transformation, diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index acc962870..ada693798 100644 --- a/src/Trade/SceneData.h +++ b/src/Trade/SceneData.h @@ -22,6 +22,8 @@ #include #include +#include "Types.h" + namespace Magnum { namespace Trade { /** From 5f049c50b853da2baae6e305fb5ecc0d56bed8ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 23:38:55 +0100 Subject: [PATCH 470/567] Physics: using new type aliases in whole Physics namespace. --- src/Physics/AbstractShape.cpp | 2 +- src/Physics/AbstractShape.h | 8 ++++---- src/Physics/AxisAlignedBox.cpp | 6 +++--- src/Physics/AxisAlignedBox.h | 4 ++-- src/Physics/Box.cpp | 2 +- src/Physics/Box.h | 2 +- src/Physics/Capsule.cpp | 10 +++++----- src/Physics/Capsule.h | 16 ++++++++-------- src/Physics/Line.cpp | 2 +- src/Physics/Line.h | 2 +- src/Physics/LineSegment.h | 2 +- src/Physics/ObjectShape.cpp | 12 ++++++------ src/Physics/ObjectShape.h | 2 +- src/Physics/ObjectShapeGroup.cpp | 4 ++-- src/Physics/ObjectShapeGroup.h | 2 +- src/Physics/Physics.h | 24 ++++++++++++------------ src/Physics/Plane.cpp | 6 +++--- src/Physics/Point.cpp | 2 +- src/Physics/Point.h | 2 +- src/Physics/ShapeGroup.cpp | 10 +++++----- src/Physics/ShapeGroup.h | 6 +++--- src/Physics/Sphere.cpp | 16 ++++++++-------- src/Physics/Sphere.h | 18 +++++++++--------- 23 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index c6d2511d9..adedf7f85 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { -template bool AbstractShape::collides(const AbstractShape* other) const { +template bool AbstractShape::collides(const AbstractShape* other) const { /* Operate only with simpler types than this */ if(static_cast(other->type()) > static_cast(type())) return other->collides(this); diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 85aee4ad3..9b2f882b7 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct ShapeDimensionTraits {}; + template struct ShapeDimensionTraits {}; template<> struct ShapeDimensionTraits<2> { enum class Type { @@ -68,10 +68,10 @@ namespace Implementation { See @ref collision-detection for brief introduction. @see AbstractShape2D, AbstractShape3D */ -template class MAGNUM_PHYSICS_EXPORT AbstractShape { +template class MAGNUM_PHYSICS_EXPORT AbstractShape { public: /** @brief Dimension count */ - static const std::uint8_t Dimensions = dimensions; + static const UnsignedInt Dimensions = dimensions; /** * @brief Shape type @@ -130,7 +130,7 @@ typedef AbstractShape<3> AbstractShape3D; #ifdef DOXYGEN_GENERATING_OUTPUT /** @debugoperator{Magnum::Physics::AbstractShape} */ -template Debug operator<<(Debug debug, typename AbstractShape::Type value); +template Debug operator<<(Debug debug, typename AbstractShape::Type value); #endif }} diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 822315464..36714d8bb 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -21,19 +21,19 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedMin = matrix.transformPoint(_min); _transformedMax = matrix.transformPoint(_max); } -template bool AxisAlignedBox::collides(const AbstractShape* other) const { +template bool AxisAlignedBox::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); return AbstractShape::collides(other); } -template bool AxisAlignedBox::operator%(const Point& other) const { +template bool AxisAlignedBox::operator%(const Point& other) const { return (other.transformedPosition() >= _transformedMin).all() && (other.transformedPosition() < _transformedMax).all(); } diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index aa4756c49..15137238c 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Physics { @see AxisAlignedBox2D, AxisAlignedBox3D @todo Assert for rotation */ -template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ inline explicit AxisAlignedBox(const typename DimensionTraits::VectorType& min, const typename DimensionTraits::VectorType& max): _min(min), _max(max), _transformedMin(min), _transformedMax(max) {} @@ -89,7 +89,7 @@ typedef AxisAlignedBox<2> AxisAlignedBox2D; typedef AxisAlignedBox<3> AxisAlignedBox3D; /** @collisionoperator{Point,AxisAlignedBox} */ -template inline bool operator%(const Point& a, const AxisAlignedBox& b) { return b % a; } +template inline bool operator%(const Point& a, const AxisAlignedBox& b) { return b % a; } }} diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 677855a3b..189625c6f 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Box::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedTransformation = matrix*_transformation; } diff --git a/src/Physics/Box.h b/src/Physics/Box.h index acb24e091..9507e66e8 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Physics { @see Box2D, Box3D @todo Assert for skew */ -template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline explicit Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 9fcf061c8..f48311eb6 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -26,14 +26,14 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Capsule::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedA = matrix.transformPoint(_a); _transformedB = matrix.transformPoint(_b); - float scaling = (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); + Float scaling = (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } -template bool Capsule::collides(const AbstractShape* other) const { +template bool Capsule::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Sphere) @@ -42,12 +42,12 @@ template bool Capsule::collides(const Abstr return AbstractShape::collides(other); } -template bool Capsule::operator%(const Point& other) const { +template bool Capsule::operator%(const Point& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Capsule::operator%(const Sphere& other) const { +template bool Capsule::operator%(const Sphere& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 0e0184a08..a2a7a0529 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -35,10 +35,10 @@ applying transformation, the scale factor is averaged from all axes. @see Capsule2D, Capsule3D @todo Assert for asymmetric scaling */ -template class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ - inline explicit Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline explicit Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, Float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Capsule; @@ -69,10 +69,10 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab } /** @brief Radius */ - inline float radius() const { return _radius; } + inline Float radius() const { return _radius; } /** @brief Set radius */ - inline void setRadius(float radius) { _radius = radius; } + inline void setRadius(Float radius) { _radius = radius; } /** @brief Transformed first point */ inline typename DimensionTraits::VectorType transformedA() const { @@ -85,7 +85,7 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab } /** @brief Transformed radius */ - inline float transformedRadius() const { + inline Float transformedRadius() const { return _transformedRadius; } @@ -98,7 +98,7 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab private: typename DimensionTraits::VectorType _a, _transformedA, _b, _transformedB; - float _radius, _transformedRadius; + Float _radius, _transformedRadius; }; /** @brief Two-dimensional capsule */ @@ -108,10 +108,10 @@ typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; /** @collisionoperator{Point,Capsule} */ -template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } /** @collisionoperator{Sphere,Capsule} */ -template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } }} diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 8f02bc887..d3835441e 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Line::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedA = matrix.transformPoint(_a); _transformedB = matrix.transformPoint(_b); } diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 79c721d09..0e9c949f9 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Physics { @see Line2D, Line3D @todo collision detection of two Line2D */ -template class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ inline explicit Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index f36c878f7..d057257bf 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { @see LineSegment2D, LineSegment3D */ -template class LineSegment: public Line { +template class LineSegment: public Line { public: /** @brief Constructor */ inline explicit LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index 220655125..b37d9eeee 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -22,27 +22,27 @@ namespace Magnum { namespace Physics { -template ObjectShape::ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group): SceneGraph::AbstractGroupedFeature>(object, group), _shape(nullptr) { +template ObjectShape::ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group): SceneGraph::AbstractGroupedFeature>(object, group), _shape(nullptr) { this->setCachedTransformations(SceneGraph::AbstractFeature::CachedTransformation::Absolute); } -template ObjectShape::~ObjectShape() { +template ObjectShape::~ObjectShape() { delete _shape; } -template ObjectShapeGroup* ObjectShape::group() { +template ObjectShapeGroup* ObjectShape::group() { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } -template const ObjectShapeGroup* ObjectShape::group() const { +template const ObjectShapeGroup* ObjectShape::group() const { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } -template void ObjectShape::markDirty() { +template void ObjectShape::markDirty() { group()->setDirty(); } -template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { +template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); } diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 0f7aa6e31..9eb35379e 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -49,7 +49,7 @@ shape->setShape(Physics::Sphere3D({}, 0.75f) || Physics::AxisAlignedBox3D({}, {3 @see @ref scenegraph, ObjectShape2D, ObjectShape3D, ObjectShapeGroup2D, ObjectShapeGroup3D, DebugTools::ShapeRenderer */ -template class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { +template class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { public: /** * @brief Constructor diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index 39766effd..1fea2b8ea 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void ObjectShapeGroup::setClean() { +template void ObjectShapeGroup::setClean() { /* Clean all objects */ if(!this->isEmpty()) { std::vector*> objects(this->size()); @@ -33,7 +33,7 @@ template void ObjectShapeGroup::setClean() dirty = false; } -template ObjectShape* ObjectShapeGroup::firstCollision(const ObjectShape* shape) { +template ObjectShape* ObjectShapeGroup::firstCollision(const ObjectShape* shape) { /* Nothing to test with, done */ if(!shape->shape()) return nullptr; diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 46db09721..ffc736708 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -35,7 +35,7 @@ namespace Magnum { namespace Physics { See ObjectShape for more information. @see @ref scenegraph, ObjectShapeGroup2D, ObjectShapeGroup3D */ -template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { +template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { friend class ObjectShape; public: diff --git a/src/Physics/Physics.h b/src/Physics/Physics.h index 5667d4491..ac9712de0 100644 --- a/src/Physics/Physics.h +++ b/src/Physics/Physics.h @@ -19,55 +19,55 @@ * @brief Forward declarations for Magnum::Physics namespace */ -#include +#include "Types.h" namespace Magnum { namespace Physics { /** @todoc remove when doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractShape; +template class AbstractShape; typedef AbstractShape<2> AbstractShape2D; typedef AbstractShape<3> AbstractShape3D; -template class AxisAlignedBox; +template class AxisAlignedBox; typedef AxisAlignedBox<2> AxisAlignedBox2D; typedef AxisAlignedBox<3> AxisAlignedBox3D; -template class Box; +template class Box; typedef Box<2> Box2D; typedef Box<3> Box3D; -template class Capsule; +template class Capsule; typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; -template class Line; +template class Line; typedef Line<2> Line2D; typedef Line<3> Line3D; -template class LineSegment; +template class LineSegment; typedef LineSegment<2> LineSegment2D; typedef LineSegment<3> LineSegment3D; -template class ObjectShape; +template class ObjectShape; typedef ObjectShape<2> ObjectShape2D; typedef ObjectShape<3> ObjectShape3D; -template class ObjectShapeGroup; +template class ObjectShapeGroup; typedef ObjectShapeGroup<2> ObjectShapeGroup2D; typedef ObjectShapeGroup<3> ObjectShapeGroup3D; class Plane; -template class Point; +template class Point; typedef Point<2> Point2D; typedef Point<3> Point3D; -template class ShapeGroup; +template class ShapeGroup; typedef ShapeGroup<2> ShapeGroup2D; typedef ShapeGroup<3> ShapeGroup3D; -template class Sphere; +template class Sphere; typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; #endif diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index b354447d9..098c0e071 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -40,12 +40,12 @@ bool Plane::collides(const AbstractShape<3>* other) const { } bool Plane::operator%(const Line3D& other) const { - float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); - return t != t || (t != std::numeric_limits::infinity() && t != -std::numeric_limits::infinity()); + Float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); + return t != t || (t != std::numeric_limits::infinity() && t != -std::numeric_limits::infinity()); } bool Plane::operator%(const LineSegment3D& other) const { - float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); + Float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); return t > 0.0f && t < 1.0f; } diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 94d7d20af..880c91edb 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Point::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedPosition = matrix.transformPoint(_position); } diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 10ebf9583..406197023 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { @see Point2D, Point3D */ -template class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ inline explicit Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index d77a0ce18..5c5a957b9 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -17,18 +17,18 @@ namespace Magnum { namespace Physics { -template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { +template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { other.operation = Implementation::GroupOperation::AlwaysFalse; other.a = nullptr; other.b = nullptr; } -template ShapeGroup::~ShapeGroup() { +template ShapeGroup::~ShapeGroup() { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; } -template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { +template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; @@ -43,12 +43,12 @@ template ShapeGroup& ShapeGroup return *this; } -template void ShapeGroup::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void ShapeGroup::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { if(a) a->applyTransformationMatrix(matrix); if(b) b->applyTransformationMatrix(matrix); } -template bool ShapeGroup::collides(const AbstractShape* other) const { +template bool ShapeGroup::collides(const AbstractShape* other) const { switch(operation & ~Implementation::GroupOperation::RefAB) { case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other); case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other); diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index fde6d895a..132686f77 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -58,7 +58,7 @@ Result of logical operations on shapes. See @ref collision-detection for brief introduction. @see ShapeGroup2D, ShapeGroup3D */ -template class MAGNUM_PHYSICS_EXPORT ShapeGroup: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT ShapeGroup: public AbstractShape { #ifndef DOXYGEN_GENERATING_OUTPUT // template friend constexpr operator~(const T& a) -> enableIfIsBaseType; // template friend constexpr operator~(T&& a) -> enableIfIsBaseType; @@ -186,7 +186,7 @@ is used here, so this operation can be used for providing simplified shape version, because collision with @p b is computed only if @p a collides. See @ref collision-detection-shape-simplification for an example. */ -template inline constexpr ShapeGroup operator&&(T a, U b); +template inline constexpr ShapeGroup operator&&(T a, U b); /** @relates ShapeGroup @brief Logical OR of two shapes @@ -195,7 +195,7 @@ template inline constexpr ShapeGroup< is used, so if collision with @p a is detected, collision with @p b is not computed. */ -template inline constexpr ShapeGroup operator||(T a, U b); +template inline constexpr ShapeGroup operator||(T a, U b); #else #define op(type, char) \ template inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \ diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index f5c7e5d51..752d3875f 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -27,7 +27,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { namespace { - template static typename DimensionTraits::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Constants::sqrt2()); @@ -38,13 +38,13 @@ namespace { } } -template void Sphere::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Sphere::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedPosition = matrix.transformPoint(_position); - float scaling = (matrix.rotationScaling()*unitVector()).length(); + Float scaling = (matrix.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } -template bool Sphere::collides(const AbstractShape* other) const { +template bool Sphere::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Line) @@ -57,22 +57,22 @@ template bool Sphere::collides(const Abstra return AbstractShape::collides(other); } -template bool Sphere::operator%(const Point& other) const { +template bool Sphere::operator%(const Point& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Line& other) const { +template bool Sphere::operator%(const Line& other) const { return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const LineSegment& other) const { +template bool Sphere::operator%(const LineSegment& other) const { return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Sphere& other) const { +template bool Sphere::operator%(const Sphere& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 5c60df747..ed84b3b59 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -35,10 +35,10 @@ applying transformation, the scale factor is averaged from all axes. @see Sphere2D, Sphere3D @todo Assert for asymmetric scaling */ -template class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ - inline explicit Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline explicit Sphere(const typename DimensionTraits::VectorType& position, Float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Sphere; @@ -59,10 +59,10 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs } /** @brief Radius */ - inline float radius() const { return _radius; } + inline Float radius() const { return _radius; } /** @brief Set radius */ - inline void setRadius(float radius) { _radius = radius; } + inline void setRadius(Float radius) { _radius = radius; } /** @brief Transformed position */ inline typename DimensionTraits::VectorType transformedPosition() const { @@ -70,7 +70,7 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs } /** @brief Transformed radius */ - inline float transformedRadius() const { + inline Float transformedRadius() const { return _transformedRadius; } @@ -89,7 +89,7 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs private: typename DimensionTraits::VectorType _position, _transformedPosition; - float _radius, _transformedRadius; + Float _radius, _transformedRadius; }; /** @brief Two-dimensional sphere */ @@ -99,13 +99,13 @@ typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; /** @collisionoperator{Point,Sphere} */ -template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } /** @collisionoperator{Line,Sphere} */ -template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } /** @collisionoperator{LineSegment,Sphere} */ -template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } +template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } }} From a7a4d3eeb8fbc7353423ea7d281cf4011f0e3917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 23:40:37 +0100 Subject: [PATCH 471/567] Text: using new type aliases in whole Text namespace. --- src/Text/Font.cpp | 12 +++--- src/Text/Font.h | 12 +++--- src/Text/Text.h | 4 +- src/Text/TextRenderer.cpp | 78 +++++++++++++++++++-------------------- src/Text/TextRenderer.h | 20 +++++----- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 1b77e1442..0ee3f4bd5 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -29,13 +29,13 @@ namespace Magnum { namespace Text { -Font::Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size): _size(size) { +Font::Font(FontRenderer& renderer, const std::string& fontFile, Float size): _size(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); finishConstruction(); } -Font::Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, GLfloat size): _size(size) { +Font::Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): _size(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Memory_Face(renderer.library(), data, dataSize, 0, &_ftFont) == 0); finishConstruction(); @@ -71,7 +71,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { charIndices.reserve(characters.size()+1); charIndices.push_back(0); for(std::size_t i = 0; i != characters.size(); ) { - std::uint32_t codepoint; + UnsignedInt codepoint; std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(characters, i); charIndices.push_back(FT_Get_Char_Index(_ftFont, codepoint)); } @@ -106,8 +106,8 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { const FT_Bitmap& bitmap = glyph->bitmap; CORRADE_INTERNAL_ASSERT(std::abs(bitmap.width-charPositions[i].width()) <= 2); CORRADE_INTERNAL_ASSERT(std::abs(bitmap.rows-charPositions[i].height()) <= 2); - for(std::int32_t yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout) - for(std::int32_t xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout) + for(Int yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout) + for(Int xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout) pixmap[yout*atlasSize.x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin]; /* Save character texture position and texture coordinates for given character index */ @@ -168,7 +168,7 @@ Font& Font::operator=(Font&& other) { return *this; } -const std::tuple& Font::operator[](std::uint32_t character) const { +const std::tuple& Font::operator[](char32_t character) const { auto it = glyphs.find(character); if(it == glyphs.end()) diff --git a/src/Text/Font.h b/src/Text/Font.h index 208b6d0db..247e003d5 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -73,7 +73,7 @@ class MAGNUM_TEXT_EXPORT Font { * @param fontFile %Font file * @param size %Font size */ - explicit Font(FontRenderer& renderer, const std::string& fontFile, GLfloat size); + explicit Font(FontRenderer& renderer, const std::string& fontFile, Float size); /** * @brief Create font from memory @@ -82,7 +82,7 @@ class MAGNUM_TEXT_EXPORT Font { * @param dataSize %Font data size * @param size %Font size */ - explicit Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, GLfloat size); + explicit Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); /** * @brief Prerender given character set @@ -105,7 +105,7 @@ class MAGNUM_TEXT_EXPORT Font { Font& operator=(Font&& other); /** @brief %Font size */ - inline GLfloat size() const { return _size; } + inline Float size() const { return _size; } /** @brief Count of prerendered glyphs in the font */ inline std::size_t glyphCount() const { return glyphs.size(); } @@ -117,7 +117,7 @@ class MAGNUM_TEXT_EXPORT Font { * First returned rectangle is texture position relative to point on * baseline, second is position of the texture in texture atlas. */ - const std::tuple& operator[](std::uint32_t character) const; + const std::tuple& operator[](char32_t character) const; /** @brief %Font texture atlas */ inline Texture2D& texture() { return _texture; } @@ -134,10 +134,10 @@ class MAGNUM_TEXT_EXPORT Font { void MAGNUM_TEXT_LOCAL destroy(); void MAGNUM_TEXT_LOCAL move(); - std::unordered_map> glyphs; + std::unordered_map> glyphs; Texture2D _texture; FT_Face _ftFont; - GLfloat _size; + Float _size; #ifdef MAGNUM_USE_HARFBUZZ hb_font_t* _hbFont; #endif diff --git a/src/Text/Text.h b/src/Text/Text.h index 56cef3e75..4e4d49443 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -19,14 +19,14 @@ * @brief Forward declarations for Magnum::Text namespace */ -#include +#include "Types.h" namespace Magnum { namespace Text { class Font; class FontRenderer; -template class TextRenderer; +template class TextRenderer; typedef TextRenderer<2> TextRenderer2D; typedef TextRenderer<3> TextRenderer3D; diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 4339d78f5..a77c318ce 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -36,11 +36,11 @@ namespace { class TextLayouter { public: - TextLayouter(Font& font, const GLfloat size, const std::string& text); + TextLayouter(Font& font, const Float size, const std::string& text); ~TextLayouter(); - inline std::uint32_t glyphCount() { + inline UnsignedInt glyphCount() { #ifdef MAGNUM_USE_HARFBUZZ return _glyphCount; #else @@ -48,7 +48,7 @@ class TextLayouter { #endif } - std::tuple renderGlyph(const Vector2& cursorPosition, const std::uint32_t i); + std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i); private: #ifdef MAGNUM_USE_HARFBUZZ @@ -56,16 +56,16 @@ class TextLayouter { hb_buffer_t* buffer; hb_glyph_info_t* glyphInfo; hb_glyph_position_t* glyphPositions; - std::uint32_t _glyphCount; + UnsignedInt _glyphCount; #else Font& font; std::vector glyphs; #endif - const GLfloat size; + const Float size; }; -TextLayouter::TextLayouter(Font& font, const GLfloat size, const std::string& text): font(font), size(size) { +TextLayouter::TextLayouter(Font& font, const Float size, const std::string& text): font(font), size(size) { #ifdef MAGNUM_USE_HARFBUZZ /* Prepare HarfBuzz buffer */ buffer = hb_buffer_create(); @@ -83,7 +83,7 @@ TextLayouter::TextLayouter(Font& font, const GLfloat size, const std::string& te /* Get glyph codes from characters */ glyphs.reserve(text.size()+1); for(std::size_t i = 0; i != text.size(); ) { - std::uint32_t codepoint; + UnsignedInt codepoint; std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); glyphs.push_back(FT_Get_Char_Index(font.font(), codepoint)); } @@ -97,7 +97,7 @@ TextLayouter::~TextLayouter() { #endif } -std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const std::uint32_t i) { +std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle texturePosition, textureCoordinates; #ifdef MAGNUM_USE_HARFBUZZ @@ -129,9 +129,9 @@ std::tuple TextLayouter::renderGlyph(const Vector return std::make_tuple(quadPosition, textureCoordinates, advance); } -template void createIndices(void* output, const std::uint32_t glyphCount) { +template void createIndices(void* output, const UnsignedInt glyphCount) { T* const out = reinterpret_cast(output); - for(std::uint32_t i = 0; i != glyphCount; ++i) { + for(UnsignedInt i = 0; i != glyphCount; ++i) { /* 0---2 2 | / /| | / / | @@ -149,7 +149,7 @@ template void createIndices(void* output, const std::uint32_t glyphCoun } } -template typename DimensionTraits::VectorType point(const Vector2& vec); +template typename DimensionTraits::VectorType point(const Vector2& vec); template<> inline Vector2 point<2>(const Vector2& vec) { return vec; @@ -159,17 +159,17 @@ template<> inline Vector3 point<3>(const Vector2& vec) { return {vec, 1.0f}; } -template struct Vertex { +template struct Vertex { typename DimensionTraits::VectorType position; Vector2 texcoords; }; } -template std::tuple::VectorType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, GLfloat size, const std::string& text) { +template std::tuple::VectorType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, Float size, const std::string& text) { TextLayouter layouter(font, size, text); - const std::uint32_t vertexCount = layouter.glyphCount()*4; + const UnsignedInt vertexCount = layouter.glyphCount()*4; /* Output data */ std::vector::VectorType> positions; @@ -179,7 +179,7 @@ template std::tuple std::tuple indices(layouter.glyphCount()*6); - createIndices(indices.data(), layouter.glyphCount()); + std::vector indices(layouter.glyphCount()*6); + createIndices(indices.data(), layouter.glyphCount()); /* Rendered rectangle */ Rectangle rectangle; @@ -214,11 +214,11 @@ template std::tuple std::tuple TextRenderer::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { +template std::tuple TextRenderer::render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { TextLayouter layouter(font, size, text); - const std::uint32_t vertexCount = layouter.glyphCount()*4; - const std::uint32_t indexCount = layouter.glyphCount()*6; + const UnsignedInt vertexCount = layouter.glyphCount()*4; + const UnsignedInt indexCount = layouter.glyphCount()*6; /* Vertex buffer */ std::vector> vertices; @@ -226,7 +226,7 @@ template std::tuple TextRenderer std::tuple TextRenderer(indices, layouter.glyphCount()); + createIndices(indices, layouter.glyphCount()); } else if(vertexCount < 65535) { indexType = Mesh::IndexType::UnsignedShort; - indicesSize = indexCount*sizeof(GLushort); + indicesSize = indexCount*sizeof(UnsignedShort); indices = new char[indicesSize]; - createIndices(indices, layouter.glyphCount()); + createIndices(indices, layouter.glyphCount()); } else { indexType = Mesh::IndexType::UnsignedInt; - indicesSize = indexCount*sizeof(GLuint); + indicesSize = indexCount*sizeof(UnsignedInt); indices = new char[indicesSize]; - createIndices(indices, layouter.glyphCount()); + createIndices(indices, layouter.glyphCount()); } indexBuffer->setData(indicesSize, indices, usage); delete indices; @@ -284,7 +284,7 @@ template std::tuple TextRenderer TextRenderer::TextRenderer(Font& font, const GLfloat size): font(font), size(size), _capacity(0), vertexBuffer(Buffer::Target::Array), indexBuffer(Buffer::Target::ElementArray) { +template TextRenderer::TextRenderer(Font& font, const Float size): font(font), size(size), _capacity(0), vertexBuffer(Buffer::Target::Array), indexBuffer(Buffer::Target::ElementArray) { #ifndef MAGNUM_TARGET_GLES MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::map_buffer_range); #else @@ -299,11 +299,11 @@ template TextRenderer::TextRenderer(Font& f typename Shaders::AbstractTextShader::TextureCoordinates()); } -template void TextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) { +template void TextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) { _capacity = glyphCount; - const std::uint32_t vertexCount = glyphCount*4; - const std::uint32_t indexCount = glyphCount*6; + const UnsignedInt vertexCount = glyphCount*4; + const UnsignedInt indexCount = glyphCount*6; /* Allocate vertex buffer, reset vertex count */ vertexBuffer.setData(vertexCount*sizeof(Vertex), nullptr, vertexBufferUsage); @@ -314,13 +314,13 @@ template void TextRenderer::reserve(const u std::size_t indicesSize; if(vertexCount < 255) { indexType = Mesh::IndexType::UnsignedByte; - indicesSize = indexCount*sizeof(GLushort); + indicesSize = indexCount*sizeof(UnsignedByte); } else if(vertexCount < 65535) { indexType = Mesh::IndexType::UnsignedShort; - indicesSize = indexCount*sizeof(GLushort); + indicesSize = indexCount*sizeof(UnsignedShort); } else { indexType = Mesh::IndexType::UnsignedInt; - indicesSize = indexCount*sizeof(GLuint); + indicesSize = indexCount*sizeof(UnsignedInt); } indexBuffer.setData(indicesSize, nullptr, indexBufferUsage); _mesh.setIndexCount(0) @@ -329,15 +329,15 @@ template void TextRenderer::reserve(const u /* Prefill index buffer */ void* indices = indexBuffer.map(0, indicesSize, Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write); if(vertexCount < 255) - createIndices(indices, glyphCount); + createIndices(indices, glyphCount); else if(vertexCount < 65535) - createIndices(indices, glyphCount); + createIndices(indices, glyphCount); else - createIndices(indices, glyphCount); + createIndices(indices, glyphCount); CORRADE_INTERNAL_ASSERT_OUTPUT(indexBuffer.unmap()); } -template void TextRenderer::render(const std::string& text) { +template void TextRenderer::render(const std::string& text) { TextLayouter layouter(font, size, text); CORRADE_ASSERT(layouter.glyphCount() <= _capacity, "Text::TextRenderer::render(): capacity" << _capacity << "too small to render" << layouter.glyphCount() << "glyphs", ); @@ -346,7 +346,7 @@ template void TextRenderer::render(const st Vertex* const vertices = static_cast*>(vertexBuffer.map(0, layouter.glyphCount()*4*sizeof(Vertex), Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write)); Vector2 cursorPosition; - for(std::uint32_t i = 0; i != layouter.glyphCount(); ++i) { + for(UnsignedInt i = 0; i != layouter.glyphCount(); ++i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle quadPosition, textureCoordinates; Vector2 advance; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 4c2a1c7f6..c8bfa689d 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -64,8 +64,8 @@ shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-rectan font.texture()->bind(Shaders::TextShader2D::FontTextureLayer); mesh.draw(); @endcode -See render(Font&, GLfloat, const std::string&) and -render(Font&, GLfloat, const std::string&, Buffer*, Buffer*, Buffer::Usage) +See render(Font&, Float, const std::string&) and +render(Font&, Float, const std::string&, Buffer*, Buffer*, Buffer::Usage) for more information. While this method is sufficient for one-shot rendering of static texts, for @@ -98,7 +98,7 @@ for asynchronous buffer updates. @see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractTextShader */ -template class MAGNUM_TEXT_EXPORT TextRenderer { +template class MAGNUM_TEXT_EXPORT TextRenderer { public: /** * @brief Render text @@ -109,7 +109,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * Returns tuple with vertex positions, texture coordinates, indices * and rectangle spanning the rendered text. */ - static std::tuple::VectorType>, std::vector, std::vector, Rectangle> render(Font& font, GLfloat size, const std::string& text); + static std::tuple::VectorType>, std::vector, std::vector, Rectangle> render(Font& font, Float size, const std::string& text); /** * @brief Render text @@ -123,21 +123,21 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * Returns mesh prepared for use with Shaders::AbstractTextShader * subclasses and rectangle spanning the rendered text. */ - static std::tuple render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + static std::tuple render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); /** * @brief Constructor * @param font %Font to use * @param size %Font size */ - TextRenderer(Font& font, GLfloat size); + TextRenderer(Font& font, Float size); /** * @brief Capacity for rendered glyphs * * @see reserve() */ - inline std::uint32_t capacity() const { return _capacity; } + inline UnsignedInt capacity() const { return _capacity; } /** @brief Rectangle spanning the rendered text */ inline Rectangle rectangle() const { return _rectangle; } @@ -157,7 +157,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * Initially zero capacity is reserved. * @see capacity() */ - void reserve(const std::uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage); + void reserve(const UnsignedInt glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage); /** * @brief Render text @@ -174,8 +174,8 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { private: Font& font; - GLfloat size; - std::uint32_t _capacity; + Float size; + UnsignedInt _capacity; Rectangle _rectangle; Buffer vertexBuffer, indexBuffer; Mesh _mesh; From 006dbf417a9cfd79135e8315606c6b5c9d14022b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 23:41:05 +0100 Subject: [PATCH 472/567] Platform: using new type aliases in whole Platform namespace. --- src/Platform/NaClApplication.h | 4 ++-- src/Platform/Sdl2Application.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 874499f56..050e93164 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -176,7 +176,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public /*@}*/ private: - enum class Flag: std::uint8_t { + enum class Flag: UnsignedByte { ViewportUpdated = 1 << 0, SwapInProgress = 1 << 1, Redraw = 1 << 2, @@ -184,7 +184,7 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public WillBeFullscreen = 1 << 4, MouseLocked = 1 << 5 }; - typedef Corrade::Containers::EnumSet Flags; + typedef Corrade::Containers::EnumSet Flags; inline void Graphics3DContextLost() override { CORRADE_ASSERT(false, "NaClApplication: context unexpectedly lost", ); diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 59f11c881..ec1b85058 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -152,12 +152,12 @@ class Sdl2Application { /*@}*/ private: - enum class Flag: std::uint8_t { + enum class Flag: UnsignedByte { Redraw = 1 << 0, Exit = 1 << 1 }; - typedef Corrade::Containers::EnumSet Flags; + typedef Corrade::Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) SDL_Window* window; From b5c1052c961e6760fb5c4c25bff5806b7936b0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 27 Feb 2013 23:45:08 +0100 Subject: [PATCH 473/567] DebugTools: using new type aliases in whole DebugTools namespace. --- src/DebugTools/DebugTools.h | 6 +++--- .../Implementation/AbstractBoxRenderer.h | 2 +- .../Implementation/AbstractShapeRenderer.cpp | 10 +++++----- .../Implementation/AbstractShapeRenderer.h | 4 ++-- .../Implementation/AxisAlignedBoxRenderer.cpp | 4 ++-- .../Implementation/AxisAlignedBoxRenderer.h | 2 +- src/DebugTools/Implementation/BoxRenderer.cpp | 4 ++-- src/DebugTools/Implementation/BoxRenderer.h | 2 +- .../Implementation/PointRenderer.cpp | 10 +++++----- src/DebugTools/Implementation/PointRenderer.h | 2 +- src/DebugTools/ObjectRenderer.cpp | 12 ++++++------ src/DebugTools/ObjectRenderer.h | 12 ++++++------ src/DebugTools/Profiler.h | 3 ++- src/DebugTools/ShapeRenderer.cpp | 6 +++--- src/DebugTools/ShapeRenderer.h | 18 +++++++++--------- 15 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h index 31fddcd58..1cac85e90 100644 --- a/src/DebugTools/DebugTools.h +++ b/src/DebugTools/DebugTools.h @@ -19,13 +19,13 @@ * @brief Forward declarations for Magnum::DebugTools namespace */ -#include +#include "Types.h" namespace Magnum { namespace DebugTools { /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class ObjectRenderer; +template class ObjectRenderer; typedef ObjectRenderer<2> ObjectRenderer2D; typedef ObjectRenderer<3> ObjectRenderer3D; class ObjectRendererOptions; @@ -33,7 +33,7 @@ class ObjectRendererOptions; class Profiler; class ResourceManager; -template class ShapeRenderer; +template class ShapeRenderer; typedef ShapeRenderer<2> ShapeRenderer2D; typedef ShapeRenderer<3> ShapeRenderer3D; class ShapeRendererOptions; diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.h b/src/DebugTools/Implementation/AbstractBoxRenderer.h index cc6f2a9a4..f5d494e8f 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.h +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.h @@ -24,7 +24,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template class AbstractBoxRenderer; +template class AbstractBoxRenderer; template<> class AbstractBoxRenderer<2>: public AbstractShapeRenderer<2> { public: diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index b32dc0c1f..b461cac31 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -28,11 +28,11 @@ namespace Magnum { namespace DebugTools { namespace Implementation { namespace { -template ResourceKey shaderKey(); +template ResourceKey shaderKey(); template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } -template void create(typename MeshData::Type&, Resource&, Resource&, Resource&); +template void create(typename MeshData::Type&, Resource&, Resource&, Resource&); template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, Resource& vertexBufferResource, Resource& indexBufferResource) { /* Vertex buffer */ @@ -80,7 +80,7 @@ template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, } -template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey meshKey, ResourceKey vertexBufferKey, ResourceKey indexBufferKey) { +template AbstractShapeRenderer::AbstractShapeRenderer(ResourceKey meshKey, ResourceKey vertexBufferKey, ResourceKey indexBufferKey) { shader = ResourceManager::instance()->get>(shaderKey()); mesh = ResourceManager::instance()->get(meshKey); vertexBuffer = ResourceManager::instance()->get(vertexBufferKey); @@ -90,9 +90,9 @@ template AbstractShapeRenderer::AbstractSha new Shaders::FlatShader, ResourceDataState::Final, ResourcePolicy::Resident); } -template AbstractShapeRenderer::~AbstractShapeRenderer() {} +template AbstractShapeRenderer::~AbstractShapeRenderer() {} -template void AbstractShapeRenderer::createResources(typename MeshData::Type data) { +template void AbstractShapeRenderer::createResources(typename MeshData::Type data) { create(data, this->mesh, this->vertexBuffer, this->indexBuffer); } diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index 1f530a86f..6e3b80be1 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -24,12 +24,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template struct MeshData; +template struct MeshData; template<> struct MeshData<2> { typedef Trade::MeshData2D Type; }; template<> struct MeshData<3> { typedef Trade::MeshData3D Type; }; -template class AbstractShapeRenderer { +template class AbstractShapeRenderer { public: AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer); virtual ~AbstractShapeRenderer(); diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 87b7ab1b6..cfbda116a 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -22,9 +22,9 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} +template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} -template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the box is 2x2(x2) */ typename DimensionTraits::MatrixType transformation = DimensionTraits::MatrixType::translation((axisAlignedBox.transformedMin()+axisAlignedBox.transformedMax())/2)* diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index c826a24dc..75d6a93af 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -23,7 +23,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template class AxisAlignedBoxRenderer: public AbstractBoxRenderer { +template class AxisAlignedBoxRenderer: public AbstractBoxRenderer { public: AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox); diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 291019d2d..fa42567c4 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -22,9 +22,9 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template BoxRenderer::BoxRenderer(Physics::Box& box): box(box) {} +template BoxRenderer::BoxRenderer(Physics::Box& box): box(box) {} -template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the box is 2x2(x2) */ this->shader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation()* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(0.5f))) diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index 6330ad519..7225471fa 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -23,7 +23,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template class BoxRenderer: public AbstractBoxRenderer { +template class BoxRenderer: public AbstractBoxRenderer { public: BoxRenderer(Physics::Box& box); diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp index b13f9456b..3a658bbcb 100644 --- a/src/DebugTools/Implementation/PointRenderer.cpp +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -26,24 +26,24 @@ namespace Magnum { namespace DebugTools { namespace Implementation { namespace { - template ResourceKey meshKey(); + template ResourceKey meshKey(); template<> inline ResourceKey meshKey<2>() { return ResourceKey("point2d"); } template<> inline ResourceKey meshKey<3>() { return ResourceKey("point3d"); } - template ResourceKey vertexBufferKey(); + template ResourceKey vertexBufferKey(); template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("point2d-vertices"); } template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); } - template typename MeshData::Type meshData(); + template typename MeshData::Type meshData(); template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Crosshair2D::wireframe(); } template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); } } -template PointRenderer::PointRenderer(Physics::Point& point): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), point(point) { +template PointRenderer::PointRenderer(Physics::Point& point): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), point(point) { if(!this->mesh) this->createResources(meshData()); } -template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the point is 2x2(x2) */ this->shader->setTransformationProjectionMatrix(projectionMatrix* DimensionTraits::MatrixType::translation(point.transformedPosition())* diff --git a/src/DebugTools/Implementation/PointRenderer.h b/src/DebugTools/Implementation/PointRenderer.h index 31e22c746..820098191 100644 --- a/src/DebugTools/Implementation/PointRenderer.h +++ b/src/DebugTools/Implementation/PointRenderer.h @@ -23,7 +23,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template class PointRenderer: public AbstractShapeRenderer { +template class PointRenderer: public AbstractShapeRenderer { public: PointRenderer(Physics::Point& point); diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 3deac8cdc..007dae13e 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -25,7 +25,7 @@ namespace Magnum { namespace DebugTools { namespace { -template struct Renderer; +template struct Renderer; template<> struct Renderer<2> { inline static ResourceKey shader() { return {"VertexColorShader2D"}; } @@ -35,7 +35,7 @@ template<> struct Renderer<2> { static const std::array positions; static const std::array, 8> colors; - static const std::array indices; + static const std::array indices; }; const std::array Renderer<2>::positions{{ @@ -62,7 +62,7 @@ const std::array, 8> Renderer<2>::colors{{ {0.0f, 1.0f, 0.0f}, }}; -const std::array Renderer<2>::indices{{ +const std::array Renderer<2>::indices{{ 0, 1, 1, 2, /* X axis */ 1, 3, @@ -117,7 +117,7 @@ const std::array, 12> Renderer<3>::colors{{ {0.0f, 0.0f, 1.0f} }}; -const std::array Renderer<3>::indices{{ +const std::array Renderer<3>::indices{{ 0, 1, 1, 2, /* X axis */ 1, 3, @@ -133,7 +133,7 @@ const std::array Renderer<3>::indices{{ } -template ObjectRenderer::ObjectRenderer(SceneGraph::AbstractObject* object, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(object, drawables), options(ResourceManager::instance()->get(options)) { +template ObjectRenderer::ObjectRenderer(SceneGraph::AbstractObject* object, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(object, drawables), options(ResourceManager::instance()->get(options)) { /* Shader */ shader = ResourceManager::instance()->get>(Renderer::shader()); if(!shader) ResourceManager::instance()->set(shader.key(), @@ -165,7 +165,7 @@ template ObjectRenderer::ObjectRenderer(Sce ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } -template void ObjectRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { +template void ObjectRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->size()))) ->use(); diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h index 8aab17f1d..3391d4e7e 100644 --- a/src/DebugTools/ObjectRenderer.h +++ b/src/DebugTools/ObjectRenderer.h @@ -37,7 +37,7 @@ class ObjectRendererOptions { inline constexpr ObjectRendererOptions(): _size(1.0f) {} /** @brief Size of the rendered axes */ - inline constexpr GLfloat size() const { return _size; } + inline constexpr Float size() const { return _size; } /** * @brief Set size of the rendered axes @@ -45,13 +45,13 @@ class ObjectRendererOptions { * * Default is `1.0f`. */ - inline ObjectRendererOptions* setSize(GLfloat size) { + inline ObjectRendererOptions* setSize(Float size) { _size = size; return this; } private: - GLfloat _size; + Float _size; }; /** @@ -75,7 +75,7 @@ new DebugTools::ObjectRenderer2D(object, "my", debugDrawables); @see ObjectRenderer2D, ObjectRenderer3D */ -template class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: public SceneGraph::Drawable { +template class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: public SceneGraph::Drawable { public: /** * @brief Constructor @@ -90,8 +90,8 @@ template class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: explicit ObjectRenderer(SceneGraph::AbstractObject* object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); protected: - /** @todoc Remove GLfloat when Doxygen properly treats this as override */ - void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; + /** @todoc Remove Float when Doxygen properly treats this as override */ + void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; private: Resource options; diff --git a/src/DebugTools/Profiler.h b/src/DebugTools/Profiler.h index 29f541f0a..03cb85e16 100644 --- a/src/DebugTools/Profiler.h +++ b/src/DebugTools/Profiler.h @@ -24,6 +24,7 @@ #include #include +#include "Types.h" #include "magnumDebugToolsVisibility.h" namespace Magnum { namespace DebugTools { @@ -95,7 +96,7 @@ class MAGNUM_DEBUGTOOLS_EXPORT Profiler { * * @see otherSection, addSection(), start(Section) */ - typedef std::uint32_t Section; + typedef UnsignedInt Section; /** * @brief Default section diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 54a6cf21a..5b7cfb4a4 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -78,16 +78,16 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha } #endif -template ShapeRenderer::ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { +template ShapeRenderer::ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { CORRADE_ASSERT(shape->shape() != nullptr, "DebugTools::ShapeRenderer: cannot create renderer for empty shape", ); Implementation::createDebugMesh(this, shape->shape()); } -template ShapeRenderer::~ShapeRenderer() { +template ShapeRenderer::~ShapeRenderer() { for(auto i: renderers) delete i; } -template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType&, SceneGraph::AbstractCamera* camera) { +template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType&, SceneGraph::AbstractCamera* camera) { typename DimensionTraits::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix(); for(auto i: renderers) i->draw(options, projectionMatrix); } diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 20b280e47..15db2c090 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -30,14 +30,14 @@ namespace Magnum { namespace DebugTools { /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class ShapeRenderer; +template class ShapeRenderer; #endif #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template class AbstractShapeRenderer; + template class AbstractShapeRenderer; - template void createDebugMesh(ShapeRenderer* renderer, Physics::AbstractShape* shape); + template void createDebugMesh(ShapeRenderer* renderer, Physics::AbstractShape* shape); } #endif @@ -65,7 +65,7 @@ class ShapeRendererOptions { } /** @brief Point size */ - inline constexpr GLfloat pointSize() const { return _pointSize; } + inline constexpr Float pointSize() const { return _pointSize; } /** * @brief Set point size @@ -74,14 +74,14 @@ class ShapeRendererOptions { * Size of rendered crosshairs, representing Physics::Point shapes. * Default is `0.25f`. */ - inline ShapeRendererOptions* setPointSize(GLfloat size) { + inline ShapeRendererOptions* setPointSize(Float size) { _pointSize = size; return this; } private: Color3<> _color; - GLfloat _pointSize; + Float _pointSize; }; /** @@ -105,7 +105,7 @@ new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); @see ShapeRenderer2D, ShapeRenderer3D */ -template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable { +template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable { #ifndef DOXYGEN_GENERATING_OUTPUT friend void Implementation::createDebugMesh<>(ShapeRenderer*, Physics::AbstractShape*); #endif @@ -129,8 +129,8 @@ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: ~ShapeRenderer(); protected: - /** @todoc Remove GLfloat when Doxygen properly treats this as override */ - void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; + /** @todoc Remove Float when Doxygen properly treats this as override */ + void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; private: Resource options; From c707370f30f2a0cad962f079d89f5a19da96fd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 00:32:39 +0100 Subject: [PATCH 474/567] Removed unneeded includes. --- src/AbstractResourceLoader.h | 2 -- src/Array.h | 1 - src/DimensionTraits.h | 3 ++- src/Implementation/BufferState.h | 2 -- src/Implementation/State.h | 2 -- src/Implementation/TextureState.h | 2 ++ src/MeshTools/FlipNormals.h | 1 - src/MeshTools/GenerateFlatNormals.h | 1 - src/MeshTools/Test/CombineIndexedArraysTest.cpp | 2 +- src/MeshTools/Test/SubdivideTest.cpp | 1 - src/Physics/ObjectShapeGroup.h | 1 - src/SceneGraph/AbstractFeature.h | 3 ++- src/Timeline.h | 2 +- src/Trade/TextureData.h | 2 -- 14 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h index e1d358215..47a8215da 100644 --- a/src/AbstractResourceLoader.h +++ b/src/AbstractResourceLoader.h @@ -19,8 +19,6 @@ * @brief Class Magnum::AbstractResourceLoader */ -#include "Magnum.h" - #include #include "ResourceManager.h" diff --git a/src/Array.h b/src/Array.h index cfe5dfb28..81ccb02b0 100644 --- a/src/Array.h +++ b/src/Array.h @@ -19,7 +19,6 @@ * @brief Class Magnum::Array, Magnum::Array1D, Magnum::Array2D, Magnum::Array3D */ -#include #include #include diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index eb790dbe0..b9cfba286 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -15,7 +15,8 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Magnum.h" +#include "Math/Math.h" +#include "Types.h" /** @file * @brief Class Magnum::DimensionTraits diff --git a/src/Implementation/BufferState.h b/src/Implementation/BufferState.h index 097d3ea56..fd4bdebec 100644 --- a/src/Implementation/BufferState.h +++ b/src/Implementation/BufferState.h @@ -15,8 +15,6 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Magnum.h" - #include "Buffer.h" namespace Magnum { namespace Implementation { diff --git a/src/Implementation/State.h b/src/Implementation/State.h index dd02d6823..738acb31d 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -15,8 +15,6 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Magnum.h" - namespace Magnum { namespace Implementation { struct BufferState; diff --git a/src/Implementation/TextureState.h b/src/Implementation/TextureState.h index 73eca32af..b35ae25a6 100644 --- a/src/Implementation/TextureState.h +++ b/src/Implementation/TextureState.h @@ -15,6 +15,8 @@ GNU Lesser General Public License version 3 for more details. */ +#include + #include "Magnum.h" namespace Magnum { namespace Implementation { diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index c0f6f5519..2b89892de 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -19,7 +19,6 @@ * @brief Function Magnum::MeshTools::flipNormals() */ -#include #include #include "Magnum.h" diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index b9060b292..9198d9bc4 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -19,7 +19,6 @@ * @brief Function Magnum::MeshTools::generateFlatNormals() */ -#include #include #include diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index edd14e225..ba7356f71 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -16,7 +16,7 @@ #include #include -#include "Magnum.h" +#include "Types.h" #include "MeshTools/CombineIndexedArrays.h" namespace Magnum { namespace MeshTools { namespace Test { diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index bbbab9e79..72b15c49a 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -16,7 +16,6 @@ #include #include -#include "Magnum.h" #include "MeshTools/Clean.h" #include "MeshTools/Subdivide.h" diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index ffc736708..05bf8fcc8 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -19,7 +19,6 @@ * @brief Class Magnum::Physics::ObjectShapeGroup */ -#include #include #include "Physics/ObjectShape.h" diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index c8b81f45e..4d119f2a7 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -22,7 +22,8 @@ #include #include -#include "AbstractObject.h" +#include "Magnum.h" +#include "SceneGraph/AbstractObject.h" namespace Magnum { namespace SceneGraph { diff --git a/src/Timeline.h b/src/Timeline.h index 91908937e..8b8b2b2d6 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -17,7 +17,7 @@ #include -#include "Magnum.h" +#include "Types.h" #include "magnumVisibility.h" diff --git a/src/Trade/TextureData.h b/src/Trade/TextureData.h index 1dc4f16d0..ad2c70003 100644 --- a/src/Trade/TextureData.h +++ b/src/Trade/TextureData.h @@ -19,8 +19,6 @@ * @brief Class Magnum::Trade::TextureData */ -#include - namespace Magnum { namespace Trade { /** From 1693c772ada30e7d4cf63a05ec3ad9b32e0b7445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 01:02:23 +0100 Subject: [PATCH 475/567] Moved OpenGL includes out from Magnum.h. OpenGL includes are ~35k lines together and it is a waste of compilation time to include them even if they are not needed at all (e.g. whole SceneGraph and Physics libraries). Saves ~10s of compilation time (6:46 before, now 6:35). --- src/AbstractImage.h | 2 +- src/AbstractShaderProgram.cpp | 14 ---------- src/AbstractShaderProgram.h | 2 +- src/Buffer.h | 2 +- src/CMakeLists.txt | 2 ++ src/Context.h | 2 +- src/Magnum.h | 15 +---------- src/OpenGL.cpp | 35 ++++++++++++++++++++++++ src/OpenGL.h | 36 +++++++++++++++++++++++++ src/Platform/ExtensionWrangler.cpp | 1 + src/Platform/GlutApplication.h | 1 + src/Platform/GlxContextHandler.h | 2 +- src/Platform/WindowlessGlxApplication.h | 5 ++-- src/Query.h | 2 +- src/Renderbuffer.h | 2 +- 15 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 src/OpenGL.cpp create mode 100644 src/OpenGL.h diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 2ba2279c7..35e427b56 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -22,7 +22,7 @@ #include #include "Magnum.h" - +#include "OpenGL.h" #include "magnumVisibility.h" namespace Magnum { diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index b5f09a957..88f30d040 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -28,20 +28,6 @@ namespace Magnum { -#ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(std::is_same::value, "GLubyte is not the same as UnsignedByte"); -static_assert(std::is_same::value, "GLbyte is not the same as Byte"); -static_assert(std::is_same::value, "GLushort is not the same as UnsignedShort"); -static_assert(std::is_same::value, "GLshort is not the same as Short"); -static_assert(std::is_same::value, "GLuint is not the same as UnsignedInt"); -static_assert(std::is_same::value, "GLint is not the same as Int"); -static_assert(std::is_same::value, "GLsizei is not the same as Int"); -static_assert(std::is_same::value, "GLfloat is not the same as Float"); -#ifndef MAGNUM_TARGET_GLES -static_assert(std::is_same::value, "GLdouble is not the same as Double"); -#endif -#endif - AbstractShaderProgram::Uniform1fImplementation AbstractShaderProgram::uniform1fImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform2fvImplementation AbstractShaderProgram::uniform2fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; AbstractShaderProgram::Uniform3fvImplementation AbstractShaderProgram::uniform3fvImplementation = &AbstractShaderProgram::uniformImplementationDefault; diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 658281fa6..3aa6a9108 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -23,7 +23,7 @@ #include #include "Magnum.h" - +#include "OpenGL.h" #include "magnumVisibility.h" /** @todo early asserts (no bool returns?) */ diff --git a/src/Buffer.h b/src/Buffer.h index 0f2b30b08..ef2447cb4 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -25,7 +25,7 @@ #include #include "Magnum.h" - +#include "OpenGL.h" #include "magnumVisibility.h" namespace Magnum { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 136a082dc..5565c3d16 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ set(Magnum_SRCS Framebuffer.cpp Image.cpp Mesh.cpp + OpenGL.cpp Query.cpp Renderbuffer.cpp Resource.cpp @@ -69,6 +70,7 @@ set(Magnum_HEADERS ImageWrapper.h Magnum.h Mesh.h + OpenGL.h Query.h Renderbuffer.h Renderer.h diff --git a/src/Context.h b/src/Context.h index 86cc209b6..f9b8c18d4 100644 --- a/src/Context.h +++ b/src/Context.h @@ -23,7 +23,7 @@ #include #include "Magnum.h" - +#include "OpenGL.h" #include "magnumVisibility.h" namespace Magnum { diff --git a/src/Magnum.h b/src/Magnum.h index 782d97a0c..efd95f02a 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -16,28 +16,15 @@ */ /** @file - * @brief Basic definitions and forward declarations for Magnum namespace + * @brief Forward declarations for Magnum namespace */ #include #include "Math/Math.h" #include "Types.h" - #include "magnumConfigure.h" -#ifndef MAGNUM_TARGET_GLES -#include -#include -#else -#ifndef MAGNUM_TARGET_GLES2 -#include -#else -#include -#include -#endif -#endif - namespace Corrade { namespace Utility { class Debug; diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp new file mode 100644 index 000000000..ec410cee2 --- /dev/null +++ b/src/OpenGL.cpp @@ -0,0 +1,35 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "OpenGL.h" +#include "Types.h" + +namespace Magnum { + +static_assert(std::is_same::value, "GLubyte is not the same as UnsignedByte"); +static_assert(std::is_same::value, "GLbyte is not the same as Byte"); +static_assert(std::is_same::value, "GLushort is not the same as UnsignedShort"); +static_assert(std::is_same::value, "GLshort is not the same as Short"); +static_assert(std::is_same::value, "GLuint is not the same as UnsignedInt"); +static_assert(std::is_same::value, "GLint is not the same as Int"); +static_assert(std::is_same::value, "GLsizei is not the same as Int"); +static_assert(std::is_same::value, "GLfloat is not the same as Float"); +#ifndef MAGNUM_TARGET_GLES +static_assert(std::is_same::value, "GLdouble is not the same as Double"); +#endif + +} diff --git a/src/OpenGL.h b/src/OpenGL.h new file mode 100644 index 000000000..100b85ca7 --- /dev/null +++ b/src/OpenGL.h @@ -0,0 +1,36 @@ +#ifndef Magnum_OpenGL_h +#define Magnum_OpenGL_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief OpenGL headers + */ + +#include "magnumConfigure.h" + +#ifndef MAGNUM_TARGET_GLES +#include +#include +#else +#ifndef MAGNUM_TARGET_GLES2 +#include +#else +#include +#include +#endif +#endif + +#endif diff --git a/src/Platform/ExtensionWrangler.cpp b/src/Platform/ExtensionWrangler.cpp index 3c58b7da1..b5fdce9f0 100644 --- a/src/Platform/ExtensionWrangler.cpp +++ b/src/Platform/ExtensionWrangler.cpp @@ -19,6 +19,7 @@ #include #include "Magnum.h" +#include "OpenGL.h" namespace Magnum { namespace Platform { diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 06c91984f..8d1030eec 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -23,6 +23,7 @@ #include "Math/Vector2.h" #include "Magnum.h" +#include "OpenGL.h" #include diff --git a/src/Platform/GlxContextHandler.h b/src/Platform/GlxContextHandler.h index e78df00ba..fd9e3adcf 100644 --- a/src/Platform/GlxContextHandler.h +++ b/src/Platform/GlxContextHandler.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Platform::GlxContextHandler */ -#include "Magnum.h" +#include "OpenGL.h" #include /* undef Xlib nonsense to avoid conflicts */ #undef Complex diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 541b0a9f4..8e35d4492 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Platform::WindowlessGlxApplication */ -#include "Magnum.h" +#include "OpenGL.h" #include #include #include @@ -28,7 +28,8 @@ #undef None #undef Always -#include "AbstractContextHandler.h" +#include "Magnum.h" +#include "Platform/AbstractContextHandler.h" namespace Magnum { namespace Platform { diff --git a/src/Query.h b/src/Query.h index 22aace60f..21063f516 100644 --- a/src/Query.h +++ b/src/Query.h @@ -20,7 +20,7 @@ */ #include "Magnum.h" - +#include "OpenGL.h" #include "magnumVisibility.h" namespace Magnum { diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 35df11a25..20f53aa6a 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -20,7 +20,7 @@ */ #include "Magnum.h" - +#include "OpenGL.h" #include "magnumVisibility.h" namespace Magnum { From 618b556381ee07a35d46b29aed31a2326ea165d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 11:58:31 +0100 Subject: [PATCH 476/567] Math: crosslinked documentation with missing type aliases. --- doc/types.dox | 5 ++++- src/Math/Angle.h | 4 ++-- src/Math/Complex.h | 2 +- src/Math/Constants.h | 2 +- src/Math/DualComplex.h | 2 +- src/Math/DualQuaternion.h | 2 +- src/Math/Geometry/Rectangle.h | 2 +- src/Math/Matrix.h | 1 + src/Math/Quaternion.h | 2 +- src/Math/RectangularMatrix.h | 3 +++ 10 files changed, 16 insertions(+), 9 deletions(-) diff --git a/doc/types.dox b/doc/types.dox index bce7c53ef..f0a721938 100644 --- a/doc/types.dox +++ b/doc/types.dox @@ -60,7 +60,7 @@ equivalently (e.g. Math::Vector or Color3 instead of @ref Vector3). Other types, which don't have their GLSL equivalent, are: - - @ref Rectangle or @ref Rectanglei + - @ref Rectangle, @ref Rectanglei or @ref Rectangled - @ref Complex or @ref Complexd, @ref DualComplex or @ref DualComplexd - @ref Quaternion or @ref Quaterniond, @ref DualQuaternion or @ref DualQuaterniond @@ -68,5 +68,8 @@ These types can be used in GLSL either by extracting values from their underlying structure or converting them to types supported by GLSL (e.g. quaternion to matrix). +For your convenience, there is also alias for class with often used constants -- +@ref Constants or @ref Constantsd. + */ } diff --git a/src/Math/Angle.h b/src/Math/Angle.h index 3d6e6a319..cc6d4489a 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -109,7 +109,7 @@ std::sin(Float(Rad(angleInDegrees)); // required explicit conversion hint // attention (i.e., conversion to radians) @endcode -@see Magnum::Deg, Magnum::Rad +@see Magnum::Deg, Magnum::Degd */ template class Deg: public Unit { public: @@ -168,7 +168,7 @@ inline constexpr Deg operator "" _degf(long double value) { return Deg class Rad: public Unit { public: diff --git a/src/Math/Complex.h b/src/Math/Complex.h index cd3139a0b..97a4c38fb 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Math { @tparam T Data type Represents 2D rotation. See @ref transformations for brief introduction. -@see Magnum::Complex, Matrix3 +@see Magnum::Complex, Magnum::Complexd, Matrix3 */ template class Complex { public: diff --git a/src/Math/Constants.h b/src/Math/Constants.h index bbc8b047c..98057ef5f 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -26,7 +26,7 @@ namespace Magnum { namespace Math { /** @brief Numeric constants -@see Magnum::Constants +@see Magnum::Constants, Magnum::Constantsd */ template struct Constants { Constants() = delete; diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 8c47152f4..e25babc85 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Math { Represents 2D rotation and translation. See @ref transformations for brief introduction. -@see Magnum::DualComplex, Dual, Complex, Matrix3 +@see Magnum::DualComplex, Magnum::DualComplexd, Dual, Complex, Matrix3 @todo Can this be done similarly as in dual quaternions? It sort of works, but the math beneath is weird. */ diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 0cb8bd6d0..6d563cc3e 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Math { Represents 3D rotation and translation. See @ref transformations for brief introduction. -@see Magnum::DualQuaternion, Dual, Quaternion, Matrix4 +@see Magnum::DualQuaternion, Magnum::DualQuaterniond, Dual, Quaternion, Matrix4 */ template class DualQuaternion: public Dual> { public: diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index c2601383f..1b122497f 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Math { namespace Geometry { Helper class for storing axis-aligned rectangles consisting of bottom left and top right corner positions with origin in bottom left. Bottom/left positions are inclusive, while top/right positions are exclusive. -@see Magnum::Rectangle, Magnum::Rectanglei +@see Magnum::Rectangle, Magnum::Rectanglei, Magnum::Rectangled */ template class Rectangle { template friend class Rectangle; diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 89e070f57..ed423e27c 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -37,6 +37,7 @@ namespace Implementation { See @ref matrix-vector for brief introduction. @configurationvalueref{Magnum::Math::Matrix} +@see Magnum::Matrix2, Magnum::Matrix2d */ template class Matrix: public RectangularMatrix { public: diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 97024a248..cd4f4b07e 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Math { @tparam T Underlying data type Represents 3D rotation. See @ref transformations for brief introduction. -@see Magnum::Quaternion, DualQuaternion, Matrix4 +@see Magnum::Quaternion, Magnum::Quaterniond, DualQuaternion, Matrix4 */ template class Quaternion { public: diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 0702ff57d..982a1fa5d 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -35,6 +35,9 @@ Vector. The data are stored in column-major order, to reflect that, all indices in math formulas are in reverse order (i.e. @f$ \boldsymbol A_{ji} @f$ instead of @f$ \boldsymbol A_{ij} @f$). +@see Magnum::Matrix2x3, Magnum::Matrix3x2, Magnum::Matrix2x4, Magnum::Matrix4x2, + Magnum::Matrix3x4, Magnum::Matrix4x3, Magnum::Matrix2x3d, Magnum::Matrix3x2d, + Magnum::Matrix2x4d, Magnum::Matrix4x2d, Magnum::Matrix3x4d, Magnum::Matrix4x3d */ template class RectangularMatrix { static_assert(cols != 0 && rows != 0, "RectangularMatrix cannot have zero elements"); From a75ed22d4e46ed2f31b34128453124275b7ff030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 11:59:05 +0100 Subject: [PATCH 477/567] Updated portability tips documentation. --- doc/portability.dox | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/doc/portability.dox b/doc/portability.dox index 77d359ebb..f483e10dd 100644 --- a/doc/portability.dox +++ b/doc/portability.dox @@ -71,10 +71,20 @@ You can also decide on particular OpenGL version using Context::isVersionSupport but remember that some features from that version might be available even if the drivers don't expose that version. -Each feature is marked accordingly if it needs specific extension or specific -OpenGL version. Various classes in %Magnum are taking advantage of some -extensions and enable faster code paths if given extension is available, for -example @ref AbstractShaderProgram-performance-optimization "AbstractShaderProgram", +On the other hand, if you don't want to write fallback code for unsupported +extensions, you can use macros MAGNUM_ASSERT_EXTENSION_SUPPORTED() or +MAGNUM_ASSERT_VERSION_SUPPORTED() to add mandatory requirement of given +extension or version: +@code +MAGNUM_ASSERT_EXTENSION_SUPPORTED(GL::ARB::geometry_shader4); +// just use geometry shader and don't care about old hardware +@endcode + +Each class, function or enum value is marked accordingly if it needs specific +extension or specific OpenGL version. Various classes in %Magnum are taking +advantage of some extensions and enable faster code paths if given extension is +available, but also have proper fallback when it's not, for example +@ref AbstractShaderProgram-performance-optimization "AbstractShaderProgram", @ref AbstractTexture-performance-optimization "AbstractTexture" or @ref Mesh-performance-optimization "Mesh". See also @ref required-extensions. @@ -121,7 +131,7 @@ Your application might run on Windows box, on some embedded Linux or even in browser - each platform has different requirements how to create entry point to the application, how to handle input events, how to create window and OpenGL context etc. Namespace Platform contains base classes for applications -which are abstracting most of it for your convenience. +which are abstracting out most of it for your convenience. All the classes support limited form of static polymorphism, which means you can switch to another base class and probably don't need to change any other From 2cdb159cbd849eccd7f1cd78d91b18cca817635a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:40:04 +0100 Subject: [PATCH 478/567] GCC 4.6 compatibility: no user-defined literals. --- src/Magnum.h | 4 ++++ src/Math/Angle.h | 1 + src/Math/Test/AngleTest.cpp | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/Magnum.h b/src/Magnum.h index efd95f02a..1466bbde7 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -40,10 +40,12 @@ namespace Magnum { namespace Math { template struct Constants; + #ifndef CORRADE_GCC46_COMPATIBILITY constexpr Rad operator "" _rad(long double); constexpr Rad operator "" _radf(long double); constexpr Deg operator "" _deg(long double); constexpr Deg operator "" _degf(long double); + #endif } /* Bring debugging facility from Corrade::Utility namespace */ @@ -240,11 +242,13 @@ typedef Math::Geometry::Rectangle Rectangled; /*@}*/ #endif +#ifndef CORRADE_GCC46_COMPATIBILITY /* Using angle literals from Math namespace */ using Math::operator "" _deg; using Math::operator "" _degf; using Math::operator "" _rad; using Math::operator "" _radf; +#endif /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Math/Angle.h b/src/Math/Angle.h index cc6d4489a..6ba1be5d4 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -20,6 +20,7 @@ */ #include +#include #include "Math/Constants.h" #include "Math/Math.h" diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp index 7ac2f7e6b..5a2817893 100644 --- a/src/Math/Test/AngleTest.cpp +++ b/src/Math/Test/AngleTest.cpp @@ -73,6 +73,7 @@ void AngleTest::construct() { } void AngleTest::literals() { + #ifndef CORRADE_GCC46_COMPATIBILITY constexpr auto a = 25.0_deg; constexpr auto b = 25.0_degf; CORRADE_VERIFY((std::is_same::value)); @@ -86,6 +87,9 @@ void AngleTest::literals() { CORRADE_VERIFY((std::is_same::value)); CORRADE_COMPARE(Double(m), 3.14); CORRADE_COMPARE(Float(n), 3.14f); + #else + CORRADE_SKIP("User-defined literals are not available on GCC < 4.7."); + #endif } void AngleTest::conversion() { From 3c407f2226ec042a12614e69530bf7621e4b0709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:40:55 +0100 Subject: [PATCH 479/567] GCC 4.6 compatibility: fix warning about injected-class-name. --- src/Math/Angle.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Math/Angle.h b/src/Math/Angle.h index 6ba1be5d4..2614453b6 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -118,13 +118,13 @@ template class Deg: public Unit { inline constexpr /*implicit*/ Deg() {} /** @brief Explicit constructor from unitless type */ - inline constexpr explicit Deg(T value): Unit(value) {} + inline constexpr explicit Deg(T value): Unit(value) {} /** @brief Copy constructor */ - inline constexpr /*implicit*/ Deg(Unit value): Unit(value) {} + inline constexpr /*implicit*/ Deg(Unit value): Unit(value) {} /** @brief Construct from another underlying type */ - template inline constexpr explicit Deg(Unit value): Unit(value) {} + template inline constexpr explicit Deg(Unit value): Unit(value) {} /** * @brief Construct degrees from radians @@ -177,13 +177,13 @@ template class Rad: public Unit { inline constexpr /*implicit*/ Rad() {} /** @brief Construct from unitless type */ - inline constexpr explicit Rad(T value): Unit(value) {} + inline constexpr explicit Rad(T value): Unit(value) {} /** @brief Copy constructor */ - inline constexpr /*implicit*/ Rad(Unit value): Unit(value) {} + inline constexpr /*implicit*/ Rad(Unit value): Unit(value) {} /** @brief Construct from another underlying type */ - template inline constexpr explicit Rad(Unit value): Unit(value) {} + template inline constexpr explicit Rad(Unit value): Unit(value) {} /** * @brief Construct radians from degrees @@ -216,8 +216,8 @@ See operator""_degf() for more information. inline constexpr Rad operator "" _radf(long double value) { return Rad(value); } #endif -template inline constexpr Deg::Deg(Unit value): Unit(T(180)*T(value)/Math::Constants::pi()) {} -template inline constexpr Rad::Rad(Unit value): Unit(T(value)*Math::Constants::pi()/T(180)) {} +template inline constexpr Deg::Deg(Unit value): Unit(T(180)*T(value)/Math::Constants::pi()) {} +template inline constexpr Rad::Rad(Unit value): Unit(T(value)*Math::Constants::pi()/T(180)) {} /** @debugoperator{Magnum::Math::Rad} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Unit& value) { From 0e34eeda58fdff5a5caf143686a1e6642e181563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:42:17 +0100 Subject: [PATCH 480/567] GCC 4.6 compatibility: no delegating constructors in Math::BoolVector. --- src/Math/BoolVector.h | 7 +++++++ src/Math/Test/BoolVectorTest.cpp | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Math/BoolVector.h b/src/Math/BoolVector.h index 14166de15..2ef2495ce 100644 --- a/src/Math/BoolVector.h +++ b/src/Math/BoolVector.h @@ -20,6 +20,7 @@ */ #include +#include #include "Types.h" @@ -75,7 +76,13 @@ template class BoolVector { #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit BoolVector(T value); #else + #ifndef CORRADE_GCC46_COMPATIBILITY template::value && size != 1, bool>::type> inline constexpr explicit BoolVector(T value): BoolVector(typename Implementation::GenerateSequence::Type(), value ? FullSegmentMask : 0) {} + #else + template::value && size != 1, bool>::type> inline explicit BoolVector(T value) { + *this = BoolVector(typename Implementation::GenerateSequence::Type(), value ? FullSegmentMask : 0); + } + #endif #endif /** @brief Copy constructor */ diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp index c0328348f..e4440965f 100644 --- a/src/Math/Test/BoolVectorTest.cpp +++ b/src/Math/Test/BoolVectorTest.cpp @@ -111,9 +111,11 @@ void BoolVectorTest::constExpressions() { constexpr BoolVector19 b(0xa5, 0x5f, 0x07); CORRADE_COMPARE(b, BoolVector19(0xa5, 0x5f, 0x07)); - /* One-value constructor */ + /* One-value constructor, not constexpr under GCC < 4.7 */ + #ifndef CORRADE_GCC46_COMPATIBILITY constexpr BoolVector19 c(true); CORRADE_COMPARE(c, BoolVector19(0xff, 0xff, 0x07)); + #endif /* Copy constructor */ constexpr BoolVector19 d(b); From deb54fc92f2b76ae562cd2a6c707fbc844e6bbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:43:06 +0100 Subject: [PATCH 481/567] GCC 4.6 compatibility: no inheriting constructors in Math::Vector. --- src/Math/Test/VectorTest.cpp | 8 ++++++-- src/Math/Vector.h | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 24a1003ca..5d25b7b2d 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -154,13 +154,17 @@ void VectorTest::constExpressions() { constexpr Vector4 b(1.0f, 3.5f, 4.0f, -2.7f); CORRADE_COMPARE(b, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); - /* One-value constructor */ + /* One-value constructor, not constexpr under GCC < 4.7 */ + #ifndef CORRADE_GCC46_COMPATIBILITY constexpr Vector4 c(7.0f); CORRADE_COMPARE(c, Vector4(7.0f, 7.0f, 7.0f, 7.0f)); + #endif - /* Conversion constructor */ + /* Conversion constructor, not constexpr under GCC < 4.7 */ + #ifndef CORRADE_GCC46_COMPATIBILITY constexpr Vector4i d(b); CORRADE_COMPARE(d, Vector4i(1, 3, 4, -2)); + #endif /* Copy constructor */ constexpr Vector4 e(b); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 833554cb8..d496abcce 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -118,7 +118,13 @@ template class Vector { #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit Vector(T value); #else + #ifndef CORRADE_GCC46_COMPATIBILITY template::value && size != 1, T>::type> inline constexpr explicit Vector(U value): Vector(typename Implementation::GenerateSequence::Type(), value) {} + #else + template::value && size != 1, T>::type> inline explicit Vector(U value) { + *this = Vector(typename Implementation::GenerateSequence::Type(), value); + } + #endif #endif /** @@ -132,7 +138,13 @@ template class Vector { * // integral == {1, 2, -15, 7} * @endcode */ + #ifndef CORRADE_GCC46_COMPATIBILITY template inline constexpr explicit Vector(const Vector& other): Vector(typename Implementation::GenerateSequence::Type(), other) {} + #else + template inline explicit Vector(const Vector& other) { + *this = Vector(typename Implementation::GenerateSequence::Type(), other); + } + #endif /** @brief Copy constructor */ inline constexpr Vector(const Vector&) = default; From 99062ed248327808239910e160ee6c3070c0331a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:43:44 +0100 Subject: [PATCH 482/567] GCC 4.6 compatibility: no delegating ctr in Math::RectangularMatrix. --- src/Math/RectangularMatrix.h | 6 ++++++ src/Math/Test/RectangularMatrixTest.cpp | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 982a1fa5d..af38a25d2 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -112,7 +112,13 @@ template class RectangularMatrix { * // integral == {1, 2, -15, 7} * @endcode */ + #ifndef CORRADE_GCC46_COMPATIBILITY template inline constexpr explicit RectangularMatrix(const RectangularMatrix& other): RectangularMatrix(typename Implementation::GenerateSequence::Type(), other) {} + #else + template inline explicit RectangularMatrix(const RectangularMatrix& other) { + *this = RectangularMatrix(typename Implementation::GenerateSequence::Type(), other); + } + #endif /** @brief Copy constructor */ inline constexpr RectangularMatrix(const RectangularMatrix&) = default; diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 2e1cf095d..00d8de449 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -193,13 +193,15 @@ void RectangularMatrixTest::constExpressions() { Vector4(4.5f, 4.0f, 7.0f, 3.0f), Vector4(7.0f, -1.7f, 8.0f, 0.0f))); - /* Conversion constructor */ + /* Conversion constructor, not constexpr under GCC < 4.7 */ + #ifndef CORRADE_GCC46_COMPATIBILITY typedef RectangularMatrix<3, 4, Int> Matrix3x4i; typedef Vector<4, Int> Vector4i; constexpr Matrix3x4i c(b); CORRADE_COMPARE(c, Matrix3x4i(Vector4i(3, 5, 8, 4), Vector4i(4, 4, 7, 3), Vector4i(7, -1, 8, 0))); + #endif /* Copy constructor */ constexpr Matrix3x4 d(b); From 7f951ee39cec6d8d00a50a735d6fd3fc9ffa947d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:53:00 +0100 Subject: [PATCH 483/567] GCC 4.6 compatibility: {} can't be used as default function parameter. --- src/Trade/AbstractImporter.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index b2c78dea5..7e4250a0b 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -62,7 +62,8 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { typedef Corrade::Containers::EnumSet Features; /** @brief Constructor */ - inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = {}): Plugin(manager, plugin) {} + /* GCC 4.6 can't handle {} as default parameter */ + inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = std::string()): Plugin(manager, plugin) {} /** @brief Features supported by this importer */ virtual Features features() const = 0; From 181cf2cf111b03deb42e1048240aa5c79f933601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 17:53:27 +0100 Subject: [PATCH 484/567] GCC 4.6 compatibility: std::array can't be constexpr. Don't know why. --- src/MeshTools/Test/TransformTest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/MeshTools/Test/TransformTest.cpp b/src/MeshTools/Test/TransformTest.cpp index 1cfe3b934..9f5ede231 100644 --- a/src/MeshTools/Test/TransformTest.cpp +++ b/src/MeshTools/Test/TransformTest.cpp @@ -41,6 +41,11 @@ TransformTest::TransformTest() { &TransformTest::transformPoints3D); } +/* GCC < 4.7 doesn't like constexpr here, don't know why */ +#ifdef CORRADE_GCC46_COMPATIBILITY +#define constexpr const +#endif + constexpr static std::array points2D{{ {-3.0f, 4.0f}, { 2.5f, -15.0f} @@ -71,6 +76,10 @@ constexpr static std::array points3DRotatedTranslated{{ {15.0f, 1.5f, 1.5f} }}; +#ifdef CORRADE_GCC46_COMPATIBILITY +#undef constexpr +#endif + void TransformTest::transformVectors2D() { auto matrix = MeshTools::transformVectors(Matrix3::rotation(Deg(90.0f)), points2D); auto complex = MeshTools::transformVectors(Complex::rotation(Deg(90.0f)), points2D); From fc538c3a57e8e631fe89f6e50c25ea062b8c07ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 23:37:10 +0100 Subject: [PATCH 485/567] Math: properly test constexpr in all Vector classes. * Merged constExpressions() into other test cases, simplified the test a lot and removing duplicate code. * Fixed Vector3::xy(), Vector3::xy() and Vector3::xyz() constexpr overloads, they now return copy instead of reinterpret_cast reference. The copy is const to make constexpr operations working even on returned subclass, e.g.: constexpr Vector4 a; constexpr Float b = a.xyz().y(); --- src/Math/Test/Vector2Test.cpp | 66 ++++++++++++++++++++---- src/Math/Test/Vector3Test.cpp | 95 +++++++++++++++++++++++++++++------ src/Math/Test/Vector4Test.cpp | 91 ++++++++++++++++++++++++++++----- src/Math/Test/VectorTest.cpp | 87 +++++++++++++++----------------- src/Math/Vector3.h | 2 +- src/Math/Vector4.h | 4 +- 6 files changed, 260 insertions(+), 85 deletions(-) diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 31d017b6f..d4936ad48 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -26,6 +26,11 @@ class Vector2Test: public Corrade::TestSuite::Tester { Vector2Test(); void construct(); + void constructDefault(); + void constructOneValue(); + void constructConversion(); + void constructCopy(); + void access(); void axes(); void scales(); @@ -35,9 +40,15 @@ class Vector2Test: public Corrade::TestSuite::Tester { }; typedef Math::Vector2 Vector2; +typedef Math::Vector2 Vector2i; Vector2Test::Vector2Test() { addTests(&Vector2Test::construct, + &Vector2Test::constructDefault, + &Vector2Test::constructOneValue, + &Vector2Test::constructConversion, + &Vector2Test::constructCopy, + &Vector2Test::access, &Vector2Test::axes, &Vector2Test::scales, @@ -46,27 +57,64 @@ Vector2Test::Vector2Test() { } void Vector2Test::construct() { - CORRADE_COMPARE(Vector2(1, 2), (Vector<2, Float>(1.0f, 2.0f))); + constexpr Vector2 a(1.5f, 2.5f); + CORRADE_COMPARE(a, (Vector<2, Float>(1.5f, 2.5f))); +} + +void Vector2Test::constructDefault() { + constexpr Vector2 a; + CORRADE_COMPARE(a, Vector2(0.0f, 0.0f)); +} + +void Vector2Test::constructOneValue() { + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector2 a(3.0f); + #else + Vector2 a(3.0f); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(a, Vector2(3.0f, 3.0f)); +} + +void Vector2Test::constructConversion() { + constexpr Vector2 a(1.5f, 2.5f); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector2i b(a); + #else + Vector2i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(b, Vector2i(1, 2)); +} + +void Vector2Test::constructCopy() { + constexpr Vector2 a(1.5f, 2.5f); + constexpr Vector2 b(a); + CORRADE_COMPARE(b, Vector2(1.5f, 2.5f)); } void Vector2Test::access() { Vector2 vec(1.0f, -2.0f); - const Vector2 cvec(1.0f, -2.0f); - CORRADE_COMPARE(vec.x(), 1.0f); CORRADE_COMPARE(vec.y(), -2.0f); - CORRADE_COMPARE(cvec.x(), 1.0f); - CORRADE_COMPARE(cvec.y(), -2.0f); + + constexpr Vector2 cvec(1.0f, -2.0f); + constexpr Float x = cvec.x(); + constexpr Float y = cvec.y(); + CORRADE_COMPARE(x, 1.0f); + CORRADE_COMPARE(y, -2.0f); } void Vector2Test::axes() { - CORRADE_COMPARE(Vector2::xAxis(5.0f), Vector2(5.0f, 0.0f)); - CORRADE_COMPARE(Vector2::yAxis(6.0f), Vector2(0.0f, 6.0f)); + constexpr Vector2 x = Vector2::xAxis(5.0f); + constexpr Vector2 y = Vector2::yAxis(6.0f); + CORRADE_COMPARE(x, Vector2(5.0f, 0.0f)); + CORRADE_COMPARE(y, Vector2(0.0f, 6.0f)); } void Vector2Test::scales() { - CORRADE_COMPARE(Vector2::xScale(-5.0f), Vector2(-5.0f, 1.0f)); - CORRADE_COMPARE(Vector2::yScale(-0.2f), Vector2(1.0f, -0.2f)); + constexpr Vector2 x = Vector2::xScale(-5.0f); + constexpr Vector2 y = Vector2::yScale(-0.2f); + CORRADE_COMPARE(x, Vector2(-5.0f, 1.0f)); + CORRADE_COMPARE(y, Vector2(1.0f, -0.2f)); } void Vector2Test::debug() { diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 4c25b28c6..e30508de7 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -26,6 +26,12 @@ class Vector3Test: public Corrade::TestSuite::Tester { Vector3Test(); void construct(); + void constructDefault(); + void constructOneValue(); + void constructParts(); + void constructConversion(); + void constructCopy(); + void access(); void cross(); void axes(); @@ -37,35 +43,81 @@ class Vector3Test: public Corrade::TestSuite::Tester { }; typedef Math::Vector3 Vector3; +typedef Math::Vector3 Vector3i; typedef Math::Vector2 Vector2; Vector3Test::Vector3Test() { addTests(&Vector3Test::construct, + &Vector3Test::constructDefault, + &Vector3Test::constructOneValue, + &Vector3Test::constructParts, + &Vector3Test::constructConversion, + &Vector3Test::constructCopy, + &Vector3Test::access, &Vector3Test::cross, &Vector3Test::axes, &Vector3Test::scales, &Vector3Test::twoComponent, + &Vector3Test::debug, &Vector3Test::configuration); } void Vector3Test::construct() { - CORRADE_COMPARE(Vector3(), Vector3(0.0f, 0.0f, 0.0f)); - CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, Float>(1.0f, 2.0f, 3.0f))); - CORRADE_COMPARE(Vector3(Vector<2, Float>(1.0f, 2.0f), 3), (Vector<3, Float>(1.0f, 2.0f, 3.0f))); + constexpr Vector3 a(1.0f, 2.5f, -3.0f); + CORRADE_COMPARE(a, (Vector<3, Float>(1.0f, 2.5f, -3.0f))); +} + +void Vector3Test::constructDefault() { + constexpr Vector3 a; + CORRADE_COMPARE(a, Vector3(0.0f, 0.0f, 0.0f)); +} + +void Vector3Test::constructOneValue() { + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector3 a(-3.0f); + #else + Vector3 a(-3.0f); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(a, Vector3(-3.0f, -3.0f, -3.0f)); +} + +void Vector3Test::constructParts() { + constexpr Vector2 a(1.0f, 2.0f); + constexpr Vector3 b(a, 3.0f); + CORRADE_COMPARE(b, Vector3(1.0f, 2.0f, 3.0f)); +} + +void Vector3Test::constructConversion() { + constexpr Vector3 a(1.0f, 2.5f, -3.0f); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector3i b(a); + #else + Vector3i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(b, Vector3i(1, 2, -3)); +} + +void Vector3Test::constructCopy() { + constexpr Vector3 a(1.0f, 2.5f, -3.0f); + constexpr Vector3 b(a); + CORRADE_COMPARE(b, Vector3(1.0f, 2.5f, -3.0f)); } void Vector3Test::access() { Vector3 vec(1.0f, -2.0f, 5.0f); - const Vector3 cvec(1.0f, -2.0f, 5.0f); - CORRADE_COMPARE(vec.x(), 1.0f); CORRADE_COMPARE(vec.y(), -2.0f); CORRADE_COMPARE(vec.z(), 5.0f); - CORRADE_COMPARE(cvec.x(), 1.0f); - CORRADE_COMPARE(cvec.y(), -2.0f); - CORRADE_COMPARE(cvec.z(), 5.0f); + + constexpr Vector3 cvec(1.0f, -2.0f, 5.0f); + constexpr Float x = cvec.x(); + constexpr Float y = cvec.y(); + constexpr Float z = cvec.z(); + CORRADE_COMPARE(x, 1.0f); + CORRADE_COMPARE(y, -2.0f); + CORRADE_COMPARE(z, 5.0f); } void Vector3Test::cross() { @@ -76,19 +128,32 @@ void Vector3Test::cross() { } void Vector3Test::axes() { - CORRADE_COMPARE(Vector3::xAxis(5.0f), Vector3(5.0f, 0.0f, 0.0f)); - CORRADE_COMPARE(Vector3::yAxis(6.0f), Vector3(0.0f, 6.0f, 0.0f)); - CORRADE_COMPARE(Vector3::zAxis(7.0f), Vector3(0.0f, 0.0f, 7.0f)); + constexpr Vector3 x = Vector3::xAxis(5.0f); + constexpr Vector3 y = Vector3::yAxis(6.0f); + constexpr Vector3 z = Vector3::zAxis(7.0f); + CORRADE_COMPARE(x, Vector3(5.0f, 0.0f, 0.0f)); + CORRADE_COMPARE(y, Vector3(0.0f, 6.0f, 0.0f)); + CORRADE_COMPARE(z, Vector3(0.0f, 0.0f, 7.0f)); } void Vector3Test::scales() { - CORRADE_COMPARE(Vector3::xScale(-5.0f), Vector3(-5.0f, 1.0f, 1.0f)); - CORRADE_COMPARE(Vector3::yScale(-0.2f), Vector3(1.0f, -0.2f, 1.0f)); - CORRADE_COMPARE(Vector3::zScale(71.0f), Vector3(1.0f, 1.0f, 71.0f)); + constexpr Vector3 x = Vector3::xScale(-5.0f); + constexpr Vector3 y = Vector3::yScale(-0.2f); + constexpr Vector3 z = Vector3::zScale(71.0f); + CORRADE_COMPARE(x, Vector3(-5.0f, 1.0f, 1.0f)); + CORRADE_COMPARE(y, Vector3(1.0f, -0.2f, 1.0f)); + CORRADE_COMPARE(z, Vector3(1.0f, 1.0f, 71.0f)); } void Vector3Test::twoComponent() { - CORRADE_COMPARE(Vector3(1.0f, 2.0f, 3.0f).xy(), Vector2(1.0f, 2.0f)); + Vector3 a(1.0f, 2.0f, 3.0f); + CORRADE_COMPARE(a.xy(), Vector2(1.0f, 2.0f)); + + constexpr Vector3 b(1.0f, 2.0f, 3.0f); + constexpr Vector2 c = b.xy(); + constexpr Float d = b.xy().y(); + CORRADE_COMPARE(c, Vector2(1.0f, 2.0f)); + CORRADE_COMPARE(d, 2.0f); } void Vector3Test::debug() { diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index a52063e65..c1496c31f 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -25,8 +25,14 @@ class Vector4Test: public Corrade::TestSuite::Tester { public: Vector4Test(); - void access(); void construct(); + void constructDefault(); + void constructOneValue(); + void constructParts(); + void constructConversion(); + void constructCopy(); + + void access(); void threeComponent(); void twoComponent(); @@ -35,44 +41,105 @@ class Vector4Test: public Corrade::TestSuite::Tester { }; typedef Math::Vector4 Vector4; +typedef Math::Vector4 Vector4i; typedef Math::Vector3 Vector3; typedef Math::Vector2 Vector2; Vector4Test::Vector4Test() { addTests(&Vector4Test::construct, + &Vector4Test::constructDefault, + &Vector4Test::constructOneValue, + &Vector4Test::constructParts, + &Vector4Test::constructConversion, + &Vector4Test::constructCopy, + &Vector4Test::access, &Vector4Test::threeComponent, &Vector4Test::twoComponent, + &Vector4Test::debug, &Vector4Test::configuration); } void Vector4Test::construct() { - CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); - CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, Float>(1.0f, 2.0f, 3.0f, 4.0f))); - CORRADE_COMPARE(Vector4(Vector<3, Float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, Float>(1.0f, 2.0f, 3.0f, 4.0f))); + constexpr Vector4 a(1.0f, -2.5f, 3.0f, 4.1f); + CORRADE_COMPARE(a, (Vector<4, Float>(1.0f, -2.5f, 3.0f, 4.1f))); +} + +void Vector4Test::constructDefault() { + constexpr Vector4 a; + CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); +} + +void Vector4Test::constructOneValue() { + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector4 a(4.3f); + #else + Vector4 a(4.3f); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(a, Vector4(4.3f, 4.3f, 4.3f, 4.3f)); +} + +void Vector4Test::constructParts() { + constexpr Vector3 a(1.0f, 2.0f, 3.0f); + constexpr Vector4 b(a, 4.0f); + CORRADE_COMPARE(b, Vector4(1.0f, 2.0f, 3.0f, 4.0f)); +} + +void Vector4Test::constructConversion() { + constexpr Vector4 a(1.0f, -2.5f, 3.0f, 4.1f); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector4i b(a); + #else + Vector4i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(b, Vector4i(1, -2, 3, 4)); +} + +void Vector4Test::constructCopy() { + constexpr Vector4 a(1.0f, -2.5f, 3.0f, 4.1f); + constexpr Vector4 b(a); + CORRADE_COMPARE(b, Vector4(1.0f, -2.5f, 3.0f, 4.1f)); } void Vector4Test::access() { Vector4 vec(1.0f, -2.0f, 5.0f, 0.5f); - const Vector4 cvec(1.0f, -2.0f, 5.0f, 0.5f); - CORRADE_COMPARE(vec.x(), 1.0f); CORRADE_COMPARE(vec.y(), -2.0f); CORRADE_COMPARE(vec.z(), 5.0f); CORRADE_COMPARE(vec.w(), 0.5f); - CORRADE_COMPARE(cvec.x(), 1.0f); - CORRADE_COMPARE(cvec.y(), -2.0f); - CORRADE_COMPARE(cvec.z(), 5.0f); - CORRADE_COMPARE(cvec.w(), 0.5f); + + constexpr Vector4 cvec(1.0f, -2.0f, 5.0f, 0.5f); + constexpr Float x = cvec.x(); + constexpr Float y = cvec.y(); + constexpr Float z = cvec.z(); + constexpr Float w = cvec.w(); + CORRADE_COMPARE(x, 1.0f); + CORRADE_COMPARE(y, -2.0f); + CORRADE_COMPARE(z, 5.0f); + CORRADE_COMPARE(w, 0.5f); } void Vector4Test::threeComponent() { - CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xyz(), Vector3(1.0f, 2.0f, 3.0f)); + Vector4 a(1.0f, 2.0f, 3.0f, 4.0f); + CORRADE_COMPARE(a.xyz(), Vector3(1.0f, 2.0f, 3.0f)); + + constexpr Vector4 b(1.0f, 2.0f, 3.0f, 4.0f); + constexpr Vector3 c = b.xyz(); + constexpr Float d = b.xyz().y(); + CORRADE_COMPARE(c, Vector3(1.0f, 2.0f, 3.0f)); + CORRADE_COMPARE(d, 2.0f); } void Vector4Test::twoComponent() { - CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xy(), Vector2(1.0f, 2.0f)); + Vector4 a(1.0f, 2.0f, 3.0f, 4.0f); + CORRADE_COMPARE(a.xy(), Vector2(1.0f, 2.0f)); + + constexpr Vector4 b(1.0f, 2.0f, 3.0f, 4.0f); + constexpr Vector2 c = b.xy(); + constexpr Float d = b.xy().x(); + CORRADE_COMPARE(c, Vector2(1.0f, 2.0f)); + CORRADE_COMPARE(d, 1.0f); } void Vector4Test::debug() { diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 5d25b7b2d..8c364b458 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -25,15 +25,15 @@ class VectorTest: public Corrade::TestSuite::Tester { public: VectorTest(); + void construct(); void constructFromData(); void constructDefault(); void constructOneValue(); void constructOneComponent(); void constructConversion(); + void constructCopy(); void data(); - void constExpressions(); - void negative(); void addSubtract(); void multiplyDivide(); @@ -68,15 +68,15 @@ typedef Vector<4, Float> Vector4; typedef Vector<4, Int> Vector4i; VectorTest::VectorTest() { - addTests(&VectorTest::constructFromData, + addTests(&VectorTest::construct, + &VectorTest::constructFromData, &VectorTest::constructDefault, &VectorTest::constructOneValue, &VectorTest::constructOneComponent, &VectorTest::constructConversion, + &VectorTest::constructCopy, &VectorTest::data, - &VectorTest::constExpressions, - &VectorTest::negative, &VectorTest::addSubtract, &VectorTest::multiplyDivide, @@ -105,34 +105,54 @@ VectorTest::VectorTest() { &VectorTest::configuration); } -void VectorTest::constructFromData() { - Float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; - CORRADE_COMPARE(Vector4::from(data), Vector4(1.0f, 2.0f, 3.0f, 4.0f)); +void VectorTest::construct() { + constexpr Vector4 a(1.0f, 2.0f, -3.0f, 4.5f); + CORRADE_COMPARE(a, Vector4(1.0f, 2.0f, -3.0f, 4.5f)); } void VectorTest::constructDefault() { - CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f)); + constexpr Vector4 a; + CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); +} + +void VectorTest::constructFromData() { + Float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; + CORRADE_COMPARE(Vector4::from(data), Vector4(1.0f, 2.0f, 3.0f, 4.0f)); } void VectorTest::constructOneValue() { - CORRADE_COMPARE(Vector4(7.25f), Vector4(7.25f, 7.25f, 7.25f, 7.25f)); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector4 a(7.25f); + #else + Vector4 a(7.25f); /* Not constexpr under GCC < 4.7 */ + #endif + + CORRADE_COMPARE(a, Vector4(7.25f, 7.25f, 7.25f, 7.25f)); } void VectorTest::constructOneComponent() { typedef Vector<1, Float> Vector1; /* Implicit constructor must work */ - Vector1 vec = 1; + constexpr Vector1 vec = 1.0f; CORRADE_COMPARE(vec, Vector1(1)); } void VectorTest::constructConversion() { - Vector4 FloatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - Vector4 FloatingPointRounded(1.0f, 2.0f, -15.0f, 7.0f); - Vector4i integral(1, 2, -15, 7); + constexpr Vector4 a(1.3f, 2.7f, -15.0f, 7.0f); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Vector4i b(a); + #else + Vector4i b(a); /* Not constexpr under GCC < 4.7 */ + #endif - CORRADE_COMPARE(Vector4i(FloatingPoint), integral); - CORRADE_COMPARE(Vector4(integral), FloatingPointRounded); + CORRADE_COMPARE(b, Vector4i(1, 2, -15, 7)); +} + +void VectorTest::constructCopy() { + constexpr Vector4 a(1.0f, 3.5f, 4.0f, -2.7f); + constexpr Vector4 b(a); + CORRADE_COMPARE(b, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); } void VectorTest::data() { @@ -143,37 +163,12 @@ void VectorTest::data() { CORRADE_COMPARE(vector[2], 1.0f); CORRADE_COMPARE(vector[3], 1.5f); CORRADE_COMPARE(vector, Vector4(4.0f, 5.0f, 1.0f, 1.5f)); -} - -void VectorTest::constExpressions() { - /* Default constructor */ - constexpr Vector4 a; - CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f)); - - /* Value constructor */ - constexpr Vector4 b(1.0f, 3.5f, 4.0f, -2.7f); - CORRADE_COMPARE(b, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); - - /* One-value constructor, not constexpr under GCC < 4.7 */ - #ifndef CORRADE_GCC46_COMPATIBILITY - constexpr Vector4 c(7.0f); - CORRADE_COMPARE(c, Vector4(7.0f, 7.0f, 7.0f, 7.0f)); - #endif - - /* Conversion constructor, not constexpr under GCC < 4.7 */ - #ifndef CORRADE_GCC46_COMPATIBILITY - constexpr Vector4i d(b); - CORRADE_COMPARE(d, Vector4i(1, 3, 4, -2)); - #endif - - /* Copy constructor */ - constexpr Vector4 e(b); - CORRADE_COMPARE(e, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); - /* Data access, pointer chasings, i.e. *(b.data()[3]), are not possible */ - constexpr Float f = b[3]; - constexpr Float g = *b.data(); - CORRADE_COMPARE(f, -2.7f); + /* Pointer chasings, i.e. *(b.data()[3]), are not possible */ + constexpr Vector4 a(1.0f, 2.0f, -3.0f, 4.5f); + constexpr Float f = a[3]; + constexpr Float g = *a.data(); + CORRADE_COMPARE(f, 4.5f); CORRADE_COMPARE(g, 1.0f); } diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 1c92d26d1..60a116a9b 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -147,7 +147,7 @@ template class Vector3: public Vector<3, T> { * @see swizzle() */ inline Vector2& xy() { return Vector2::from(Vector<3, T>::data()); } - inline constexpr Vector2 xy() const { return Vector2::from(Vector<3, T>::data()); } /**< @overload */ + inline constexpr const Vector2 xy() const { return {x(), y()}; } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector3, 3) }; diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index d54000222..5a4fa4f09 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -79,7 +79,7 @@ template class Vector4: public Vector<4, T> { * @see swizzle() */ inline Vector3& xyz() { return Vector3::from(Vector<4, T>::data()); } - inline constexpr Vector3 xyz() const { return Vector3::from(Vector<4, T>::data()); } /**< @overload */ + inline constexpr const Vector3 xyz() const { return {x(), y(), z()}; } /**< @overload */ /** * @brief XY part of the vector @@ -88,7 +88,7 @@ template class Vector4: public Vector<4, T> { * @see swizzle() */ inline Vector2& xy() { return Vector2::from(Vector<4, T>::data()); } - inline constexpr Vector2 xy() const { return Vector2::from(Vector<4, T>::data()); } /**< @overload */ + inline constexpr const Vector2 xy() const { return {x(), y()}; } /**< @overload */ MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Vector4, 4) }; From 677aa8485eb94521ef6212f45f433f67be866282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 23:40:47 +0100 Subject: [PATCH 486/567] Math: properly test constexpr in all Matrix classes. * Merged constExpressions() into other test cases, reducing duplicates and simplifying the checks. * Fixed old-and-forgotten operator[] overload in Matrix subclasses, it was reinterpret_cast on T* array, it is now sufficient to do only static_cast. Constexpr operator[] overload returns const copy to make constexpr operations working even on returned value, e.g.: constexpr Matrix4 a; constexpr Vector3 b = a[2].xyz(); --- src/Math/Matrix.h | 6 +- src/Math/Matrix3.h | 4 +- src/Math/Matrix4.h | 4 +- src/Math/Test/Matrix3Test.cpp | 123 ++++++++++++++------ src/Math/Test/Matrix4Test.cpp | 148 +++++++++++++++++------- src/Math/Test/MatrixTest.cpp | 67 ++++++++--- src/Math/Test/RectangularMatrixTest.cpp | 142 +++++++++-------------- 7 files changed, 300 insertions(+), 194 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index ed423e27c..9e7185af0 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -186,10 +186,10 @@ template inline Corrade::Utility::Debug operator<<(Co #ifndef DOXYGEN_GENERATING_OUTPUT #define MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Type, VectorType, size) \ inline VectorType& operator[](std::size_t col) { \ - return VectorType::from(Matrix::data()+col*size); \ + return static_cast&>(Matrix::operator[](col)); \ } \ - inline constexpr const VectorType& operator[](std::size_t col) const { \ - return VectorType::from(Matrix::data()+col*size); \ + inline constexpr const VectorType operator[](std::size_t col) const { \ + return VectorType(Matrix::operator[](col)); \ } \ \ inline Type operator*(const Matrix& other) const { \ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 81d930e7b..4d7ba282d 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -111,7 +111,7 @@ template class Matrix3: public Matrix<3, T> { * * @see rotationScaling() const, translation() const */ - static Matrix3 from(const Matrix<2, T>& rotationScaling, const Vector2& translation) { + inline constexpr static Matrix3 from(const Matrix<2, T>& rotationScaling, const Vector2& translation) { return {{rotationScaling[0], T(0)}, {rotationScaling[1], T(0)}, { translation, T(1)}}; @@ -150,7 +150,7 @@ template class Matrix3: public Matrix<3, T> { * @see from(const Matrix<2, T>&, const Vector2&), rotation() const, * rotation(T), Matrix4::rotationScaling() const */ - inline Matrix<2, T> rotationScaling() const { + inline constexpr Matrix<2, T> rotationScaling() const { return {(*this)[0].xy(), (*this)[1].xy()}; } diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 8ba2e4f7a..5a073f55a 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -240,7 +240,7 @@ template class Matrix4: public Matrix<4, T> { * * @see rotationScaling() const, translation() const */ - static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation) { + inline constexpr static Matrix4 from(const Matrix<3, T>& rotationScaling, const Vector3& translation) { return {{rotationScaling[0], T(0)}, {rotationScaling[1], T(0)}, {rotationScaling[2], T(0)}, @@ -281,7 +281,7 @@ template class Matrix4: public Matrix<4, T> { * @see from(const Matrix<3, T>&, const Vector3&), rotation() const, * rotation(T, const Vector3&), Matrix3::rotationScaling() const */ - inline Matrix<3, T> rotationScaling() const { + inline constexpr Matrix<3, T> rotationScaling() const { /* Not Matrix3, because it is for affine 2D transformations */ return {(*this)[0].xyz(), (*this)[1].xyz(), diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 6df37ed9f..e34123275 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -25,7 +25,11 @@ class Matrix3Test: public Corrade::TestSuite::Tester { public: Matrix3Test(); + void construct(); void constructIdentity(); + void constructZero(); + void constructConversion(); + void constructCopy(); void translation(); void scaling(); @@ -45,11 +49,16 @@ class Matrix3Test: public Corrade::TestSuite::Tester { typedef Math::Deg Deg; typedef Math::Matrix3 Matrix3; +typedef Math::Matrix3 Matrix3i; typedef Math::Matrix<2, Float> Matrix2; typedef Math::Vector2 Vector2; Matrix3Test::Matrix3Test() { - addTests(&Matrix3Test::constructIdentity, + addTests(&Matrix3Test::construct, + &Matrix3Test::constructIdentity, + &Matrix3Test::constructZero, + &Matrix3Test::constructConversion, + &Matrix3Test::constructCopy, &Matrix3Test::translation, &Matrix3Test::scaling, @@ -67,10 +76,19 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::configuration); } +void Matrix3Test::construct() { + constexpr Matrix3 a({3.0f, 5.0f, 8.0f}, + {4.5f, 4.0f, 7.0f}, + {7.9f, -1.0f, 8.0f}); + CORRADE_COMPARE(a, Matrix3({3.0f, 5.0f, 8.0f}, + {4.5f, 4.0f, 7.0f}, + {7.9f, -1.0f, 8.0f})); +} + void Matrix3Test::constructIdentity() { - Matrix3 identity; - Matrix3 identity2(Matrix3::Identity); - Matrix3 identity3(Matrix3::Identity, 4.0f); + constexpr Matrix3 identity; + constexpr Matrix3 identity2(Matrix3::Identity); + constexpr Matrix3 identity3(Matrix3::Identity, 4.0f); Matrix3 identityExpected({1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, @@ -85,20 +103,49 @@ void Matrix3Test::constructIdentity() { CORRADE_COMPARE(identity3, identity3Expected); } -void Matrix3Test::translation() { - Matrix3 matrix({1.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f}, - {3.0f, 1.0f, 1.0f}); +void Matrix3Test::constructZero() { + constexpr Matrix3 a(Matrix3::Zero); + CORRADE_COMPARE(a, Matrix3({0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f})); +} - CORRADE_COMPARE(Matrix3::translation({3.0f, 1.0f}), matrix); +void Matrix3Test::constructConversion() { + constexpr Matrix3 a({3.0f, 5.0f, 8.0f}, + {4.5f, 4.0f, 7.0f}, + {7.9f, -1.0f, 8.0f}); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Matrix3i b(a); + #else + Matrix3i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(b, Matrix3i({3, 5, 8}, + {4, 4, 7}, + {7, -1, 8})); } -void Matrix3Test::scaling() { - Matrix3 matrix({3.0f, 0.0f, 0.0f}, - {0.0f, 1.5f, 0.0f}, - {0.0f, 0.0f, 1.0f}); +void Matrix3Test::constructCopy() { + constexpr Matrix3 a({3.0f, 5.0f, 8.0f}, + {4.5f, 4.0f, 7.0f}, + {7.9f, -1.0f, 8.0f}); + constexpr Matrix3 b(a); + CORRADE_COMPARE(b, Matrix3({3.0f, 5.0f, 8.0f}, + {4.5f, 4.0f, 7.0f}, + {7.9f, -1.0f, 8.0f})); +} + +void Matrix3Test::translation() { + constexpr Matrix3 a = Matrix3::translation({3.0f, 1.0f}); + CORRADE_COMPARE(a, Matrix3({1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {3.0f, 1.0f, 1.0f})); +} - CORRADE_COMPARE(Matrix3::scaling({3.0f, 1.5f}), matrix); +void Matrix3Test::scaling() { + constexpr Matrix3 a = Matrix3::scaling({3.0f, 1.5f}); + CORRADE_COMPARE(a, Matrix3({3.0f, 0.0f, 0.0f}, + {0.0f, 1.5f, 0.0f}, + {0.0f, 0.0f, 1.0f})); } void Matrix3Test::rotation() { @@ -137,27 +184,24 @@ void Matrix3Test::projection() { } void Matrix3Test::fromParts() { - Matrix2 rotationScaling(Vector2(3.0f, 5.0f), - Vector2(4.0f, 4.0f)); - - Vector2 translation(7.0f, -1.0f); - - Matrix3 expected({3.0f, 5.0f, 0.0f}, - {4.0f, 4.0f, 0.0f}, - {7.0f, -1.0f, 1.0f}); - - CORRADE_COMPARE(Matrix3::from(rotationScaling, translation), expected); + constexpr Matrix2 rotationScaling(Vector2(3.0f, 5.0f), + Vector2(4.0f, 4.0f)); + constexpr Vector2 translation(7.0f, -1.0f); + constexpr Matrix3 a = Matrix3::from(rotationScaling, translation); + + CORRADE_COMPARE(a, Matrix3({3.0f, 5.0f, 0.0f}, + {4.0f, 4.0f, 0.0f}, + {7.0f, -1.0f, 1.0f})); } void Matrix3Test::rotationScalingPart() { - Matrix3 m({3.0f, 5.0f, 8.0f}, - {4.0f, 4.0f, 7.0f}, - {7.0f, -1.0f, 8.0f}); + constexpr Matrix3 a({3.0f, 5.0f, 8.0f}, + {4.0f, 4.0f, 7.0f}, + {7.0f, -1.0f, 8.0f}); + constexpr Matrix2 b = a.rotationScaling(); - Matrix2 expected(Vector2(3.0f, 5.0f), - Vector2(4.0f, 4.0f)); - - CORRADE_COMPARE(m.rotationScaling(), expected); + CORRADE_COMPARE(b, Matrix2(Vector2(3.0f, 5.0f), + Vector2(4.0f, 4.0f))); } void Matrix3Test::rotationPart() { @@ -190,13 +234,16 @@ void Matrix3Test::rotationPart() { } void Matrix3Test::vectorParts() { - Matrix3 m({15.0f, 0.0f, 0.0f}, - { 0.0f, -3.0f, 0.0f}, - {-5.0f, 12.0f, 1.0f}); - - CORRADE_COMPARE(m.right(), Vector2::xAxis(15.0f)); - CORRADE_COMPARE(m.up(), Vector2::yAxis(-3.0f)); - CORRADE_COMPARE(m.translation(), Vector2(-5.0f, 12.0f)); + constexpr Matrix3 a({15.0f, 0.0f, 0.0f}, + { 0.0f, -3.0f, 0.0f}, + {-5.0f, 12.0f, 1.0f}); + constexpr Vector2 right = a.right(); + constexpr Vector2 up = a.up(); + constexpr Vector2 translation = a.translation(); + + CORRADE_COMPARE(right, Vector2::xAxis(15.0f)); + CORRADE_COMPARE(up, Vector2::yAxis(-3.0f)); + CORRADE_COMPARE(translation, Vector2(-5.0f, 12.0f)); } void Matrix3Test::invertedEuclidean() { diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 9258c9ff8..09894f084 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -25,7 +25,11 @@ class Matrix4Test: public Corrade::TestSuite::Tester { public: Matrix4Test(); + void construct(); void constructIdentity(); + void constructZero(); + void constructConversion(); + void constructCopy(); void translation(); void scaling(); @@ -51,11 +55,16 @@ class Matrix4Test: public Corrade::TestSuite::Tester { typedef Math::Deg Deg; typedef Math::Rad Rad; typedef Math::Matrix4 Matrix4; +typedef Math::Matrix4 Matrix4i; typedef Math::Matrix<3, Float> Matrix3; typedef Math::Vector3 Vector3; Matrix4Test::Matrix4Test() { - addTests(&Matrix4Test::constructIdentity, + addTests(&Matrix4Test::construct, + &Matrix4Test::constructIdentity, + &Matrix4Test::constructZero, + &Matrix4Test::constructConversion, + &Matrix4Test::constructCopy, &Matrix4Test::translation, &Matrix4Test::scaling, @@ -78,10 +87,21 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::configuration); } +void Matrix4Test::construct() { + constexpr Matrix4 a({3.0f, 5.0f, 8.0f, -3.0f}, + {4.5f, 4.0f, 7.0f, 2.0f}, + {1.0f, 2.0f, 3.0f, -1.0f}, + {7.9f, -1.0f, 8.0f, -1.5f}); + CORRADE_COMPARE(a, Matrix4({3.0f, 5.0f, 8.0f, -3.0f}, + {4.5f, 4.0f, 7.0f, 2.0f}, + {1.0f, 2.0f, 3.0f, -1.0f}, + {7.9f, -1.0f, 8.0f, -1.5f})); +} + void Matrix4Test::constructIdentity() { - Matrix4 identity; - Matrix4 identity2(Matrix4::Identity); - Matrix4 identity3(Matrix4::Identity, 4.0f); + constexpr Matrix4 identity; + constexpr Matrix4 identity2(Matrix4::Identity); + constexpr Matrix4 identity3(Matrix4::Identity, 4.0f); Matrix4 identityExpected({1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, @@ -98,22 +118,57 @@ void Matrix4Test::constructIdentity() { CORRADE_COMPARE(identity3, identity3Expected); } -void Matrix4Test::translation() { - Matrix4 matrix({1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {3.0f, 1.0f, 2.0f, 1.0f}); +void Matrix4Test::constructZero() { + /* Zero constructor */ + constexpr Matrix4 a(Matrix4::Zero); + CORRADE_COMPARE(a, Matrix4({0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f})); +} - CORRADE_COMPARE(Matrix4::translation({3.0f, 1.0f, 2.0f}), matrix); +void Matrix4Test::constructConversion() { + constexpr Matrix4 a({3.0f, 5.0f, 8.0f, -3.0f}, + {4.5f, 4.0f, 7.0f, 2.0f}, + {1.0f, 2.0f, 3.0f, -1.0f}, + {7.9f, -1.0f, 8.0f, -1.5f}); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Matrix4i b(a); + #else + Matrix4i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(b, Matrix4i({3, 5, 8, -3}, + {4, 4, 7, 2}, + {1, 2, 3, -1}, + {7, -1, 8, -1})); } -void Matrix4Test::scaling() { - Matrix4 matrix({3.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.5f, 0.0f, 0.0f}, - {0.0f, 0.0f, 2.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f}); +void Matrix4Test::constructCopy() { + constexpr Matrix4 a({3.0f, 5.0f, 8.0f, -3.0f}, + {4.5f, 4.0f, 7.0f, 2.0f}, + {1.0f, 2.0f, 3.0f, -1.0f}, + {7.9f, -1.0f, 8.0f, -1.5f}); + constexpr Matrix4 b(a); + CORRADE_COMPARE(b, Matrix4({3.0f, 5.0f, 8.0f, -3.0f}, + {4.5f, 4.0f, 7.0f, 2.0f}, + {1.0f, 2.0f, 3.0f, -1.0f}, + {7.9f, -1.0f, 8.0f, -1.5f})); +} - CORRADE_COMPARE(Matrix4::scaling({3.0f, 1.5f, 2.0f}), matrix); +void Matrix4Test::translation() { + constexpr Matrix4 a = Matrix4::translation({3.0f, 1.0f, 2.0f}); + CORRADE_COMPARE(a, Matrix4({1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {3.0f, 1.0f, 2.0f, 1.0f})); +} + +void Matrix4Test::scaling() { + constexpr Matrix4 a = Matrix4::scaling({3.0f, 1.5f, 2.0f}); + CORRADE_COMPARE(a, Matrix4({3.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.5f, 0.0f, 0.0f}, + {0.0f, 0.0f, 2.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f})); } void Matrix4Test::rotation() { @@ -202,29 +257,28 @@ void Matrix4Test::perspectiveProjectionFov() { } void Matrix4Test::fromParts() { - Matrix3 rotationScaling(Vector3(3.0f, 5.0f, 8.0f), - Vector3(4.0f, 4.0f, 7.0f), - Vector3(7.0f, -1.0f, 8.0f)); - - Vector3 translation(9.0f, 4.0f, 5.0f); - - Matrix4 expected({3.0f, 5.0f, 8.0f, 0.0f}, - {4.0f, 4.0f, 7.0f, 0.0f}, - {7.0f, -1.0f, 8.0f, 0.0f}, - {9.0f, 4.0f, 5.0f, 1.0f}); - CORRADE_COMPARE(Matrix4::from(rotationScaling, translation), expected); + constexpr Matrix3 rotationScaling(Vector3(3.0f, 5.0f, 8.0f), + Vector3(4.0f, 4.0f, 7.0f), + Vector3(7.0f, -1.0f, 8.0f)); + constexpr Vector3 translation(9.0f, 4.0f, 5.0f); + constexpr Matrix4 a = Matrix4::from(rotationScaling, translation); + + CORRADE_COMPARE(a, Matrix4({3.0f, 5.0f, 8.0f, 0.0f}, + {4.0f, 4.0f, 7.0f, 0.0f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 1.0f})); } void Matrix4Test::rotationScalingPart() { - Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, - {4.0f, 4.0f, 7.0f, 3.0f}, - {7.0f, -1.0f, 8.0f, 0.0f}, - {9.0f, 4.0f, 5.0f, 9.0f}); - - Matrix3 expected(Vector3(3.0f, 5.0f, 8.0f), - Vector3(4.0f, 4.0f, 7.0f), - Vector3(7.0f, -1.0f, 8.0f)); - CORRADE_COMPARE(m.rotationScaling(), expected); + constexpr Matrix4 a({3.0f, 5.0f, 8.0f, 4.0f}, + {4.0f, 4.0f, 7.0f, 3.0f}, + {7.0f, -1.0f, 8.0f, 0.0f}, + {9.0f, 4.0f, 5.0f, 9.0f}); + constexpr Matrix3 b = a.rotationScaling(); + + CORRADE_COMPARE(b, Matrix3(Vector3(3.0f, 5.0f, 8.0f), + Vector3(4.0f, 4.0f, 7.0f), + Vector3(7.0f, -1.0f, 8.0f))); } void Matrix4Test::rotationPart() { @@ -258,15 +312,19 @@ void Matrix4Test::rotationPart() { } void Matrix4Test::vectorParts() { - Matrix4 m({-1.0f, 0.0f, 0.0f, 0.0f}, - { 0.0f, 12.0f, 0.0f, 0.0f}, - { 0.0f, 0.0f, 35.0f, 0.0f}, - {-5.0f, 12.0f, 0.5f, 1.0f}); - - CORRADE_COMPARE(m.right(), Vector3::xAxis(-1.0f)); - CORRADE_COMPARE(m.up(), Vector3::yAxis(12.0f)); - CORRADE_COMPARE(m.backward(), Vector3::zAxis(35.0f)); - CORRADE_COMPARE(m.translation(), Vector3(-5.0f, 12.0f, 0.5f)); + constexpr Matrix4 a({-1.0f, 0.0f, 0.0f, 0.0f}, + { 0.0f, 12.0f, 0.0f, 0.0f}, + { 0.0f, 0.0f, 35.0f, 0.0f}, + {-5.0f, 12.0f, 0.5f, 1.0f}); + constexpr Vector3 right = a.right(); + constexpr Vector3 up = a.up(); + constexpr Vector3 backward = a.backward(); + constexpr Vector3 translation = a.translation(); + + CORRADE_COMPARE(right, Vector3::xAxis(-1.0f)); + CORRADE_COMPARE(up, Vector3::yAxis(12.0f)); + CORRADE_COMPARE(backward, Vector3::zAxis(35.0f)); + CORRADE_COMPARE(translation, Vector3(-5.0f, 12.0f, 0.5f)); } void Matrix4Test::invertedEuclidean() { diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index a862326be..72525cd45 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -28,6 +28,9 @@ class MatrixTest: public Corrade::TestSuite::Tester { void construct(); void constructIdentity(); void constructZero(); + void constructConversion(); + void constructCopy(); + void trace(); void ij(); void determinant(); @@ -38,14 +41,19 @@ class MatrixTest: public Corrade::TestSuite::Tester { }; typedef Matrix<4, Float> Matrix4; +typedef Matrix<4, Int> Matrix4i; typedef Matrix<3, Float> Matrix3; typedef Vector<4, Float> Vector4; +typedef Vector<4, Int> Vector4i; typedef Vector<3, Float> Vector3; MatrixTest::MatrixTest() { addTests(&MatrixTest::construct, &MatrixTest::constructIdentity, &MatrixTest::constructZero, + &MatrixTest::constructConversion, + &MatrixTest::constructCopy, + &MatrixTest::trace, &MatrixTest::ij, &MatrixTest::determinant, @@ -55,19 +63,15 @@ MatrixTest::MatrixTest() { } void MatrixTest::construct() { - Float m[] = { - 3.0f, 5.0f, 8.0f, 4.0f, - 4.0f, 4.0f, 7.0f, 3.0f, - 7.0f, -1.0f, 8.0f, 0.0f, - 9.0f, 4.0f, 5.0f, 9.0f - }; - - Matrix4 expected(Vector4(3.0f, 5.0f, 8.0f, 4.0f), - Vector4(4.0f, 4.0f, 7.0f, 3.0f), - Vector4(7.0f, -1.0f, 8.0f, 0.0f), - Vector4(9.0f, 4.0f, 5.0f, 9.0f)); - - CORRADE_COMPARE(Matrix4::from(m), expected); + /* Value constructor */ + constexpr Matrix4 a(Vector4(3.0f, 5.0f, 8.0f, -3.0f), + Vector4(4.5f, 4.0f, 7.0f, 2.0f), + Vector4(1.0f, 2.0f, 3.0f, -1.0f), + Vector4(7.9f, -1.0f, 8.0f, -1.5f)); + CORRADE_COMPARE(a, Matrix4(Vector4(3.0f, 5.0f, 8.0f, -3.0f), + Vector4(4.5f, 4.0f, 7.0f, 2.0f), + Vector4(1.0f, 2.0f, 3.0f, -1.0f), + Vector4(7.9f, -1.0f, 8.0f, -1.5f))); } void MatrixTest::constructIdentity() { @@ -91,14 +95,39 @@ void MatrixTest::constructIdentity() { } void MatrixTest::constructZero() { - Matrix4 zero(Matrix4::Zero); + constexpr Matrix4 a(Matrix4::Zero); + CORRADE_COMPARE(a, Matrix4(Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f), + Vector4(0.0f, 0.0f, 0.0f, 0.0f))); +} - Matrix4 zeroExpected(Vector4(0.0f, 0.0f, 0.0f, 0.0f), - Vector4(0.0f, 0.0f, 0.0f, 0.0f), - Vector4(0.0f, 0.0f, 0.0f, 0.0f), - Vector4(0.0f, 0.0f, 0.0f, 0.0f)); +void MatrixTest::constructConversion() { + constexpr Matrix4 a(Vector4(3.0f, 5.0f, 8.0f, -3.0f), + Vector4(4.5f, 4.0f, 7.0f, 2.0f), + Vector4(1.0f, 2.0f, 3.0f, -1.0f), + Vector4(7.9f, -1.0f, 8.0f, -1.5f)); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Matrix4i b(a); + #else + Matrix4i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + CORRADE_COMPARE(b, Matrix4i(Vector4i(3, 5, 8, -3), + Vector4i(4, 4, 7, 2), + Vector4i(1, 2, 3, -1), + Vector4i(7, -1, 8, -1))); +} - CORRADE_COMPARE(zero, zeroExpected); +void MatrixTest::constructCopy() { + constexpr Matrix4 a(Vector4(3.0f, 5.0f, 8.0f, -3.0f), + Vector4(4.5f, 4.0f, 7.0f, 2.0f), + Vector4(1.0f, 2.0f, 3.0f, -1.0f), + Vector4(7.9f, -1.0f, 8.0f, -1.5f)); + constexpr Matrix4 b(a); + CORRADE_COMPARE(b, Matrix4(Vector4(3.0f, 5.0f, 8.0f, -3.0f), + Vector4(4.5f, 4.0f, 7.0f, 2.0f), + Vector4(1.0f, 2.0f, 3.0f, -1.0f), + Vector4(7.9f, -1.0f, 8.0f, -1.5f))); } void MatrixTest::trace() { diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 00d8de449..5782f1635 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -25,15 +25,14 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { public: RectangularMatrixTest(); - void constructFromData(); + void construct(); void constructDefault(); void constructConversion(); - void constructFromVectors(); + void constructFromData(); void constructFromDiagonal(); + void constructCopy(); void data(); - void constExpressions(); - void compare(); void negative(); @@ -65,15 +64,14 @@ typedef Vector<2, Float> Vector2; typedef Vector<2, Int> Vector2i; RectangularMatrixTest::RectangularMatrixTest() { - addTests(&RectangularMatrixTest::constructFromData, + addTests(&RectangularMatrixTest::construct, &RectangularMatrixTest::constructDefault, &RectangularMatrixTest::constructConversion, - &RectangularMatrixTest::constructFromVectors, + &RectangularMatrixTest::constructFromData, &RectangularMatrixTest::constructFromDiagonal, + &RectangularMatrixTest::constructCopy, &RectangularMatrixTest::data, - &RectangularMatrixTest::constExpressions, - &RectangularMatrixTest::compare, &RectangularMatrixTest::negative, @@ -95,6 +93,36 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::configuration); } +void RectangularMatrixTest::construct() { + constexpr Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); + CORRADE_COMPARE(a, Matrix3x4(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f))); +} + +void RectangularMatrixTest::constructDefault() { + constexpr Matrix4x3 a; + CORRADE_COMPARE(a, Matrix4x3(Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f), + Vector3(0.0f, 0.0f, 0.0f))); +} + +void RectangularMatrixTest::constructConversion() { + constexpr Matrix2 a(Vector2( 1.3f, 2.7f), + Vector2(-15.0f, 7.0f)); + #ifndef CORRADE_GCC46_COMPATIBILITY + constexpr Matrix2i b(a); + #else + Matrix2i b(a); /* Not constexpr under GCC < 4.7 */ + #endif + + CORRADE_COMPARE(b, Matrix2i(Vector2i( 1, 2), + Vector2i(-15, 7))); +} + void RectangularMatrixTest::constructFromData() { Float m[] = { 3.0f, 5.0f, 8.0f, 4.0f, @@ -109,41 +137,6 @@ void RectangularMatrixTest::constructFromData() { CORRADE_COMPARE(Matrix3x4::from(m), expected); } -void RectangularMatrixTest::constructDefault() { - Matrix4x3 zero; - - Matrix4x3 zeroExpected(Vector3(0.0f, 0.0f, 0.0f), - Vector3(0.0f, 0.0f, 0.0f), - Vector3(0.0f, 0.0f, 0.0f), - Vector3(0.0f, 0.0f, 0.0f)); - - CORRADE_COMPARE(zero, zeroExpected); -} - -void RectangularMatrixTest::constructConversion() { - Matrix2 FloatingPoint(Vector2( 1.3f, 2.7f), - Vector2(-15.0f, 7.0f)); - Matrix2 FloatingPointRounded(Vector2(1.0f, 2.0f), - Vector2(-15.0f, 7.0f)); - Matrix2i integral(Vector2i( 1, 2), - Vector2i(-15, 7)); - - CORRADE_COMPARE(Matrix2i(FloatingPoint), integral); - CORRADE_COMPARE(Matrix2(integral), FloatingPointRounded); -} - -void RectangularMatrixTest::constructFromVectors() { - Matrix3x4 actual(Vector4(1.0f, 2.0f, 3.0f, 4.0f), - Vector4(5.0f, 6.0f, 7.0f, 8.0f), - Vector4(9.0f, 10.0f, 11.0f, 12.0f)); - - Matrix3x4 expected(Vector4(1.0f, 2.0f, 3.0f, 4.0f), - Vector4(5.0f, 6.0f, 7.0f, 8.0f), - Vector4(9.0f, 10.0f, 11.0f, 12.0f)); - - CORRADE_COMPARE(actual, expected); -} - void RectangularMatrixTest::constructFromDiagonal() { Vector3 diagonal(-1.0f, 5.0f, 11.0f); @@ -159,6 +152,16 @@ void RectangularMatrixTest::constructFromDiagonal() { CORRADE_COMPARE(Matrix4x3::fromDiagonal(diagonal), expectedB); } +void RectangularMatrixTest::constructCopy() { + constexpr Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); + constexpr Matrix3x4 b(a); + CORRADE_COMPARE(b, Matrix3x4(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f))); +} + void RectangularMatrixTest::data() { Matrix3x4 m; Vector4 vector(4.0f, 5.0f, 6.0f, 7.0f); @@ -171,51 +174,20 @@ void RectangularMatrixTest::data() { CORRADE_COMPARE(m[0][2], 1.5f); CORRADE_COMPARE(m[2], vector); - Matrix3x4 expected(Vector4(0.0f, 0.0f, 1.5f, 0.0f), - Vector4(0.0f, 1.0f, 0.0f, 0.0f), - Vector4(4.0f, 5.0f, 6.0f, 7.0f)); - - CORRADE_COMPARE(m, expected); -} - -void RectangularMatrixTest::constExpressions() { - /* Default constructor */ - constexpr Matrix3x4 a; - CORRADE_COMPARE(a, Matrix3x4(Vector4(0.0f, 0.0f, 0.0f, 0.0f), - Vector4(0.0f, 0.0f, 0.0f, 0.0f), - Vector4(0.0f, 0.0f, 0.0f, 0.0f))); + CORRADE_COMPARE(m, Matrix3x4(Vector4(0.0f, 0.0f, 1.5f, 0.0f), + Vector4(0.0f, 1.0f, 0.0f, 0.0f), + Vector4(4.0f, 5.0f, 6.0f, 7.0f))); - /* Value constructor */ - constexpr Matrix3x4 b(Vector4(3.0f, 5.0f, 8.0f, 4.0f), + /* Pointer chasings, i.e. *(b.data()[1]), are not possible */ + constexpr Matrix3x4 a(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Vector4(4.5f, 4.0f, 7.0f, 3.0f), Vector4(7.0f, -1.7f, 8.0f, 0.0f)); - CORRADE_COMPARE(b, Matrix3x4(Vector4(3.0f, 5.0f, 8.0f, 4.0f), - Vector4(4.5f, 4.0f, 7.0f, 3.0f), - Vector4(7.0f, -1.7f, 8.0f, 0.0f))); - - /* Conversion constructor, not constexpr under GCC < 4.7 */ - #ifndef CORRADE_GCC46_COMPATIBILITY - typedef RectangularMatrix<3, 4, Int> Matrix3x4i; - typedef Vector<4, Int> Vector4i; - constexpr Matrix3x4i c(b); - CORRADE_COMPARE(c, Matrix3x4i(Vector4i(3, 5, 8, 4), - Vector4i(4, 4, 7, 3), - Vector4i(7, -1, 8, 0))); - #endif - - /* Copy constructor */ - constexpr Matrix3x4 d(b); - CORRADE_COMPARE(d, Matrix3x4(Vector4(3.0f, 5.0f, 8.0f, 4.0f), - Vector4(4.5f, 4.0f, 7.0f, 3.0f), - Vector4(7.0f, -1.7f, 8.0f, 0.0f))); - - /* Data access, pointer chasings, i.e. *(b.data()[1]), are not possible */ - constexpr Vector4 e = b[2]; - constexpr Float f = b[1][2]; - constexpr Float g = *b.data(); - CORRADE_COMPARE(e, Vector4(7.0f, -1.7f, 8.0f, 0.0f)); - CORRADE_COMPARE(f, 7.0f); - CORRADE_COMPARE(g, 3.0f); + constexpr Vector4 b = a[2]; + constexpr Float c = a[1][2]; + constexpr Float d = *a.data(); + CORRADE_COMPARE(b, Vector4(7.0f, -1.7f, 8.0f, 0.0f)); + CORRADE_COMPARE(c, 7.0f); + CORRADE_COMPARE(d, 3.0f); } void RectangularMatrixTest::compare() { From 5eb98494b309f13ff9a6a5c839f25a552ca3b572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Mar 2013 12:20:41 +0100 Subject: [PATCH 487/567] Doc++ --- src/AbstractShaderProgram.h | 38 ++++++++++++++++++++++---------- src/Physics/AxisAlignedBox.cpp | 2 ++ src/Physics/Capsule.cpp | 2 ++ src/Physics/ObjectShape.cpp | 2 ++ src/Physics/ObjectShapeGroup.cpp | 2 ++ src/Physics/Sphere.cpp | 2 ++ src/Query.h | 7 +++--- 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 3aa6a9108..f501557bd 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -223,25 +223,39 @@ See @ref types for more information, only types with GLSL equivalent can be used (and their super- or subclasses with the same size and underlying type). @requires_gl30 %Extension @extension{EXT,gpu_shader4} is required when using - integer attributes (i.e. UnsignedInt, Int, Vector2ui, Vector2i, Vector3ui, - Vector3i, Vector4ui and Vector4i) or unsigned integer uniforms. (i.e. - UnsignedInt, Vector2ui, Vector3ui and Vector4ui). + integer attributes (i.e. @ref Magnum::UnsignedInt "UnsignedInt", + @ref Magnum::Int "Int", @ref Magnum::Vector2ui "Vector2ui", + @ref Magnum::Vector2i "Vector2i", @ref Magnum::Vector3ui "Vector3ui", + @ref Magnum::Vector3i "Vector3i", @ref Magnum::Vector4ui "Vector4ui" and + @ref Magnum::Vector4i "Vector4i") or unsigned integer uniforms (i.e. + @ref Magnum::UnsignedInt "UnsignedInt", @ref Magnum::Vector2ui "Vector2ui", + @ref Magnum::Vector3ui "Vector3ui" and @ref Magnum::Vector4ui "Vector4ui"). @requires_gles30 Integer attributes and unsigned integer uniforms are not available in OpenGL ES 2.0. @requires_gl40 %Extension @extension{ARB,gpu_shader_fp64} is required when - using double uniforms (i.e. Double, Vector2d, Vector3d, Vector4d, Matrix2d, - Matrix3d, Matrix4d, Matrix2x3d, Matrix3x2d, Matrix2x4d, Matrix4x2d, - Matrix3x4d and Matrix4x3d). + using double uniforms (i.e. @ref Magnum::Double "Double", + @ref Magnum::Vector2d "Vector2d", @ref Magnum::Vector3d "Vector3d", + @ref Magnum::Vector4d "Vector4d", @ref Magnum::Matrix2d "Matrix2d", + @ref Magnum::Matrix3d "Matrix3d", @ref Magnum::Matrix4d "Matrix4d", + @ref Magnum::Matrix2x3d "Matrix2x3d", @ref Magnum::Matrix3x2d "Matrix3x2d", + @ref Magnum::Matrix2x4d "Matrix2x4d", @ref Magnum::Matrix4x2d "Matrix4x2d", + @ref Magnum::Matrix3x4d "Matrix3x4d" and @ref Magnum::Matrix4x3d "Matrix4x3d"). @requires_gl41 %Extension @extension{ARB,vertex_attrib_64bit} is required when - using double attributes (i.e. Double, Vector2d, Vector3d, Vector4d, Matrix2d, - Matrix3d, Matrix4d, Matrix2x3d, Matrix3x2d, Matrix2x4d, Matrix4x2d, - Matrix3x4d and Matrix4x3d). + using double attributes (i.e. @ref Magnum::Double "Double", + @ref Magnum::Vector2d "Vector2d", @ref Magnum::Vector3d "Vector3d", + @ref Magnum::Vector4d "Vector4d", @ref Magnum::Matrix2d "Matrix2d", + @ref Magnum::Matrix3d "Matrix3d", @ref Magnum::Matrix4d "Matrix4d", + @ref Magnum::Matrix2x3d "Matrix2x3d", @ref Magnum::Matrix3x2d "Matrix3x2d", + @ref Magnum::Matrix2x4d "Matrix2x4d", @ref Magnum::Matrix4x2d "Matrix4x2d", + @ref Magnum::Matrix3x4d "Matrix3x4d" and @ref Magnum::Matrix4x3d "Matrix4x3d"). @requires_gl Double attributes and uniforms are not available in OpenGL ES. -@requires_gles30 Non-square matrix attributes and uniforms (i.e. Matrix2x3, - Matrix3x2, Matrix2x4, Matrix4x2, Matrix3x4 and Matrix4x3) are not available - in OpenGL ES 2.0. +@requires_gles30 Non-square matrix attributes and uniforms (i.e. + @ref Magnum::Matrix2x3 "Matrix2x3", @ref Magnum::Matrix3x2 "Matrix3x2", + @ref Magnum::Matrix2x4 "Matrix2x4", @ref Magnum::Matrix4x2d "Matrix4x2", + @ref Magnum::Matrix3x4 "Matrix3x4" and @ref Magnum::Matrix4x3 "Matrix4x3") + are not available in OpenGL ES 2.0. @section AbstractShaderProgram-performance-optimization Performance optimizations diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 36714d8bb..68f28ca11 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -38,7 +38,9 @@ template bool AxisAlignedBox::operator%(cons (other.transformedPosition() < _transformedMax).all(); } +#ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox<2>; template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox<3>; +#endif }} diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index f48311eb6..18bf0fab9 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -52,7 +52,9 @@ template bool Capsule::operator%(const Spher Math::pow<2>(transformedRadius()+other.transformedRadius()); } +#ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_PHYSICS_EXPORT Capsule<2>; template class MAGNUM_PHYSICS_EXPORT Capsule<3>; +#endif }} diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index b37d9eeee..a34f46e3e 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -46,7 +46,9 @@ template void ObjectShape::clean(const typen if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); } +#ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_PHYSICS_EXPORT ObjectShape<2>; template class MAGNUM_PHYSICS_EXPORT ObjectShape<3>; +#endif }} diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index 1fea2b8ea..16580d012 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -45,7 +45,9 @@ template ObjectShape* ObjectShapeGroup; template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup<3>; +#endif }} diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 752d3875f..2bf35b7f8 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -77,7 +77,9 @@ template bool Sphere::operator%(const Sphere Math::pow<2>(transformedRadius()+other.transformedRadius()); } +#ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_PHYSICS_EXPORT Sphere<2>; template class MAGNUM_PHYSICS_EXPORT Sphere<3>; +#endif }} diff --git a/src/Query.h b/src/Query.h index 21063f516..7b3e9ebc2 100644 --- a/src/Query.h +++ b/src/Query.h @@ -79,9 +79,10 @@ class MAGNUM_EXPORT AbstractQuery { * See resultAvailable(). * @see @fn_gl{GetQueryObject} with @def_gl{QUERY_RESULT} * @requires_gl33 %Extension @extension{ARB,timer_query} (result type - * UnsignedInt and Long) - * @requires_gl Result types Int, UnsignedLong and Long are not - * available in OpenGL ES. + * @ref Magnum::UnsignedInt "UnsignedInt" and @ref Magnum::Long + * "Long") + * @requires_gl Result types @ref Magnum::Int "Int", @ref Magnum::UnsignedLong "UnsignedLong" + * and @ref Magnum::Long "Long" are not available in OpenGL ES. */ template T result(); From f6ab8cfec2b4ef24897c74871d16ff96cad4cd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Mar 2013 12:30:55 +0100 Subject: [PATCH 488/567] Guidelines for builtin type aliases in coding style documentation. --- doc/coding-style.dox | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/coding-style.dox b/doc/coding-style.dox index 6817a1e16..d7a1ecec8 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -27,6 +27,15 @@ have `*.hpp` extension (hinting that they are something between `*.h` and @subsection cpp-format Code format +@subsubsection cpp-types Builtin types + +Use %Magnum's own type aliases for public API (e.g. @ref UnsignedInt, see +@ref types for more information), but use specific types when interacting with +third party libraries and OpenGL (e.g. `GLuint`) and rely only on implicit +conversions when converting between them. This helps avoiding sign, truncation +and other issues, e.g. `%Math::%Vector2` will implicitly convert to +@ref Vector2i if and only if @ref Int is the same type as `GLsizei`. + @subsubsection cpp-naming Naming When writing wrappers for OpenGL functions and defines, try to match the From 3929a6225a23f160734ba1415fabf0f5e8669b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Mar 2013 15:20:03 +0100 Subject: [PATCH 489/567] Properly delete arrays. --- src/DefaultFramebuffer.cpp | 4 ++-- src/Framebuffer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 6a0d40899..0303e3e2e 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -52,7 +52,7 @@ void DefaultFramebuffer::invalidate(std::initializer_list attachments, const Rectanglei& rectangle) { @@ -62,7 +62,7 @@ void DefaultFramebuffer::invalidate(std::initializer_list attac invalidateImplementation(attachments.size(), _attachments); - delete _attachments; + delete[] _attachments; } void Framebuffer::invalidate(std::initializer_list attachments, const Rectanglei& rectangle) { @@ -91,7 +91,7 @@ void Framebuffer::invalidate(std::initializer_list attac invalidateImplementation(attachments.size(), _attachments, rectangle); - delete _attachments; + delete[] _attachments; } void Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int mipLevel) { From 23ba74c8c32863f420a7346e6dc416219832b450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Mar 2013 15:21:24 +0100 Subject: [PATCH 490/567] Added missing method chaining to framebuffer configuration functions. --- src/AbstractFramebuffer.cpp | 4 +++- src/AbstractFramebuffer.h | 3 ++- src/DefaultFramebuffer.cpp | 3 ++- src/DefaultFramebuffer.h | 19 ++++++++++++++++--- src/Framebuffer.cpp | 6 ++++-- src/Framebuffer.h | 38 +++++++++++++++++++++++++++++-------- 6 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index e0855a4de..ef5761a97 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -92,12 +92,14 @@ void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& #endif } -void AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { +AbstractFramebuffer* AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { _viewport = rectangle; /* Update the viewport if the framebuffer is currently bound */ if(Context::current()->state()->framebuffer->drawBinding == _id) setViewportInternal(); + + return this; } #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 443d5982b..3d1d1b76a 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -195,13 +195,14 @@ class MAGNUM_EXPORT AbstractFramebuffer { /** * @brief Set viewport + * @return Pointer to self (for method chaining) * * Saves the viewport to be used at later time in bind(). If the * framebuffer is currently bound, updates the viewport to given * rectangle. * @see @fn_gl{Viewport} */ - void setViewport(const Rectanglei& rectangle); + AbstractFramebuffer* setViewport(const Rectanglei& rectangle); /** * @brief Clear specified buffers in framebuffer diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 0303e3e2e..6b1f61b69 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -28,7 +28,7 @@ DefaultFramebuffer defaultFramebuffer; DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } #ifndef MAGNUM_TARGET_GLES2 -void DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { +DefaultFramebuffer* DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) @@ -42,6 +42,7 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; + return this; } #endif diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 6bbb736bd..a6fd57dc1 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -264,6 +264,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #ifndef MAGNUM_TARGET_GLES2 /** * @brief Map shader outputs to buffer attachment + * @return Pointer to self (for method chaining) * * @p attachments is list of shader outputs mapped to buffer * attachments. %Shader outputs which are not listed are not used, you @@ -282,11 +283,12 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - void mapForDraw(std::initializer_list> attachments); + DefaultFramebuffer* mapForDraw(std::initializer_list> attachments); /** * @brief Map shader output to buffer attachment * @param attachment %Buffer attachment + * @return Pointer to self (for method chaining) * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -299,14 +301,16 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - inline void mapForDraw(DrawAttachment attachment) { + inline DefaultFramebuffer* mapForDraw(DrawAttachment attachment) { (this->*drawBufferImplementation)(static_cast(attachment)); + return this; } #endif /** * @brief Map given attachment for reading * @param attachment %Buffer attachment + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -315,8 +319,9 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - inline void mapForRead(ReadAttachment attachment) { + inline DefaultFramebuffer* mapForRead(ReadAttachment attachment) { (this->*readBufferImplementation)(static_cast(attachment)); + return this; } /** @@ -350,6 +355,14 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { */ void invalidate(std::initializer_list attachments, const Rectanglei& rectangle); + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline DefaultFramebuffer* setViewport(const Rectanglei& rectangle) { + AbstractFramebuffer::setViewport(rectangle); + return this; + } + #endif + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); }; diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 89ee445e5..a4f5e0102 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -58,7 +58,7 @@ Framebuffer::~Framebuffer() { glDeleteFramebuffers(1, &_id); } -void Framebuffer::mapForDraw(std::initializer_list> attachments) { +Framebuffer* Framebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) @@ -72,6 +72,7 @@ void Framebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; + return this; } void Framebuffer::invalidate(std::initializer_list attachments) { @@ -94,9 +95,10 @@ void Framebuffer::invalidate(std::initializer_list attac delete[] _attachments; } -void Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int mipLevel) { +Framebuffer* Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int mipLevel) { /** @todo Check for texture target compatibility */ (this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel); + return this; } void Framebuffer::initializeContextBasedFunctionality(Context* context) { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 706374210..78ebbcc95 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -221,6 +221,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { /** * @brief Map shader output to attachments + * @return Pointer to self (for method chaining) * * @p attachments is list of shader outputs mapped to framebuffer * color attachment IDs. %Shader outputs which are not listed are not @@ -238,11 +239,12 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - void mapForDraw(std::initializer_list> attachments); + Framebuffer* mapForDraw(std::initializer_list> attachments); /** * @brief Map shader output to attachment * @param attachment Draw attachment + * @return Pointer to self (for method chaining) * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -254,8 +256,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - inline void mapForDraw(DrawAttachment attachment) { + inline Framebuffer* mapForDraw(DrawAttachment attachment) { (this->*drawBufferImplementation)(GLenum(attachment)); + return this; } /** @@ -292,6 +295,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { /** * @brief Map given color attachment for reading * @param attachment Color attachment + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -300,14 +304,16 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - inline void mapForRead(ColorAttachment attachment) { + inline Framebuffer* mapForRead(ColorAttachment attachment) { (this->*readBufferImplementation)(GLenum(attachment)); + return this; } /** * @brief Attach renderbuffer to given buffer * @param attachment %Buffer attachment * @param renderbuffer %Renderbuffer + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -315,8 +321,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} */ - inline void attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { + inline Framebuffer* attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { (this->*renderbufferImplementation)(attachment, renderbuffer); + return this; } #ifndef MAGNUM_TARGET_GLES @@ -325,6 +332,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param attachment %Buffer attachment * @param texture 1D texture * @param level Mip level + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -333,8 +341,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - inline void attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { + inline Framebuffer* attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { (this->*texture1DImplementation)(attachment, texture, level); + return this; } #endif @@ -343,6 +352,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param attachment %Buffer attachment * @param texture 2D texture * @param level Mip level + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -350,7 +360,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); + Framebuffer* attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); /** * @brief Attach cube map texture to given buffer @@ -358,6 +368,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param texture Cube map texture * @param coordinate Cube map coordinate * @param level Mip level + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -365,8 +376,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - inline void attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { + inline Framebuffer* attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { (this->*texture2DImplementation)(attachment, GLenum(coordinate), texture->id(), level); + return this; } /** @@ -375,6 +387,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param texture 3D texture * @param level Mip level * @param layer Layer of 2D image within a 3D texture + * @return Pointer to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -383,11 +396,20 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - inline void attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { + inline Framebuffer* attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { /** @todo Check for texture target compatibility */ (this->*texture3DImplementation)(attachment, texture, level, layer); + return this; } + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Framebuffer* setViewport(const Rectanglei& rectangle) { + AbstractFramebuffer::setViewport(rectangle); + return this; + } + #endif + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); From 7ae405b36043122d57a29fae2cfa78acc9315bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Mar 2013 15:22:38 +0100 Subject: [PATCH 491/567] Introductory documentation about method chaining. --- doc/method-chaining.dox | 66 +++++++++++++++++++++++++++++++++++++++++ doc/tips.dox | 7 +++-- 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 doc/method-chaining.dox diff --git a/doc/method-chaining.dox b/doc/method-chaining.dox new file mode 100644 index 000000000..9ed291b49 --- /dev/null +++ b/doc/method-chaining.dox @@ -0,0 +1,66 @@ +namespace Magnum { +/** @page method-chaining Method chaining + +@brief Little feature helping to reduce typing and encourage best practices. + +Method chaining ([Wikipedia](http://en.wikipedia.org/wiki/Method_chaining)) is a +feature which allows you to chain method calls one after another without +repeatedly specifying variable the method is called on. Its primary goal is to +reduce unnecessary repeated names, improving code readability. + +%Magnum uses this feature for configuring OpenGL objects (such as various mesh +and framebuffer options, shader uniforms etc.). Because OpenGL was designed with +"bind-to-modify" approach, most configuration calls need to bind the object +first and only after that change the parameters (unless @extension{EXT,direct_state_access} +extension is available to avoid this). To reduce unneeded bind calls, %Magnum +binds the object only if it is not already bound somewhere. Method chaining +encourages you to configure whole object in one run, effectively reducing the +number of needed bindings. Consider the following example: +@code +Texture2D *carDiffuseTexture, *carSpecularTexture, *carBumpTexture; + +carDiffuseTexture->setStorage(5, Texture2D::InternalFormat::SRGB8); +carSpecularTexture->setStorage(3, Texture2D::InternalFormat::R8); +carBumpTexture->setStorage(5, Texture2D::InternalFormat::RGB8); +carDiffuseTexture->setSubImage(0, {}, diffuse); +carSpecularTexture->setSubImage(0, {}, specular; +carBumpTexture->setSubImage(0, {}, bump); +carDiffuseTexture->generateMipmap(); +carSpecularTexture->generateMipmap(); +carBumpTexture->generateMipmap(); +@endcode + +This code is written that similar configuration steps are grouped together, +which might be good when somebody needs to change something for all three +textures at once, but on the other hand the code is cluttered with repeated +names and after each configuration step the texture must be rebound to another. +With method chaining used the code looks much lighter and each object is +configured in one run, reducing count of bind calls from 9 to 3. +@code +carDiffuseTexture->setStorage(5, Texture2D::InternalFormat::SRGB8) + ->setSubImage(0, {}, diffuse) + ->generateMipmap(); +carSpecularTexture->setStorage(3, Texture2D::InternalFormat::R8) + ->setSubImage(0, {}, diffuse) + ->generateMipmap(); +carBumpTexture->setStorage(5, Texture2D::InternalFormat::RGB8) + ->setSubImage(0, {}, bump) + ->generateMipmap(); +@endcode + +Method chaining is not used on non-configuring functions, such as Framebuffer::clear() +or Mesh::draw(), as these won't be commonly used in conjunction with other +functions anyway. + +Method chaining is also used in SceneGraph and other libraries and in some cases +it allows you to just "configure and forget" without even saving the created +object to some variable, for example when adding static object to an scene: +@code +Scene3D scene; + +(new MyObject(&scene)) + ->rotateX(90.0_degf) + ->translate({-1.5f, 0.5f, 7.0f}); +@endcode +*/ +} diff --git a/doc/tips.dox b/doc/tips.dox index 85e0d6ad4..88800e65d 100644 --- a/doc/tips.dox +++ b/doc/tips.dox @@ -2,8 +2,9 @@ namespace Magnum { /** @page tips Tips and tricks @brief Hints for better productivity and performance. -- @subpage portability - @copybrief portability -- @subpage best-practices - @copybrief best-practices -- @subpage compilation-speedup - @copybrief compilation-speedup +- @subpage method-chaining -- @copybrief method-chaining +- @subpage portability -- @copybrief portability +- @subpage best-practices -- @copybrief best-practices +- @subpage compilation-speedup -- @copybrief compilation-speedup */ } From b1a97ed134a71da99c9ece8d7ce0c105c97ea54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Mar 2013 22:28:50 +0100 Subject: [PATCH 492/567] TextureTools: initial rude implementation of distance field computation. Not yet ported anywhere else than GL >= 3.3 with some GL 4.3 features. Still, this closes #3. --- src/TextureTools/CMakeLists.txt | 9 ++- src/TextureTools/DistanceField.cpp | 97 +++++++++++++++++++++++ src/TextureTools/DistanceField.h | 65 +++++++++++++++ src/TextureTools/DistanceFieldShader.frag | 59 ++++++++++++++ src/TextureTools/DistanceFieldShader.vert | 4 + 5 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 src/TextureTools/DistanceField.cpp create mode 100644 src/TextureTools/DistanceField.h create mode 100644 src/TextureTools/DistanceFieldShader.frag create mode 100644 src/TextureTools/DistanceFieldShader.vert diff --git a/src/TextureTools/CMakeLists.txt b/src/TextureTools/CMakeLists.txt index e7bbd4fa6..825658dad 100644 --- a/src/TextureTools/CMakeLists.txt +++ b/src/TextureTools/CMakeLists.txt @@ -1,8 +1,15 @@ +corrade_add_resource(MagnumTextureTools_RCS MagnumTextureTools + DistanceFieldShader.vert DistanceFieldShader.frag + ../Shaders/compatibility.glsl ALIAS compatibility.glsl) + set(MagnumTextureTools_SRCS - Atlas.cpp) + Atlas.cpp + DistanceField.cpp + ${MagnumTextureTools_RCS}) set(MagnumTextureTools_HEADERS Atlas.h + DistanceField.h magnumTextureToolsVisibility.h) diff --git a/src/TextureTools/DistanceField.cpp b/src/TextureTools/DistanceField.cpp new file mode 100644 index 000000000..e67146ef0 --- /dev/null +++ b/src/TextureTools/DistanceField.cpp @@ -0,0 +1,97 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "TextureTools/DistanceField.h" + +#include +#include "Math/Geometry/Rectangle.h" +#include "AbstractShaderProgram.h" +#include "Extensions.h" +#include "Framebuffer.h" +#include "Mesh.h" +#include "Shader.h" +#include "Texture.h" + +namespace Magnum { namespace TextureTools { + +namespace { + +class DistanceFieldShader: public AbstractShaderProgram { + public: + enum: Int { + TextureLayer = 8 + }; + + explicit DistanceFieldShader(); + + inline DistanceFieldShader* setRadius(Int radius) { + setUniform(radiusUniform, radius); + return this; + } + + inline DistanceFieldShader* setScaling(Vector2 scaling) { + setUniform(scalingUniform, scaling); + return this; + } + + private: + static const Int radiusUniform = 0, + scalingUniform = 1; +}; + +DistanceFieldShader::DistanceFieldShader() { + MAGNUM_ASSERT_VERSION_SUPPORTED(Version::GL330); + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::explicit_attrib_location); + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::explicit_uniform_location); + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::shading_language_420pack); + + /** @todo compatibility! */ + + Corrade::Utility::Resource rs("MagnumTextureTools"); + attachShader(Shader::fromData(Version::GL330, Shader::Type::Vertex, rs.get("DistanceFieldShader.vert"))); + + Shader fragmentShader(Version::GL330, Shader::Type::Fragment); + fragmentShader.addSource(rs.get("compatibility.glsl")); + fragmentShader.addSource(rs.get("DistanceFieldShader.frag")); + attachShader(fragmentShader); + + link(); +} + +} + +void distanceField(Texture2D* input, Texture2D* output, const Rectanglei& rectangle, const Int radius) { + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::framebuffer_object); + + /** @todo Disable depth test and then enable it back (if was previously) */ + + Framebuffer framebuffer(rectangle); + framebuffer.attachTexture2D(Framebuffer::ColorAttachment(0), output, 0); + framebuffer.bind(Framebuffer::Target::Draw); + + DistanceFieldShader shader; + shader.setRadius(radius) + ->setScaling(Vector2(input->imageSize(0))/rectangle.size()) + ->use(); + + input->bind(DistanceFieldShader::TextureLayer); + + Mesh mesh; + mesh.setPrimitive(Mesh::Primitive::Triangles) + ->setVertexCount(3) + ->draw(); +} + +}} diff --git a/src/TextureTools/DistanceField.h b/src/TextureTools/DistanceField.h new file mode 100644 index 000000000..fe107020d --- /dev/null +++ b/src/TextureTools/DistanceField.h @@ -0,0 +1,65 @@ +#ifndef Magnum_TextureTools_DistanceField_h +#define Magnum_TextureTools_DistanceField_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::TextureTools::distanceField() + */ + +#include "Magnum.h" + +#include "TextureTools/magnumTextureToolsVisibility.h" + +namespace Magnum { namespace TextureTools { + +/** +@brief Create signed distance field +@param input Input texture +@param output Output texture +@param rectangle Rectangle in output texture where to render +@param radius Max lookup radius in input texture + +Converts binary image (stored in red channel of @p input) to signed distance +field (stored in red channel in @p rectangle of @p output). The purpose of this +function is to convert high-resolution binary image (such as vector artwork or +font glyphs) to low-resolution grayscale image. The image will then occupy much +less memory and can be scaled without aliasing issues. Additionally it provides +foundation for features like outlining, glow or drop shadow essentialy for free. + +For each pixel inside @p rectangle the algorithm looks at corresponding pixel in +@p input and tries to find nearest pixel of opposite color in area given by +@p radius. Signed distance between the points is then saved as value of given +pixel in @p output. Value of `0` means that the pixel was originally colored +white and nearest black pixel is farther than @p radius, value of `1` means that +the pixel was originally black and nearest white pixel is farther than +@p radius. Values around `0.5` are around edges. + +The resulting texture can be used with bilinear filtering. It can be converted +back to binary form in shader using e.g. GLSL `smoothstep()` function with step +around `0.5` to create antialiased edges. Or you can exploit the distance field +features to create many other effects. + +Based on: *Chris Green - Improved Alpha-Tested Magnification for Vector Textures +and Special Effects, SIGGRAPH 2007, +http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf* + +@attention This is GPU-only implementation, so it expects active context. +*/ +void MAGNUM_TEXTURETOOLS_EXPORT distanceField(Texture2D* input, Texture2D* output, const Rectanglei& rectangle, const Int radius); + +}} + +#endif diff --git a/src/TextureTools/DistanceFieldShader.frag b/src/TextureTools/DistanceFieldShader.frag new file mode 100644 index 000000000..e47f0447f --- /dev/null +++ b/src/TextureTools/DistanceFieldShader.frag @@ -0,0 +1,59 @@ +layout(location = 0) uniform int radius; +layout(location = 1) uniform vec2 scaling; +layout(binding = 8) uniform sampler2D texture; + +layout(pixel_center_integer) in vec4 gl_FragCoord; + +out float value; + +ivec2 rotate(const ivec2 vec) { + return ivec2(-vec.y, vec.x); +} + +bool hasValue(const ivec2 position, const ivec2 offset) { + return texelFetch(texture, position+offset, 0).r > 0.5; +} + +void main() { + const ivec2 position = ivec2(gl_FragCoord.xy*scaling); + + /* If pixel at the position is inside (1), we are looking for nearest pixel + outside and the value will be positive (> 0.5). If it is outside (0), we + are looking for nearest pixel inside and the value will be negative + (< 0.5). */ + const bool isInside = hasValue(position, ivec2(0, 0)); + const float sign = isInside ? 1.0 : -1.0; + + /* Minimal found distance is just out of the radius (i.e. infinity) */ + float minDistanceSquared = float((radius+1)*(radius+1)); + + /* Go in circles around the point and find nearest value */ + int radiusLimit = radius; + for(int i = 1; i <= radiusLimit; ++i) { + for(int j = 0, jmax = i*2; j != jmax; ++j) { + const ivec2 offset = {-i+j, i}; + + /* If any of the four values is opposite of what is on the pixel, + we found nearest value */ + if(hasValue(position, offset) == !isInside || + hasValue(position, rotate(offset)) == !isInside || + hasValue(position, rotate(rotate(offset))) == !isInside || + hasValue(position, rotate(rotate(rotate(offset)))) == !isInside) { + const float distanceSquared = dot(vec2(offset), vec2(offset)); + + /* Set smaller distance, if found, or continue with lookup for + smaller */ + if(minDistanceSquared < distanceSquared) continue; + else minDistanceSquared = distanceSquared; + + /* Set radius limit to max radius which can contain smaller + value, e.g. for distance 3.5 we can find smaller value even + in radius 3 */ + radiusLimit = min(radius, int(floor(length(vec2(offset))))); + } + } + } + + /* Final signed distance, normalized from [-radius-1, radius+1] to [0, 1] */ + value = sign*sqrt(minDistanceSquared)/float(radius*2+2)+0.5; +} diff --git a/src/TextureTools/DistanceFieldShader.vert b/src/TextureTools/DistanceFieldShader.vert new file mode 100644 index 000000000..325b2e733 --- /dev/null +++ b/src/TextureTools/DistanceFieldShader.vert @@ -0,0 +1,4 @@ +void main() { + gl_Position = vec4((gl_VertexID == 2) ? 3.0 : -1.0, + (gl_VertexID == 1) ? -3.0 : 1.0, 0.0, 1.0); +} From 79d29ea947e71692c41aa5695b7bb13c1ba18d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Mar 2013 23:42:04 +0100 Subject: [PATCH 493/567] TextureTools: proper function name in assert. --- src/TextureTools/Atlas.cpp | 6 +++--- src/TextureTools/Test/AtlasTest.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TextureTools/Atlas.cpp b/src/TextureTools/Atlas.cpp index 2963515e6..e5ece9e47 100644 --- a/src/TextureTools/Atlas.cpp +++ b/src/TextureTools/Atlas.cpp @@ -33,9 +33,9 @@ std::vector atlas(const Vector2i& atlasSize, const std::vector Date: Sun, 3 Mar 2013 00:00:57 +0100 Subject: [PATCH 494/567] A little bit of const fascism. --- src/Text/Font.cpp | 2 +- src/TextureTools/Atlas.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 0ee3f4bd5..c502be3ae 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -89,7 +89,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { } /* Create texture atlas */ - std::vector charPositions = TextureTools::atlas(atlasSize, charSizes); + const std::vector charPositions = TextureTools::atlas(atlasSize, charSizes); /* Render all characters to the atlas and create character map */ glyphs.reserve(charPositions.size()); diff --git a/src/TextureTools/Atlas.cpp b/src/TextureTools/Atlas.cpp index e5ece9e47..101123986 100644 --- a/src/TextureTools/Atlas.cpp +++ b/src/TextureTools/Atlas.cpp @@ -31,7 +31,7 @@ std::vector atlas(const Vector2i& atlasSize, const std::vector atlas; /* Columns and rows */ - Vector2i gridSize = atlasSize/maxSize; + const Vector2i gridSize = atlasSize/maxSize; if(std::size_t(gridSize.product()) < sizes.size()) { Error() << "TextureTools::atlas(): requested atlas size" << atlasSize << "is too small to fit" << sizes.size() << maxSize From a9f62e3f1cc34e78d17e44c259dc07a0ced0f8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 01:02:14 +0100 Subject: [PATCH 495/567] TextureTools: support padding in atlas(). --- src/TextureTools/Atlas.cpp | 9 +++++---- src/TextureTools/Atlas.h | 8 +++++++- src/TextureTools/Test/AtlasTest.cpp | 24 ++++++++++++++++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/TextureTools/Atlas.cpp b/src/TextureTools/Atlas.cpp index 101123986..2d4b87b30 100644 --- a/src/TextureTools/Atlas.cpp +++ b/src/TextureTools/Atlas.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace TextureTools { -std::vector atlas(const Vector2i& atlasSize, const std::vector& sizes) { +std::vector atlas(const Vector2i& atlasSize, const std::vector& sizes, const Vector2i& padding) { if(sizes.empty()) return {}; /* Size of largest texture */ @@ -31,10 +31,11 @@ std::vector atlas(const Vector2i& atlasSize, const std::vector atlas; /* Columns and rows */ - const Vector2i gridSize = atlasSize/maxSize; + const Vector2i paddedSize = maxSize+2*padding; + const Vector2i gridSize = atlasSize/paddedSize; if(std::size_t(gridSize.product()) < sizes.size()) { Error() << "TextureTools::atlas(): requested atlas size" << atlasSize - << "is too small to fit" << sizes.size() << maxSize + << "is too small to fit" << sizes.size() << paddedSize << "textures. Generated atlas will be empty."; return atlas; } @@ -43,7 +44,7 @@ std::vector atlas(const Vector2i& atlasSize, const std::vector +#include "Math/Vector2.h" #include "Magnum.h" #include "magnumTextureToolsVisibility.h" @@ -31,11 +32,16 @@ namespace Magnum { namespace TextureTools { @brief Pack textures into texture atlas @param atlasSize Size of resulting atlas @param sizes Sizes of all textures in the atlas +@param padding Padding around each texture Packs many small textures into one larger. If the textures cannot be packed into required size, empty vector is returned. + +Padding is added twice to each size and the atlas is laid out so the padding +don't overlap. Returned sizes are the same as original sizes, i.e. without the +padding. */ -std::vector MAGNUM_TEXTURETOOLS_EXPORT atlas(const Vector2i& atlasSize, const std::vector& sizes); +std::vector MAGNUM_TEXTURETOOLS_EXPORT atlas(const Vector2i& atlasSize, const std::vector& sizes, const Vector2i& padding = Vector2i()); }} diff --git a/src/TextureTools/Test/AtlasTest.cpp b/src/TextureTools/Test/AtlasTest.cpp index d45734b80..9525f1a0f 100644 --- a/src/TextureTools/Test/AtlasTest.cpp +++ b/src/TextureTools/Test/AtlasTest.cpp @@ -26,12 +26,14 @@ class AtlasTest: public Corrade::TestSuite::Tester { explicit AtlasTest(); void create(); + void createPadding(); void createEmpty(); void createTooSmall(); }; AtlasTest::AtlasTest() { addTests(&AtlasTest::create, + &AtlasTest::createPadding, &AtlasTest::createEmpty, &AtlasTest::createTooSmall); } @@ -50,6 +52,20 @@ void AtlasTest::create() { Rectanglei::fromSize({0, 25}, {23, 25})})); } +void AtlasTest::createPadding() { + std::vector atlas = TextureTools::atlas({64, 64}, { + {8, 16}, + {28, 13}, + {19, 23} + }, {2, 1}); + + CORRADE_COMPARE(atlas.size(), 3); + CORRADE_COMPARE(atlas, (std::vector{ + Rectanglei::fromSize({2, 1}, {8, 16}), + Rectanglei::fromSize({34, 1}, {28, 13}), + Rectanglei::fromSize({2, 26}, {19, 23})})); +} + void AtlasTest::createEmpty() { std::vector atlas = TextureTools::atlas({}, {}); CORRADE_VERIFY(atlas.empty()); @@ -60,10 +76,10 @@ void AtlasTest::createTooSmall() { Error::setOutput(&o); std::vector atlas = TextureTools::atlas({64, 32}, { - {12, 18}, - {25, 15}, - {23, 31} - }); + {8, 16}, + {21, 13}, + {19, 29} + }, {2, 1}); CORRADE_VERIFY(atlas.empty()); CORRADE_COMPARE(o.str(), "TextureTools::atlas(): requested atlas size Vector(64, 32) is too small to fit 3 Vector(25, 31) textures. Generated atlas will be empty.\n"); } From babc850102d49a26bc4905caf1307f78bf8e5db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 01:02:50 +0100 Subject: [PATCH 496/567] Text: minor code cleanup. --- src/Text/Font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index c502be3ae..95df89380 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -85,7 +85,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { charSizes.reserve(charIndices.size()); for(FT_UInt c: charIndices) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(_ftFont, c, FT_LOAD_DEFAULT) == 0); - charSizes.push_back((Vector2i(_ftFont->glyph->metrics.width, _ftFont->glyph->metrics.height))/64); + charSizes.push_back(Vector2i(_ftFont->glyph->metrics.width, _ftFont->glyph->metrics.height)/64); } /* Create texture atlas */ From 12f719f177374c8f6141e3ea2b5685500c6338a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 01:06:18 +0100 Subject: [PATCH 497/567] Text: prerendering Font for use with distance-field rendering. Currently there is no builtin shader capable of it, will come later. --- src/Text/Font.cpp | 39 ++++++++++++++++++++++++++++++--------- src/Text/Font.h | 16 ++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 95df89380..77b3b99ef 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -26,6 +26,7 @@ #include "Extensions.h" #include "Image.h" #include "TextureTools/Atlas.h" +#include "TextureTools/DistanceField.h" namespace Magnum { namespace Text { @@ -61,7 +62,7 @@ void Font::finishConstruction() { ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); } -void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { +void Font::prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output) { glyphs.clear(); /** @bug Crash when atlas is too small */ @@ -81,6 +82,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end()); /* Sizes of all characters */ + const Vector2i padding = Vector2i(radius); std::vector charSizes; charSizes.reserve(charIndices.size()); for(FT_UInt c: charIndices) { @@ -89,7 +91,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { } /* Create texture atlas */ - const std::vector charPositions = TextureTools::atlas(atlasSize, charSizes); + const std::vector charPositions = TextureTools::atlas(atlasSize, charSizes, padding); /* Render all characters to the atlas and create character map */ glyphs.reserve(charPositions.size()); @@ -97,7 +99,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { Image2D image(atlasSize, Image2D::Format::Red, Image2D::Type::UnsignedByte, pixmap); for(std::size_t i = 0; i != charPositions.size(); ++i) { /* Load and render glyph */ - /** @todo B&W only */ + /** @todo B&W only if radius != 0 */ FT_GlyphSlot glyph = _ftFont->glyph; CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(_ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0); CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0); @@ -112,21 +114,40 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { /* Save character texture position and texture coordinates for given character index */ CORRADE_INTERNAL_ASSERT_OUTPUT(glyphs.insert({charIndices[i], std::make_tuple( - Rectangle::fromSize(Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height())/_size, - Vector2(charPositions[i].size())/_size), - Rectangle(Vector2(charPositions[i].bottomLeft())/atlasSize, - Vector2(charPositions[i].topRight())/atlasSize) + Rectangle::fromSize((Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height()) - Vector2(radius))/_size, + Vector2(charPositions[i].size() + 2*padding)/_size), + Rectangle(Vector2(charPositions[i].bottomLeft() - padding)/atlasSize, + Vector2(charPositions[i].topRight() + padding)/atlasSize) )}).second); } /* Set texture data */ #ifndef MAGNUM_TARGET_GLES - _texture.setImage(0, Texture2D::InternalFormat::R8, &image); + output->setImage(0, Texture2D::InternalFormat::R8, &image); #else - _texture.setImage(0, Texture2D::InternalFormat::Red, &image); + output->setImage(0, Texture2D::InternalFormat::Red, &image); #endif } +void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { + prerenderInternal(characters, atlasSize, 0, &_texture); +} + +void Font::prerenderDistanceField(const std::string& characters, const Vector2i& atlasSize, const Vector2i& distanceFieldAtlasSize, Int radius) { + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_storage); + + /* Render input texture */ + Texture2D input; + input.setWrapping(Texture2D::Wrapping::ClampToEdge) + ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) + ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); + prerenderInternal(characters, atlasSize, radius, &input); + + /* Create distance field from input texture */ + _texture.setStorage(1, Texture2D::InternalFormat::R8, distanceFieldAtlasSize); + TextureTools::distanceField(&input, &_texture, Rectanglei::fromSize({}, distanceFieldAtlasSize), radius); +} + void Font::destroy() { if(!_ftFont) return; diff --git a/src/Text/Font.h b/src/Text/Font.h index 247e003d5..6745ddf90 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -96,6 +96,21 @@ class MAGNUM_TEXT_EXPORT Font { */ void prerender(const std::string& characters, const Vector2i& atlasSize); + /** + * @brief Prerender given character set for use with distance-field rendering + * @param characters UTF-8 characters to render + * @param sourceAtlasSize Size of distance field source atlas + * @param atlasSize Size of resulting atlas + * @param radius Max lookup radius for distance-field creation + * + * Creates new atlas with prerendered characters, replacing the + * previous one (if any). See TextureTools::distanceField() for more + * information. + * @attention @p sourceAtlasSize must be large enough to contain all + * rendered glyphs with padding given by @p radius. + */ + void prerenderDistanceField(const std::string& characters, const Vector2i& atlasSize, const Vector2i& distanceFieldAtlasSize, Int radius); + ~Font(); /** @brief Move constructor */ @@ -133,6 +148,7 @@ class MAGNUM_TEXT_EXPORT Font { void MAGNUM_TEXT_LOCAL finishConstruction(); void MAGNUM_TEXT_LOCAL destroy(); void MAGNUM_TEXT_LOCAL move(); + void MAGNUM_TEXT_LOCAL prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output); std::unordered_map> glyphs; Texture2D _texture; From 7a99a4b32614eeb46799b4bd77fc0a8adb3acf46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 01:12:26 +0100 Subject: [PATCH 498/567] Shortened (texture) filtering types to comply with OpenGL naming. The documentation already used them, so why complicate things further. --- src/AbstractFramebuffer.h | 9 ++++----- src/AbstractTexture.cpp | 14 +++++++------- src/AbstractTexture.h | 14 +++++++------- src/CubeMapTexture.h | 2 +- src/CubeMapTextureArray.h | 2 +- src/Text/Font.cpp | 8 ++++---- src/Texture.h | 2 +- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 3d1d1b76a..a7f5b8291 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -97,8 +97,8 @@ class MAGNUM_EXPORT AbstractFramebuffer { * @see blit() */ enum class BlitFilter: GLenum { - NearestNeighbor = GL_NEAREST, /**< Nearest neighbor filtering */ - LinearInterpolation = GL_LINEAR /**< Linear interpolation filtering */ + Nearest = GL_NEAREST, /**< Nearest neighbor filtering */ + Linear = GL_LINEAR /**< Linear interpolation filtering */ }; /** @@ -166,14 +166,13 @@ class MAGNUM_EXPORT AbstractFramebuffer { * Convenience alternative to above function when source rectangle is * the same as destination rectangle. As the image is copied * pixel-by-pixel, no interpolation is needed and thus - * @ref BlitFilter "BlitFilter::NearestNeighbor" filtering is used by - * default. + * @ref BlitFilter "BlitFilter::Nearest" filtering is used by default. * @see @fn_gl{BlitFramebuffer} * @requires_gl30 %Extension @extension{EXT,framebuffer_blit} * @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} */ inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& rectangle, BlitMask mask) { - blit(source, destination, rectangle, rectangle, mask, BlitFilter::NearestNeighbor); + blit(source, destination, rectangle, rectangle, mask, BlitFilter::Nearest); } explicit AbstractFramebuffer() = default; diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 440b3820d..aa2a497ab 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -73,12 +73,12 @@ AbstractTexture::InvalidateSubImplementation AbstractTexture::invalidateSubImple thus testing only on AbstractTexture. */ #define filter_or(filter, mipmap) \ (static_cast(AbstractTexture::Filter::filter)|static_cast(AbstractTexture::Mipmap::mipmap)) -static_assert((filter_or(NearestNeighbor, BaseLevel) == GL_NEAREST) && - (filter_or(NearestNeighbor, NearestLevel) == GL_NEAREST_MIPMAP_NEAREST) && - (filter_or(NearestNeighbor, LinearInterpolation) == GL_NEAREST_MIPMAP_LINEAR) && - (filter_or(LinearInterpolation, BaseLevel) == GL_LINEAR) && - (filter_or(LinearInterpolation, NearestLevel) == GL_LINEAR_MIPMAP_NEAREST) && - (filter_or(LinearInterpolation, LinearInterpolation) == GL_LINEAR_MIPMAP_LINEAR), +static_assert((filter_or(Nearest, Base) == GL_NEAREST) && + (filter_or(Nearest, Nearest) == GL_NEAREST_MIPMAP_NEAREST) && + (filter_or(Nearest, Linear) == GL_NEAREST_MIPMAP_LINEAR) && + (filter_or(Linear, Base) == GL_LINEAR) && + (filter_or(Linear, Nearest) == GL_LINEAR_MIPMAP_NEAREST) && + (filter_or(Linear, Linear) == GL_LINEAR_MIPMAP_LINEAR), "Unsupported constants for GL texture filtering"); #undef filter_or #endif @@ -159,7 +159,7 @@ void AbstractTexture::bindImplementationDSA(GLint layer) { AbstractTexture* AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::BaseLevel, "AbstractTexture: rectangle textures cannot have mipmaps", this); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Mipmap::Base, "AbstractTexture: rectangle textures cannot have mipmaps", this); #endif (this->*parameteriImplementation)(GL_TEXTURE_MIN_FILTER, diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index b1a6095ed..f979af4b2 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -83,7 +83,7 @@ class MAGNUM_EXPORT AbstractTexture { * @see setMagnificationFilter() and setMinificationFilter() */ enum class Filter: GLint { - NearestNeighbor = GL_NEAREST, /**< Nearest neighbor filtering */ + Nearest = GL_NEAREST, /**< Nearest neighbor filtering */ /** * Linear interpolation filtering. @@ -94,7 +94,7 @@ class MAGNUM_EXPORT AbstractTexture { * / @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::Float" * in OpenGL ES 2.0. */ - LinearInterpolation = GL_LINEAR + Linear = GL_LINEAR }; /** @@ -103,12 +103,12 @@ class MAGNUM_EXPORT AbstractTexture { * @see setMinificationFilter() */ enum class Mipmap: GLint { - BaseLevel = GL_NEAREST & ~GL_NEAREST, /**< Select base mip level */ + Base = GL_NEAREST & ~GL_NEAREST, /**< Select base mip level */ /** * Select nearest mip level. **Unavailable on rectangle textures.** */ - NearestLevel = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST, + Nearest = GL_NEAREST_MIPMAP_NEAREST & ~GL_NEAREST, /** * Linear interpolation of nearest mip levels. **Unavailable on @@ -120,7 +120,7 @@ class MAGNUM_EXPORT AbstractTexture { * / @ref Magnum::AbstractTexture::InternalFormat "InternalFormat::Float" * in OpenGL ES 2.0. */ - LinearInterpolation = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST + Linear = GL_NEAREST_MIPMAP_LINEAR & ~GL_NEAREST }; /** @@ -1043,7 +1043,7 @@ class MAGNUM_EXPORT AbstractTexture { * Sets filter used when the object pixel size is smaller than the * texture size. If @extension{EXT,direct_state_access} is not * available, the texture is bound to some layer before the operation. - * Initial value is (@ref AbstractTexture::Filter "Filter::NearestNeighbor", + * Initial value is (@ref AbstractTexture::Filter "Filter::Nearest", * @ref AbstractTexture::Mipmap "Mipmap::Linear"). * @attention For rectangle textures only some modes are supported, * see @ref AbstractTexture::Filter "Filter" and @@ -1053,7 +1053,7 @@ class MAGNUM_EXPORT AbstractTexture { * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_MIN_FILTER} */ - AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel); + AbstractTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base); /** * @brief Set magnification filter diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 59c3d68c8..bbb54814d 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -184,7 +184,7 @@ class CubeMapTexture: public AbstractTexture { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - inline CubeMapTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + inline CubeMapTexture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base) { AbstractTexture::setMinificationFilter(filter, mipmap); return this; } diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 2a6ffb35c..a7dad46cd 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -200,7 +200,7 @@ class CubeMapTextureArray: public AbstractTexture { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - inline CubeMapTextureArray* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + inline CubeMapTextureArray* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base) { AbstractTexture::setMinificationFilter(filter, mipmap); return this; } diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 77b3b99ef..9f3cd9c61 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -58,8 +58,8 @@ void Font::finishConstruction() { /* Set up the texture */ _texture.setWrapping(Texture2D::Wrapping::ClampToEdge) - ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) - ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); + ->setMinificationFilter(Texture2D::Filter::Linear) + ->setMagnificationFilter(Texture2D::Filter::Linear); } void Font::prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output) { @@ -139,8 +139,8 @@ void Font::prerenderDistanceField(const std::string& characters, const Vector2i& /* Render input texture */ Texture2D input; input.setWrapping(Texture2D::Wrapping::ClampToEdge) - ->setMinificationFilter(Texture2D::Filter::LinearInterpolation) - ->setMagnificationFilter(Texture2D::Filter::LinearInterpolation); + ->setMinificationFilter(Texture2D::Filter::Linear) + ->setMagnificationFilter(Texture2D::Filter::Linear); prerenderInternal(characters, atlasSize, radius, &input); /* Create distance field from input texture */ diff --git a/src/Texture.h b/src/Texture.h index 6e946227c..05e706623 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -314,7 +314,7 @@ template class Texture: public AbstractTexture { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - inline Texture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::BaseLevel) { + inline Texture* setMinificationFilter(Filter filter, Mipmap mipmap = Mipmap::Base) { AbstractTexture::setMinificationFilter(filter, mipmap); return this; } From 31582ce2f8377ac3ec4d6800fb12d6c7939d5f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 01:28:08 +0100 Subject: [PATCH 499/567] Todo++ --- src/Math/DualQuaternion.h | 2 ++ src/Platform/AbstractContextHandler.h | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 6d563cc3e..c6f82a1e4 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -53,6 +53,8 @@ template class DualQuaternion: public Dual> { return {Quaternion::rotation(angle, normalizedAxis), {{}, T(0)}}; } + /** @todo Rotation about axis with arbitrary origin, screw motion */ + /** * @brief Translation dual quaternion * @param vector Translation vector diff --git a/src/Platform/AbstractContextHandler.h b/src/Platform/AbstractContextHandler.h index fd342ca7c..9c6376342 100644 --- a/src/Platform/AbstractContextHandler.h +++ b/src/Platform/AbstractContextHandler.h @@ -23,7 +23,11 @@ namespace Magnum { namespace Platform { -/** @brief Base for OpenGL context handlers */ +/** +@brief Base for OpenGL context handlers + +@todo GLX_MESA_query_renderer, EGL_MESA_query_renderer +*/ template class AbstractContextHandler { public: /** From 91f0d302c2ac9d8c9724cb03b79209d8f8dd8e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 17:31:53 +0100 Subject: [PATCH 500/567] Shaders: renamed TextShader to VectorShader. The code can be used for drawing any vector art, not only font glyphs. --- ...actTextShader.h => AbstractVectorShader.h} | 22 ++++++------ src/Shaders/CMakeLists.txt | 8 ++--- src/Shaders/Shaders.h | 12 +++---- .../{TextShader.cpp => VectorShader.cpp} | 30 ++++++++-------- .../{TextShader.frag => VectorShader.frag} | 6 ++-- src/Shaders/{TextShader.h => VectorShader.h} | 34 +++++++++---------- ...{TextShader2D.vert => VectorShader2D.vert} | 0 ...{TextShader3D.vert => VectorShader3D.vert} | 0 src/Text/TextRenderer.cpp | 10 +++--- src/Text/TextRenderer.h | 12 +++---- 10 files changed, 67 insertions(+), 67 deletions(-) rename src/Shaders/{AbstractTextShader.h => AbstractVectorShader.h} (63%) rename src/Shaders/{TextShader.cpp => VectorShader.cpp} (63%) rename src/Shaders/{TextShader.frag => VectorShader.frag} (69%) rename src/Shaders/{TextShader.h => VectorShader.h} (51%) rename src/Shaders/{TextShader2D.vert => VectorShader2D.vert} (100%) rename src/Shaders/{TextShader3D.vert => VectorShader3D.vert} (100%) diff --git a/src/Shaders/AbstractTextShader.h b/src/Shaders/AbstractVectorShader.h similarity index 63% rename from src/Shaders/AbstractTextShader.h rename to src/Shaders/AbstractVectorShader.h index e1fe529af..98c68fdb2 100644 --- a/src/Shaders/AbstractTextShader.h +++ b/src/Shaders/AbstractVectorShader.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Shaders_AbstractTextShader_h -#define Magnum_Shaders_AbstractTextShader_h +#ifndef Magnum_Shaders_AbstractVectorShader_h +#define Magnum_Shaders_AbstractVectorShader_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Shaders::AbstractTextShader + * @brief Class Magnum::Shaders::AbstractVectorShader */ #include "AbstractShaderProgram.h" @@ -26,11 +26,11 @@ namespace Magnum { namespace Shaders { /** -@brief Base for text shaders +@brief Base for vector shaders -@see AbstractTextShader2D, AbstractTextShader3D +@see AbstractVectorShader2D, AbstractVectorShader3D */ -template class AbstractTextShader: public AbstractShaderProgram { +template class AbstractVectorShader: public AbstractShaderProgram { public: /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::VectorType> Position; @@ -39,19 +39,19 @@ template class AbstractTextShader: public AbstractShader typedef Attribute<1, Vector2> TextureCoordinates; enum: GLint { - FontTextureLayer = 16 /**< Layer for font texture */ + VectorTextureLayer = 16 /**< Layer for vector texture */ }; - ~AbstractTextShader() = 0; + ~AbstractVectorShader() = 0; }; -template inline AbstractTextShader::~AbstractTextShader() {} +template inline AbstractVectorShader::~AbstractVectorShader() {} /** @brief Base for two-dimensional text shaders */ -typedef AbstractTextShader<2> AbstractTextShader2D; +typedef AbstractVectorShader<2> AbstractVectorShader2D; /** @brief Base for three-dimensional text shader */ -typedef AbstractTextShader<3> AbstractTextShader3D; +typedef AbstractVectorShader<3> AbstractVectorShader3D; }} diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index f4591c4fe..e2cd2b050 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,21 +1,21 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders FlatShader2D.vert FlatShader3D.vert FlatShader.frag PhongShader.vert PhongShader.frag - TextShader2D.vert TextShader3D.vert TextShader.frag + VectorShader2D.vert VectorShader3D.vert VectorShader.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) set(MagnumShaders_SRCS FlatShader.cpp PhongShader.cpp - TextShader.cpp + VectorShader.cpp VertexColorShader.cpp ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS - AbstractTextShader.h + AbstractVectorShader.h FlatShader.h PhongShader.h Shaders.h - TextShader.h + VectorShader.h VertexColorShader.h magnumShadersVisibility.h) diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index b4733ffd5..d068b588e 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -25,9 +25,9 @@ namespace Magnum { namespace Shaders { /** @todoc remove when doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractTextShader; -typedef AbstractTextShader<2> AbstractTextShader2D; -typedef AbstractTextShader<3> AbstractTextShader3D; +template class AbstractVectorShader; +typedef AbstractVectorShader<2> AbstractVectorShader2D; +typedef AbstractVectorShader<3> AbstractVectorShader3D; template class FlatShader; typedef FlatShader<2> FlatShader2D; @@ -35,9 +35,9 @@ typedef FlatShader<3> FlatShader3D; class PhongShader; -template class TextShader; -typedef TextShader<2> TextShader2D; -typedef TextShader<3> TextShader3D; +template class VectorShader; +typedef VectorShader<2> VectorShader2D; +typedef VectorShader<3> VectorShader3D; template class VertexColorShader; typedef VertexColorShader<2> VertexColorShader2D; diff --git a/src/Shaders/TextShader.cpp b/src/Shaders/VectorShader.cpp similarity index 63% rename from src/Shaders/TextShader.cpp rename to src/Shaders/VectorShader.cpp index 37519d7ae..b10975b4d 100644 --- a/src/Shaders/TextShader.cpp +++ b/src/Shaders/VectorShader.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "TextShader.h" +#include "VectorShader.h" #include @@ -25,11 +25,11 @@ namespace Magnum { namespace Shaders { namespace { template constexpr const char* vertexShaderName(); - template<> constexpr const char* vertexShaderName<2>() { return "TextShader2D.vert"; } - template<> constexpr const char* vertexShaderName<3>() { return "TextShader3D.vert"; } + template<> constexpr const char* vertexShaderName<2>() { return "VectorShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "VectorShader3D.vert"; } } -template TextShader::TextShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { +template VectorShader::VectorShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { Corrade::Utility::Resource rs("MagnumShaders"); #ifndef MAGNUM_TARGET_GLES @@ -41,12 +41,12 @@ template TextShader::TextShader(): transform Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); vertexShader.addSource(rs.get(vertexShaderName())); - AbstractTextShader::attachShader(vertexShader); + AbstractVectorShader::attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); - fragmentShader.addSource(rs.get("TextShader.frag")); - AbstractTextShader::attachShader(fragmentShader); + fragmentShader.addSource(rs.get("VectorShader.frag")); + AbstractVectorShader::attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || @@ -54,28 +54,28 @@ template TextShader::TextShader(): transform #else if(!Context::current()->isVersionSupported(Version::GLES300)) { #endif - AbstractTextShader::bindAttributeLocation(AbstractTextShader::Position::Location, "position"); - AbstractTextShader::bindAttributeLocation(AbstractTextShader::TextureCoordinates::Location, "textureCoordinates"); + AbstractVectorShader::bindAttributeLocation(AbstractVectorShader::Position::Location, "position"); + AbstractVectorShader::bindAttributeLocation(AbstractVectorShader::TextureCoordinates::Location, "textureCoordinates"); } - AbstractTextShader::link(); + AbstractVectorShader::link(); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) { #else { #endif - transformationProjectionMatrixUniform = AbstractTextShader::uniformLocation("transformationProjectionMatrix"); - colorUniform = AbstractTextShader::uniformLocation("color"); + transformationProjectionMatrixUniform = AbstractVectorShader::uniformLocation("transformationProjectionMatrix"); + colorUniform = AbstractVectorShader::uniformLocation("color"); } #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) - AbstractTextShader::setUniform(AbstractTextShader::uniformLocation("fontTexture"), AbstractTextShader::FontTextureLayer); + AbstractVectorShader::setUniform(AbstractVectorShader::uniformLocation("vectorTexture"), AbstractVectorShader::VectorTextureLayer); #endif } -template class TextShader<2>; -template class TextShader<3>; +template class VectorShader<2>; +template class VectorShader<3>; }} diff --git a/src/Shaders/TextShader.frag b/src/Shaders/VectorShader.frag similarity index 69% rename from src/Shaders/TextShader.frag rename to src/Shaders/VectorShader.frag index fdc02e682..d763ec4cc 100644 --- a/src/Shaders/TextShader.frag +++ b/src/Shaders/VectorShader.frag @@ -10,9 +10,9 @@ uniform lowp vec3 color; #endif #ifdef EXPLICIT_TEXTURE_LAYER -layout(binding = 16) uniform sampler2D fontTexture; +layout(binding = 16) uniform sampler2D vectorTexture; #else -uniform lowp sampler2D fontTexture; +uniform lowp sampler2D vectorTexture; #endif in vec2 fragmentTextureCoordinates; @@ -22,6 +22,6 @@ out vec4 fragmentColor; #endif void main() { - lowp float intensity = texture(fontTexture, fragmentTextureCoordinates).r; + lowp float intensity = texture(vectorTexture, fragmentTextureCoordinates).r; fragmentColor = vec4(intensity*color, intensity); } diff --git a/src/Shaders/TextShader.h b/src/Shaders/VectorShader.h similarity index 51% rename from src/Shaders/TextShader.h rename to src/Shaders/VectorShader.h index 564581506..642b8c7fb 100644 --- a/src/Shaders/TextShader.h +++ b/src/Shaders/VectorShader.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Shaders_TextShader_h -#define Magnum_Shaders_TextShader_h +#ifndef Magnum_Shaders_VectorShader_h +#define Magnum_Shaders_VectorShader_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,35 +16,35 @@ */ /** @file - * @brief Class Magnum::Shaders::TextShader + * @brief Class Magnum::Shaders::VectorShader */ #include "Math/Matrix3.h" #include "Math/Matrix4.h" -#include "AbstractTextShader.h" +#include "AbstractVectorShader.h" #include "magnumShadersVisibility.h" namespace Magnum { namespace Shaders { /** -@brief %Text shader +@brief Vector shader -@see TextShader2D, TextShader3D +@see VectorShader2D, VectorShader3D */ -template class MAGNUM_SHADERS_EXPORT TextShader: public AbstractTextShader { +template class MAGNUM_SHADERS_EXPORT VectorShader: public AbstractVectorShader { public: - TextShader(); + VectorShader(); /** @brief Set transformation and projection matrix */ - inline TextShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { - AbstractTextShader::setUniform(transformationProjectionMatrixUniform, matrix); + inline VectorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + AbstractVectorShader::setUniform(transformationProjectionMatrixUniform, matrix); return this; } - /** @brief Set text color */ - inline TextShader* setColor(const Color3<>& color) { - AbstractTextShader::setUniform(colorUniform, color); + /** @brief Set fill color */ + inline VectorShader* setColor(const Color3<>& color) { + AbstractVectorShader::setUniform(colorUniform, color); return this; } @@ -53,11 +53,11 @@ template class MAGNUM_SHADERS_EXPORT TextShader: public colorUniform; }; -/** @brief Two-dimensional text shader */ -typedef TextShader<2> TextShader2D; +/** @brief Two-dimensional vector shader */ +typedef VectorShader<2> VectorShader2D; -/** @brief Three-dimensional text shader */ -typedef TextShader<3> TextShader3D; +/** @brief Three-dimensional vector shader */ +typedef VectorShader<3> VectorShader3D; }} diff --git a/src/Shaders/TextShader2D.vert b/src/Shaders/VectorShader2D.vert similarity index 100% rename from src/Shaders/TextShader2D.vert rename to src/Shaders/VectorShader2D.vert diff --git a/src/Shaders/TextShader3D.vert b/src/Shaders/VectorShader3D.vert similarity index 100% rename from src/Shaders/TextShader3D.vert rename to src/Shaders/VectorShader3D.vert diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index a77c318ce..806069b7f 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -27,7 +27,7 @@ #include "Extensions.h" #include "Mesh.h" #include "Swizzle.h" -#include "Shaders/AbstractTextShader.h" +#include "Shaders/AbstractVectorShader.h" #include "Text/Font.h" namespace Magnum { namespace Text { @@ -277,8 +277,8 @@ template std::tuple TextRenderersetIndexCount(indexCount) ->addInterleavedVertexBuffer(vertexBuffer, 0, - typename Shaders::AbstractTextShader::Position(), - typename Shaders::AbstractTextShader::TextureCoordinates()) + typename Shaders::AbstractVectorShader::Position(), + typename Shaders::AbstractVectorShader::TextureCoordinates()) ->setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); return std::make_tuple(std::move(mesh), rectangle); @@ -295,8 +295,8 @@ template TextRenderer::TextRenderer(Font& fo _mesh.setPrimitive(Mesh::Primitive::Triangles) ->addInterleavedVertexBuffer(&vertexBuffer, 0, - typename Shaders::AbstractTextShader::Position(), - typename Shaders::AbstractTextShader::TextureCoordinates()); + typename Shaders::AbstractVectorShader::Position(), + typename Shaders::AbstractVectorShader::TextureCoordinates()); } template void TextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) { diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index c8bfa689d..4fdb27f28 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -48,7 +48,7 @@ The text can be then drawn by configuring text shader, binding font texture and drawing the mesh: @code Text::Font font; -Shaders::TextShader2D shader; +Shaders::VectorShader2D shader; Buffer vertexBuffer, indexBuffer; Mesh mesh; @@ -61,7 +61,7 @@ std::tie(mesh, rectangle) = Text::TextRenderer2D::render(font, 0.15f, shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-rectangle.width()/2.0f)) ->setColor(Color3<>(1.0f)); ->use(); -font.texture()->bind(Shaders::TextShader2D::FontTextureLayer); +font.texture()->bind(Shaders::VectorShader2D::FontTextureLayer); mesh.draw(); @endcode See render(Font&, Float, const std::string&) and @@ -73,7 +73,7 @@ mutable texts (e.g. FPS counters, chat messages) there is another approach that doesn't recreate everything on each text change: @code Text::Font font; -Shaders::TextShader2D shader; +Shaders::VectorShader2D shader; // Initialize renderer and reserve memory for enough glyphs Text::TextRenderer2D renderer(font, 0.15f); @@ -86,7 +86,7 @@ renderer.render("Hello World Countdown: 10"); shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-renderer.rectangle().width()/2.0f)) ->setColor(Color3<>(1.0f)); ->use(); -font.texture()->bind(Shaders::TextShader2D::FontTextureLayer); +font.texture()->bind(Shaders::VectorShader2D::FontTextureLayer); renderer.mesh().draw(); @endcode @@ -96,7 +96,7 @@ Mutable text rendering requires @extension{ARB,map_buffer_range} (also part of OpenGL ES 3.0 or available as @es_extension{EXT,map_buffer_range} in ES 2.0) for asynchronous buffer updates. -@see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractTextShader +@see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractVectorShader */ template class MAGNUM_TEXT_EXPORT TextRenderer { public: @@ -120,7 +120,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * @param indexBuffer %Buffer where to store indices * @param usage Usage of vertex and index buffer * - * Returns mesh prepared for use with Shaders::AbstractTextShader + * Returns mesh prepared for use with Shaders::AbstractVectorShader * subclasses and rectangle spanning the rendered text. */ static std::tuple render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); From b6caae10b0caa0e0528a4091ff54dafb9a1cded4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 17:40:19 +0100 Subject: [PATCH 501/567] Shaders: vertex VectorShader is implementation independent. Renamed it to AbstractVectorShader. --- .../{VectorShader2D.vert => AbstractVectorShader2D.vert} | 0 .../{VectorShader3D.vert => AbstractVectorShader3D.vert} | 0 src/Shaders/CMakeLists.txt | 3 ++- src/Shaders/VectorShader.cpp | 4 ++-- 4 files changed, 4 insertions(+), 3 deletions(-) rename src/Shaders/{VectorShader2D.vert => AbstractVectorShader2D.vert} (100%) rename src/Shaders/{VectorShader3D.vert => AbstractVectorShader3D.vert} (100%) diff --git a/src/Shaders/VectorShader2D.vert b/src/Shaders/AbstractVectorShader2D.vert similarity index 100% rename from src/Shaders/VectorShader2D.vert rename to src/Shaders/AbstractVectorShader2D.vert diff --git a/src/Shaders/VectorShader3D.vert b/src/Shaders/AbstractVectorShader3D.vert similarity index 100% rename from src/Shaders/VectorShader3D.vert rename to src/Shaders/AbstractVectorShader3D.vert diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index e2cd2b050..f20f432c6 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,7 +1,8 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders + AbstractVectorShader2D.vert AbstractVectorShader3D.vert FlatShader2D.vert FlatShader3D.vert FlatShader.frag PhongShader.vert PhongShader.frag - VectorShader2D.vert VectorShader3D.vert VectorShader.frag + VectorShader.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) set(MagnumShaders_SRCS diff --git a/src/Shaders/VectorShader.cpp b/src/Shaders/VectorShader.cpp index b10975b4d..f3c563b59 100644 --- a/src/Shaders/VectorShader.cpp +++ b/src/Shaders/VectorShader.cpp @@ -25,8 +25,8 @@ namespace Magnum { namespace Shaders { namespace { template constexpr const char* vertexShaderName(); - template<> constexpr const char* vertexShaderName<2>() { return "VectorShader2D.vert"; } - template<> constexpr const char* vertexShaderName<3>() { return "VectorShader3D.vert"; } + template<> constexpr const char* vertexShaderName<2>() { return "AbstractVectorShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "AbstractVectorShader3D.vert"; } } template VectorShader::VectorShader(): transformationProjectionMatrixUniform(0), colorUniform(1) { From 5a374dd73ee5647305ed9cc30877106d0d4c9dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 17:44:25 +0100 Subject: [PATCH 502/567] Shaders: support alpha in VectorShader::setColor(). --- src/Shaders/VectorShader.frag | 6 +++--- src/Shaders/VectorShader.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Shaders/VectorShader.frag b/src/Shaders/VectorShader.frag index d763ec4cc..eb1238fb1 100644 --- a/src/Shaders/VectorShader.frag +++ b/src/Shaders/VectorShader.frag @@ -4,9 +4,9 @@ #endif #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 1) uniform vec3 color; +layout(location = 1) uniform vec4 color; #else -uniform lowp vec3 color; +uniform lowp vec4 color; #endif #ifdef EXPLICIT_TEXTURE_LAYER @@ -23,5 +23,5 @@ out vec4 fragmentColor; void main() { lowp float intensity = texture(vectorTexture, fragmentTextureCoordinates).r; - fragmentColor = vec4(intensity*color, intensity); + fragmentColor = intensity*color; } diff --git a/src/Shaders/VectorShader.h b/src/Shaders/VectorShader.h index 642b8c7fb..b116803fa 100644 --- a/src/Shaders/VectorShader.h +++ b/src/Shaders/VectorShader.h @@ -43,7 +43,7 @@ template class MAGNUM_SHADERS_EXPORT VectorShader: publi } /** @brief Set fill color */ - inline VectorShader* setColor(const Color3<>& color) { + inline VectorShader* setColor(const Color4<>& color) { AbstractVectorShader::setUniform(colorUniform, color); return this; } From 3c31519133d573b757e5b945384435f17e646386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 23:22:11 +0100 Subject: [PATCH 503/567] Shaders: cleanup of VectorShader. Using this-> for accessing parent class members breaks KDevelop autocompletion, using explicit class name instead (but the shorter one). --- src/Shaders/VectorShader.cpp | 16 ++++++++-------- src/Shaders/VectorShader.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Shaders/VectorShader.cpp b/src/Shaders/VectorShader.cpp index f3c563b59..da1706824 100644 --- a/src/Shaders/VectorShader.cpp +++ b/src/Shaders/VectorShader.cpp @@ -41,12 +41,12 @@ template VectorShader::VectorShader(): trans Shader vertexShader(v, Shader::Type::Vertex); vertexShader.addSource(rs.get("compatibility.glsl")); vertexShader.addSource(rs.get(vertexShaderName())); - AbstractVectorShader::attachShader(vertexShader); + AbstractShaderProgram::attachShader(vertexShader); Shader fragmentShader(v, Shader::Type::Fragment); fragmentShader.addSource(rs.get("compatibility.glsl")); fragmentShader.addSource(rs.get("VectorShader.frag")); - AbstractVectorShader::attachShader(fragmentShader); + AbstractShaderProgram::attachShader(fragmentShader); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported() || @@ -54,24 +54,24 @@ template VectorShader::VectorShader(): trans #else if(!Context::current()->isVersionSupported(Version::GLES300)) { #endif - AbstractVectorShader::bindAttributeLocation(AbstractVectorShader::Position::Location, "position"); - AbstractVectorShader::bindAttributeLocation(AbstractVectorShader::TextureCoordinates::Location, "textureCoordinates"); + AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader::Position::Location, "position"); + AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader::TextureCoordinates::Location, "textureCoordinates"); } - AbstractVectorShader::link(); + AbstractShaderProgram::link(); #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) { #else { #endif - transformationProjectionMatrixUniform = AbstractVectorShader::uniformLocation("transformationProjectionMatrix"); - colorUniform = AbstractVectorShader::uniformLocation("color"); + transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); + colorUniform = AbstractShaderProgram::uniformLocation("color"); } #ifndef MAGNUM_TARGET_GLES if(!Context::current()->isExtensionSupported()) - AbstractVectorShader::setUniform(AbstractVectorShader::uniformLocation("vectorTexture"), AbstractVectorShader::VectorTextureLayer); + AbstractShaderProgram::setUniform(AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVectorShader::VectorTextureLayer); #endif } diff --git a/src/Shaders/VectorShader.h b/src/Shaders/VectorShader.h index b116803fa..2c17989f2 100644 --- a/src/Shaders/VectorShader.h +++ b/src/Shaders/VectorShader.h @@ -38,13 +38,13 @@ template class MAGNUM_SHADERS_EXPORT VectorShader: publi /** @brief Set transformation and projection matrix */ inline VectorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { - AbstractVectorShader::setUniform(transformationProjectionMatrixUniform, matrix); + AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); return this; } /** @brief Set fill color */ inline VectorShader* setColor(const Color4<>& color) { - AbstractVectorShader::setUniform(colorUniform, color); + AbstractShaderProgram::setUniform(colorUniform, color); return this; } From e891bd9b31347c7282a72346ba1650dc3fa06c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 23:24:48 +0100 Subject: [PATCH 504/567] Shaders: use Int instead of GLint. Don't know how this only place got forgotten. --- src/Shaders/AbstractVectorShader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shaders/AbstractVectorShader.h b/src/Shaders/AbstractVectorShader.h index 98c68fdb2..fe2244434 100644 --- a/src/Shaders/AbstractVectorShader.h +++ b/src/Shaders/AbstractVectorShader.h @@ -38,7 +38,7 @@ template class AbstractVectorShader: public AbstractShad /** @brief Texture coordinates */ typedef Attribute<1, Vector2> TextureCoordinates; - enum: GLint { + enum: Int { VectorTextureLayer = 16 /**< Layer for vector texture */ }; From d256d7a0c426b0e4ef49a07481d2f081554bfdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 23:25:42 +0100 Subject: [PATCH 505/567] Shaders: missing virtual keyword. This was compiling?! It seems that I don't know more than I think. --- src/Shaders/AbstractVectorShader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shaders/AbstractVectorShader.h b/src/Shaders/AbstractVectorShader.h index fe2244434..e8c043fc7 100644 --- a/src/Shaders/AbstractVectorShader.h +++ b/src/Shaders/AbstractVectorShader.h @@ -42,7 +42,7 @@ template class AbstractVectorShader: public AbstractShad VectorTextureLayer = 16 /**< Layer for vector texture */ }; - ~AbstractVectorShader() = 0; + virtual ~AbstractVectorShader() = 0; }; template inline AbstractVectorShader::~AbstractVectorShader() {} From 549558b502b85f8bae1c75f5d2db2e1ed1c6c2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 23:26:43 +0100 Subject: [PATCH 506/567] Shaders: doc++ --- src/Shaders/AbstractVectorShader.h | 2 +- src/Shaders/VectorShader.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Shaders/AbstractVectorShader.h b/src/Shaders/AbstractVectorShader.h index e8c043fc7..b0ced8634 100644 --- a/src/Shaders/AbstractVectorShader.h +++ b/src/Shaders/AbstractVectorShader.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Shaders::AbstractVectorShader + * @brief Class Magnum::Shaders::AbstractVectorShader, typedef Magnum::Shaders::AbstractVectorShader2D, Magnum::Shaders::AbstractVectorShader3D */ #include "AbstractShaderProgram.h" diff --git a/src/Shaders/VectorShader.h b/src/Shaders/VectorShader.h index 2c17989f2..ccd177352 100644 --- a/src/Shaders/VectorShader.h +++ b/src/Shaders/VectorShader.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Shaders::VectorShader + * @brief Class Magnum::Shaders::VectorShader, typedef Magnum::Shaders::VectorShader2D, Magnum::Shaders::VectorShader3D */ #include "Math/Matrix3.h" @@ -36,13 +36,19 @@ template class MAGNUM_SHADERS_EXPORT VectorShader: publi public: VectorShader(); - /** @brief Set transformation and projection matrix */ + /** + * @brief Set transformation and projection matrix + * @return Pointer to self (for method chaining) + */ inline VectorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); return this; } - /** @brief Set fill color */ + /** + * @brief Set fill color + * @return Pointer to self (for method chaining) + */ inline VectorShader* setColor(const Color4<>& color) { AbstractShaderProgram::setUniform(colorUniform, color); return this; From 2d98dadb0ac1dae8bf0f60c8fa7b16a6709605e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 Mar 2013 23:37:24 +0100 Subject: [PATCH 507/567] Shaders: first DistanceFieldVectorShader implementation. Currently only fill and outline can be specified. Also crosslinked from documentation of VectorShader and TextureTools::distanceField(). --- src/Shaders/CMakeLists.txt | 4 +- src/Shaders/DistanceFieldVectorShader.cpp | 85 +++++++++++++++ src/Shaders/DistanceFieldVectorShader.frag | 49 +++++++++ src/Shaders/DistanceFieldVectorShader.h | 118 +++++++++++++++++++++ src/Shaders/Shaders.h | 5 + src/Shaders/VectorShader.h | 2 + src/TextureTools/DistanceField.h | 2 +- 7 files changed, 263 insertions(+), 2 deletions(-) create mode 100644 src/Shaders/DistanceFieldVectorShader.cpp create mode 100644 src/Shaders/DistanceFieldVectorShader.frag create mode 100644 src/Shaders/DistanceFieldVectorShader.h diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index f20f432c6..41c0e0731 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -2,16 +2,18 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders AbstractVectorShader2D.vert AbstractVectorShader3D.vert FlatShader2D.vert FlatShader3D.vert FlatShader.frag PhongShader.vert PhongShader.frag - VectorShader.frag + VectorShader.frag DistanceFieldVectorShader.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) set(MagnumShaders_SRCS + DistanceFieldVectorShader.cpp FlatShader.cpp PhongShader.cpp VectorShader.cpp VertexColorShader.cpp ${MagnumShaders_RCS}) set(MagnumShaders_HEADERS + DistanceFieldVectorShader.h AbstractVectorShader.h FlatShader.h PhongShader.h diff --git a/src/Shaders/DistanceFieldVectorShader.cpp b/src/Shaders/DistanceFieldVectorShader.cpp new file mode 100644 index 000000000..6631a0ddf --- /dev/null +++ b/src/Shaders/DistanceFieldVectorShader.cpp @@ -0,0 +1,85 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "DistanceFieldVectorShader.h" + +#include + +#include "Context.h" +#include "Extensions.h" +#include "Shader.h" + +namespace Magnum { namespace Shaders { + +namespace { + template constexpr const char* vertexShaderName(); + template<> constexpr const char* vertexShaderName<2>() { return "AbstractVectorShader2D.vert"; } + template<> constexpr const char* vertexShaderName<3>() { return "AbstractVectorShader3D.vert"; } +} + +template DistanceFieldVectorShader::DistanceFieldVectorShader(): transformationProjectionMatrixUniform(0), colorUniform(1), outlineColorUniform(2), outlineRangeUniform(3), smoothnessUniform(4) { + Corrade::Utility::Resource rs("MagnumShaders"); + + #ifndef MAGNUM_TARGET_GLES + Version v = Context::current()->supportedVersion({Version::GL320, Version::GL210}); + #else + Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); + #endif + + Shader vertexShader(v, Shader::Type::Vertex); + vertexShader.addSource(rs.get("compatibility.glsl")); + vertexShader.addSource(rs.get(vertexShaderName())); + AbstractShaderProgram::attachShader(vertexShader); + + Shader fragmentShader(v, Shader::Type::Fragment); + fragmentShader.addSource(rs.get("compatibility.glsl")); + fragmentShader.addSource(rs.get("DistanceFieldVectorShader.frag")); + AbstractShaderProgram::attachShader(fragmentShader); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported() || + Context::current()->version() == Version::GL210) { + #else + if(!Context::current()->isVersionSupported(Version::GLES300)) { + #endif + AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader::Position::Location, "position"); + AbstractShaderProgram::bindAttributeLocation(AbstractVectorShader::TextureCoordinates::Location, "textureCoordinates"); + } + + AbstractShaderProgram::link(); + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) { + #else + { + #endif + transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix"); + colorUniform = AbstractShaderProgram::uniformLocation("color"); + outlineColorUniform = AbstractShaderProgram::uniformLocation("outlineColor"); + outlineRangeUniform = AbstractShaderProgram::uniformLocation("outlineRange"); + smoothnessUniform = AbstractShaderProgram::uniformLocation("smoothness"); + } + + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) + AbstractShaderProgram::setUniform(AbstractShaderProgram::uniformLocation("vectorTexture"), + AbstractVectorShader::VectorTextureLayer); + #endif +} + +template class DistanceFieldVectorShader<2>; +template class DistanceFieldVectorShader<3>; + +}} diff --git a/src/Shaders/DistanceFieldVectorShader.frag b/src/Shaders/DistanceFieldVectorShader.frag new file mode 100644 index 000000000..7ec900bf1 --- /dev/null +++ b/src/Shaders/DistanceFieldVectorShader.frag @@ -0,0 +1,49 @@ +#ifndef NEW_GLSL +#define in varying +#define fragmentColor gl_FragColor +#endif + +#ifndef GL_ES +#ifdef EXPLICIT_UNIFORM_LOCATION +layout(location = 1) uniform lowp vec4 color; +layout(location = 2) uniform lowp vec4 outlineColor; +layout(location = 3) uniform lowp vec2 outlineRange = vec2(0.5, 0.0); +layout(location = 4) uniform lowp float smoothness = 0.04; +#else +uniform lowp vec4 color; +uniform lowp vec4 outlineColor; +uniform lowp vec2 outlineRange = vec2(0.5, 0.0); +uniform lowp float smoothness = 0.04; +#endif +#else +uniform lowp vec4 color; +uniform lowp vec4 outlineColor; +uniform lowp vec2 outlineRange; +uniform lowp float smoothness; +#endif + +#ifdef EXPLICIT_TEXTURE_LAYER +layout(binding = 16) uniform sampler2D vectorTexture; +#else +uniform lowp sampler2D vectorTexture; +#endif + +in vec2 fragmentTextureCoordinates; + +#ifdef NEW_GLSL +out vec4 fragmentColor; +#endif + +void main() { + lowp float intensity = texture(vectorTexture, fragmentTextureCoordinates).r; + + /* Fill color */ + fragmentColor = smoothstep(outlineRange.x-smoothness, outlineRange.x+smoothness, intensity)*color; + + /* Outline */ + if(outlineRange.x < outlineRange.y) { + lowp float mid = (outlineRange.x + outlineRange.y)/2.0; + lowp float half = (outlineRange.y - outlineRange.x)/2.0; + fragmentColor += smoothstep(half+smoothness, half-smoothness, distance(mid, intensity))*outlineColor; + } +} diff --git a/src/Shaders/DistanceFieldVectorShader.h b/src/Shaders/DistanceFieldVectorShader.h new file mode 100644 index 000000000..40f58ab49 --- /dev/null +++ b/src/Shaders/DistanceFieldVectorShader.h @@ -0,0 +1,118 @@ +#ifndef Magnum_Shaders_DistanceFieldVectorShader_h +#define Magnum_Shaders_DistanceFieldVectorShader_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Shaders::DistanceFieldVectorShader, typedef Magnum::Shaders::DistanceFieldVectorShader2D, Magnum::Shaders::DistanceFieldVectorShader3D + */ + +#include "Math/Matrix3.h" +#include "Math/Matrix4.h" +#include "AbstractVectorShader.h" + +#include "magnumShadersVisibility.h" + +namespace Magnum { namespace Shaders { + +/** +@brief Distance field vector shader + +Renders vector art in form of signed distance field. See TextureTools::distanceField() +for more information. Note that the final rendered outlook will greatly depend +on radius of input distance field and value passed to setSmoothness(). +@see DistanceFieldVectorShader2D, DistanceFieldVectorShader3D +*/ +template class MAGNUM_SHADERS_EXPORT DistanceFieldVectorShader: public AbstractVectorShader { + public: + DistanceFieldVectorShader(); + + /** @brief Set transformation and projection matrix */ + inline DistanceFieldVectorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); + return this; + } + + /** + * @brief Set fill color + * @return Pointer to self (for method chaining) + * + * @see setOutlineColor() + */ + inline DistanceFieldVectorShader* setColor(const Color4<>& color) { + AbstractShaderProgram::setUniform(colorUniform, color); + return this; + } + + /** + * @brief Set outline color + * @return Pointer to self (for method chaining) + * + * @see setOutlineRange(), setColor() + */ + inline DistanceFieldVectorShader* setOutlineColor(const Color4<>& color) { + AbstractShaderProgram::setUniform(outlineColorUniform, color); + return this; + } + + /** + * @brief Set outline range + * @return Pointer to self (for method chaining) + * + * Parameter @p start describes where fill ends and possible outline + * starts. Initial value is `0.5f`, smaller values will make the vector + * art look thinner, larger will make it look thicker. + * + * Parameter @p end describes where outline ends. If set to value + * smaller than @p start the outline is not drawn. Initial value is + * `0.0f`. + * + * @see setOutlineColor() + */ + inline DistanceFieldVectorShader* setOutlineRange(Float start, Float end) { + AbstractShaderProgram::setUniform(outlineRangeUniform, Vector2(start, end)); + return this; + } + + /** + * @brief Set smoothness radius + * @return Pointer to self (for method chaining) + * + * Larger values will make edges look less aliased (but blurry), smaller + * values will make them look more crisp (but possibly aliased). Initial + * value is `0.04f`. + */ + inline DistanceFieldVectorShader* setSmoothness(Float value) { + AbstractShaderProgram::setUniform(smoothnessUniform, value); + return this; + } + + private: + Int transformationProjectionMatrixUniform, + colorUniform, + outlineColorUniform, + outlineRangeUniform, + smoothnessUniform; +}; + +/** @brief Two-dimensional distance field vector shader */ +typedef DistanceFieldVectorShader<2> DistanceFieldVectorShader2D; + +/** @brief Three-dimensional distance field vector shader */ +typedef DistanceFieldVectorShader<3> DistanceFieldVectorShader3D; + +}} + +#endif diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index d068b588e..f5e8f2a40 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -25,6 +25,11 @@ namespace Magnum { namespace Shaders { /** @todoc remove when doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT + +template class DistanceFieldVectorShader; +typedef DistanceFieldVectorShader<2> DistanceFieldVectorShader2D; +typedef DistanceFieldVectorShader<3> DistanceFieldVectorShader3D; + template class AbstractVectorShader; typedef AbstractVectorShader<2> AbstractVectorShader2D; typedef AbstractVectorShader<3> AbstractVectorShader3D; diff --git a/src/Shaders/VectorShader.h b/src/Shaders/VectorShader.h index ccd177352..f2dee2480 100644 --- a/src/Shaders/VectorShader.h +++ b/src/Shaders/VectorShader.h @@ -30,6 +30,8 @@ namespace Magnum { namespace Shaders { /** @brief Vector shader +Renders vector art in plain grayscale form. See also DistanceFieldVectorShader +for more advanced effects. @see VectorShader2D, VectorShader3D */ template class MAGNUM_SHADERS_EXPORT VectorShader: public AbstractVectorShader { diff --git a/src/TextureTools/DistanceField.h b/src/TextureTools/DistanceField.h index fe107020d..85bd4ab6d 100644 --- a/src/TextureTools/DistanceField.h +++ b/src/TextureTools/DistanceField.h @@ -50,7 +50,7 @@ the pixel was originally black and nearest white pixel is farther than The resulting texture can be used with bilinear filtering. It can be converted back to binary form in shader using e.g. GLSL `smoothstep()` function with step around `0.5` to create antialiased edges. Or you can exploit the distance field -features to create many other effects. +features to create many other effects. See also Shaders::DistanceFieldVectorShader. Based on: *Chris Green - Improved Alpha-Tested Magnification for Vector Textures and Special Effects, SIGGRAPH 2007, From 195ec4e9b203f723bbacab46821afbd8bb8b52bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 10:35:49 +0100 Subject: [PATCH 508/567] Text: synchronized function parameter naming with documentation. --- src/Text/Font.cpp | 8 ++++---- src/Text/Font.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 9f3cd9c61..f99416904 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -133,7 +133,7 @@ void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { prerenderInternal(characters, atlasSize, 0, &_texture); } -void Font::prerenderDistanceField(const std::string& characters, const Vector2i& atlasSize, const Vector2i& distanceFieldAtlasSize, Int radius) { +void Font::prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius) { MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_storage); /* Render input texture */ @@ -141,11 +141,11 @@ void Font::prerenderDistanceField(const std::string& characters, const Vector2i& input.setWrapping(Texture2D::Wrapping::ClampToEdge) ->setMinificationFilter(Texture2D::Filter::Linear) ->setMagnificationFilter(Texture2D::Filter::Linear); - prerenderInternal(characters, atlasSize, radius, &input); + prerenderInternal(characters, sourceAtlasSize, radius, &input); /* Create distance field from input texture */ - _texture.setStorage(1, Texture2D::InternalFormat::R8, distanceFieldAtlasSize); - TextureTools::distanceField(&input, &_texture, Rectanglei::fromSize({}, distanceFieldAtlasSize), radius); + _texture.setStorage(1, Texture2D::InternalFormat::R8, atlasSize); + TextureTools::distanceField(&input, &_texture, Rectanglei::fromSize({}, atlasSize), radius); } void Font::destroy() { diff --git a/src/Text/Font.h b/src/Text/Font.h index 6745ddf90..82592e9b0 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -109,7 +109,7 @@ class MAGNUM_TEXT_EXPORT Font { * @attention @p sourceAtlasSize must be large enough to contain all * rendered glyphs with padding given by @p radius. */ - void prerenderDistanceField(const std::string& characters, const Vector2i& atlasSize, const Vector2i& distanceFieldAtlasSize, Int radius); + void prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius); ~Font(); From 0d7baef932717db7ec0cbbcec131686cf8b23495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 10:50:00 +0100 Subject: [PATCH 509/567] Text: no need to explicitly specify Z coordinate in 3D text. The coordinate is always 0 and Mesh can be configured to add it implicitly. The code is now nearly the same for 2D and 3D, will redo it without templates later. --- src/Text/TextRenderer.cpp | 61 +++++++++++++++------------------------ src/Text/TextRenderer.h | 2 +- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 806069b7f..c21983470 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -26,7 +26,6 @@ #include "Context.h" #include "Extensions.h" #include "Mesh.h" -#include "Swizzle.h" #include "Shaders/AbstractVectorShader.h" #include "Text/Font.h" @@ -149,31 +148,19 @@ template void createIndices(void* output, const UnsignedInt glyphCount) } } -template typename DimensionTraits::VectorType point(const Vector2& vec); - -template<> inline Vector2 point<2>(const Vector2& vec) { - return vec; -} - -template<> inline Vector3 point<3>(const Vector2& vec) { - return {vec, 1.0f}; -} - -template struct Vertex { - typename DimensionTraits::VectorType position; - Vector2 texcoords; +struct Vertex { + Vector2 position, texcoords; }; } -template std::tuple::VectorType>, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, Float size, const std::string& text) { +template std::tuple, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, Float size, const std::string& text) { TextLayouter layouter(font, size, text); const UnsignedInt vertexCount = layouter.glyphCount()*4; /* Output data */ - std::vector::VectorType> positions; - std::vector texcoords; + std::vector positions, texcoords; positions.reserve(vertexCount); texcoords.reserve(vertexCount); @@ -186,10 +173,10 @@ template std::tuple(quadPosition.topLeft()), - point(quadPosition.bottomLeft()), - point(quadPosition.topRight()), - point(quadPosition.bottomRight()), + quadPosition.topLeft(), + quadPosition.bottomLeft(), + quadPosition.topRight(), + quadPosition.bottomRight(), }); texcoords.insert(texcoords.end(), { textureCoordinates.topLeft(), @@ -208,8 +195,7 @@ template std::tuple(positions[1]), swizzle<'x', 'y'>(positions[positions.size()-2])}; + if(layouter.glyphCount()) rectangle = {positions[1], positions[positions.size()-2]}; return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle); } @@ -221,7 +207,7 @@ template std::tuple TextRenderer> vertices; + std::vector vertices; vertices.reserve(vertexCount); /* Render all glyphs */ @@ -233,10 +219,10 @@ template std::tuple TextRenderer(quadPosition.topLeft()), textureCoordinates.topLeft()}, - {point(quadPosition.bottomLeft()), textureCoordinates.bottomLeft()}, - {point(quadPosition.topRight()), textureCoordinates.topRight()}, - {point(quadPosition.bottomRight()), textureCoordinates.bottomRight()} + {quadPosition.topLeft(), textureCoordinates.topLeft()}, + {quadPosition.bottomLeft(), textureCoordinates.bottomLeft()}, + {quadPosition.topRight(), textureCoordinates.topRight()}, + {quadPosition.bottomRight(), textureCoordinates.bottomRight()} }); /* Advance cursor position to next character */ @@ -269,15 +255,14 @@ template std::tuple TextRenderer(vertices[1].position), swizzle<'x', 'y'>(vertices[vertices.size()-2].position)}; + if(layouter.glyphCount()) rectangle = {vertices[1].position, vertices[vertices.size()-2].position}; /* Configure mesh */ Mesh mesh; mesh.setPrimitive(Mesh::Primitive::Triangles) ->setIndexCount(indexCount) ->addInterleavedVertexBuffer(vertexBuffer, 0, - typename Shaders::AbstractVectorShader::Position(), + typename Shaders::AbstractVectorShader::Position(Shaders::AbstractVectorShader::Position::Components::Two), typename Shaders::AbstractVectorShader::TextureCoordinates()) ->setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); @@ -295,7 +280,7 @@ template TextRenderer::TextRenderer(Font& fo _mesh.setPrimitive(Mesh::Primitive::Triangles) ->addInterleavedVertexBuffer(&vertexBuffer, 0, - typename Shaders::AbstractVectorShader::Position(), + typename Shaders::AbstractVectorShader::Position(Shaders::AbstractVectorShader::Position::Components::Two), typename Shaders::AbstractVectorShader::TextureCoordinates()); } @@ -306,7 +291,7 @@ template void TextRenderer::reserve(const ui const UnsignedInt indexCount = glyphCount*6; /* Allocate vertex buffer, reset vertex count */ - vertexBuffer.setData(vertexCount*sizeof(Vertex), nullptr, vertexBufferUsage); + vertexBuffer.setData(vertexCount*sizeof(Vertex), nullptr, vertexBufferUsage); _mesh.setVertexCount(0); /* Allocate index buffer, reset index count and reconfigure buffer binding */ @@ -343,7 +328,7 @@ template void TextRenderer::render(const std CORRADE_ASSERT(layouter.glyphCount() <= _capacity, "Text::TextRenderer::render(): capacity" << _capacity << "too small to render" << layouter.glyphCount() << "glyphs", ); /* Render all glyphs */ - Vertex* const vertices = static_cast*>(vertexBuffer.map(0, layouter.glyphCount()*4*sizeof(Vertex), + Vertex* const vertices = static_cast(vertexBuffer.map(0, layouter.glyphCount()*4*sizeof(Vertex), Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write)); Vector2 cursorPosition; for(UnsignedInt i = 0; i != layouter.glyphCount(); ++i) { @@ -358,10 +343,10 @@ template void TextRenderer::render(const std _rectangle.topRight() = quadPosition.topRight(); const std::size_t vertex = i*4; - vertices[vertex] = {point(quadPosition.topLeft()), textureCoordinates.topLeft()}; - vertices[vertex+1] = {point(quadPosition.bottomLeft()), textureCoordinates.bottomLeft()}; - vertices[vertex+2] = {point(quadPosition.topRight()), textureCoordinates.topRight()}; - vertices[vertex+3] = {point(quadPosition.bottomRight()), textureCoordinates.bottomRight()}; + vertices[vertex] = {quadPosition.topLeft(), textureCoordinates.topLeft()}; + vertices[vertex+1] = {quadPosition.bottomLeft(), textureCoordinates.bottomLeft()}; + vertices[vertex+2] = {quadPosition.topRight(), textureCoordinates.topRight()}; + vertices[vertex+3] = {quadPosition.bottomRight(), textureCoordinates.bottomRight()}; /* Advance cursor position to next character */ cursorPosition += advance; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 4fdb27f28..33a7362c2 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -109,7 +109,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { * Returns tuple with vertex positions, texture coordinates, indices * and rectangle spanning the rendered text. */ - static std::tuple::VectorType>, std::vector, std::vector, Rectangle> render(Font& font, Float size, const std::string& text); + static std::tuple, std::vector, std::vector, Rectangle> render(Font& font, Float size, const std::string& text); /** * @brief Render text From 2944a4e20539708ad4f229a132aef7cb5151a545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 11:19:42 +0100 Subject: [PATCH 510/567] Text: non-templated base for TextRenderer. Saves a lot of duplicated generated code. --- src/Text/Text.h | 1 + src/Text/TextRenderer.cpp | 38 +++++++--- src/Text/TextRenderer.h | 148 ++++++++++++++++++++++---------------- 3 files changed, 116 insertions(+), 71 deletions(-) diff --git a/src/Text/Text.h b/src/Text/Text.h index 4e4d49443..08b708df2 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -26,6 +26,7 @@ namespace Magnum { namespace Text { class Font; class FontRenderer; +class AbstractTextRenderer; template class TextRenderer; typedef TextRenderer<2> TextRenderer2D; typedef TextRenderer<3> TextRenderer3D; diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index c21983470..634e90244 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -154,7 +154,7 @@ struct Vertex { } -template std::tuple, std::vector, std::vector, Rectangle> TextRenderer::render(Font& font, Float size, const std::string& text) { +std::tuple, std::vector, std::vector, Rectangle> AbstractTextRenderer::render(Font& font, Float size, const std::string& text) { TextLayouter layouter(font, size, text); const UnsignedInt vertexCount = layouter.glyphCount()*4; @@ -200,7 +200,7 @@ template std::tuple, std::vector std::tuple TextRenderer::render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { +std::tuple AbstractTextRenderer::render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { TextLayouter layouter(font, size, text); const UnsignedInt vertexCount = layouter.glyphCount()*4; @@ -257,19 +257,28 @@ template std::tuple TextRenderersetIndexCount(indexCount) - ->addInterleavedVertexBuffer(vertexBuffer, 0, - typename Shaders::AbstractVectorShader::Position(Shaders::AbstractVectorShader::Position::Components::Two), - typename Shaders::AbstractVectorShader::TextureCoordinates()) ->setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); return std::make_tuple(std::move(mesh), rectangle); } -template TextRenderer::TextRenderer(Font& font, const Float size): font(font), size(size), _capacity(0), vertexBuffer(Buffer::Target::Array), indexBuffer(Buffer::Target::ElementArray) { +template std::tuple TextRenderer::render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { + /* Finalize mesh configuration and return the result */ + auto r = AbstractTextRenderer::render(font, size, text, vertexBuffer, indexBuffer, usage); + Mesh& mesh = std::get<0>(r); + mesh.addInterleavedVertexBuffer(vertexBuffer, 0, + typename Shaders::AbstractVectorShader::Position( + Shaders::AbstractVectorShader::Position::Components::Two), + typename Shaders::AbstractVectorShader::TextureCoordinates()); + return std::move(r); +} + +AbstractTextRenderer::AbstractTextRenderer(Font& font, Float size): vertexBuffer(Buffer::Target::Array), indexBuffer(Buffer::Target::ElementArray), font(font), size(size), _capacity(0) { #ifndef MAGNUM_TARGET_GLES MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::map_buffer_range); #else @@ -278,13 +287,20 @@ template TextRenderer::TextRenderer(Font& fo #endif #endif - _mesh.setPrimitive(Mesh::Primitive::Triangles) - ->addInterleavedVertexBuffer(&vertexBuffer, 0, + /* Vertex buffer configuration depends on dimension count, done in subclass */ + _mesh.setPrimitive(Mesh::Primitive::Triangles); +} + +AbstractTextRenderer::~AbstractTextRenderer() {} + +template TextRenderer::TextRenderer(Font& font, const Float size): AbstractTextRenderer(font, size) { + /* Finalize mesh configuration */ + _mesh.addInterleavedVertexBuffer(&vertexBuffer, 0, typename Shaders::AbstractVectorShader::Position(Shaders::AbstractVectorShader::Position::Components::Two), typename Shaders::AbstractVectorShader::TextureCoordinates()); } -template void TextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) { +void AbstractTextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage) { _capacity = glyphCount; const UnsignedInt vertexCount = glyphCount*4; @@ -322,7 +338,7 @@ template void TextRenderer::reserve(const ui CORRADE_INTERNAL_ASSERT_OUTPUT(indexBuffer.unmap()); } -template void TextRenderer::render(const std::string& text) { +void AbstractTextRenderer::render(const std::string& text) { TextLayouter layouter(font, size, text); CORRADE_ASSERT(layouter.glyphCount() <= _capacity, "Text::TextRenderer::render(): capacity" << _capacity << "too small to render" << layouter.glyphCount() << "glyphs", ); diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 33a7362c2..f4932fdf2 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Text::TextRenderer + * @brief Class Magnum::Text::AbstractTextRenderer, Magnum::Text::TextRenderer, typedef Magnum::Text::TextRenderer2D, Magnum::Text::TextRenderer3D */ #include "Math/Geometry/Rectangle.h" @@ -33,6 +33,91 @@ namespace Magnum { namespace Text { +/** +@brief Base for text renderers + +Not meant to be used directly, see TextRenderer for more information. +@see TextRenderer2D, TextRenderer3D +*/ +class MAGNUM_TEXT_EXPORT AbstractTextRenderer { + public: + /** + * @brief Render text + * @param font %Font to use + * @param size %Font size + * @param text %Text to render + * + * Returns tuple with vertex positions, texture coordinates, indices + * and rectangle spanning the rendered text. + */ + static std::tuple, std::vector, std::vector, Rectangle> render(Font& font, Float size, const std::string& text); + + /** + * @brief Constructor + * @param font %Font to use + * @param size %Font size + */ + AbstractTextRenderer(Font& font, Float size); + + virtual ~AbstractTextRenderer() = 0; + + /** + * @brief Capacity for rendered glyphs + * + * @see reserve() + */ + inline UnsignedInt capacity() const { return _capacity; } + + /** @brief Rectangle spanning the rendered text */ + inline Rectangle rectangle() const { return _rectangle; } + + /** @brief Text mesh */ + inline Mesh* mesh() { return &_mesh; } + + /** + * @brief Reserve capacity for rendered glyphs + * + * Reallocates memory in buffers to hold @p glyphCount glyphs and + * prefills index buffer. Consider using appropriate @p vertexBufferUsage + * if the text will be changed frequently. Index buffer is changed + * only by calling this function, thus @p indexBufferUsage generally + * doesn't need to be so dynamic if the capacity won't be changed much. + * + * Initially zero capacity is reserved. + * @see capacity() + */ + void reserve(const UnsignedInt glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage); + + /** + * @brief Render text + * + * Renders the text to vertex buffer, reusing index buffer already + * filled with reserve(). Rectangle spanning the rendered text is + * available through rectangle(). + * + * Initially no text is rendered. + * @attention The capacity must be large enough to contain all glyphs, + * see reserve() for more information. + */ + void render(const std::string& text); + + #ifndef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif + static std::tuple MAGNUM_LOCAL render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + + Mesh _mesh; + Buffer vertexBuffer, indexBuffer; + + private: + Font& font; + Float size; + UnsignedInt _capacity; + Rectangle _rectangle; +}; + /** @brief %Text renderer @@ -98,19 +183,8 @@ for asynchronous buffer updates. @see TextRenderer2D, TextRenderer3D, Font, Shaders::AbstractVectorShader */ -template class MAGNUM_TEXT_EXPORT TextRenderer { +template class MAGNUM_TEXT_EXPORT TextRenderer: public AbstractTextRenderer { public: - /** - * @brief Render text - * @param font %Font to use - * @param size %Font size - * @param text %Text to render - * - * Returns tuple with vertex positions, texture coordinates, indices - * and rectangle spanning the rendered text. - */ - static std::tuple, std::vector, std::vector, Rectangle> render(Font& font, Float size, const std::string& text); - /** * @brief Render text * @param font %Font to use @@ -132,53 +206,7 @@ template class MAGNUM_TEXT_EXPORT TextRenderer { */ TextRenderer(Font& font, Float size); - /** - * @brief Capacity for rendered glyphs - * - * @see reserve() - */ - inline UnsignedInt capacity() const { return _capacity; } - - /** @brief Rectangle spanning the rendered text */ - inline Rectangle rectangle() const { return _rectangle; } - - /** @brief Text mesh */ - inline Mesh* mesh() { return &_mesh; } - - /** - * @brief Reserve capacity for rendered glyphs - * - * Reallocates memory in buffers to hold @p glyphCount glyphs and - * prefills index buffer. Consider using appropriate @p vertexBufferUsage - * if the text will be changed frequently. Index buffer is changed - * only by calling this function, thus @p indexBufferUsage generally - * doesn't need to be so dynamic if the capacity won't be changed much. - * - * Initially zero capacity is reserved. - * @see capacity() - */ - void reserve(const UnsignedInt glyphCount, const Buffer::Usage vertexBufferUsage, const Buffer::Usage indexBufferUsage); - - /** - * @brief Render text - * - * Renders the text to vertex buffer, reusing index buffer already - * filled with reserve(). Rectangle spanning the rendered text is - * available through rectangle(). - * - * Initially no text is rendered. - * @attention The capacity must be large enough to contain all glyphs, - * see reserve() for more information. - */ - void render(const std::string& text); - - private: - Font& font; - Float size; - UnsignedInt _capacity; - Rectangle _rectangle; - Buffer vertexBuffer, indexBuffer; - Mesh _mesh; + using AbstractTextRenderer::render; }; /** @brief Two-dimensional text renderer */ From b4950b59acbe1681d79c9c4b9166991219b1e861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 11:42:32 +0100 Subject: [PATCH 511/567] Text: moved TextLayouter from TextRenderer internals to Font header. Preparation for the whole thing to be testable, moving implementation-dependent (FreeType/HarfBuzz) things together. --- src/Text/Font.cpp | 64 +++++++++++++++++++++++ src/Text/Font.h | 56 ++++++++++++++++++++- src/Text/Text.h | 1 + src/Text/TextRenderer.cpp | 103 -------------------------------------- 4 files changed, 120 insertions(+), 104 deletions(-) diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index f99416904..30c03f11d 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -197,4 +197,68 @@ const std::tuple& Font::operator[](char32_t character) con return it->second; } +TextLayouter::TextLayouter(Font& font, const Float size, const std::string& text): font(font), size(size) { + #ifdef MAGNUM_USE_HARFBUZZ + /* Prepare HarfBuzz buffer */ + buffer = hb_buffer_create(); + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); + hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); + + /* Layout the text */ + hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); + hb_shape(font.font(), buffer, nullptr, 0); + + glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); + glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); + #else + /* Get glyph codes from characters */ + glyphs.reserve(text.size()+1); + for(std::size_t i = 0; i != text.size(); ) { + UnsignedInt codepoint; + std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); + glyphs.push_back(FT_Get_Char_Index(font.font(), codepoint)); + } + #endif +} + +TextLayouter::~TextLayouter() { + #ifdef MAGNUM_USE_HARFBUZZ + /* Destroy HarfBuzz buffer */ + hb_buffer_destroy(buffer); + #endif +} + +std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle texturePosition, textureCoordinates; + #ifdef MAGNUM_USE_HARFBUZZ + std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; + #else + std::tie(texturePosition, textureCoordinates) = font[glyphs[i]]; + #endif + + #ifdef MAGNUM_USE_HARFBUZZ + /* Glyph offset and advance to next glyph in normalized coordinates */ + Vector2 offset = Vector2(glyphPositions[i].x_offset, + glyphPositions[i].y_offset)/(64*font.size()); + Vector2 advance = Vector2(glyphPositions[i].x_advance, + glyphPositions[i].y_advance)/(64*font.size()); + #else + /* Load glyph */ + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(font.font(), glyphs[i], FT_LOAD_DEFAULT) == 0); + const FT_GlyphSlot slot = font.font()->glyph; + Vector2 offset = Vector2(0, 0); /** @todo really? */ + Vector2 advance = Vector2(slot->advance.x, slot->advance.y)/(64*font.size()); + #endif + + /* Absolute quad position, composed from cursor position, glyph offset + and texture position, denormalized to requested text size */ + Rectangle quadPosition = Rectangle::fromSize( + (cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, + texturePosition.size()*size); + + return std::make_tuple(quadPosition, textureCoordinates, advance); +} + }} diff --git a/src/Text/Font.h b/src/Text/Font.h index 82592e9b0..a864c01ee 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Text::Font + * @brief Class Magnum::Text::Font, Magnum::Text::TextLayouter */ #include @@ -31,6 +31,9 @@ struct FT_FaceRec_; typedef FT_FaceRec_* FT_Face; struct hb_font_t; +struct hb_buffer_t; +struct hb_glyph_info_t; +struct hb_glyph_position_t; #endif namespace Magnum { namespace Text { @@ -159,6 +162,57 @@ class MAGNUM_TEXT_EXPORT Font { #endif }; +/** +@brief %Text layouter + +Provides low-level text rendering using Font, used internally in TextRenderer. +*/ +class TextLayouter { + public: + /** + * @brief Constructor + * @param font %Font + * @param size %Font size + * @param text Text to layout + */ + TextLayouter(Font& font, const Float size, const std::string& text); + + ~TextLayouter(); + + /** @brief Count of glyphs in laid out text */ + inline UnsignedInt glyphCount() { + #ifdef MAGNUM_USE_HARFBUZZ + return _glyphCount; + #else + return glyphs.size(); + #endif + } + + /** + * @brief Render glyph + * @param i Glyph index + * @param cursorPosition Cursor position + * + * Returns quad position, texture coordinates and advance to next + * glyph. + */ + std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i); + + private: + #ifdef MAGNUM_USE_HARFBUZZ + const Font& font; + hb_buffer_t* buffer; + hb_glyph_info_t* glyphInfo; + hb_glyph_position_t* glyphPositions; + UnsignedInt _glyphCount; + #else + Font& font; + std::vector glyphs; + #endif + + const Float size; +}; + }} #endif diff --git a/src/Text/Text.h b/src/Text/Text.h index 08b708df2..03e126beb 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -25,6 +25,7 @@ namespace Magnum { namespace Text { class Font; class FontRenderer; +class TextLayouter; class AbstractTextRenderer; template class TextRenderer; diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 634e90244..218fa0a77 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -15,14 +15,6 @@ #include "TextRenderer.h" -#ifdef MAGNUM_USE_HARFBUZZ -#include -#else -#include -#include FT_FREETYPE_H -#include -#endif - #include "Context.h" #include "Extensions.h" #include "Mesh.h" @@ -33,101 +25,6 @@ namespace Magnum { namespace Text { namespace { -class TextLayouter { - public: - TextLayouter(Font& font, const Float size, const std::string& text); - - ~TextLayouter(); - - inline UnsignedInt glyphCount() { - #ifdef MAGNUM_USE_HARFBUZZ - return _glyphCount; - #else - return glyphs.size(); - #endif - } - - std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i); - - private: - #ifdef MAGNUM_USE_HARFBUZZ - const Font& font; - hb_buffer_t* buffer; - hb_glyph_info_t* glyphInfo; - hb_glyph_position_t* glyphPositions; - UnsignedInt _glyphCount; - #else - Font& font; - std::vector glyphs; - #endif - - const Float size; -}; - -TextLayouter::TextLayouter(Font& font, const Float size, const std::string& text): font(font), size(size) { - #ifdef MAGNUM_USE_HARFBUZZ - /* Prepare HarfBuzz buffer */ - buffer = hb_buffer_create(); - hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); - hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); - hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); - - /* Layout the text */ - hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); - hb_shape(font.font(), buffer, nullptr, 0); - - glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); - glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); - #else - /* Get glyph codes from characters */ - glyphs.reserve(text.size()+1); - for(std::size_t i = 0; i != text.size(); ) { - UnsignedInt codepoint; - std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); - glyphs.push_back(FT_Get_Char_Index(font.font(), codepoint)); - } - #endif -} - -TextLayouter::~TextLayouter() { - #ifdef MAGNUM_USE_HARFBUZZ - /* Destroy HarfBuzz buffer */ - hb_buffer_destroy(buffer); - #endif -} - -std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { - /* Position of the texture in the resulting glyph, texture coordinates */ - Rectangle texturePosition, textureCoordinates; - #ifdef MAGNUM_USE_HARFBUZZ - std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; - #else - std::tie(texturePosition, textureCoordinates) = font[glyphs[i]]; - #endif - - #ifdef MAGNUM_USE_HARFBUZZ - /* Glyph offset and advance to next glyph in normalized coordinates */ - Vector2 offset = Vector2(glyphPositions[i].x_offset, - glyphPositions[i].y_offset)/(64*font.size()); - Vector2 advance = Vector2(glyphPositions[i].x_advance, - glyphPositions[i].y_advance)/(64*font.size()); - #else - /* Load glyph */ - CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(font.font(), glyphs[i], FT_LOAD_DEFAULT) == 0); - const FT_GlyphSlot slot = font.font()->glyph; - Vector2 offset = Vector2(0, 0); /** @todo really? */ - Vector2 advance = Vector2(slot->advance.x, slot->advance.y)/(64*font.size()); - #endif - - /* Absolute quad position, composed from cursor position, glyph offset - and texture position, denormalized to requested text size */ - Rectangle quadPosition = Rectangle::fromSize( - (cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, - texturePosition.size()*size); - - return std::make_tuple(quadPosition, textureCoordinates, advance); -} - template void createIndices(void* output, const UnsignedInt glyphCount) { T* const out = reinterpret_cast(output); for(UnsignedInt i = 0; i != glyphCount; ++i) { From c864fefb951aa82775f0b24d62e7545578a055d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 11:48:31 +0100 Subject: [PATCH 512/567] Text: moved FontRenderer into Font header. Now everything related to FreeType and HarfBuzz is in one header. --- src/Text/CMakeLists.txt | 2 -- src/Text/Font.cpp | 8 ++++++ src/Text/Font.h | 24 ++++++++++++++++-- src/Text/FontRenderer.cpp | 32 ------------------------ src/Text/FontRenderer.h | 52 --------------------------------------- 5 files changed, 30 insertions(+), 88 deletions(-) delete mode 100644 src/Text/FontRenderer.cpp delete mode 100644 src/Text/FontRenderer.h diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index c97dcaed0..42d2586d7 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -8,11 +8,9 @@ endif() set(MagnumText_SRCS Font.cpp - FontRenderer.cpp TextRenderer.cpp) set(MagnumText_HEADERS Font.h - FontRenderer.h Text.h TextRenderer.h diff --git a/src/Text/Font.cpp b/src/Text/Font.cpp index 30c03f11d..f95802d6b 100644 --- a/src/Text/Font.cpp +++ b/src/Text/Font.cpp @@ -30,6 +30,14 @@ namespace Magnum { namespace Text { +FontRenderer::FontRenderer() { + CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Init_FreeType(&_library) == 0); +} + +FontRenderer::~FontRenderer() { + FT_Done_FreeType(_library); +} + Font::Font(FontRenderer& renderer, const std::string& fontFile, Float size): _size(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); diff --git a/src/Text/Font.h b/src/Text/Font.h index a864c01ee..e14040c33 100644 --- a/src/Text/Font.h +++ b/src/Text/Font.h @@ -16,18 +16,19 @@ */ /** @file - * @brief Class Magnum::Text::Font, Magnum::Text::TextLayouter + * @brief Class Magnum::Text::FontRenderer, Magnum::Text::Font, Magnum::Text::TextLayouter */ #include #include "Math/Geometry/Rectangle.h" #include "Texture.h" -#include "Text/FontRenderer.h" #include "magnumTextVisibility.h" #ifndef DOXYGEN_GENERATING_OUTPUT +struct FT_LibraryRec_; +typedef FT_LibraryRec_* FT_Library; struct FT_FaceRec_; typedef FT_FaceRec_* FT_Face; struct hb_font_t; @@ -38,6 +39,25 @@ struct hb_glyph_position_t; namespace Magnum { namespace Text { +/** +@brief %Font renderer + +Contains global instance of font renderer. See Font class documentation for +more information. +*/ +class MAGNUM_TEXT_EXPORT FontRenderer { + public: + explicit FontRenderer(); + + ~FontRenderer(); + + /** @brief FreeType library handle */ + inline FT_Library library() { return _library; } + + private: + FT_Library _library; +}; + /** @brief %Font diff --git a/src/Text/FontRenderer.cpp b/src/Text/FontRenderer.cpp deleted file mode 100644 index 8b1f540f9..000000000 --- a/src/Text/FontRenderer.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "FontRenderer.h" - -#include -#include FT_FREETYPE_H -#include - -namespace Magnum { namespace Text { - -FontRenderer::FontRenderer() { - CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Init_FreeType(&_library) == 0); -} - -FontRenderer::~FontRenderer() { - FT_Done_FreeType(_library); -} - -}} diff --git a/src/Text/FontRenderer.h b/src/Text/FontRenderer.h deleted file mode 100644 index 6fd72ec57..000000000 --- a/src/Text/FontRenderer.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef Magnum_Text_FontRenderer_h -#define Magnum_Text_FontRenderer_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -/** @file - * @brief Class Magnum::Text::FontRenderer - */ - -#include "magnumTextVisibility.h" - -#ifndef DOXYGEN_GENERATING_OUTPUT -struct FT_LibraryRec_; -typedef FT_LibraryRec_* FT_Library; -#endif - -namespace Magnum { namespace Text { - -/** -@brief %Font renderer - -Contains global instance of font renderer. See Font class documentation for -more information. -*/ -class MAGNUM_TEXT_EXPORT FontRenderer { - public: - explicit FontRenderer(); - - ~FontRenderer(); - - /** @brief FreeType library handle */ - inline FT_Library library() { return _library; } - - private: - FT_Library _library; -}; - -}} - -#endif From 9525dfd51bb410306050b7f7f61b8be5b9a85720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 14:41:35 +0100 Subject: [PATCH 513/567] Text: abstract base for fonts and layouters. Font and text layouting is now abstracted out from its implementation. Font class is renamed to FreeTypeFont and all the work can be done through AbstractFont and AbstractLayouter interface. --- src/Text/AbstractFont.cpp | 26 ++++++ src/Text/AbstractFont.h | 103 ++++++++++++++++++++++ src/Text/CMakeLists.txt | 6 +- src/Text/{Font.cpp => FreeTypeFont.cpp} | 96 ++++++++++---------- src/Text/{Font.h => FreeTypeFont.h} | 112 +++++------------------- src/Text/Text.h | 8 +- src/Text/TextRenderer.cpp | 63 ++++++------- src/Text/TextRenderer.h | 12 +-- 8 files changed, 249 insertions(+), 177 deletions(-) create mode 100644 src/Text/AbstractFont.cpp create mode 100644 src/Text/AbstractFont.h rename src/Text/{Font.cpp => FreeTypeFont.cpp} (80%) rename src/Text/{Font.h => FreeTypeFont.h} (63%) diff --git a/src/Text/AbstractFont.cpp b/src/Text/AbstractFont.cpp new file mode 100644 index 000000000..5daef1fa2 --- /dev/null +++ b/src/Text/AbstractFont.cpp @@ -0,0 +1,26 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Text/AbstractFont.h" + +namespace Magnum { namespace Text { + +AbstractFont::AbstractFont() {} +AbstractFont::~AbstractFont() {} + +AbstractLayouter::AbstractLayouter(): _glyphCount(0) {} +AbstractLayouter::~AbstractLayouter() {} + +}} diff --git a/src/Text/AbstractFont.h b/src/Text/AbstractFont.h new file mode 100644 index 000000000..561133bcc --- /dev/null +++ b/src/Text/AbstractFont.h @@ -0,0 +1,103 @@ +#ifndef Magnum_Text_AbstractFont_h +#define Magnum_Text_AbstractFont_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Text::AbstractFont, Magnum::Text::AbstractLayouter + */ + +#include +#include + +#include "Magnum.h" +#include "Texture.h" +#include "Text/Text.h" +#include "Text/magnumTextVisibility.h" + +namespace Magnum { namespace Text { + +/** +@brief Base for fonts +*/ +class MAGNUM_TEXT_EXPORT AbstractFont { + AbstractFont(const AbstractFont&) = delete; + AbstractFont(AbstractFont&&) = delete; + AbstractFont& operator=(const AbstractFont&) = delete; + AbstractFont& operator=(const AbstractFont&&) = delete; + + public: + AbstractFont(); + virtual ~AbstractFont() = 0; + + /** @brief %Font texture atlas */ + inline Texture2D& texture() { return _texture; } + + /** + * @brief Layout the text using fon't own layouter + * @param size %Font size + * @param text Text to layout + */ + virtual AbstractLayouter* layout(const Float size, const std::string& text) = 0; + + #ifdef DOXYGEN_GENERATING_OUTPUT + private: + #else + protected: + #endif + Texture2D _texture; +}; + +/** +@brief Base for text layouters + +Returned by AbstractFont::layout(). +*/ +class MAGNUM_TEXT_EXPORT AbstractLayouter { + AbstractLayouter(const AbstractLayouter&) = delete; + AbstractLayouter(AbstractLayouter&&) = delete; + AbstractLayouter& operator=(const AbstractLayouter&) = delete; + AbstractLayouter& operator=(const AbstractLayouter&&) = delete; + + public: + AbstractLayouter(); + virtual ~AbstractLayouter() = 0; + + /** @brief Count of glyphs in laid out text */ + inline UnsignedInt glyphCount() const { + return _glyphCount; + } + + /** + * @brief Render glyph + * @param i Glyph index + * @param cursorPosition Cursor position + * + * Returns quad position, texture coordinates and advance to next + * glyph. + */ + virtual std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) = 0; + + #ifdef DOXYGEN_GENERATING_OUTPUT + private: + #else + protected: + #endif + UnsignedInt _glyphCount; +}; + +}} + +#endif diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index 42d2586d7..dd747e59e 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -7,10 +7,12 @@ if(USE_HARFBUZZ) endif() set(MagnumText_SRCS - Font.cpp + AbstractFont.cpp + FreeTypeFont.cpp TextRenderer.cpp) set(MagnumText_HEADERS - Font.h + AbstractFont.h + FreeTypeFont.h Text.h TextRenderer.h diff --git a/src/Text/Font.cpp b/src/Text/FreeTypeFont.cpp similarity index 80% rename from src/Text/Font.cpp rename to src/Text/FreeTypeFont.cpp index f95802d6b..9444f3bce 100644 --- a/src/Text/Font.cpp +++ b/src/Text/FreeTypeFont.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Font.h" +#include "FreeTypeFont.h" #include #include @@ -30,27 +30,52 @@ namespace Magnum { namespace Text { -FontRenderer::FontRenderer() { +namespace { + +class FreeTypeLayouter: public AbstractLayouter { + public: + FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text); + ~FreeTypeLayouter(); + + std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; + + private: + #ifdef MAGNUM_USE_HARFBUZZ + const FreeTypeFont& font; + hb_buffer_t* buffer; + hb_glyph_info_t* glyphInfo; + hb_glyph_position_t* glyphPositions; + #else + FreeTypeFont& font; + std::vector glyphs; + #endif + + const Float size; +}; + +} + +FreeTypeFontRenderer::FreeTypeFontRenderer() { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Init_FreeType(&_library) == 0); } -FontRenderer::~FontRenderer() { +FreeTypeFontRenderer::~FreeTypeFontRenderer() { FT_Done_FreeType(_library); } -Font::Font(FontRenderer& renderer, const std::string& fontFile, Float size): _size(size) { +FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): _size(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); finishConstruction(); } -Font::Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): _size(size) { +FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): _size(size) { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Memory_Face(renderer.library(), data, dataSize, 0, &_ftFont) == 0); finishConstruction(); } -void Font::finishConstruction() { +void FreeTypeFont::finishConstruction() { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); #ifdef MAGNUM_USE_HARFBUZZ @@ -70,7 +95,7 @@ void Font::finishConstruction() { ->setMagnificationFilter(Texture2D::Filter::Linear); } -void Font::prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output) { +void FreeTypeFont::prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output) { glyphs.clear(); /** @bug Crash when atlas is too small */ @@ -137,11 +162,11 @@ void Font::prerenderInternal(const std::string& characters, const Vector2i& atla #endif } -void Font::prerender(const std::string& characters, const Vector2i& atlasSize) { +void FreeTypeFont::prerender(const std::string& characters, const Vector2i& atlasSize) { prerenderInternal(characters, atlasSize, 0, &_texture); } -void Font::prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius) { +void FreeTypeFont::prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius) { MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_storage); /* Render input texture */ @@ -156,48 +181,14 @@ void Font::prerenderDistanceField(const std::string& characters, const Vector2i& TextureTools::distanceField(&input, &_texture, Rectanglei::fromSize({}, atlasSize), radius); } -void Font::destroy() { - if(!_ftFont) return; - +FreeTypeFont::~FreeTypeFont() { #ifdef MAGNUM_USE_HARFBUZZ hb_font_destroy(_hbFont); #endif FT_Done_Face(_ftFont); } -void Font::move() { - #ifdef MAGNUM_USE_HARFBUZZ - _hbFont = nullptr; - #endif - _ftFont = nullptr; -} - -Font::~Font() { destroy(); } - -Font::Font(Font&& other): glyphs(std::move(other.glyphs)), _texture(std::move(other._texture)), _ftFont(other._ftFont), _size(other._size) - #ifdef MAGNUM_USE_HARFBUZZ - , _hbFont(other._hbFont) - #endif -{ - other.move(); -} - -Font& Font::operator=(Font&& other) { - destroy(); - - glyphs = std::move(other.glyphs); - _texture = std::move(other._texture); - _ftFont = other._ftFont; - #ifdef MAGNUM_USE_HARFBUZZ - _hbFont = other._hbFont; - #endif - _size = other._size; - - other.move(); - return *this; -} - -const std::tuple& Font::operator[](char32_t character) const { +const std::tuple& FreeTypeFont::operator[](char32_t character) const { auto it = glyphs.find(character); if(it == glyphs.end()) @@ -205,7 +196,13 @@ const std::tuple& Font::operator[](char32_t character) con return it->second; } -TextLayouter::TextLayouter(Font& font, const Float size, const std::string& text): font(font), size(size) { +AbstractLayouter* FreeTypeFont::layout(const Float size, const std::string& text) { + return new FreeTypeLayouter(*this, size, text); +} + +namespace { + +FreeTypeLayouter::FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text): font(font), size(size) { #ifdef MAGNUM_USE_HARFBUZZ /* Prepare HarfBuzz buffer */ buffer = hb_buffer_create(); @@ -222,6 +219,7 @@ TextLayouter::TextLayouter(Font& font, const Float size, const std::string& text #else /* Get glyph codes from characters */ glyphs.reserve(text.size()+1); + _glyphCount = text.size(); for(std::size_t i = 0; i != text.size(); ) { UnsignedInt codepoint; std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); @@ -230,14 +228,14 @@ TextLayouter::TextLayouter(Font& font, const Float size, const std::string& text #endif } -TextLayouter::~TextLayouter() { +FreeTypeLayouter::~FreeTypeLayouter() { #ifdef MAGNUM_USE_HARFBUZZ /* Destroy HarfBuzz buffer */ hb_buffer_destroy(buffer); #endif } -std::tuple TextLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { +std::tuple FreeTypeLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle texturePosition, textureCoordinates; #ifdef MAGNUM_USE_HARFBUZZ @@ -269,4 +267,6 @@ std::tuple TextLayouter::renderGlyph(const Vector return std::make_tuple(quadPosition, textureCoordinates, advance); } +} + }} diff --git a/src/Text/Font.h b/src/Text/FreeTypeFont.h similarity index 63% rename from src/Text/Font.h rename to src/Text/FreeTypeFont.h index e14040c33..62da7c0b9 100644 --- a/src/Text/Font.h +++ b/src/Text/FreeTypeFont.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Text_Font_h -#define Magnum_Text_Font_h +#ifndef Magnum_Text_FreeTypeFont_h +#define Magnum_Text_FreeTypeFont_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,15 +16,15 @@ */ /** @file - * @brief Class Magnum::Text::FontRenderer, Magnum::Text::Font, Magnum::Text::TextLayouter + * @brief Class Magnum::Text::FreeTypeFontRenderer, Magnum::Text::FreeTypeFont */ #include #include "Math/Geometry/Rectangle.h" #include "Texture.h" - -#include "magnumTextVisibility.h" +#include "Text/AbstractFont.h" +#include "Text/magnumTextVisibility.h" #ifndef DOXYGEN_GENERATING_OUTPUT struct FT_LibraryRec_; @@ -40,16 +40,16 @@ struct hb_glyph_position_t; namespace Magnum { namespace Text { /** -@brief %Font renderer +@brief FreeType font renderer -Contains global instance of font renderer. See Font class documentation for -more information. +Contains global instance of font renderer. See FreeTypeFont class documentation +for more information. */ -class MAGNUM_TEXT_EXPORT FontRenderer { +class MAGNUM_TEXT_EXPORT FreeTypeFontRenderer { public: - explicit FontRenderer(); + explicit FreeTypeFontRenderer(); - ~FontRenderer(); + ~FreeTypeFontRenderer(); /** @brief FreeType library handle */ inline FT_Library library() { return _library; } @@ -59,36 +59,33 @@ class MAGNUM_TEXT_EXPORT FontRenderer { }; /** -@brief %Font +@brief FreeType font Contains font with characters prerendered into texture atlas. -@section Font-usage Usage +@section FreeTypeFont-usage Usage -You need to maintain instance of FontRenderer during the lifetime of all Font +You need to maintain instance of FreeTypeFontRenderer during the lifetime of all FreeTypeFont instances. The font can be created either from file or from memory location of format supported by [FreeType](http://www.freetype.org/) library. Next step is to prerender all the glyphs which will be used in text rendering later. @code -Text::FontRenderer fontRenderer; +Text::FreeTypeFontRenderer fontRenderer; -Text::Font font(fontRenderer, "MyFont.ttf", 48.0f); +Text::FreeTypeFont font(fontRenderer, "MyFreeTypeFont.ttf", 48.0f); font.prerender("abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789 ", Vector2i(512)); @endcode See TextRenderer for information about text rendering. -@section Font-extensions Required OpenGL functionality +@section FreeTypeFont-extensions Required OpenGL functionality %Font texture uses one-component internal format, which requires @extension{ARB,texture_rg} (also part of OpenGL ES 3.0 or available as @es_extension{EXT,texture_rg} in ES 2.0). */ -class MAGNUM_TEXT_EXPORT Font { - Font(const Font&) = delete; - Font& operator=(const Font&) = delete; - +class MAGNUM_TEXT_EXPORT FreeTypeFont: public AbstractFont { public: /** * @brief Create font from file @@ -96,7 +93,7 @@ class MAGNUM_TEXT_EXPORT Font { * @param fontFile %Font file * @param size %Font size */ - explicit Font(FontRenderer& renderer, const std::string& fontFile, Float size); + explicit FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size); /** * @brief Create font from memory @@ -105,7 +102,7 @@ class MAGNUM_TEXT_EXPORT Font { * @param dataSize %Font data size * @param size %Font size */ - explicit Font(FontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); + explicit FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); /** * @brief Prerender given character set @@ -134,13 +131,7 @@ class MAGNUM_TEXT_EXPORT Font { */ void prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius); - ~Font(); - - /** @brief Move constructor */ - Font(Font&& other); - - /** @brief Move assignment */ - Font& operator=(Font&& other); + ~FreeTypeFont(); /** @brief %Font size */ inline Float size() const { return _size; } @@ -157,24 +148,20 @@ class MAGNUM_TEXT_EXPORT Font { */ const std::tuple& operator[](char32_t character) const; - /** @brief %Font texture atlas */ - inline Texture2D& texture() { return _texture; } - - /** @brief Font handle */ + /** @brief %Font handle */ #ifdef MAGNUM_USE_HARFBUZZ inline hb_font_t* font() { return _hbFont; } #else inline FT_Face font() { return _ftFont; } #endif + AbstractLayouter* layout(const Float size, const std::string& text) override; + private: void MAGNUM_TEXT_LOCAL finishConstruction(); - void MAGNUM_TEXT_LOCAL destroy(); - void MAGNUM_TEXT_LOCAL move(); void MAGNUM_TEXT_LOCAL prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output); std::unordered_map> glyphs; - Texture2D _texture; FT_Face _ftFont; Float _size; #ifdef MAGNUM_USE_HARFBUZZ @@ -182,57 +169,6 @@ class MAGNUM_TEXT_EXPORT Font { #endif }; -/** -@brief %Text layouter - -Provides low-level text rendering using Font, used internally in TextRenderer. -*/ -class TextLayouter { - public: - /** - * @brief Constructor - * @param font %Font - * @param size %Font size - * @param text Text to layout - */ - TextLayouter(Font& font, const Float size, const std::string& text); - - ~TextLayouter(); - - /** @brief Count of glyphs in laid out text */ - inline UnsignedInt glyphCount() { - #ifdef MAGNUM_USE_HARFBUZZ - return _glyphCount; - #else - return glyphs.size(); - #endif - } - - /** - * @brief Render glyph - * @param i Glyph index - * @param cursorPosition Cursor position - * - * Returns quad position, texture coordinates and advance to next - * glyph. - */ - std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i); - - private: - #ifdef MAGNUM_USE_HARFBUZZ - const Font& font; - hb_buffer_t* buffer; - hb_glyph_info_t* glyphInfo; - hb_glyph_position_t* glyphPositions; - UnsignedInt _glyphCount; - #else - Font& font; - std::vector glyphs; - #endif - - const Float size; -}; - }} #endif diff --git a/src/Text/Text.h b/src/Text/Text.h index 03e126beb..d3ba2db87 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -23,9 +23,11 @@ namespace Magnum { namespace Text { -class Font; -class FontRenderer; -class TextLayouter; +class AbstractFont; +class AbstractLayouter; + +class FreeTypeFontRenderer; +class FreeTypeFont; class AbstractTextRenderer; template class TextRenderer; diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 218fa0a77..5de5724f1 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -19,7 +19,7 @@ #include "Extensions.h" #include "Mesh.h" #include "Shaders/AbstractVectorShader.h" -#include "Text/Font.h" +#include "Text/AbstractFont.h" namespace Magnum { namespace Text { @@ -51,10 +51,9 @@ struct Vertex { } -std::tuple, std::vector, std::vector, Rectangle> AbstractTextRenderer::render(Font& font, Float size, const std::string& text) { - TextLayouter layouter(font, size, text); - - const UnsignedInt vertexCount = layouter.glyphCount()*4; +std::tuple, std::vector, std::vector, Rectangle> AbstractTextRenderer::render(AbstractFont& font, Float size, const std::string& text) { + AbstractLayouter* const layouter = font.layout(size, text); + const UnsignedInt vertexCount = layouter->glyphCount()*4; /* Output data */ std::vector positions, texcoords; @@ -63,11 +62,11 @@ std::tuple, std::vector, std::vector, /* Render all glyphs */ Vector2 cursorPosition; - for(UnsignedInt i = 0; i != layouter.glyphCount(); ++i) { + for(UnsignedInt i = 0; i != layouter->glyphCount(); ++i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle quadPosition, textureCoordinates; Vector2 advance; - std::tie(quadPosition, textureCoordinates, advance) = layouter.renderGlyph(cursorPosition, i); + std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(cursorPosition, i); positions.insert(positions.end(), { quadPosition.topLeft(), @@ -87,21 +86,22 @@ std::tuple, std::vector, std::vector, } /* Create indices */ - std::vector indices(layouter.glyphCount()*6); - createIndices(indices.data(), layouter.glyphCount()); + std::vector indices(layouter->glyphCount()*6); + createIndices(indices.data(), layouter->glyphCount()); /* Rendered rectangle */ Rectangle rectangle; - if(layouter.glyphCount()) rectangle = {positions[1], positions[positions.size()-2]}; + if(layouter->glyphCount()) rectangle = {positions[1], positions[positions.size()-2]}; + delete layouter; return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle); } -std::tuple AbstractTextRenderer::render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { - TextLayouter layouter(font, size, text); +std::tuple AbstractTextRenderer::render(AbstractFont& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { + AbstractLayouter* const layouter = font.layout(size, text); - const UnsignedInt vertexCount = layouter.glyphCount()*4; - const UnsignedInt indexCount = layouter.glyphCount()*6; + const UnsignedInt vertexCount = layouter->glyphCount()*4; + const UnsignedInt indexCount = layouter->glyphCount()*6; /* Vertex buffer */ std::vector vertices; @@ -109,11 +109,11 @@ std::tuple AbstractTextRenderer::render(Font& font, Float size, /* Render all glyphs */ Vector2 cursorPosition; - for(UnsignedInt i = 0; i != layouter.glyphCount(); ++i) { + for(UnsignedInt i = 0; i != layouter->glyphCount(); ++i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle quadPosition, textureCoordinates; Vector2 advance; - std::tie(quadPosition, textureCoordinates, advance) = layouter.renderGlyph(cursorPosition, i); + std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(cursorPosition, i); vertices.insert(vertices.end(), { {quadPosition.topLeft(), textureCoordinates.topLeft()}, @@ -135,24 +135,24 @@ std::tuple AbstractTextRenderer::render(Font& font, Float size, indexType = Mesh::IndexType::UnsignedByte; indicesSize = indexCount*sizeof(UnsignedByte); indices = new char[indicesSize]; - createIndices(indices, layouter.glyphCount()); + createIndices(indices, layouter->glyphCount()); } else if(vertexCount < 65535) { indexType = Mesh::IndexType::UnsignedShort; indicesSize = indexCount*sizeof(UnsignedShort); indices = new char[indicesSize]; - createIndices(indices, layouter.glyphCount()); + createIndices(indices, layouter->glyphCount()); } else { indexType = Mesh::IndexType::UnsignedInt; indicesSize = indexCount*sizeof(UnsignedInt); indices = new char[indicesSize]; - createIndices(indices, layouter.glyphCount()); + createIndices(indices, layouter->glyphCount()); } indexBuffer->setData(indicesSize, indices, usage); delete indices; /* Rendered rectangle */ Rectangle rectangle; - if(layouter.glyphCount()) rectangle = {vertices[1].position, vertices[vertices.size()-2].position}; + if(layouter->glyphCount()) rectangle = {vertices[1].position, vertices[vertices.size()-2].position}; /* Configure mesh except for vertex buffer (depends on dimension count, done in subclass) */ @@ -161,10 +161,11 @@ std::tuple AbstractTextRenderer::render(Font& font, Float size, ->setIndexCount(indexCount) ->setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); + delete layouter; return std::make_tuple(std::move(mesh), rectangle); } -template std::tuple TextRenderer::render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { +template std::tuple TextRenderer::render(AbstractFont& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { /* Finalize mesh configuration and return the result */ auto r = AbstractTextRenderer::render(font, size, text, vertexBuffer, indexBuffer, usage); Mesh& mesh = std::get<0>(r); @@ -175,7 +176,7 @@ template std::tuple TextRenderer TextRenderer::TextRenderer(Font& font, const Float size): AbstractTextRenderer(font, size) { +template TextRenderer::TextRenderer(AbstractFont& font, const Float size): AbstractTextRenderer(font, size) { /* Finalize mesh configuration */ _mesh.addInterleavedVertexBuffer(&vertexBuffer, 0, typename Shaders::AbstractVectorShader::Position(Shaders::AbstractVectorShader::Position::Components::Two), @@ -236,23 +237,23 @@ void AbstractTextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usag } void AbstractTextRenderer::render(const std::string& text) { - TextLayouter layouter(font, size, text); + AbstractLayouter* layouter = font.layout(size, text); - CORRADE_ASSERT(layouter.glyphCount() <= _capacity, "Text::TextRenderer::render(): capacity" << _capacity << "too small to render" << layouter.glyphCount() << "glyphs", ); + CORRADE_ASSERT(layouter->glyphCount() <= _capacity, "Text::TextRenderer::render(): capacity" << _capacity << "too small to render" << layouter->glyphCount() << "glyphs", ); /* Render all glyphs */ - Vertex* const vertices = static_cast(vertexBuffer.map(0, layouter.glyphCount()*4*sizeof(Vertex), + Vertex* const vertices = static_cast(vertexBuffer.map(0, layouter->glyphCount()*4*sizeof(Vertex), Buffer::MapFlag::InvalidateBuffer|Buffer::MapFlag::Write)); Vector2 cursorPosition; - for(UnsignedInt i = 0; i != layouter.glyphCount(); ++i) { + for(UnsignedInt i = 0; i != layouter->glyphCount(); ++i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle quadPosition, textureCoordinates; Vector2 advance; - std::tie(quadPosition, textureCoordinates, advance) = layouter.renderGlyph(cursorPosition, i); + std::tie(quadPosition, textureCoordinates, advance) = layouter->renderGlyph(cursorPosition, i); if(i == 0) _rectangle.bottomLeft() = quadPosition.bottomLeft(); - else if(i == layouter.glyphCount()-1) + else if(i == layouter->glyphCount()-1) _rectangle.topRight() = quadPosition.topRight(); const std::size_t vertex = i*4; @@ -267,7 +268,9 @@ void AbstractTextRenderer::render(const std::string& text) { CORRADE_INTERNAL_ASSERT_OUTPUT(vertexBuffer.unmap()); /* Update index count */ - _mesh.setIndexCount(layouter.glyphCount()*6); + _mesh.setIndexCount(layouter->glyphCount()*6); + + delete layouter; } template class TextRenderer<2>; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index f4932fdf2..32d792521 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -50,14 +50,14 @@ class MAGNUM_TEXT_EXPORT AbstractTextRenderer { * Returns tuple with vertex positions, texture coordinates, indices * and rectangle spanning the rendered text. */ - static std::tuple, std::vector, std::vector, Rectangle> render(Font& font, Float size, const std::string& text); + static std::tuple, std::vector, std::vector, Rectangle> render(AbstractFont& font, Float size, const std::string& text); /** * @brief Constructor * @param font %Font to use * @param size %Font size */ - AbstractTextRenderer(Font& font, Float size); + AbstractTextRenderer(AbstractFont& font, Float size); virtual ~AbstractTextRenderer() = 0; @@ -106,13 +106,13 @@ class MAGNUM_TEXT_EXPORT AbstractTextRenderer { #else private: #endif - static std::tuple MAGNUM_LOCAL render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + static std::tuple MAGNUM_LOCAL render(AbstractFont& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); Mesh _mesh; Buffer vertexBuffer, indexBuffer; private: - Font& font; + AbstractFont& font; Float size; UnsignedInt _capacity; Rectangle _rectangle; @@ -197,14 +197,14 @@ template class MAGNUM_TEXT_EXPORT TextRenderer: public A * Returns mesh prepared for use with Shaders::AbstractVectorShader * subclasses and rectangle spanning the rendered text. */ - static std::tuple render(Font& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); + static std::tuple render(AbstractFont& font, Float size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); /** * @brief Constructor * @param font %Font to use * @param size %Font size */ - TextRenderer(Font& font, Float size); + TextRenderer(AbstractFont& font, Float size); using AbstractTextRenderer::render; }; From 2afda6f34d7b1f8bb06d6f8e833152da86ac5203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 15:20:35 +0100 Subject: [PATCH 514/567] Text: split out HarfBuzz layouting into new HarfBuzzFont class. It now allows to transparently select between FreeType and HarfBuzz layouting. The new class is built only if USE_HARFBUZZ is enabled. --- src/Text/CMakeLists.txt | 13 +++-- src/Text/FreeTypeFont.cpp | 54 ------------------- src/Text/FreeTypeFont.h | 21 +++----- src/Text/HarfBuzzFont.cpp | 106 ++++++++++++++++++++++++++++++++++++++ src/Text/HarfBuzzFont.h | 75 +++++++++++++++++++++++++++ src/Text/Text.h | 5 ++ src/Text/TextRenderer.h | 5 +- 7 files changed, 204 insertions(+), 75 deletions(-) create mode 100644 src/Text/HarfBuzzFont.cpp create mode 100644 src/Text/HarfBuzzFont.h diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index dd747e59e..b4e0d5e96 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -1,11 +1,6 @@ find_package(Freetype REQUIRED) include_directories(${FREETYPE_INCLUDE_DIRS}) -if(USE_HARFBUZZ) - find_package(HarfBuzz REQUIRED) - include_directories(${HARFBUZZ_INCLUDE_DIRS}) -endif() - set(MagnumText_SRCS AbstractFont.cpp FreeTypeFont.cpp @@ -18,6 +13,14 @@ set(MagnumText_HEADERS magnumTextVisibility.h) +if(USE_HARFBUZZ) + find_package(HarfBuzz REQUIRED) + include_directories(${HARFBUZZ_INCLUDE_DIRS}) + + set(MagnumText_SRCS ${MagnumText_SRCS} HarfBuzzFont.cpp) + set(MagnumText_HEADERS ${MagnumText_HEADERS} HarfBuzzFont.h) +endif() + add_library(MagnumText SHARED ${MagnumText_SRCS}) target_link_libraries(MagnumText Magnum MagnumTextureTools ${FREETYPE_LIBRARIES}) diff --git a/src/Text/FreeTypeFont.cpp b/src/Text/FreeTypeFont.cpp index 9444f3bce..37be7d45f 100644 --- a/src/Text/FreeTypeFont.cpp +++ b/src/Text/FreeTypeFont.cpp @@ -18,9 +18,6 @@ #include #include #include FT_FREETYPE_H -#ifdef MAGNUM_USE_HARFBUZZ -#include -#endif #include #include "Extensions.h" @@ -35,21 +32,12 @@ namespace { class FreeTypeLayouter: public AbstractLayouter { public: FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text); - ~FreeTypeLayouter(); std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; private: - #ifdef MAGNUM_USE_HARFBUZZ - const FreeTypeFont& font; - hb_buffer_t* buffer; - hb_glyph_info_t* glyphInfo; - hb_glyph_position_t* glyphPositions; - #else FreeTypeFont& font; std::vector glyphs; - #endif - const Float size; }; @@ -78,11 +66,6 @@ FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* void FreeTypeFont::finishConstruction() { CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); - #ifdef MAGNUM_USE_HARFBUZZ - /* Create Harfbuzz font */ - _hbFont = hb_ft_font_create(_ftFont, nullptr); - #endif - #ifndef MAGNUM_TARGET_GLES MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); #else @@ -182,9 +165,6 @@ void FreeTypeFont::prerenderDistanceField(const std::string& characters, const V } FreeTypeFont::~FreeTypeFont() { - #ifdef MAGNUM_USE_HARFBUZZ - hb_font_destroy(_hbFont); - #endif FT_Done_Face(_ftFont); } @@ -203,20 +183,6 @@ AbstractLayouter* FreeTypeFont::layout(const Float size, const std::string& text namespace { FreeTypeLayouter::FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text): font(font), size(size) { - #ifdef MAGNUM_USE_HARFBUZZ - /* Prepare HarfBuzz buffer */ - buffer = hb_buffer_create(); - hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); - hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); - hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); - - /* Layout the text */ - hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); - hb_shape(font.font(), buffer, nullptr, 0); - - glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); - glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); - #else /* Get glyph codes from characters */ glyphs.reserve(text.size()+1); _glyphCount = text.size(); @@ -225,38 +191,18 @@ FreeTypeLayouter::FreeTypeLayouter(FreeTypeFont& font, const Float size, const s std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); glyphs.push_back(FT_Get_Char_Index(font.font(), codepoint)); } - #endif -} - -FreeTypeLayouter::~FreeTypeLayouter() { - #ifdef MAGNUM_USE_HARFBUZZ - /* Destroy HarfBuzz buffer */ - hb_buffer_destroy(buffer); - #endif } std::tuple FreeTypeLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { /* Position of the texture in the resulting glyph, texture coordinates */ Rectangle texturePosition, textureCoordinates; - #ifdef MAGNUM_USE_HARFBUZZ - std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; - #else std::tie(texturePosition, textureCoordinates) = font[glyphs[i]]; - #endif - #ifdef MAGNUM_USE_HARFBUZZ - /* Glyph offset and advance to next glyph in normalized coordinates */ - Vector2 offset = Vector2(glyphPositions[i].x_offset, - glyphPositions[i].y_offset)/(64*font.size()); - Vector2 advance = Vector2(glyphPositions[i].x_advance, - glyphPositions[i].y_advance)/(64*font.size()); - #else /* Load glyph */ CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(font.font(), glyphs[i], FT_LOAD_DEFAULT) == 0); const FT_GlyphSlot slot = font.font()->glyph; Vector2 offset = Vector2(0, 0); /** @todo really? */ Vector2 advance = Vector2(slot->advance.x, slot->advance.y)/(64*font.size()); - #endif /* Absolute quad position, composed from cursor position, glyph offset and texture position, denormalized to requested text size */ diff --git a/src/Text/FreeTypeFont.h b/src/Text/FreeTypeFont.h index 62da7c0b9..f75285844 100644 --- a/src/Text/FreeTypeFont.h +++ b/src/Text/FreeTypeFont.h @@ -31,10 +31,6 @@ struct FT_LibraryRec_; typedef FT_LibraryRec_* FT_Library; struct FT_FaceRec_; typedef FT_FaceRec_* FT_Face; -struct hb_font_t; -struct hb_buffer_t; -struct hb_glyph_info_t; -struct hb_glyph_position_t; #endif namespace Magnum { namespace Text { @@ -148,25 +144,24 @@ class MAGNUM_TEXT_EXPORT FreeTypeFont: public AbstractFont { */ const std::tuple& operator[](char32_t character) const; - /** @brief %Font handle */ - #ifdef MAGNUM_USE_HARFBUZZ - inline hb_font_t* font() { return _hbFont; } - #else + /** @brief FreeType font handle */ inline FT_Face font() { return _ftFont; } - #endif AbstractLayouter* layout(const Float size, const std::string& text) override; + #ifdef DOXYGEN_GENERATING_OUTPUT + private: + #else + protected: + #endif + FT_Face _ftFont; + private: void MAGNUM_TEXT_LOCAL finishConstruction(); void MAGNUM_TEXT_LOCAL prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output); std::unordered_map> glyphs; - FT_Face _ftFont; Float _size; - #ifdef MAGNUM_USE_HARFBUZZ - hb_font_t* _hbFont; - #endif }; }} diff --git a/src/Text/HarfBuzzFont.cpp b/src/Text/HarfBuzzFont.cpp new file mode 100644 index 000000000..31b1ba1f8 --- /dev/null +++ b/src/Text/HarfBuzzFont.cpp @@ -0,0 +1,106 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "HarfBuzzFont.h" + +#include + +namespace Magnum { namespace Text { + +namespace { + +class HarfBuzzLayouter: public AbstractLayouter { + public: + HarfBuzzLayouter(HarfBuzzFont& font, const Float size, const std::string& text); + ~HarfBuzzLayouter(); + + std::tuple renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; + + private: + const HarfBuzzFont& font; + hb_buffer_t* buffer; + hb_glyph_info_t* glyphInfo; + hb_glyph_position_t* glyphPositions; + const Float size; +}; + +} + +HarfBuzzFont::HarfBuzzFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): FreeTypeFont(renderer, fontFile, size) { + finishConstruction(); +} + +HarfBuzzFont::HarfBuzzFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): FreeTypeFont(renderer, data, dataSize, size) { + finishConstruction(); +} + +void HarfBuzzFont::finishConstruction() { + /* Create Harfbuzz font */ + _hbFont = hb_ft_font_create(_ftFont, nullptr); +} + +HarfBuzzFont::~HarfBuzzFont() { + hb_font_destroy(_hbFont); +} + +AbstractLayouter* HarfBuzzFont::layout(const Float size, const std::string& text) { + return new HarfBuzzLayouter(*this, size, text); +} + +namespace { + +HarfBuzzLayouter::HarfBuzzLayouter(HarfBuzzFont& font, const Float size, const std::string& text): font(font), size(size) { + /* Prepare HarfBuzz buffer */ + buffer = hb_buffer_create(); + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); + hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); + + /* Layout the text */ + hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); + hb_shape(font.font(), buffer, nullptr, 0); + + glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); + glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); +} + +HarfBuzzLayouter::~HarfBuzzLayouter() { + /* Destroy HarfBuzz buffer */ + hb_buffer_destroy(buffer); +} + +std::tuple HarfBuzzLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Rectangle texturePosition, textureCoordinates; + std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; + + /* Glyph offset and advance to next glyph in normalized coordinates */ + Vector2 offset = Vector2(glyphPositions[i].x_offset, + glyphPositions[i].y_offset)/(64*font.size()); + Vector2 advance = Vector2(glyphPositions[i].x_advance, + glyphPositions[i].y_advance)/(64*font.size()); + + /* Absolute quad position, composed from cursor position, glyph offset + and texture position, denormalized to requested text size */ + Rectangle quadPosition = Rectangle::fromSize( + (cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, + texturePosition.size()*size); + + return std::make_tuple(quadPosition, textureCoordinates, advance); +} + +} + +}} diff --git a/src/Text/HarfBuzzFont.h b/src/Text/HarfBuzzFont.h new file mode 100644 index 000000000..01a264b5c --- /dev/null +++ b/src/Text/HarfBuzzFont.h @@ -0,0 +1,75 @@ +#ifndef Magnum_Text_HarfBuzzFont_h +#define Magnum_Text_HarfBuzzFont_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::Text::HarfBuzzFont + */ + +#include "Text/FreeTypeFont.h" + +#ifndef DOXYGEN_GENERATING_OUTPUT +struct hb_font_t; +#endif + +#ifndef MAGNUM_USE_HARFBUZZ +#error Magnum is not compiled with HarfBuzz support +#endif + +namespace Magnum { namespace Text { + +/** +@brief HarfBuzz font + +Improves FreeTypeFont with [HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz) +text layouting capabilities, such as kerning, ligatures etc. See FreeTypeFont +class documentation for more information about usage. +*/ +class MAGNUM_TEXT_EXPORT HarfBuzzFont: public FreeTypeFont { + public: + /** + * @brief Create font from file + * @param renderer %Font renderer + * @param fontFile %Font file + * @param size %Font size + */ + explicit HarfBuzzFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size); + + /** + * @brief Create font from memory + * @param renderer %Font renderer + * @param data %Font data + * @param dataSize %Font data size + * @param size %Font size + */ + explicit HarfBuzzFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); + + ~HarfBuzzFont(); + + /** @brief HarfBuzz font handle */ + inline hb_font_t* font() { return _hbFont; } + + AbstractLayouter* layout(const Float size, const std::string& text) override; + + private: + void MAGNUM_TEXT_LOCAL finishConstruction(); + + hb_font_t* _hbFont; +}; + +}} + +#endif diff --git a/src/Text/Text.h b/src/Text/Text.h index d3ba2db87..1beb1ee51 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -21,6 +21,8 @@ #include "Types.h" +#include "magnumConfigure.h" + namespace Magnum { namespace Text { class AbstractFont; @@ -28,6 +30,9 @@ class AbstractLayouter; class FreeTypeFontRenderer; class FreeTypeFont; +#ifdef MAGNUM_USE_HARFBUZZ +class HarfBuzzFont; +#endif class AbstractTextRenderer; template class TextRenderer; diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 32d792521..0cbefe4af 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -121,9 +121,8 @@ class MAGNUM_TEXT_EXPORT AbstractTextRenderer { /** @brief %Text renderer -Lays out the text into mesh using [HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz) -library. Use of ligatures, kerning etc. depends on features supported by -particular font. See also Font. +Lays out the text into mesh using given Font. Use of ligatures, kerning etc. +depends on features supported by particular font and its layouter. @section TextRenderer-usage Usage From e9efd87e1219d16246741710283b580cd6dda688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 4 Mar 2013 15:22:12 +0100 Subject: [PATCH 515/567] Text: off-by-one mistake. Not exactly an error, because reserving one byte more doesn't harm anything, but probably result of earlier copypaste from prerender(). --- src/Text/FreeTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/FreeTypeFont.cpp b/src/Text/FreeTypeFont.cpp index 37be7d45f..2078db100 100644 --- a/src/Text/FreeTypeFont.cpp +++ b/src/Text/FreeTypeFont.cpp @@ -184,7 +184,7 @@ namespace { FreeTypeLayouter::FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text): font(font), size(size) { /* Get glyph codes from characters */ - glyphs.reserve(text.size()+1); + glyphs.reserve(text.size()); _glyphCount = text.size(); for(std::size_t i = 0; i != text.size(); ) { UnsignedInt codepoint; From 3251660f81f54e7964d1bbb9ef5c9c80d67ef361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 8 Mar 2013 21:43:43 +0100 Subject: [PATCH 516/567] Physics: doc++ --- src/Physics/AbstractShape.h | 2 +- src/Physics/ObjectShape.h | 2 +- src/Physics/ObjectShapeGroup.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 9b2f882b7..9cd1cb1a4 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::AbstractShape + * @brief Class Magnum::Physics::AbstractShape, typedef Magnum::Physics::AbstractShape2D, Magnum::Physics::AbstractShape3D */ #include "Magnum.h" diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 9eb35379e..6c0b13ca9 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::ObjectShape + * @brief Class Magnum::Physics::ObjectShape, typedef Magnum::Physics::ObjectShape2D, Magnum::Physics::ObjectShape3D */ #include "SceneGraph/AbstractGroupedFeature.h" diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 05bf8fcc8..0e3ca7d28 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Physics::ObjectShapeGroup + * @brief Class Magnum::Physics::ObjectShapeGroup, typedef Magnum::Physics::ObjectShapeGroup2D, Magnum::Physics::ObjectShapeGroup3D */ #include From 231f3277ab9ca1d6852f44336dde6dc43bc0c954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 8 Mar 2013 23:16:01 +0100 Subject: [PATCH 517/567] Adapted to Corrade changes. Allowing to instantiate Trade::AbstractImporter subclasses directly without plugin manager. --- src/Math/Algorithms/Test/GaussJordanTest.cpp | 4 +- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 4 +- src/Math/Algorithms/Test/SvdTest.cpp | 4 +- src/Math/Geometry/Test/DistanceTest.cpp | 8 +-- src/Math/Geometry/Test/IntersectionTest.cpp | 2 +- src/Math/Geometry/Test/RectangleTest.cpp | 11 +-- src/Math/Test/AngleTest.cpp | 10 +-- src/Math/Test/BoolVectorTest.cpp | 26 +++---- src/Math/Test/ComplexTest.cpp | 42 +++++------ src/Math/Test/ConstantsTest.cpp | 2 +- src/Math/Test/DualComplexTest.cpp | 38 +++++----- src/Math/Test/DualQuaternionTest.cpp | 48 ++++++------- src/Math/Test/DualTest.cpp | 20 +++--- src/Math/Test/FunctionsTest.cpp | 38 +++++----- src/Math/Test/MathTypeTraitsTest.cpp | 4 +- src/Math/Test/Matrix3Test.cpp | 40 +++++------ src/Math/Test/Matrix4Test.cpp | 50 ++++++------- src/Math/Test/MatrixTest.cpp | 24 +++---- src/Math/Test/QuaternionTest.cpp | 60 ++++++++-------- src/Math/Test/RectangularMatrixTest.cpp | 54 +++++++------- src/Math/Test/SwizzleTest.cpp | 8 +-- src/Math/Test/UnitTest.cpp | 16 ++--- src/Math/Test/Vector2Test.cpp | 23 +++--- src/Math/Test/Vector3Test.cpp | 30 ++++---- src/Math/Test/Vector4Test.cpp | 26 +++---- src/Math/Test/VectorTest.cpp | 70 +++++++++---------- src/MeshTools/Test/CleanTest.cpp | 31 ++++---- .../Test/CombineIndexedArraysTest.cpp | 4 +- src/MeshTools/Test/CompressIndicesTest.cpp | 6 +- src/MeshTools/Test/FlipNormalsTest.cpp | 6 +- .../Test/GenerateFlatNormalsTest.cpp | 4 +- src/MeshTools/Test/InterleaveTest.cpp | 12 ++-- src/MeshTools/Test/SubdivideTest.cpp | 4 +- src/MeshTools/Test/TipsifyTest.cpp | 4 +- src/MeshTools/Test/TransformTest.cpp | 8 +-- src/Physics/Test/AbstractShapeTest.cpp | 2 +- src/Physics/Test/AxisAlignedBoxTest.cpp | 4 +- src/Physics/Test/BoxTest.cpp | 2 +- src/Physics/Test/CapsuleTest.cpp | 4 +- src/Physics/Test/LineTest.cpp | 2 +- src/Physics/Test/ObjectShapeTest.cpp | 4 +- src/Physics/Test/PlaneTest.cpp | 6 +- src/Physics/Test/PointTest.cpp | 2 +- src/Physics/Test/ShapeGroupTest.cpp | 4 +- src/Physics/Test/SphereTest.cpp | 10 +-- src/Primitives/Test/CapsuleTest.cpp | 4 +- src/Primitives/Test/CylinderTest.cpp | 4 +- src/Primitives/Test/UVSphereTest.cpp | 4 +- src/SceneGraph/Test/AnimableTest.cpp | 15 ++-- src/SceneGraph/Test/CameraTest.cpp | 16 ++--- .../EuclideanMatrixTransformation2DTest.cpp | 20 +++--- .../EuclideanMatrixTransformation3DTest.cpp | 20 +++--- .../Test/MatrixTransformation2DTest.cpp | 22 +++--- .../Test/MatrixTransformation3DTest.cpp | 22 +++--- src/SceneGraph/Test/ObjectTest.cpp | 18 ++--- src/SceneGraph/Test/SceneTest.cpp | 4 +- src/Test/AbstractImageTest.cpp | 4 +- src/Test/AbstractShaderProgramTest.cpp | 28 ++++---- src/Test/ArrayTest.cpp | 8 +-- src/Test/ColorTest.cpp | 24 +++---- src/Test/MeshTest.cpp | 8 +-- src/Test/ResourceManagerTest.cpp | 16 ++--- src/Test/SwizzleTest.cpp | 6 +- src/TextureTools/Test/AtlasTest.cpp | 8 +-- src/Trade/AbstractImporter.h | 12 ++-- src/Trade/Test/ObjectData2DTest.cpp | 2 +- src/Trade/Test/ObjectData3DTest.cpp | 2 +- 67 files changed, 526 insertions(+), 522 deletions(-) diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index c2ef7c925..2f1383197 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -31,8 +31,8 @@ typedef RectangularMatrix<4, 4, Float> Matrix4; typedef Vector<4, Float> Vector4; GaussJordanTest::GaussJordanTest() { - addTests(&GaussJordanTest::singular, - &GaussJordanTest::invert); + addTests({&GaussJordanTest::singular, + &GaussJordanTest::invert}); } void GaussJordanTest::singular() { diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 6af54d4e6..80ad62ab2 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -31,8 +31,8 @@ typedef RectangularMatrix<3, 3, Float> Matrix3; typedef Vector<3, Float> Vector3; GramSchmidtTest::GramSchmidtTest() { - addTests(&GramSchmidtTest::orthogonalize, - &GramSchmidtTest::orthonormalize); + addTests({&GramSchmidtTest::orthogonalize, + &GramSchmidtTest::orthonormalize}); } void GramSchmidtTest::orthogonalize() { diff --git a/src/Math/Algorithms/Test/SvdTest.cpp b/src/Math/Algorithms/Test/SvdTest.cpp index b0ccade4d..aebea8cfb 100644 --- a/src/Math/Algorithms/Test/SvdTest.cpp +++ b/src/Math/Algorithms/Test/SvdTest.cpp @@ -50,8 +50,8 @@ constexpr static Matrix5x8d a( static const Vector5d expected(std::sqrt(1248.0), 0.0, 20.0, std::sqrt(384.0), 0.0); SvdTest::SvdTest() { - addTests(&SvdTest::testDouble, - &SvdTest::testFloat); + addTests({&SvdTest::testDouble, + &SvdTest::testFloat}); } void SvdTest::testDouble() { diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index 2ddf630d2..01053098d 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -36,10 +36,10 @@ typedef Math::Vector3 Vector3; typedef Math::Constants Constants; DistanceTest::DistanceTest() { - addTests(&DistanceTest::linePoint2D, - &DistanceTest::linePoint3D, - &DistanceTest::lineSegmentPoint2D, - &DistanceTest::lineSegmentPoint3D); + addTests({&DistanceTest::linePoint2D, + &DistanceTest::linePoint3D, + &DistanceTest::lineSegmentPoint2D, + &DistanceTest::lineSegmentPoint3D}); } void DistanceTest::linePoint2D() { diff --git a/src/Math/Geometry/Test/IntersectionTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp index c9cb17fdb..4004dacf6 100644 --- a/src/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -30,7 +30,7 @@ class IntersectionTest: public Corrade::TestSuite::Tester { typedef Math::Vector3 Vector3; IntersectionTest::IntersectionTest() { - addTests(&IntersectionTest::planeLine); + addTests({&IntersectionTest::planeLine}); } void IntersectionTest::planeLine() { diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 99eb5e309..1ef1de127 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -37,11 +37,12 @@ typedef Geometry::Rectangle Rectanglei; typedef Vector2 Vector2i; RectangleTest::RectangleTest() { - addTests(&RectangleTest::access, - &RectangleTest::compare, - &RectangleTest::construct, - &RectangleTest::size, - &RectangleTest::debug); + addTests({&RectangleTest::access, + &RectangleTest::compare, + &RectangleTest::construct, + &RectangleTest::size, + + &RectangleTest::debug}); } void RectangleTest::access() { diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp index 5a2817893..9cc2ca081 100644 --- a/src/Math/Test/AngleTest.cpp +++ b/src/Math/Test/AngleTest.cpp @@ -38,12 +38,12 @@ typedef Math::Deg Degd; typedef Math::Rad Radd; AngleTest::AngleTest() { - addTests(&AngleTest::construct, - &AngleTest::literals, - &AngleTest::conversion, + addTests({&AngleTest::construct, + &AngleTest::literals, + &AngleTest::conversion, - &AngleTest::debugDeg, - &AngleTest::debugRad); + &AngleTest::debugDeg, + &AngleTest::debugRad}); } void AngleTest::construct() { diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp index e4440965f..312be39b3 100644 --- a/src/Math/Test/BoolVectorTest.cpp +++ b/src/Math/Test/BoolVectorTest.cpp @@ -50,23 +50,23 @@ static_assert(BoolVector<17>::DataSize == 3, "Improper DataSize"); typedef Math::BoolVector<19> BoolVector19; BoolVectorTest::BoolVectorTest() { - addTests(&BoolVectorTest::constructDefault, - &BoolVectorTest::constructOneValue, - &BoolVectorTest::constructOneElement, - &BoolVectorTest::data, + addTests({&BoolVectorTest::constructDefault, + &BoolVectorTest::constructOneValue, + &BoolVectorTest::constructOneElement, + &BoolVectorTest::data, - &BoolVectorTest::constExpressions, + &BoolVectorTest::constExpressions, - &BoolVectorTest::compare, - &BoolVectorTest::compareUndefined, - &BoolVectorTest::all, - &BoolVectorTest::none, - &BoolVectorTest::any, + &BoolVectorTest::compare, + &BoolVectorTest::compareUndefined, + &BoolVectorTest::all, + &BoolVectorTest::none, + &BoolVectorTest::any, - &BoolVectorTest::bitInverse, - &BoolVectorTest::bitAndOrXor, + &BoolVectorTest::bitInverse, + &BoolVectorTest::bitAndOrXor, - &BoolVectorTest::debug); + &BoolVectorTest::debug}); } void BoolVectorTest::constructDefault() { diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index ec407d53b..7f7bd484a 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -55,33 +55,33 @@ class ComplexTest: public Corrade::TestSuite::Tester { }; ComplexTest::ComplexTest() { - addTests(&ComplexTest::construct, - &ComplexTest::constructDefault, - &ComplexTest::constructFromVector, - &ComplexTest::compare, + addTests({&ComplexTest::construct, + &ComplexTest::constructDefault, + &ComplexTest::constructFromVector, + &ComplexTest::compare, - &ComplexTest::constExpressions, + &ComplexTest::constExpressions, - &ComplexTest::addSubtract, - &ComplexTest::negated, - &ComplexTest::multiplyDivideScalar, - &ComplexTest::multiply, + &ComplexTest::addSubtract, + &ComplexTest::negated, + &ComplexTest::multiplyDivideScalar, + &ComplexTest::multiply, - &ComplexTest::dot, - &ComplexTest::dotSelf, - &ComplexTest::length, - &ComplexTest::normalized, + &ComplexTest::dot, + &ComplexTest::dotSelf, + &ComplexTest::length, + &ComplexTest::normalized, - &ComplexTest::conjugated, - &ComplexTest::inverted, - &ComplexTest::invertedNormalized, + &ComplexTest::conjugated, + &ComplexTest::inverted, + &ComplexTest::invertedNormalized, - &ComplexTest::angle, - &ComplexTest::rotation, - &ComplexTest::matrix, - &ComplexTest::transformVector, + &ComplexTest::angle, + &ComplexTest::rotation, + &ComplexTest::matrix, + &ComplexTest::transformVector, - &ComplexTest::debug); + &ComplexTest::debug}); } typedef Math::Deg Deg; diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index 7192b2db7..a6e244b89 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -28,7 +28,7 @@ class ConstantsTest: public Corrade::TestSuite::Tester { }; ConstantsTest::ConstantsTest() { - addTests(&ConstantsTest::constants); + addTests({&ConstantsTest::constants}); } void ConstantsTest::constants() { diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index ee292a6ba..025c3d72b 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -61,31 +61,31 @@ typedef Math::Matrix3 Matrix3; typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { - addTests(&DualComplexTest::construct, - &DualComplexTest::constructDefault, - &DualComplexTest::constructFromVector, + addTests({&DualComplexTest::construct, + &DualComplexTest::constructDefault, + &DualComplexTest::constructFromVector, - &DualComplexTest::constExpressions, + &DualComplexTest::constExpressions, - &DualComplexTest::multiply, + &DualComplexTest::multiply, - &DualComplexTest::lengthSquared, - &DualComplexTest::length, - &DualComplexTest::normalized, + &DualComplexTest::lengthSquared, + &DualComplexTest::length, + &DualComplexTest::normalized, - &DualComplexTest::complexConjugated, - &DualComplexTest::dualConjugated, - &DualComplexTest::conjugated, - &DualComplexTest::inverted, - &DualComplexTest::invertedNormalized, + &DualComplexTest::complexConjugated, + &DualComplexTest::dualConjugated, + &DualComplexTest::conjugated, + &DualComplexTest::inverted, + &DualComplexTest::invertedNormalized, - &DualComplexTest::rotation, - &DualComplexTest::translation, - &DualComplexTest::combinedTransformParts, - &DualComplexTest::matrix, - &DualComplexTest::transformPoint, + &DualComplexTest::rotation, + &DualComplexTest::translation, + &DualComplexTest::combinedTransformParts, + &DualComplexTest::matrix, + &DualComplexTest::transformPoint, - &DualComplexTest::debug); + &DualComplexTest::debug}); } void DualComplexTest::construct() { diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 7bcbcbccd..fcbe9e021 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -59,30 +59,30 @@ typedef Math::Quaternion Quaternion; typedef Math::Vector3 Vector3; DualQuaternionTest::DualQuaternionTest() { - addTests(&DualQuaternionTest::construct, - &DualQuaternionTest::constructDefault, - &DualQuaternionTest::constructFromVector, - - &DualQuaternionTest::constExpressions, - - &DualQuaternionTest::lengthSquared, - &DualQuaternionTest::length, - &DualQuaternionTest::normalized, - - &DualQuaternionTest::quaternionConjugated, - &DualQuaternionTest::dualConjugated, - &DualQuaternionTest::conjugated, - &DualQuaternionTest::inverted, - &DualQuaternionTest::invertedNormalized, - - &DualQuaternionTest::rotation, - &DualQuaternionTest::translation, - &DualQuaternionTest::combinedTransformParts, - &DualQuaternionTest::matrix, - &DualQuaternionTest::transformPoint, - &DualQuaternionTest::transformPointNormalized, - - &DualQuaternionTest::debug); + addTests({&DualQuaternionTest::construct, + &DualQuaternionTest::constructDefault, + &DualQuaternionTest::constructFromVector, + + &DualQuaternionTest::constExpressions, + + &DualQuaternionTest::lengthSquared, + &DualQuaternionTest::length, + &DualQuaternionTest::normalized, + + &DualQuaternionTest::quaternionConjugated, + &DualQuaternionTest::dualConjugated, + &DualQuaternionTest::conjugated, + &DualQuaternionTest::inverted, + &DualQuaternionTest::invertedNormalized, + + &DualQuaternionTest::rotation, + &DualQuaternionTest::translation, + &DualQuaternionTest::combinedTransformParts, + &DualQuaternionTest::matrix, + &DualQuaternionTest::transformPoint, + &DualQuaternionTest::transformPointNormalized, + + &DualQuaternionTest::debug}); } void DualQuaternionTest::construct() { diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index e1be57922..74c7588b6 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -43,20 +43,20 @@ class DualTest: public Corrade::TestSuite::Tester { typedef Math::Dual Dual; DualTest::DualTest() { - addTests(&DualTest::construct, - &DualTest::constructDefault, - &DualTest::compare, + addTests({&DualTest::construct, + &DualTest::constructDefault, + &DualTest::compare, - &DualTest::constExpressions, + &DualTest::constExpressions, - &DualTest::addSubtract, - &DualTest::negated, - &DualTest::multiplyDivide, + &DualTest::addSubtract, + &DualTest::negated, + &DualTest::multiplyDivide, - &DualTest::conjugated, - &DualTest::sqrt, + &DualTest::conjugated, + &DualTest::sqrt, - &DualTest::debug); + &DualTest::debug}); } void DualTest::construct() { diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index cfe7b64d4..3551aa338 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -54,25 +54,25 @@ typedef Math::Vector3 Vector3b; typedef Math::Vector3 Vector3i; FunctionsTest::FunctionsTest() { - addTests(&FunctionsTest::min, - &FunctionsTest::max, - &FunctionsTest::abs, - &FunctionsTest::sqrt, - &FunctionsTest::clamp, - &FunctionsTest::lerp, - &FunctionsTest::normalizeUnsigned, - &FunctionsTest::normalizeSigned, - &FunctionsTest::denormalizeUnsigned, - &FunctionsTest::denormalizeSigned, - &FunctionsTest::renormalizeUnsinged, - &FunctionsTest::renormalizeSinged, - - &FunctionsTest::normalizeTypeDeduction, - - &FunctionsTest::pow, - &FunctionsTest::log, - &FunctionsTest::log2, - &FunctionsTest::trigonometric); + addTests({&FunctionsTest::min, + &FunctionsTest::max, + &FunctionsTest::abs, + &FunctionsTest::sqrt, + &FunctionsTest::clamp, + &FunctionsTest::lerp, + &FunctionsTest::normalizeUnsigned, + &FunctionsTest::normalizeSigned, + &FunctionsTest::denormalizeUnsigned, + &FunctionsTest::denormalizeSigned, + &FunctionsTest::renormalizeUnsinged, + &FunctionsTest::renormalizeSinged, + + &FunctionsTest::normalizeTypeDeduction, + + &FunctionsTest::pow, + &FunctionsTest::log, + &FunctionsTest::log2, + &FunctionsTest::trigonometric}); } void FunctionsTest::min() { diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index 1f276b3a5..42616fb6e 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -33,8 +33,8 @@ class MathTypeTraitsTest: public Corrade::TestSuite::Tester { }; MathTypeTraitsTest::MathTypeTraitsTest() { - addTests(&MathTypeTraitsTest::equalsIntegral, - &MathTypeTraitsTest::equalsFloatingPoint); + addTests({&MathTypeTraitsTest::equalsIntegral, + &MathTypeTraitsTest::equalsFloatingPoint}); } void MathTypeTraitsTest::equalsIntegral() { diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index e34123275..f10efb385 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -54,26 +54,26 @@ typedef Math::Matrix<2, Float> Matrix2; typedef Math::Vector2 Vector2; Matrix3Test::Matrix3Test() { - addTests(&Matrix3Test::construct, - &Matrix3Test::constructIdentity, - &Matrix3Test::constructZero, - &Matrix3Test::constructConversion, - &Matrix3Test::constructCopy, - - &Matrix3Test::translation, - &Matrix3Test::scaling, - &Matrix3Test::rotation, - &Matrix3Test::reflection, - &Matrix3Test::projection, - &Matrix3Test::fromParts, - &Matrix3Test::rotationScalingPart, - &Matrix3Test::rotationPart, - &Matrix3Test::vectorParts, - &Matrix3Test::invertedEuclidean, - &Matrix3Test::transform, - - &Matrix3Test::debug, - &Matrix3Test::configuration); + addTests({&Matrix3Test::construct, + &Matrix3Test::constructIdentity, + &Matrix3Test::constructZero, + &Matrix3Test::constructConversion, + &Matrix3Test::constructCopy, + + &Matrix3Test::translation, + &Matrix3Test::scaling, + &Matrix3Test::rotation, + &Matrix3Test::reflection, + &Matrix3Test::projection, + &Matrix3Test::fromParts, + &Matrix3Test::rotationScalingPart, + &Matrix3Test::rotationPart, + &Matrix3Test::vectorParts, + &Matrix3Test::invertedEuclidean, + &Matrix3Test::transform, + + &Matrix3Test::debug, + &Matrix3Test::configuration}); } void Matrix3Test::construct() { diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 09894f084..3cd612692 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -60,31 +60,31 @@ typedef Math::Matrix<3, Float> Matrix3; typedef Math::Vector3 Vector3; Matrix4Test::Matrix4Test() { - addTests(&Matrix4Test::construct, - &Matrix4Test::constructIdentity, - &Matrix4Test::constructZero, - &Matrix4Test::constructConversion, - &Matrix4Test::constructCopy, - - &Matrix4Test::translation, - &Matrix4Test::scaling, - &Matrix4Test::rotation, - &Matrix4Test::rotationX, - &Matrix4Test::rotationY, - &Matrix4Test::rotationZ, - &Matrix4Test::reflection, - &Matrix4Test::orthographicProjection, - &Matrix4Test::perspectiveProjection, - &Matrix4Test::perspectiveProjectionFov, - &Matrix4Test::fromParts, - &Matrix4Test::rotationScalingPart, - &Matrix4Test::rotationPart, - &Matrix4Test::vectorParts, - &Matrix4Test::invertedEuclidean, - &Matrix4Test::transform, - - &Matrix4Test::debug, - &Matrix4Test::configuration); + addTests({&Matrix4Test::construct, + &Matrix4Test::constructIdentity, + &Matrix4Test::constructZero, + &Matrix4Test::constructConversion, + &Matrix4Test::constructCopy, + + &Matrix4Test::translation, + &Matrix4Test::scaling, + &Matrix4Test::rotation, + &Matrix4Test::rotationX, + &Matrix4Test::rotationY, + &Matrix4Test::rotationZ, + &Matrix4Test::reflection, + &Matrix4Test::orthographicProjection, + &Matrix4Test::perspectiveProjection, + &Matrix4Test::perspectiveProjectionFov, + &Matrix4Test::fromParts, + &Matrix4Test::rotationScalingPart, + &Matrix4Test::rotationPart, + &Matrix4Test::vectorParts, + &Matrix4Test::invertedEuclidean, + &Matrix4Test::transform, + + &Matrix4Test::debug, + &Matrix4Test::configuration}); } void Matrix4Test::construct() { diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 72525cd45..6d5567731 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -48,18 +48,18 @@ typedef Vector<4, Int> Vector4i; typedef Vector<3, Float> Vector3; MatrixTest::MatrixTest() { - addTests(&MatrixTest::construct, - &MatrixTest::constructIdentity, - &MatrixTest::constructZero, - &MatrixTest::constructConversion, - &MatrixTest::constructCopy, - - &MatrixTest::trace, - &MatrixTest::ij, - &MatrixTest::determinant, - &MatrixTest::inverted, - &MatrixTest::debug, - &MatrixTest::configuration); + addTests({&MatrixTest::construct, + &MatrixTest::constructIdentity, + &MatrixTest::constructZero, + &MatrixTest::constructConversion, + &MatrixTest::constructCopy, + + &MatrixTest::trace, + &MatrixTest::ij, + &MatrixTest::determinant, + &MatrixTest::inverted, + &MatrixTest::debug, + &MatrixTest::configuration}); } void MatrixTest::construct() { diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 2d4be8a32..b7ba2aad9 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -66,36 +66,36 @@ typedef Math::Vector3 Vector3; typedef Math::Vector4 Vector4; QuaternionTest::QuaternionTest() { - addTests(&QuaternionTest::construct, - &QuaternionTest::constructDefault, - &QuaternionTest::constructFromVector, - &QuaternionTest::compare, - - &QuaternionTest::constExpressions, - - &QuaternionTest::addSubtract, - &QuaternionTest::negated, - &QuaternionTest::multiplyDivideScalar, - &QuaternionTest::multiply, - - &QuaternionTest::dot, - &QuaternionTest::dotSelf, - &QuaternionTest::length, - &QuaternionTest::normalized, - - &QuaternionTest::conjugated, - &QuaternionTest::inverted, - &QuaternionTest::invertedNormalized, - - &QuaternionTest::rotation, - &QuaternionTest::angle, - &QuaternionTest::matrix, - &QuaternionTest::lerp, - &QuaternionTest::slerp, - &QuaternionTest::transformVector, - &QuaternionTest::transformVectorNormalized, - - &QuaternionTest::debug); + addTests({&QuaternionTest::construct, + &QuaternionTest::constructDefault, + &QuaternionTest::constructFromVector, + &QuaternionTest::compare, + + &QuaternionTest::constExpressions, + + &QuaternionTest::addSubtract, + &QuaternionTest::negated, + &QuaternionTest::multiplyDivideScalar, + &QuaternionTest::multiply, + + &QuaternionTest::dot, + &QuaternionTest::dotSelf, + &QuaternionTest::length, + &QuaternionTest::normalized, + + &QuaternionTest::conjugated, + &QuaternionTest::inverted, + &QuaternionTest::invertedNormalized, + + &QuaternionTest::rotation, + &QuaternionTest::angle, + &QuaternionTest::matrix, + &QuaternionTest::lerp, + &QuaternionTest::slerp, + &QuaternionTest::transformVector, + &QuaternionTest::transformVectorNormalized, + + &QuaternionTest::debug}); } void QuaternionTest::construct() { diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 5782f1635..bfdd0f3b4 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -64,33 +64,33 @@ typedef Vector<2, Float> Vector2; typedef Vector<2, Int> Vector2i; RectangularMatrixTest::RectangularMatrixTest() { - addTests(&RectangularMatrixTest::construct, - &RectangularMatrixTest::constructDefault, - &RectangularMatrixTest::constructConversion, - &RectangularMatrixTest::constructFromData, - &RectangularMatrixTest::constructFromDiagonal, - &RectangularMatrixTest::constructCopy, - &RectangularMatrixTest::data, - - &RectangularMatrixTest::compare, - - &RectangularMatrixTest::negative, - &RectangularMatrixTest::addSubtract, - &RectangularMatrixTest::multiplyDivide, - &RectangularMatrixTest::multiply, - - &RectangularMatrixTest::transposed, - &RectangularMatrixTest::diagonal, - - &RectangularMatrixTest::sum, - &RectangularMatrixTest::product, - &RectangularMatrixTest::min, - &RectangularMatrixTest::minAbs, - &RectangularMatrixTest::max, - &RectangularMatrixTest::maxAbs, - - &RectangularMatrixTest::debug, - &RectangularMatrixTest::configuration); + addTests({&RectangularMatrixTest::construct, + &RectangularMatrixTest::constructDefault, + &RectangularMatrixTest::constructConversion, + &RectangularMatrixTest::constructFromData, + &RectangularMatrixTest::constructFromDiagonal, + &RectangularMatrixTest::constructCopy, + &RectangularMatrixTest::data, + + &RectangularMatrixTest::compare, + + &RectangularMatrixTest::negative, + &RectangularMatrixTest::addSubtract, + &RectangularMatrixTest::multiplyDivide, + &RectangularMatrixTest::multiply, + + &RectangularMatrixTest::transposed, + &RectangularMatrixTest::diagonal, + + &RectangularMatrixTest::sum, + &RectangularMatrixTest::product, + &RectangularMatrixTest::min, + &RectangularMatrixTest::minAbs, + &RectangularMatrixTest::max, + &RectangularMatrixTest::maxAbs, + + &RectangularMatrixTest::debug, + &RectangularMatrixTest::configuration}); } void RectangularMatrixTest::construct() { diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp index fd51bdc38..4ce3dfca9 100644 --- a/src/Math/Test/SwizzleTest.cpp +++ b/src/Math/Test/SwizzleTest.cpp @@ -32,10 +32,10 @@ class SwizzleTest: public Corrade::TestSuite::Tester { typedef Vector<4, Int> Vector4i; SwizzleTest::SwizzleTest() { - addTests(&SwizzleTest::components, - &SwizzleTest::constants, - &SwizzleTest::sizes, - &SwizzleTest::constExpressions); + addTests({&SwizzleTest::components, + &SwizzleTest::constants, + &SwizzleTest::sizes, + &SwizzleTest::constExpressions}); } void SwizzleTest::components() { diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index 347474d53..b575342ed 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -34,14 +34,14 @@ class UnitTest: public Corrade::TestSuite::Tester { }; UnitTest::UnitTest() { - addTests(&UnitTest::construct, - &UnitTest::constructDefault, - &UnitTest::constructConversion, - &UnitTest::compare, - - &UnitTest::negated, - &UnitTest::addSubtract, - &UnitTest::multiplyDivide); + addTests({&UnitTest::construct, + &UnitTest::constructDefault, + &UnitTest::constructConversion, + &UnitTest::compare, + + &UnitTest::negated, + &UnitTest::addSubtract, + &UnitTest::multiplyDivide}); } template struct Sec_; diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index d4936ad48..3367b9814 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -43,17 +43,18 @@ typedef Math::Vector2 Vector2; typedef Math::Vector2 Vector2i; Vector2Test::Vector2Test() { - addTests(&Vector2Test::construct, - &Vector2Test::constructDefault, - &Vector2Test::constructOneValue, - &Vector2Test::constructConversion, - &Vector2Test::constructCopy, - - &Vector2Test::access, - &Vector2Test::axes, - &Vector2Test::scales, - &Vector2Test::debug, - &Vector2Test::configuration); + addTests({&Vector2Test::construct, + &Vector2Test::constructDefault, + &Vector2Test::constructOneValue, + &Vector2Test::constructConversion, + &Vector2Test::constructCopy, + + &Vector2Test::access, + &Vector2Test::axes, + &Vector2Test::scales, + + &Vector2Test::debug, + &Vector2Test::configuration}); } void Vector2Test::construct() { diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index e30508de7..b046c9b32 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -47,21 +47,21 @@ typedef Math::Vector3 Vector3i; typedef Math::Vector2 Vector2; Vector3Test::Vector3Test() { - addTests(&Vector3Test::construct, - &Vector3Test::constructDefault, - &Vector3Test::constructOneValue, - &Vector3Test::constructParts, - &Vector3Test::constructConversion, - &Vector3Test::constructCopy, - - &Vector3Test::access, - &Vector3Test::cross, - &Vector3Test::axes, - &Vector3Test::scales, - &Vector3Test::twoComponent, - - &Vector3Test::debug, - &Vector3Test::configuration); + addTests({&Vector3Test::construct, + &Vector3Test::constructDefault, + &Vector3Test::constructOneValue, + &Vector3Test::constructParts, + &Vector3Test::constructConversion, + &Vector3Test::constructCopy, + + &Vector3Test::access, + &Vector3Test::cross, + &Vector3Test::axes, + &Vector3Test::scales, + &Vector3Test::twoComponent, + + &Vector3Test::debug, + &Vector3Test::configuration}); } void Vector3Test::construct() { diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index c1496c31f..df5407ff8 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -46,19 +46,19 @@ typedef Math::Vector3 Vector3; typedef Math::Vector2 Vector2; Vector4Test::Vector4Test() { - addTests(&Vector4Test::construct, - &Vector4Test::constructDefault, - &Vector4Test::constructOneValue, - &Vector4Test::constructParts, - &Vector4Test::constructConversion, - &Vector4Test::constructCopy, - - &Vector4Test::access, - &Vector4Test::threeComponent, - &Vector4Test::twoComponent, - - &Vector4Test::debug, - &Vector4Test::configuration); + addTests({&Vector4Test::construct, + &Vector4Test::constructDefault, + &Vector4Test::constructOneValue, + &Vector4Test::constructParts, + &Vector4Test::constructConversion, + &Vector4Test::constructCopy, + + &Vector4Test::access, + &Vector4Test::threeComponent, + &Vector4Test::twoComponent, + + &Vector4Test::debug, + &Vector4Test::configuration}); } void Vector4Test::construct() { diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 8c364b458..5086c0de8 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -68,41 +68,41 @@ typedef Vector<4, Float> Vector4; typedef Vector<4, Int> Vector4i; VectorTest::VectorTest() { - addTests(&VectorTest::construct, - &VectorTest::constructFromData, - &VectorTest::constructDefault, - &VectorTest::constructOneValue, - &VectorTest::constructOneComponent, - &VectorTest::constructConversion, - &VectorTest::constructCopy, - &VectorTest::data, - - &VectorTest::negative, - &VectorTest::addSubtract, - &VectorTest::multiplyDivide, - &VectorTest::multiplyDivideComponentWise, - - &VectorTest::compare, - &VectorTest::compareComponentWise, - - &VectorTest::dot, - &VectorTest::dotSelf, - &VectorTest::length, - &VectorTest::normalized, - - &VectorTest::sum, - &VectorTest::product, - &VectorTest::min, - &VectorTest::minAbs, - &VectorTest::max, - &VectorTest::maxAbs, - - &VectorTest::projected, - &VectorTest::projectedOntoNormalized, - &VectorTest::angle, - - &VectorTest::debug, - &VectorTest::configuration); + addTests({&VectorTest::construct, + &VectorTest::constructFromData, + &VectorTest::constructDefault, + &VectorTest::constructOneValue, + &VectorTest::constructOneComponent, + &VectorTest::constructConversion, + &VectorTest::constructCopy, + &VectorTest::data, + + &VectorTest::negative, + &VectorTest::addSubtract, + &VectorTest::multiplyDivide, + &VectorTest::multiplyDivideComponentWise, + + &VectorTest::compare, + &VectorTest::compareComponentWise, + + &VectorTest::dot, + &VectorTest::dotSelf, + &VectorTest::length, + &VectorTest::normalized, + + &VectorTest::sum, + &VectorTest::product, + &VectorTest::min, + &VectorTest::minAbs, + &VectorTest::max, + &VectorTest::maxAbs, + + &VectorTest::projected, + &VectorTest::projectedOntoNormalized, + &VectorTest::angle, + + &VectorTest::debug, + &VectorTest::configuration}); } void VectorTest::construct() { diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index 658c1296f..2e6372fc8 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -24,27 +24,26 @@ class CleanTest: public Corrade::TestSuite::Tester { CleanTest(); void cleanMesh(); +}; + +class Vector1 { + public: + static const std::size_t Size = 1; + typedef Int Type; + + Vector1(): data(0) {} + 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: - class Vector1 { - public: - static const std::size_t Size = 1; - typedef Int Type; - - Vector1(): data(0) {} - 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: - Type data; - }; + Type data; }; CleanTest::CleanTest() { - addTests(&CleanTest::cleanMesh); + addTests({&CleanTest::cleanMesh}); } void CleanTest::cleanMesh() { diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index ba7356f71..ee704b1c7 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -30,8 +30,8 @@ class CombineIndexedArraysTest: public Corrade::TestSuite::Tester { }; CombineIndexedArraysTest::CombineIndexedArraysTest() { - addTests(&CombineIndexedArraysTest::wrongIndexCount, - &CombineIndexedArraysTest::combine); + addTests({&CombineIndexedArraysTest::wrongIndexCount, + &CombineIndexedArraysTest::combine}); } void CombineIndexedArraysTest::wrongIndexCount() { diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index 417f7dda2..f18cfc712 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -32,9 +32,9 @@ class CompressIndicesTest: public Corrade::TestSuite::Tester { }; CompressIndicesTest::CompressIndicesTest() { - addTests(&CompressIndicesTest::compressChar, - &CompressIndicesTest::compressShort, - &CompressIndicesTest::compressInt); + addTests({&CompressIndicesTest::compressChar, + &CompressIndicesTest::compressShort, + &CompressIndicesTest::compressInt}); } void CompressIndicesTest::compressChar() { diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index a38a832e7..8cfa4c73f 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -31,9 +31,9 @@ class FlipNormalsTest: public Corrade::TestSuite::Tester { }; FlipNormalsTest::FlipNormalsTest() { - addTests(&FlipNormalsTest::wrongIndexCount, - &FlipNormalsTest::flipFaceWinding, - &FlipNormalsTest::flipNormals); + addTests({&FlipNormalsTest::wrongIndexCount, + &FlipNormalsTest::flipFaceWinding, + &FlipNormalsTest::flipNormals}); } void FlipNormalsTest::wrongIndexCount() { diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index f476452a1..5859ff549 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -30,8 +30,8 @@ class GenerateFlatNormalsTest: public Corrade::TestSuite::Tester { }; GenerateFlatNormalsTest::GenerateFlatNormalsTest() { - addTests(&GenerateFlatNormalsTest::wrongIndexCount, - &GenerateFlatNormalsTest::generate); + addTests({&GenerateFlatNormalsTest::wrongIndexCount, + &GenerateFlatNormalsTest::generate}); } void GenerateFlatNormalsTest::wrongIndexCount() { diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index fde0b5bd6..4b10121ec 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -37,12 +37,12 @@ class InterleaveTest: public Corrade::TestSuite::Tester { }; InterleaveTest::InterleaveTest() { - addTests(&InterleaveTest::attributeCount, - &InterleaveTest::attributeCountGaps, - &InterleaveTest::stride, - &InterleaveTest::strideGaps, - &InterleaveTest::write, - &InterleaveTest::writeGaps); + addTests({&InterleaveTest::attributeCount, + &InterleaveTest::attributeCountGaps, + &InterleaveTest::stride, + &InterleaveTest::strideGaps, + &InterleaveTest::write, + &InterleaveTest::writeGaps}); } void InterleaveTest::attributeCount() { diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 72b15c49a..35919bd16 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -49,8 +49,8 @@ class SubdivideTest: public Corrade::TestSuite::Tester { }; SubdivideTest::SubdivideTest() { - addTests(&SubdivideTest::wrongIndexCount, - &SubdivideTest::subdivide); + addTests({&SubdivideTest::wrongIndexCount, + &SubdivideTest::subdivide}); } void SubdivideTest::wrongIndexCount() { diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index 38177e80e..98c32b98b 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -70,8 +70,8 @@ TipsifyTest::TipsifyTest(): indices{ 16, 17, 18 }, vertexCount(19) { - addTests(&TipsifyTest::buildAdjacency, - &TipsifyTest::tipsify); + addTests({&TipsifyTest::buildAdjacency, + &TipsifyTest::tipsify}); } void TipsifyTest::buildAdjacency() { diff --git a/src/MeshTools/Test/TransformTest.cpp b/src/MeshTools/Test/TransformTest.cpp index 9f5ede231..a0ad8184c 100644 --- a/src/MeshTools/Test/TransformTest.cpp +++ b/src/MeshTools/Test/TransformTest.cpp @@ -34,11 +34,11 @@ class TransformTest: public Corrade::TestSuite::Tester { }; TransformTest::TransformTest() { - addTests(&TransformTest::transformVectors2D, - &TransformTest::transformVectors3D, + addTests({&TransformTest::transformVectors2D, + &TransformTest::transformVectors3D, - &TransformTest::transformPoints2D, - &TransformTest::transformPoints3D); + &TransformTest::transformPoints2D, + &TransformTest::transformPoints3D}); } /* GCC < 4.7 doesn't like constexpr here, don't know why */ diff --git a/src/Physics/Test/AbstractShapeTest.cpp b/src/Physics/Test/AbstractShapeTest.cpp index 575d1d6df..1a44f46a6 100644 --- a/src/Physics/Test/AbstractShapeTest.cpp +++ b/src/Physics/Test/AbstractShapeTest.cpp @@ -28,7 +28,7 @@ class AbstractShapeTest: public Corrade::TestSuite::Tester { }; AbstractShapeTest::AbstractShapeTest() { - addTests(&AbstractShapeTest::debug); + addTests({&AbstractShapeTest::debug}); } void AbstractShapeTest::debug() { diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index ec8b0fde4..097c0f704 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -32,8 +32,8 @@ class AxisAlignedBoxTest: public Corrade::TestSuite::Tester, ShapeTestBase { }; AxisAlignedBoxTest::AxisAlignedBoxTest() { - addTests(&AxisAlignedBoxTest::applyTransformation, - &AxisAlignedBoxTest::collisionPoint); + addTests({&AxisAlignedBoxTest::applyTransformation, + &AxisAlignedBoxTest::collisionPoint}); } void AxisAlignedBoxTest::applyTransformation() { diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp index 7c162baee..880f497d6 100644 --- a/src/Physics/Test/BoxTest.cpp +++ b/src/Physics/Test/BoxTest.cpp @@ -28,7 +28,7 @@ class BoxTest: public Corrade::TestSuite::Tester { }; BoxTest::BoxTest() { - addTests(&BoxTest::applyTransformation); + addTests({&BoxTest::applyTransformation}); } void BoxTest::applyTransformation() { diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 6d0233a45..88636f4e6 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -31,8 +31,8 @@ class CapsuleTest: public Corrade::TestSuite::Tester, ShapeTestBase { }; CapsuleTest::CapsuleTest() { - addTests(&CapsuleTest::applyTransformation, - &CapsuleTest::collisionPoint); + addTests({&CapsuleTest::applyTransformation, + &CapsuleTest::collisionPoint}); } void CapsuleTest::applyTransformation() { diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 31cb982cb..05a2076c7 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -28,7 +28,7 @@ class LineTest: public Corrade::TestSuite::Tester { }; LineTest::LineTest() { - addTests(&LineTest::applyTransformation); + addTests({&LineTest::applyTransformation}); } void LineTest::applyTransformation() { diff --git a/src/Physics/Test/ObjectShapeTest.cpp b/src/Physics/Test/ObjectShapeTest.cpp index 132dc48f4..8e978c813 100644 --- a/src/Physics/Test/ObjectShapeTest.cpp +++ b/src/Physics/Test/ObjectShapeTest.cpp @@ -36,8 +36,8 @@ typedef SceneGraph::Scene> Scene3D; typedef SceneGraph::Object> Object3D; ObjectShapeTest::ObjectShapeTest() { - addTests(&ObjectShapeTest::clean, - &ObjectShapeTest::firstCollision); + addTests({&ObjectShapeTest::clean, + &ObjectShapeTest::firstCollision}); } void ObjectShapeTest::clean() { diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index 81d021ada..877c1d01d 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -31,9 +31,9 @@ class PlaneTest: public Corrade::TestSuite::Tester, ShapeTestBase { }; PlaneTest::PlaneTest() { - addTests(&PlaneTest::applyTransformation, - &PlaneTest::collisionLine, - &PlaneTest::collisionLineSegment); + addTests({&PlaneTest::applyTransformation, + &PlaneTest::collisionLine, + &PlaneTest::collisionLineSegment}); } void PlaneTest::applyTransformation() { diff --git a/src/Physics/Test/PointTest.cpp b/src/Physics/Test/PointTest.cpp index 5a2cbe83f..d751d2b23 100644 --- a/src/Physics/Test/PointTest.cpp +++ b/src/Physics/Test/PointTest.cpp @@ -28,7 +28,7 @@ class PointTest: public Corrade::TestSuite::Tester { }; PointTest::PointTest() { - addTests(&PointTest::applyTransformation); + addTests({&PointTest::applyTransformation}); } void PointTest::applyTransformation() { diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index 74189b5ca..c5140db92 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -31,8 +31,8 @@ class ShapeGroupTest: public Corrade::TestSuite::Tester { }; ShapeGroupTest::ShapeGroupTest() { - addTests(&ShapeGroupTest::copy, - &ShapeGroupTest::reference); + addTests({&ShapeGroupTest::copy, + &ShapeGroupTest::reference}); } void ShapeGroupTest::copy() { diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index 544fc802e..225d31072 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -33,11 +33,11 @@ class SphereTest: public Corrade::TestSuite::Tester, ShapeTestBase { }; SphereTest::SphereTest() { - addTests(&SphereTest::applyTransformation, - &SphereTest::collisionPoint, - &SphereTest::collisionLine, - &SphereTest::collisionLineSegment, - &SphereTest::collisionSphere); + addTests({&SphereTest::applyTransformation, + &SphereTest::collisionPoint, + &SphereTest::collisionLine, + &SphereTest::collisionLineSegment, + &SphereTest::collisionSphere}); } void SphereTest::applyTransformation() { diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index d37ae82d9..bebcb9f4e 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -35,8 +35,8 @@ class CapsuleTest: public Corrade::TestSuite::Tester { }; CapsuleTest::CapsuleTest() { - addTests(&CapsuleTest::withoutTextureCoords, - &CapsuleTest::withTextureCoords); + addTests({&CapsuleTest::withoutTextureCoords, + &CapsuleTest::withTextureCoords}); } void CapsuleTest::withoutTextureCoords() { diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 76cc5562e..351d5e28f 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -32,8 +32,8 @@ class CylinderTest: public Corrade::TestSuite::Tester { }; CylinderTest::CylinderTest() { - addTests(&CylinderTest::withoutAnything, - &CylinderTest::withTextureCoordsAndCaps); + addTests({&CylinderTest::withoutAnything, + &CylinderTest::withTextureCoordsAndCaps}); } void CylinderTest::withoutAnything() { diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 3ede74162..65ce46088 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -32,8 +32,8 @@ class UVSphereTest: public Corrade::TestSuite::Tester { }; UVSphereTest::UVSphereTest() { - addTests(&UVSphereTest::withoutTextureCoords, - &UVSphereTest::withTextureCoords); + addTests({&UVSphereTest::withoutTextureCoords, + &UVSphereTest::withTextureCoords}); } void UVSphereTest::withoutTextureCoords() { diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index b7984c849..493a57739 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -39,13 +39,14 @@ class AnimableTest: public Corrade::TestSuite::Tester { typedef SceneGraph::Object> Object3D; AnimableTest::AnimableTest() { - addTests(&AnimableTest::state, - &AnimableTest::step, - &AnimableTest::duration, - &AnimableTest::repeat, - &AnimableTest::stop, - &AnimableTest::pause, - &AnimableTest::debug); + addTests({&AnimableTest::state, + &AnimableTest::step, + &AnimableTest::duration, + &AnimableTest::repeat, + &AnimableTest::stop, + &AnimableTest::pause, + + &AnimableTest::debug}); } void AnimableTest::state() { diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 82e47eb8e..6ab6446ff 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -46,14 +46,14 @@ typedef SceneGraph::Camera2D<> Camera2D; typedef SceneGraph::Camera3D<> Camera3D; CameraTest::CameraTest() { - addTests(&CameraTest::fixAspectRatio, - &CameraTest::defaultProjection2D, - &CameraTest::defaultProjection3D, - &CameraTest::projectionSize2D, - &CameraTest::projectionSizeOrthographic, - &CameraTest::projectionSizePerspective, - &CameraTest::projectionSizeViewport, - &CameraTest::draw); + addTests({&CameraTest::fixAspectRatio, + &CameraTest::defaultProjection2D, + &CameraTest::defaultProjection3D, + &CameraTest::projectionSize2D, + &CameraTest::projectionSizeOrthographic, + &CameraTest::projectionSizePerspective, + &CameraTest::projectionSizeViewport, + &CameraTest::draw}); } void CameraTest::fixAspectRatio() { diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp index 7c8a112a1..0be0e4795 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -40,16 +40,16 @@ class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { }; EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() { - addTests(&EuclideanMatrixTransformation2DTest::fromMatrix, - &EuclideanMatrixTransformation2DTest::toMatrix, - &EuclideanMatrixTransformation2DTest::compose, - &EuclideanMatrixTransformation2DTest::inverted, - - &EuclideanMatrixTransformation2DTest::setTransformation, - &EuclideanMatrixTransformation2DTest::translate, - &EuclideanMatrixTransformation2DTest::rotate, - &EuclideanMatrixTransformation2DTest::reflect, - &EuclideanMatrixTransformation2DTest::normalizeRotation); + addTests({&EuclideanMatrixTransformation2DTest::fromMatrix, + &EuclideanMatrixTransformation2DTest::toMatrix, + &EuclideanMatrixTransformation2DTest::compose, + &EuclideanMatrixTransformation2DTest::inverted, + + &EuclideanMatrixTransformation2DTest::setTransformation, + &EuclideanMatrixTransformation2DTest::translate, + &EuclideanMatrixTransformation2DTest::rotate, + &EuclideanMatrixTransformation2DTest::reflect, + &EuclideanMatrixTransformation2DTest::normalizeRotation}); } void EuclideanMatrixTransformation2DTest::fromMatrix() { diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp index 63d16772e..b3182236b 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -40,16 +40,16 @@ class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { }; EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() { - addTests(&EuclideanMatrixTransformation3DTest::fromMatrix, - &EuclideanMatrixTransformation3DTest::toMatrix, - &EuclideanMatrixTransformation3DTest::compose, - &EuclideanMatrixTransformation3DTest::inverted, - - &EuclideanMatrixTransformation3DTest::setTransformation, - &EuclideanMatrixTransformation3DTest::translate, - &EuclideanMatrixTransformation3DTest::rotate, - &EuclideanMatrixTransformation3DTest::reflect, - &EuclideanMatrixTransformation3DTest::normalizeRotation); + addTests({&EuclideanMatrixTransformation3DTest::fromMatrix, + &EuclideanMatrixTransformation3DTest::toMatrix, + &EuclideanMatrixTransformation3DTest::compose, + &EuclideanMatrixTransformation3DTest::inverted, + + &EuclideanMatrixTransformation3DTest::setTransformation, + &EuclideanMatrixTransformation3DTest::translate, + &EuclideanMatrixTransformation3DTest::rotate, + &EuclideanMatrixTransformation3DTest::reflect, + &EuclideanMatrixTransformation3DTest::normalizeRotation}); } void EuclideanMatrixTransformation3DTest::fromMatrix() { diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp index 617743c4b..eca05d982 100644 --- a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -41,17 +41,17 @@ class MatrixTransformation2DTest: public Corrade::TestSuite::Tester { }; MatrixTransformation2DTest::MatrixTransformation2DTest() { - addTests(&MatrixTransformation2DTest::fromMatrix, - &MatrixTransformation2DTest::toMatrix, - &MatrixTransformation2DTest::compose, - &MatrixTransformation2DTest::inverted, - - &MatrixTransformation2DTest::setTransformation, - &MatrixTransformation2DTest::transform, - &MatrixTransformation2DTest::translate, - &MatrixTransformation2DTest::rotate, - &MatrixTransformation2DTest::scale, - &MatrixTransformation2DTest::reflect); + addTests({&MatrixTransformation2DTest::fromMatrix, + &MatrixTransformation2DTest::toMatrix, + &MatrixTransformation2DTest::compose, + &MatrixTransformation2DTest::inverted, + + &MatrixTransformation2DTest::setTransformation, + &MatrixTransformation2DTest::transform, + &MatrixTransformation2DTest::translate, + &MatrixTransformation2DTest::rotate, + &MatrixTransformation2DTest::scale, + &MatrixTransformation2DTest::reflect}); } void MatrixTransformation2DTest::fromMatrix() { diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index 9844869a2..03c037fbb 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -41,17 +41,17 @@ class MatrixTransformation3DTest: public Corrade::TestSuite::Tester { }; MatrixTransformation3DTest::MatrixTransformation3DTest() { - addTests(&MatrixTransformation3DTest::fromMatrix, - &MatrixTransformation3DTest::toMatrix, - &MatrixTransformation3DTest::compose, - &MatrixTransformation3DTest::inverted, - - &MatrixTransformation3DTest::setTransformation, - &MatrixTransformation3DTest::transform, - &MatrixTransformation3DTest::translate, - &MatrixTransformation3DTest::rotate, - &MatrixTransformation3DTest::scale, - &MatrixTransformation3DTest::reflect); + addTests({&MatrixTransformation3DTest::fromMatrix, + &MatrixTransformation3DTest::toMatrix, + &MatrixTransformation3DTest::compose, + &MatrixTransformation3DTest::inverted, + + &MatrixTransformation3DTest::setTransformation, + &MatrixTransformation3DTest::transform, + &MatrixTransformation3DTest::translate, + &MatrixTransformation3DTest::rotate, + &MatrixTransformation3DTest::scale, + &MatrixTransformation3DTest::reflect}); } void MatrixTransformation3DTest::fromMatrix() { diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 227a387e6..61988025f 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -54,15 +54,15 @@ class CachingObject: public Object3D, AbstractFeature<3> { }; ObjectTest::ObjectTest() { - addTests(&ObjectTest::parenting, - &ObjectTest::scene, - &ObjectTest::absoluteTransformation, - &ObjectTest::transformations, - &ObjectTest::transformationsRelative, - &ObjectTest::transformationsOrphan, - &ObjectTest::transformationsDuplicate, - &ObjectTest::setClean, - &ObjectTest::bulkSetClean); + addTests({&ObjectTest::parenting, + &ObjectTest::scene, + &ObjectTest::absoluteTransformation, + &ObjectTest::transformations, + &ObjectTest::transformationsRelative, + &ObjectTest::transformationsOrphan, + &ObjectTest::transformationsDuplicate, + &ObjectTest::setClean, + &ObjectTest::bulkSetClean}); } void ObjectTest::parenting() { diff --git a/src/SceneGraph/Test/SceneTest.cpp b/src/SceneGraph/Test/SceneTest.cpp index 1baebacb5..64d9cff35 100644 --- a/src/SceneGraph/Test/SceneTest.cpp +++ b/src/SceneGraph/Test/SceneTest.cpp @@ -32,8 +32,8 @@ typedef SceneGraph::Scene> Scene3D; typedef SceneGraph::Object> Object3D; SceneTest::SceneTest() { - addTests(&SceneTest::transformation, - &SceneTest::parent); + addTests({&SceneTest::transformation, + &SceneTest::parent}); } void SceneTest::transformation() { diff --git a/src/Test/AbstractImageTest.cpp b/src/Test/AbstractImageTest.cpp index 405cf26bf..e2007d9f0 100644 --- a/src/Test/AbstractImageTest.cpp +++ b/src/Test/AbstractImageTest.cpp @@ -29,8 +29,8 @@ class AbstractImageTest: public Corrade::TestSuite::Tester { }; AbstractImageTest::AbstractImageTest() { - addTests(&AbstractImageTest::debugFormat, - &AbstractImageTest::debugType); + addTests({&AbstractImageTest::debugFormat, + &AbstractImageTest::debugType}); } void AbstractImageTest::debugFormat() { diff --git a/src/Test/AbstractShaderProgramTest.cpp b/src/Test/AbstractShaderProgramTest.cpp index 1f8738b55..a7af82851 100644 --- a/src/Test/AbstractShaderProgramTest.cpp +++ b/src/Test/AbstractShaderProgramTest.cpp @@ -40,20 +40,20 @@ class AbstractShaderProgramTest: public Corrade::TestSuite::Tester { }; AbstractShaderProgramTest::AbstractShaderProgramTest() { - addTests(&AbstractShaderProgramTest::attributeScalar, - &AbstractShaderProgramTest::attributeScalarInt, - &AbstractShaderProgramTest::attributeScalarUnsignedInt, - &AbstractShaderProgramTest::attributeScalarDouble, - - &AbstractShaderProgramTest::attributeVector, - &AbstractShaderProgramTest::attributeVectorInt, - &AbstractShaderProgramTest::attributeVectorUnsignedInt, - &AbstractShaderProgramTest::attributeVectorDouble, - &AbstractShaderProgramTest::attributeVector4, - &AbstractShaderProgramTest::attributeVectorBGRA, - - &AbstractShaderProgramTest::attributeMatrix, - &AbstractShaderProgramTest::attributeMatrixDouble); + addTests({&AbstractShaderProgramTest::attributeScalar, + &AbstractShaderProgramTest::attributeScalarInt, + &AbstractShaderProgramTest::attributeScalarUnsignedInt, + &AbstractShaderProgramTest::attributeScalarDouble, + + &AbstractShaderProgramTest::attributeVector, + &AbstractShaderProgramTest::attributeVectorInt, + &AbstractShaderProgramTest::attributeVectorUnsignedInt, + &AbstractShaderProgramTest::attributeVectorDouble, + &AbstractShaderProgramTest::attributeVector4, + &AbstractShaderProgramTest::attributeVectorBGRA, + + &AbstractShaderProgramTest::attributeMatrix, + &AbstractShaderProgramTest::attributeMatrixDouble}); } void AbstractShaderProgramTest::attributeScalar() { diff --git a/src/Test/ArrayTest.cpp b/src/Test/ArrayTest.cpp index eb3fe1da9..8743a9526 100644 --- a/src/Test/ArrayTest.cpp +++ b/src/Test/ArrayTest.cpp @@ -34,10 +34,10 @@ typedef Magnum::Array2D Array2D; typedef Magnum::Array3D Array3D; ArrayTest::ArrayTest() { - addTests(&ArrayTest::construct, - &ArrayTest::constexprConstruct, - &ArrayTest::equality, - &ArrayTest::access); + addTests({&ArrayTest::construct, + &ArrayTest::constexprConstruct, + &ArrayTest::equality, + &ArrayTest::access}); } void ArrayTest::construct() { diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index d171637d4..e54fbf2ef 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -49,22 +49,22 @@ typedef Magnum::Color3 Color3f; typedef Magnum::Color4 Color4f; ColorTest::ColorTest() { - addTests(&ColorTest::access, + addTests({&ColorTest::access, - &ColorTest::fromHue, - &ColorTest::fromSaturation, - &ColorTest::fromValue, + &ColorTest::fromHue, + &ColorTest::fromSaturation, + &ColorTest::fromValue, - &ColorTest::hue, - &ColorTest::saturation, - &ColorTest::value, + &ColorTest::hue, + &ColorTest::saturation, + &ColorTest::value, - &ColorTest::hsv, - &ColorTest::hsvOverflow, - &ColorTest::hsvAlpha, + &ColorTest::hsv, + &ColorTest::hsvOverflow, + &ColorTest::hsvAlpha, - &ColorTest::debug, - &ColorTest::configuration); + &ColorTest::debug, + &ColorTest::configuration}); } void ColorTest::access() { diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index f436c305c..8733bf7ca 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -32,10 +32,10 @@ class MeshTest: public Corrade::TestSuite::Tester { }; MeshTest::MeshTest() { - addTests(&MeshTest::debugPrimitive, - &MeshTest::debugIndexType, - &MeshTest::configurationPrimitive, - &MeshTest::configurationIndexType); + addTests({&MeshTest::debugPrimitive, + &MeshTest::debugIndexType, + &MeshTest::configurationPrimitive, + &MeshTest::configurationIndexType}); } void MeshTest::debugPrimitive() { diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 18f4ed22f..9f1bbe4ff 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -62,14 +62,14 @@ class IntResourceLoader: public AbstractResourceLoader { size_t Data::count = 0; ResourceManagerTest::ResourceManagerTest() { - addTests(&ResourceManagerTest::state, - &ResourceManagerTest::stateFallback, - &ResourceManagerTest::stateDisallowed, - &ResourceManagerTest::basic, - &ResourceManagerTest::residentPolicy, - &ResourceManagerTest::referenceCountedPolicy, - &ResourceManagerTest::manualPolicy, - &ResourceManagerTest::loader); + addTests({&ResourceManagerTest::state, + &ResourceManagerTest::stateFallback, + &ResourceManagerTest::stateDisallowed, + &ResourceManagerTest::basic, + &ResourceManagerTest::residentPolicy, + &ResourceManagerTest::referenceCountedPolicy, + &ResourceManagerTest::manualPolicy, + &ResourceManagerTest::loader}); } void ResourceManagerTest::state() { diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 5a50565a4..7994c6eb8 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -29,9 +29,9 @@ class SwizzleTest: public Corrade::TestSuite::Tester { }; SwizzleTest::SwizzleTest() { - addTests(&SwizzleTest::rgba, - &SwizzleTest::type, - &SwizzleTest::defaultType); + addTests({&SwizzleTest::rgba, + &SwizzleTest::type, + &SwizzleTest::defaultType}); } void SwizzleTest::rgba() { diff --git a/src/TextureTools/Test/AtlasTest.cpp b/src/TextureTools/Test/AtlasTest.cpp index 9525f1a0f..a5b9cc311 100644 --- a/src/TextureTools/Test/AtlasTest.cpp +++ b/src/TextureTools/Test/AtlasTest.cpp @@ -32,10 +32,10 @@ class AtlasTest: public Corrade::TestSuite::Tester { }; AtlasTest::AtlasTest() { - addTests(&AtlasTest::create, - &AtlasTest::createPadding, - &AtlasTest::createEmpty, - &AtlasTest::createTooSmall); + addTests({&AtlasTest::create, + &AtlasTest::createPadding, + &AtlasTest::createEmpty, + &AtlasTest::createTooSmall}); } void AtlasTest::create() { diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 7e4250a0b..544726b12 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -20,7 +20,7 @@ */ #include -#include +#include #include "Trade/Trade.h" @@ -44,7 +44,7 @@ be done in data parsing functions, because the user might want to import only some data. This is obviously not the case for single-data formats like images, as the file contains all data user wants to import. */ -class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { +class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::AbstractPlugin { PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImporter/0.2") public: @@ -61,9 +61,11 @@ class MAGNUM_EXPORT AbstractImporter: public Corrade::PluginManager::Plugin { /** @brief Set of features supported by this importer */ typedef Corrade::Containers::EnumSet Features; - /** @brief Constructor */ - /* GCC 4.6 can't handle {} as default parameter */ - inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager = nullptr, const std::string& plugin = std::string()): Plugin(manager, plugin) {} + /** @brief Default constructor */ + inline explicit AbstractImporter() = default; + + /** @brief Plugin manager constructor */ + inline explicit AbstractImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {} /** @brief Features supported by this importer */ virtual Features features() const = 0; diff --git a/src/Trade/Test/ObjectData2DTest.cpp b/src/Trade/Test/ObjectData2DTest.cpp index 81e35b922..c2bdd6a6c 100644 --- a/src/Trade/Test/ObjectData2DTest.cpp +++ b/src/Trade/Test/ObjectData2DTest.cpp @@ -28,7 +28,7 @@ class ObjectData2DTest: public Corrade::TestSuite::Tester { }; ObjectData2DTest::ObjectData2DTest() { - addTests(&ObjectData2DTest::debug); + addTests({&ObjectData2DTest::debug}); } void ObjectData2DTest::debug() { diff --git a/src/Trade/Test/ObjectData3DTest.cpp b/src/Trade/Test/ObjectData3DTest.cpp index 95636e0cb..d6bcdafb9 100644 --- a/src/Trade/Test/ObjectData3DTest.cpp +++ b/src/Trade/Test/ObjectData3DTest.cpp @@ -28,7 +28,7 @@ class ObjectData3DTest: public Corrade::TestSuite::Tester { }; ObjectData3DTest::ObjectData3DTest() { - addTests(&ObjectData3DTest::debug); + addTests({&ObjectData3DTest::debug}); } void ObjectData3DTest::debug() { From 297d102200f39886836af852603a7da0d1c4f146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 8 Mar 2013 16:56:23 +0100 Subject: [PATCH 518/567] Math: ability to convert Vector types from/to external types. --- src/Math/Test/Vector2Test.cpp | 34 ++++++++++++++++++++++++++++++++- src/Math/Test/Vector3Test.cpp | 35 +++++++++++++++++++++++++++++++++- src/Math/Test/Vector4Test.cpp | 36 ++++++++++++++++++++++++++++++++++- src/Math/Test/VectorTest.cpp | 35 +++++++++++++++++++++++++++++++++- src/Math/Vector.h | 14 ++++++++++++++ src/Math/Vector2.h | 3 +++ src/Math/Vector3.h | 3 +++ src/Math/Vector4.h | 3 +++ 8 files changed, 159 insertions(+), 4 deletions(-) diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 3367b9814..1d0b4b17d 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -19,7 +19,27 @@ #include "Math/Vector2.h" -namespace Magnum { namespace Math { namespace Test { +struct Vec2 { + float x, y; +}; + +namespace Magnum { namespace Math { + +namespace Implementation { + +template<> struct VectorConverter<2, float, Vec2> { + inline constexpr static Vector<2, float> from(const Vec2& other) { + return {other.x, other.y}; + } + + inline constexpr static Vec2 to(const Vector<2, float>& other) { + return {other[0], other[1]}; + } +}; + +} + +namespace Test { class Vector2Test: public Corrade::TestSuite::Tester { public: @@ -31,6 +51,8 @@ class Vector2Test: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void convert(); + void access(); void axes(); void scales(); @@ -49,6 +71,8 @@ Vector2Test::Vector2Test() { &Vector2Test::constructConversion, &Vector2Test::constructCopy, + &Vector2Test::convert, + &Vector2Test::access, &Vector2Test::axes, &Vector2Test::scales, @@ -92,6 +116,14 @@ void Vector2Test::constructCopy() { CORRADE_COMPARE(b, Vector2(1.5f, 2.5f)); } +void Vector2Test::convert() { + Vec2 a{1.5f, 2.0f}; + Vector2 b(1.5f, 2.0f); + CORRADE_COMPARE(Vector2(a), b); + CORRADE_COMPARE(Vec2(b).x, a.x); + CORRADE_COMPARE(Vec2(b).y, a.y); +} + void Vector2Test::access() { Vector2 vec(1.0f, -2.0f); CORRADE_COMPARE(vec.x(), 1.0f); diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index b046c9b32..76dc9b863 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -19,7 +19,27 @@ #include "Math/Vector3.h" -namespace Magnum { namespace Math { namespace Test { +struct Vec3 { + float x, y, z; +}; + +namespace Magnum { namespace Math { + +namespace Implementation { + +template<> struct VectorConverter<3, float, Vec3> { + inline constexpr static Vector<3, Float> from(const Vec3& other) { + return {other.x, other.y, other.z}; + } + + inline constexpr static Vec3 to(const Vector<3, Float>& other) { + return {other[0], other[1], other[2]}; + } +}; + +} + +namespace Test { class Vector3Test: public Corrade::TestSuite::Tester { public: @@ -32,6 +52,8 @@ class Vector3Test: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void convert(); + void access(); void cross(); void axes(); @@ -54,6 +76,8 @@ Vector3Test::Vector3Test() { &Vector3Test::constructConversion, &Vector3Test::constructCopy, + &Vector3Test::convert, + &Vector3Test::access, &Vector3Test::cross, &Vector3Test::axes, @@ -105,6 +129,15 @@ void Vector3Test::constructCopy() { CORRADE_COMPARE(b, Vector3(1.0f, 2.5f, -3.0f)); } +void Vector3Test::convert() { + Vec3 a{1.5f, 2.0f, -3.5f}; + Vector3 b(1.5f, 2.0f, -3.5f); + CORRADE_COMPARE(Vector3(a), b); + CORRADE_COMPARE(Vec3(b).x, a.x); + CORRADE_COMPARE(Vec3(b).y, a.y); + CORRADE_COMPARE(Vec3(b).z, a.z); +} + void Vector3Test::access() { Vector3 vec(1.0f, -2.0f, 5.0f); CORRADE_COMPARE(vec.x(), 1.0f); diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index df5407ff8..53467e4a4 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -19,7 +19,27 @@ #include "Math/Vector4.h" -namespace Magnum { namespace Math { namespace Test { +struct Vec4 { + float x, y, z, w; +}; + +namespace Magnum { namespace Math { + +namespace Implementation { + +template<> struct VectorConverter<4, float, Vec4> { + inline constexpr static Vector<4, Float> from(const Vec4& other) { + return {other.x, other.y, other.z, other.w}; + } + + inline constexpr static Vec4 to(const Vector<4, Float>& other) { + return {other[0], other[1], other[2], other[3]}; + } +}; + +} + +namespace Test { class Vector4Test: public Corrade::TestSuite::Tester { public: @@ -32,6 +52,8 @@ class Vector4Test: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void convert(); + void access(); void threeComponent(); void twoComponent(); @@ -53,6 +75,8 @@ Vector4Test::Vector4Test() { &Vector4Test::constructConversion, &Vector4Test::constructCopy, + &Vector4Test::convert, + &Vector4Test::access, &Vector4Test::threeComponent, &Vector4Test::twoComponent, @@ -102,6 +126,16 @@ void Vector4Test::constructCopy() { CORRADE_COMPARE(b, Vector4(1.0f, -2.5f, 3.0f, 4.1f)); } +void Vector4Test::convert() { + Vec4 a{1.5f, 2.0f, -3.5f, -0.5f}; + Vector4 b(1.5f, 2.0f, -3.5f, -0.5f); + CORRADE_COMPARE(Vector4(a), b); + CORRADE_COMPARE(Vec4(b).x, a.x); + CORRADE_COMPARE(Vec4(b).y, a.y); + CORRADE_COMPARE(Vec4(b).z, a.z); + CORRADE_COMPARE(Vec4(b).w, a.w); +} + void Vector4Test::access() { Vector4 vec(1.0f, -2.0f, 5.0f, 0.5f); CORRADE_COMPARE(vec.x(), 1.0f); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 5086c0de8..b874e64da 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -19,7 +19,27 @@ #include "Math/Vector.h" -namespace Magnum { namespace Math { namespace Test { +struct Vec3 { + float x, y, z; +}; + +namespace Magnum { namespace Math { + +namespace Implementation { + +template<> struct VectorConverter<3, float, Vec3> { + inline static Vector<3, Float> from(const Vec3& other) { + return {other.x, other.y, other.z}; + } + + inline static Vec3 to(const Vector<3, Float>& other) { + return {other[0], other[1], other[2]}; + } +}; + +} + +namespace Test { class VectorTest: public Corrade::TestSuite::Tester { public: @@ -32,6 +52,8 @@ class VectorTest: public Corrade::TestSuite::Tester { void constructOneComponent(); void constructConversion(); void constructCopy(); + + void convert(); void data(); void negative(); @@ -75,6 +97,8 @@ VectorTest::VectorTest() { &VectorTest::constructOneComponent, &VectorTest::constructConversion, &VectorTest::constructCopy, + + &VectorTest::convert, &VectorTest::data, &VectorTest::negative, @@ -155,6 +179,15 @@ void VectorTest::constructCopy() { CORRADE_COMPARE(b, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); } +void VectorTest::convert() { + Vec3 a{1.5f, 2.0f, -3.5f}; + Vector3 b(1.5f, 2.0f, -3.5f); + CORRADE_COMPARE(Vector3(a), b); + CORRADE_COMPARE(Vec3(b).x, a.x); + CORRADE_COMPARE(Vec3(b).y, a.y); + CORRADE_COMPARE(Vec3(b).z, a.z); +} + void VectorTest::data() { Vector4 vector(4.0f, 5.0f, 6.0f, 7.0f); vector[2] = 1.0f; diff --git a/src/Math/Vector.h b/src/Math/Vector.h index d496abcce..37be813b6 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -33,6 +33,12 @@ namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template struct VectorConverter; +} +#endif + /** @brief %Vector @tparam size %Vector size @@ -146,12 +152,20 @@ template class Vector { } #endif + /** @brief Construct vector from external representation */ + template::from(std::declval()))> inline constexpr explicit Vector(const U& other): Vector(Implementation::VectorConverter::from(other)) {} + /** @brief Copy constructor */ inline constexpr Vector(const Vector&) = default; /** @brief Assignment operator */ inline Vector& operator=(const Vector&) = default; + /** @brief Convert vector to external representation */ + template::to(std::declval>()))> inline constexpr explicit operator U() const { + return Implementation::VectorConverter::to(*this); + } + /** * @brief Raw data * @return One-dimensional array of `size*size` length. diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 397d9bc16..8abef7731 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -89,6 +89,9 @@ template class Vector2: public Vector<2, T> { /** @copydoc Vector::Vector(const Vector&) */ template inline constexpr explicit Vector2(const Vector<2, U>& other): Vector<2, T>(other) {} + /** @brief Construct vector from external representation */ + template::from(std::declval()))> inline constexpr explicit Vector2(const U& other): Vector<2, T>(Implementation::VectorConverter<2, T, U>::from(other)) {} + /** @brief Copy constructor */ inline constexpr Vector2(const Vector<2, T>& other): Vector<2, T>(other) {} diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index 60a116a9b..ff268d8b7 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -130,6 +130,9 @@ template class Vector3: public Vector<3, T> { /** @copydoc Vector::Vector(const Vector&) */ template inline constexpr explicit Vector3(const Vector<3, U>& other): Vector<3, T>(other) {} + /** @brief Construct vector from external representation */ + template::from(std::declval()))> inline constexpr explicit Vector3(const U& other): Vector<3, T>(Implementation::VectorConverter<3, T, U>::from(other)) {} + /** @brief Copy constructor */ inline constexpr Vector3(const Vector<3, T>& other): Vector<3, T>(other) {} diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 5a4fa4f09..7e36c86de 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -60,6 +60,9 @@ template class Vector4: public Vector<4, T> { /** @copydoc Vector::Vector(const Vector&) */ template inline constexpr explicit Vector4(const Vector<4, U>& other): Vector<4, T>(other) {} + /** @brief Construct vector from external representation */ + template::from(std::declval()))> inline constexpr explicit Vector4(const U& other): Vector<4, T>(Implementation::VectorConverter<4, T, U>::from(other)) {} + /** @brief Copy constructor */ inline constexpr Vector4(const Vector<4, T>& other): Vector<4, T>(other) {} From 1f8efd4a97ebb222ec797ae788dba1d8b1c7bd0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 14:21:48 +0100 Subject: [PATCH 519/567] Updated FindCorrade.cmake from Corrade repository. --- modules/FindCorrade.cmake | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index 528927df0..5b28be5db 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -7,20 +7,26 @@ # CORRADE_INCLUDE_DIR - Include dir for Corrade # CORRADE_INTERCONNECT_LIBRARIES - Corrade Interconnect library and # dependent libraries -# CORRADE_UTILITY_LIBRARIES - Corrade Utility library and dependent -# libraries -# CORRADE_PLUGINMANAGER_LIBRARIES - Corrade Plugin manager library and +# CORRADE_UTILITY_LIBRARIES - Corrade Utility library and +# dependent libraries +# CORRADE_PLUGINMANAGER_LIBRARIES - Corrade PluginManager library and +# dependent libraries +# CORRADE_TESTSUITE_LIBRARIES - Corrade TestSuite library and # dependent libraries -# CORRADE_TESTSUITE_LIBRARIES - Corrade TestSuite library and dependent -# libraries # CORRADE_RC_EXECUTABLE - Corrade resource compiler executable # Additionally these variables are defined for internal usage: +# CORRADE_INTERCONNECT_LIBRARY - Corrade Interconnect library (w/o +# dependencies) # CORRADE_UTILITY_LIBRARY - Corrade Utility library (w/o # dependencies) # CORRADE_PLUGINMANAGER_LIBRARY - Corrade Plugin manager library (w/o # dependencies) # CORRADE_TESTSUITE_LIBRARY - Corrade TestSuite library (w/o # dependencies) +# Corrade configures the compiler to use C++11 standard. Additionally you can +# use CORRADE_CXX_FLAGS to enable additional pedantic set of warnings and enable +# hidden visibility by default. +# # If Corrade library is found, these macros and functions are defined: # # @@ -42,9 +48,7 @@ # generates resource file with group group_name from given files in current # build directory. Argument name is name under which the resources can be # explicitly loaded. Variable 'name' contains compiled resource filename, -# which is then used for compiling library / executable. -# -# Example usage: +# which is then used for compiling library / executable. Example usage: # corrade_add_resource(name group_name file1 ALIAS alias1 file2 file3) # add_executable(app source1 source2 ... ${name}) # @@ -62,13 +66,10 @@ # plugin_name metadata_file # sources...) # The macro adds preprocessor directive CORRADE_STATIC_PLUGIN. Additional -# libraries can be linked in via target_link_libraries(plugin_name ...). -# -# Plugin library name will be added at the end of static_plugins_variable and -# the variable is meant to be used for linking plugins to main -# executable/library, e.g: +# libraries can be linked in via target_link_libraries(plugin_name ...). Plugin +# library name will be appended to static_plugins_variable and the variable is +# meant to be used for linking plugins to main executable/library, e.g: # target_link_libraries(app lib1 lib2 ... ${static_plugins_variable}) -# # This variable is set with parent scope to be available in parent directory. # If there are more intermediate directories between plugin directory and main # executable directory, the variable can be propagated to parent scope like @@ -124,7 +125,9 @@ set(CORRADE_UTILITY_LIBRARIES ${CORRADE_UTILITY_LIBRARY}) set(CORRADE_INTERCONNECT_LIBRARIES ${CORRADE_INTERCONNECT_LIBRARY} ${CORRADE_UTILITY_LIBRARIES}) set(CORRADE_PLUGINMANAGER_LIBRARIES ${CORRADE_PLUGINMANAGER_LIBRARY} ${CORRADE_UTILITY_LIBRARIES}) set(CORRADE_TESTSUITE_LIBRARIES ${CORRADE_TESTSUITE_LIBRARY} ${CORRADE_UTILITY_LIBRARIES}) -mark_as_advanced(CORRADE_UTILITY_LIBRARY CORRADE_PLUGINMANAGER_LIBRARY CORRADE_TESTSUITE_LIBRARY) +mark_as_advanced(CORRADE_UTILITY_LIBRARY + CORRADE_INTERCONNECT_LIBRARY + CORRADE_PLUGINMANAGER_LIBRARY + CORRADE_TESTSUITE_LIBRARY) -include(CorradeMacros) -include(CorradeLibSuffix) +include(UseCorrade) From 90dbb28763e67695dab5fe8c97cfac4809c3b0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 14:23:38 +0100 Subject: [PATCH 520/567] Thorough CMakeLists cleanup. * Calling enable_testing() only in root path. * Using CORRADE_CXX_FLAGS instead of our own set to make things easier to maintain. * Various cleanup and reorganization. --- CMakeLists.txt | 5 +++-- src/CMakeLists.txt | 22 ++++++---------------- src/DebugTools/CMakeLists.txt | 9 +++++++-- src/Math/Algorithms/CMakeLists.txt | 2 +- src/Math/CMakeLists.txt | 2 +- src/Math/Geometry/CMakeLists.txt | 2 +- src/MeshTools/CMakeLists.txt | 15 +++++++-------- src/MeshTools/Test/CMakeLists.txt | 5 ++++- src/Physics/CMakeLists.txt | 2 -- src/Platform/CMakeLists.txt | 7 ++++--- src/Primitives/CMakeLists.txt | 2 +- src/SceneGraph/CMakeLists.txt | 16 ++++++++-------- src/Shaders/CMakeLists.txt | 3 ++- src/Text/CMakeLists.txt | 1 - src/TextureTools/CMakeLists.txt | 2 -- src/Trade/CMakeLists.txt | 2 +- 16 files changed, 46 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94132ebeb..28d4834fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,13 +33,13 @@ else() cmake_dependent_option(WITH_GLUTAPPLICATION "Build GlutApplication library" OFF "NOT TARGET_GLES" OFF) option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF) endif() -option(BUILD_TESTS "Build unit tests." OFF) +option(BUILD_TESTS "Build unit tests." OFF) if(BUILD_TESTS) enable_testing() endif() -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${Magnum_SOURCE_DIR}/modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules/") # If targetting NaCl, set explicit OpenGL ES 2.0 support if(${CMAKE_SYSTEM_NAME} STREQUAL NaCl) @@ -74,6 +74,7 @@ if(USE_HARFBUZZ) endif() # Installation paths +include(CorradeLibSuffix) set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5565c3d16..7390c753f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,9 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -Winit-self -Werror=return-type -Wmissing-declarations -pedantic -std=c++0x -fvisibility=hidden") - -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") -endif() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}") +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CORRADE_INCLUDE_DIR}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumConfigure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/magnumConfigure.h) -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CORRADE_INCLUDE_DIR}) - # Files shared between main library and unit test library set(Magnum_SRCS AbstractFramebuffer.cpp @@ -97,8 +92,6 @@ if(NOT TARGET_GLES2) BufferImage.h) endif() -add_library(MagnumObjects OBJECT ${Magnum_SRCS}) - # Files shared between main library and math unit test library set(MagnumMath_SRCS Math/Angle.cpp @@ -109,10 +102,11 @@ set(MagnumMath_SRCS Math/Quaternion.cpp Math/RectangularMatrix.cpp Math/Vector.cpp) -add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well +add_library(MagnumMathObjects OBJECT ${MagnumMath_SRCS}) +add_library(MagnumObjects OBJECT ${Magnum_SRCS}) set_target_properties(MagnumObjects MagnumMathObjects PROPERTIES COMPILE_FLAGS "-DMagnumObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") # Main library @@ -134,12 +128,10 @@ target_link_libraries(Magnum ${Magnum_LIBS}) install(TARGETS Magnum DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${Magnum_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) - -# Install also configure file install(FILES ${CMAKE_CURRENT_BINARY_DIR}/magnumConfigure.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) -add_subdirectory(Platform) add_subdirectory(Math) +add_subdirectory(Platform) add_subdirectory(Trade) if(WITH_DEBUGTOOLS) @@ -175,9 +167,7 @@ if(WITH_TEXTURETOOLS) endif() if(BUILD_TESTS) - enable_testing() - - # Library with graceful assert for testing + # Libraries with graceful assert for testing add_library(MagnumMathTestLib SHARED $) set_target_properties(MagnumMathTestLib PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 3c6f7ade9..8d6dbdbc4 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -20,8 +20,13 @@ set(MagnumDebugTools_HEADERS magnumDebugToolsVisibility.h) add_library(MagnumDebugTools SHARED ${MagnumDebugTools_SRCS}) - -target_link_libraries(MagnumDebugTools Magnum MagnumMeshTools MagnumPhysics MagnumPrimitives MagnumSceneGraph MagnumShaders) +target_link_libraries(MagnumDebugTools + Magnum + MagnumMeshTools + MagnumPhysics + MagnumPrimitives + MagnumSceneGraph + MagnumShaders) install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) diff --git a/src/Math/Algorithms/CMakeLists.txt b/src/Math/Algorithms/CMakeLists.txt index 66cf6c7e9..df7bdf1f4 100644 --- a/src/Math/Algorithms/CMakeLists.txt +++ b/src/Math/Algorithms/CMakeLists.txt @@ -2,9 +2,9 @@ set(MagnumMathAlgorithms_HEADERS GaussJordan.h GramSchmidt.h Svd.h) + install(FILES ${MagnumMathAlgorithms_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Algorithms) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index e8c9997fb..602896ef5 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -20,12 +20,12 @@ set(MagnumMath_HEADERS Vector2.h Vector3.h Vector4.h) + install(FILES ${MagnumMath_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math) add_subdirectory(Algorithms) add_subdirectory(Geometry) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/Math/Geometry/CMakeLists.txt b/src/Math/Geometry/CMakeLists.txt index 73cd0f0f6..811821db3 100644 --- a/src/Math/Geometry/CMakeLists.txt +++ b/src/Math/Geometry/CMakeLists.txt @@ -2,9 +2,9 @@ set(MagnumMathGeometry_HEADERS Distance.h Intersection.h Rectangle.h) + install(FILES ${MagnumMathGeometry_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Math/Geometry) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index 5d6ecac9c..4e20509b2 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -2,6 +2,12 @@ set(MagnumMeshTools_SRCS CompressIndices.cpp Tipsify.cpp) + +# Files compiled with different flags for main library and unit test library +set(MagnumMeshTools_GracefulAssert_SRCS + FlipNormals.cpp + GenerateFlatNormals.cpp) + set(MagnumMeshTools_HEADERS Clean.h CombineIndexedArrays.h @@ -14,17 +20,12 @@ set(MagnumMeshTools_HEADERS Transform.h magnumMeshToolsVisibility.h) -add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS}) # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well +add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS}) set_target_properties(MagnumMeshToolsObjects PROPERTIES COMPILE_FLAGS "-DMagnumMeshToolsObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") -# Files compiled with different flags for main library and unit test library -set(MagnumMeshTools_GracefulAssert_SRCS - FlipNormals.cpp - GenerateFlatNormals.cpp) - # Main library add_library(MagnumMeshTools SHARED $ @@ -35,8 +36,6 @@ install(TARGETS MagnumMeshTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumMeshTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/MeshTools) if(BUILD_TESTS) - enable_testing() - # Library with graceful assert for testing add_library(MagnumMeshToolsTestLib SHARED $ diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index 369e6d411..6cd555f0b 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -10,4 +10,7 @@ corrade_add_test(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools) corrade_add_test(MeshToolsTransformTest TransformTest.cpp LIBRARIES MagnumMeshTools) # Graceful assert for testing -set_target_properties(MeshToolsCombineIndexedArraysTest MeshToolsInterleaveTest MeshToolsSubdivideTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) +set_target_properties(MeshToolsCombineIndexedArraysTest + MeshToolsInterleaveTest + MeshToolsSubdivideTest + PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 6d91069b2..36b9a0e24 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -29,13 +29,11 @@ set(MagnumPhysics_HEADERS magnumPhysicsVisibility.h) add_library(MagnumPhysics SHARED ${MagnumPhysics_SRCS}) - target_link_libraries(MagnumPhysics Magnum MagnumSceneGraph) install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 0e67226fa..2123e9120 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -1,9 +1,10 @@ -# Extension wrangler -add_library(MagnumPlatformExtensionWrangler OBJECT ExtensionWrangler.cpp) - set(MagnumPlatform_HEADERS AbstractContextHandler.h ExtensionWrangler.h) + +# Extension wrangler +add_library(MagnumPlatformExtensionWrangler OBJECT ExtensionWrangler.cpp) + install(FILES ${MagnumPlatform_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) # GLUT application diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index 19f05fff9..9c8ac8a6d 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -7,6 +7,7 @@ set(MagnumPrimitives_SRCS Plane.cpp Square.cpp UVSphere.cpp) + set(MagnumPrimitives_HEADERS Capsule.h Crosshair.h @@ -26,6 +27,5 @@ install(TARGETS MagnumPrimitives DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumPrimitives_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Primitives) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 906edde55..1b2df1a34 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -1,9 +1,16 @@ +# Files shared between main library and unit test library set(MagnumSceneGraph_SRCS Animable.cpp Camera.cpp EuclideanMatrixTransformation2D.cpp EuclideanMatrixTransformation3D.cpp Object.cpp) + +# Files compiled with different flags for main library and unit test library +set(MagnumSceneGraph_GracefulAssert_SRCS + MatrixTransformation2D.cpp + MatrixTransformation3D.cpp) + set(MagnumSceneGraph_HEADERS AbstractCamera.h AbstractCamera.hpp @@ -34,15 +41,10 @@ set(MagnumSceneGraph_HEADERS SceneGraph.h magnumSceneGraphVisibility.h) -add_library(MagnumSceneGraphObjects OBJECT ${MagnumSceneGraph_SRCS}) - -# Files compiled with different flags for main library and unit test library -set(MagnumSceneGraph_GracefulAssert_SRCS - MatrixTransformation2D.cpp - MatrixTransformation3D.cpp) # Set shared library flags for the objects, as they will be part of shared lib # TODO: fix when CMake sets target_EXPORTS for OBJECT targets as well +add_library(MagnumSceneGraphObjects OBJECT ${MagnumSceneGraph_SRCS}) set_target_properties(MagnumSceneGraphObjects PROPERTIES COMPILE_FLAGS "-DMagnumSceneGraphObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") # SceneGraph library @@ -55,8 +57,6 @@ install(TARGETS MagnumSceneGraph DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumSceneGraph_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/SceneGraph) if(BUILD_TESTS) - enable_testing() - # Library with graceful assert for testing add_library(MagnumSceneGraphTestLib SHARED $ diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index 41c0e0731..e8e96d25b 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -5,6 +5,7 @@ corrade_add_resource(MagnumShaders_RCS MagnumShaders VectorShader.frag DistanceFieldVectorShader.frag VertexColorShader2D.vert VertexColorShader3D.vert VertexColorShader.frag compatibility.glsl) + set(MagnumShaders_SRCS DistanceFieldVectorShader.cpp FlatShader.cpp @@ -12,6 +13,7 @@ set(MagnumShaders_SRCS VectorShader.cpp VertexColorShader.cpp ${MagnumShaders_RCS}) + set(MagnumShaders_HEADERS DistanceFieldVectorShader.h AbstractVectorShader.h @@ -24,7 +26,6 @@ set(MagnumShaders_HEADERS magnumShadersVisibility.h) add_library(MagnumShaders SHARED ${MagnumShaders_SRCS}) - target_link_libraries(MagnumShaders Magnum) install(TARGETS MagnumShaders DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index b4e0d5e96..92ea20ce9 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -22,7 +22,6 @@ if(USE_HARFBUZZ) endif() add_library(MagnumText SHARED ${MagnumText_SRCS}) - target_link_libraries(MagnumText Magnum MagnumTextureTools ${FREETYPE_LIBRARIES}) if(USE_HARFBUZZ) target_link_libraries(MagnumText ${HARFBUZZ_LIBRARIES}) diff --git a/src/TextureTools/CMakeLists.txt b/src/TextureTools/CMakeLists.txt index 825658dad..36eb6dae7 100644 --- a/src/TextureTools/CMakeLists.txt +++ b/src/TextureTools/CMakeLists.txt @@ -14,13 +14,11 @@ set(MagnumTextureTools_HEADERS magnumTextureToolsVisibility.h) add_library(MagnumTextureTools SHARED ${MagnumTextureTools_SRCS}) - target_link_libraries(MagnumTextureTools Magnum) install(TARGETS MagnumTextureTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumTextureTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/TextureTools) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() diff --git a/src/Trade/CMakeLists.txt b/src/Trade/CMakeLists.txt index 52cb96bb3..6e8a1efd2 100644 --- a/src/Trade/CMakeLists.txt +++ b/src/Trade/CMakeLists.txt @@ -14,9 +14,9 @@ set(MagnumTrade_HEADERS SceneData.h TextureData.h Trade.h) + install(FILES ${MagnumTrade_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Trade) if(BUILD_TESTS) - enable_testing() add_subdirectory(Test) endif() From ce89563aed3879027b57bc78610e8716271632b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 14:26:21 +0100 Subject: [PATCH 521/567] DebugTools: minor code cleanup. --- src/DebugTools/ObjectRenderer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 007dae13e..65c320a09 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -136,8 +136,7 @@ const std::array Renderer<3>::indices{{ template ObjectRenderer::ObjectRenderer(SceneGraph::AbstractObject* object, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(object, drawables), options(ResourceManager::instance()->get(options)) { /* Shader */ shader = ResourceManager::instance()->get>(Renderer::shader()); - if(!shader) ResourceManager::instance()->set(shader.key(), - new Shaders::VertexColorShader, ResourceDataState::Final, ResourcePolicy::Resident); + if(!shader) ResourceManager::instance()->set(shader.key(), new Shaders::VertexColorShader); /* Mesh and vertex buffer */ mesh = ResourceManager::instance()->get(Renderer::mesh()); From 1a051707dae50c5b05c00f7e360de065d5ea888a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 19:44:16 +0100 Subject: [PATCH 522/567] FindMagnum: it's FindFreetype.cmake, not FindFreeType.cmake. Although the library is still named FreeType. Fixes warnings in dependent projects. --- modules/FindMagnum.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 4f9d96e06..081fbfa75 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -223,7 +223,7 @@ foreach(component ${Magnum_FIND_COMPONENTS}) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Font.h) # Dependencies - find_package(FreeType) + find_package(Freetype) if(NOT FREETYPE_FOUND) unset(MAGNUM_${_COMPONENT}_LIBRARY) endif() From e8682b8893640cddc7c528b50ee038e6b6dd1a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 19:46:52 +0100 Subject: [PATCH 523/567] AbstractFramebuffer::BlitMask is available also in ES. Probably got forgotten when adding ES extensions support. --- src/AbstractFramebuffer.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index a7f5b8291..53b7b0738 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -294,9 +294,7 @@ class MAGNUM_EXPORT AbstractFramebuffer { inline AbstractFramebuffer::~AbstractFramebuffer() {} CORRADE_ENUMSET_OPERATORS(AbstractFramebuffer::ClearMask) -#ifndef MAGNUM_TARGET_GLES CORRADE_ENUMSET_OPERATORS(AbstractFramebuffer::BlitMask) -#endif } From 63cdd8ea6e47f6b4c591eacf040b28ccdd620a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 23:05:28 +0100 Subject: [PATCH 524/567] Doc++ --- src/AbstractImage.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/AbstractImage.h b/src/AbstractImage.h index 35e427b56..ba74fbb78 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -84,6 +84,8 @@ class MAGNUM_EXPORT AbstractImage { * is available in OpenGL ES. */ Blue = GL_BLUE, + + /** @todo GL_ALPHA? */ #endif /** @@ -116,8 +118,9 @@ class MAGNUM_EXPORT AbstractImage { /** * Floating-point BGRA. * @requires_es_extension %Extension @es_extension{EXT,read_format_bgra} - * for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888} or - * @es_extension{EXT,texture_format_BGRA8888} for texture data. + * for framebuffer reading, extension @es_extension{APPLE,texture_format_BGRA8888} + * or @es_extension{EXT,texture_format_BGRA8888} for texture + * data. */ #ifndef MAGNUM_TARGET_GLES BGRA = GL_BGRA, @@ -147,9 +150,9 @@ class MAGNUM_EXPORT AbstractImage { /** * Integer blue channel. * @requires_gl30 %Extension @extension{EXT,texture_integer} - * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::RedInteger" is available - * in OpenGL ES 3.0, only floating-point image data are - * available in OpenGL ES 2.0. + * @requires_gl Only @ref Magnum::AbstractImage::Format "Format::RedInteger" + * is available in OpenGL ES 3.0, only floating-point image + * data are available in OpenGL ES 2.0. */ BlueInteger = GL_BLUE_INTEGER, #endif From 90a60ce7e93f4a6383a8e951519bd80138976b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 23:30:27 +0100 Subject: [PATCH 525/567] Math: disable denormalize() test for UnsignedLong. It works with GCC and -O3, but fails on unoptimized code. --- src/Math/Functions.h | 1 + src/Math/Test/FunctionsTest.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Math/Functions.h b/src/Math/Functions.h index d123fdfad..5d294aa02 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -280,6 +280,7 @@ 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 3551aa338..69b61296f 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -174,7 +174,11 @@ void FunctionsTest::denormalizeUnsigned() { CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); CORRADE_COMPARE(Math::denormalize(0.0), 0); - CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); + { + 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.33f), 21626); CORRADE_COMPARE(Math::denormalize(0.66f), 43253); From 7e9e8913ed3bc3bbf76a623153967087fa8b19cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 23:58:31 +0100 Subject: [PATCH 526/567] Don't spit assert in Mesh::addVertexBuffer() when it's not needed. Vertex count is needed only for more than one attribute. Also updated the assertion message to include function name. --- src/Mesh.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Mesh.h b/src/Mesh.h index 4b0641879..f2a7c509c 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -592,9 +592,9 @@ class MAGNUM_EXPORT Mesh { * mesh->vertexCount(), Shaders::PhongShader::Normal()); * @endcode * - * @attention The actual vertex count must be set before calling this - * function, otherwise vertex data positions in the buffer will - * be miscalculated. + * @attention If specifying more than one attribute the actual vertex + * count must be set before calling this function. Otherwise + * vertex data positions in the buffer will be miscalculated. * @attention The buffer passed as parameter is not managed by the * mesh, you must ensure it will exist for whole lifetime of the * mesh and delete it afterwards. @@ -608,7 +608,8 @@ class MAGNUM_EXPORT Mesh { * if @extension{APPLE,vertex_array_object} is available */ template inline Mesh* addVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { - CORRADE_ASSERT(_vertexCount != 0, "Mesh: vertex count must be set before binding attributes", this); + CORRADE_ASSERT(sizeof...(attributes) == 1 || _vertexCount != 0, + "Mesh::addVertexBuffer(): vertex count must be set before binding attributes", this); addVertexBufferInternal(buffer, offset, attributes...); return this; From 0f4c13a0a6f5876289de6b35601b02d7e488e80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 00:00:42 +0100 Subject: [PATCH 527/567] Better assertion message on ResourceManager destruction. --- src/ResourceManager.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 2ae2d5075..e33687c58 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -229,7 +229,8 @@ namespace Implementation { } inline ~Data() { - CORRADE_ASSERT(referenceCount == 0, "ResourceManager: cannot destruct it while data are still referenced", ); + CORRADE_ASSERT(referenceCount == 0, + "ResourceManager::~ResourceManager(): destroyed while data are still referenced", ); delete data; } From 5ff59b609ed587c1be6da09f0351202feeacd11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 00:03:10 +0100 Subject: [PATCH 528/567] DebugTools: added ForceRenderer. Visualizes force using arrow. --- src/DebugTools/CMakeLists.txt | 6 + src/DebugTools/DebugTools.h | 5 + src/DebugTools/ForceRenderer.cpp | 89 ++++++++++++ src/DebugTools/ForceRenderer.h | 136 ++++++++++++++++++ .../ForceRendererTransformation.h | 61 ++++++++ src/DebugTools/ResourceManager.cpp | 4 +- src/DebugTools/ResourceManager.h | 7 +- src/DebugTools/Test/CMakeLists.txt | 1 + src/DebugTools/Test/ForceRendererTest.cpp | 114 +++++++++++++++ 9 files changed, 419 insertions(+), 4 deletions(-) create mode 100644 src/DebugTools/ForceRenderer.cpp create mode 100644 src/DebugTools/ForceRenderer.h create mode 100644 src/DebugTools/Implementation/ForceRendererTransformation.h create mode 100644 src/DebugTools/Test/CMakeLists.txt create mode 100644 src/DebugTools/Test/ForceRendererTest.cpp diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 8d6dbdbc4..6e91b9f05 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -1,4 +1,5 @@ set(MagnumDebugTools_SRCS + ForceRenderer.cpp ObjectRenderer.cpp Profiler.cpp ResourceManager.cpp @@ -11,6 +12,7 @@ set(MagnumDebugTools_SRCS Implementation/PointRenderer.cpp) set(MagnumDebugTools_HEADERS + ForceRenderer.h DebugTools.h ObjectRenderer.h Profiler.h @@ -30,3 +32,7 @@ target_link_libraries(MagnumDebugTools install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) + +if(BUILD_TESTS) + add_subdirectory(Test) +endif() diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h index 1cac85e90..15f1e786b 100644 --- a/src/DebugTools/DebugTools.h +++ b/src/DebugTools/DebugTools.h @@ -25,6 +25,11 @@ namespace Magnum { namespace DebugTools { /** @todoc Remove `ifndef` when Doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT +template class ForceRenderer; +typedef ForceRenderer<2> ForceRenderer2D; +typedef ForceRenderer<3> ForceRenderer3D; +class ForceRendererOptions; + template class ObjectRenderer; typedef ObjectRenderer<2> ObjectRenderer2D; typedef ObjectRenderer<3> ObjectRenderer3D; diff --git a/src/DebugTools/ForceRenderer.cpp b/src/DebugTools/ForceRenderer.cpp new file mode 100644 index 000000000..8ac198796 --- /dev/null +++ b/src/DebugTools/ForceRenderer.cpp @@ -0,0 +1,89 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "ForceRenderer.h" + +#include "Buffer.h" +#include "Mesh.h" +#include "DebugTools/ResourceManager.h" +#include "SceneGraph/AbstractCamera.h" +#include "Shaders/FlatShader.h" + +#include "DebugTools/Implementation/ForceRendererTransformation.h" + +namespace Magnum { namespace DebugTools { + +namespace { + +template ResourceKey shaderKey(); +template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } +template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } + +constexpr std::array positions{{ + {0.0f, 0.0f}, + {1.0f, 0.0f}, + {0.9f, 0.1f}, + {0.9f, -0.1f} +}}; + +constexpr std::array indices{{ + 0, 1, + 1, 2, + 1, 3 +}}; + +} + +template ForceRenderer::ForceRenderer(SceneGraph::AbstractObject* object, const typename DimensionTraits::VectorType& forcePosition, const typename DimensionTraits::VectorType* force, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(object, drawables), forcePosition(forcePosition), force(force), options(ResourceManager::instance()->get(options)) { + /* Shader */ + shader = ResourceManager::instance()->get>(shaderKey()); + if(!shader) ResourceManager::instance()->set(shader.key(), new Shaders::FlatShader); + + /* Mesh and vertex buffer */ + mesh = ResourceManager::instance()->get("force"); + vertexBuffer = ResourceManager::instance()->get("force-vertices"); + indexBuffer = ResourceManager::instance()->get("force-indices"); + if(mesh) return; + + /* Create the mesh */ + Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); + Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); + + vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + indexBuffer->setData(indices, Buffer::Usage::StaticDraw); + ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); + + Mesh* mesh = new Mesh; + mesh->setPrimitive(Mesh::Primitive::Lines) + ->setIndexCount(indices.size()) + ->addVertexBuffer(vertexBuffer, 0, + typename Shaders::FlatShader::Position(Shaders::FlatShader::Position::Components::Two)) + ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size()); + ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); +} + +template void ForceRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { + shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation(transformationMatrix.translation()+forcePosition, *force)*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->scale()))) + ->setColor(options->color()) + ->use(); + mesh->draw(); +} + +template class ForceRenderer<2>; +template class ForceRenderer<3>; + +}} diff --git a/src/DebugTools/ForceRenderer.h b/src/DebugTools/ForceRenderer.h new file mode 100644 index 000000000..56af0c141 --- /dev/null +++ b/src/DebugTools/ForceRenderer.h @@ -0,0 +1,136 @@ +#ifndef Magnum_DebugTools_ForceRenderer_h +#define Magnum_DebugTools_ForceRenderer_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::DebugTools::ForceRenderer, Magnum::DebugTools::ForceRendererOptions, typedef Magnum::DebugTools::ForceRenderer2D, Magnum::DebugTools::ForceRenderer3D + */ + +#include "Color.h" +#include "Resource.h" +#include "SceneGraph/Drawable.h" +#include "Shaders/Shaders.h" + +#include "magnumDebugToolsVisibility.h" + +namespace Magnum { namespace DebugTools { + +/** +@brief Force renderer options + +See ForceRenderer documentation for more information. +*/ +class ForceRendererOptions { + public: + inline constexpr ForceRendererOptions(): _size(1.0f) {} + + /** @brief Color of rendered arrow */ + inline constexpr Color3<> color() const { return _color; } + + /** + * @brief Set color of rendered arrow + * @return Pointer to self (for method chaining) + * + * Default is black. + */ + inline ForceRendererOptions* setColor(const Color3<>& color) { + _color = color; + return this; + } + + /** @brief Scale of rendered arrow */ + inline constexpr Float scale() const { return _size; } + + /** + * @brief Set scale of rendered arrow + * @return Pointer to self (for method chaining) + * + * Default is `1.0f`. + */ + inline ForceRendererOptions* setSize(Float size) { + _size = size; + return this; + } + + private: + Color3<> _color; + Float _size; +}; + +/** +@brief Force renderer + +Visualizes force pushing on object by an arrow of the same direction and size. +See @ref debug-tools-renderers for more information. + +@section ForceRenderer-usage Basic usage + +Example code: +@code +// Create some options +DebugTools::ResourceManager::instance()->set("my", (new DebugTools::ForceRendererOptions() + ->setScale(5.0f) + ->setColor(Color3<>::fromHSV(120.0_degf, 1.0f, 0.7f))); + +// Create debug renderer for given object, use "my" options for it +Object3D* object; +Vector3 force; +new DebugTools::ForceRenderer2D(object, {0.3f, 1.5f, -0.7f}, &force, "my", debugDrawables); +@endcode + +@see ForceRenderer2D, ForceRenderer3D +*/ +template class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer: public SceneGraph::Drawable { + public: + /** + * @brief Constructor + * @param object Object for which to create debug renderer + * @param forcePosition Where to render the force, relative to object + * @param force Force vector + * @param options Options resource key. See + * @ref ForceRenderer-usage "class documentation" for more + * information. + * @param drawables Drawable group + * + * The renderer is automatically added to object's features, @p force is + * saved as reference to original vector and thus it must be available + * for the whole lifetime of the renderer. + */ + explicit ForceRenderer(SceneGraph::AbstractObject* object, const typename DimensionTraits::VectorType& forcePosition, const typename DimensionTraits::VectorType* force, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); + + protected: + /** @todoc Remove Float when Doxygen properly treats this as override */ + void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; + + private: + const typename DimensionTraits::VectorType forcePosition; + const typename DimensionTraits::VectorType* const force; + + Resource options; + Resource> shader; + Resource mesh; + Resource vertexBuffer, indexBuffer; +}; + +/** @brief Two-dimensional force renderer */ +typedef ForceRenderer<2> ForceRenderer2D; + +/** @brief Three-dimensional force renderer */ +typedef ForceRenderer<3> ForceRenderer3D; + +}} + +#endif diff --git a/src/DebugTools/Implementation/ForceRendererTransformation.h b/src/DebugTools/Implementation/ForceRendererTransformation.h new file mode 100644 index 000000000..432ca276a --- /dev/null +++ b/src/DebugTools/Implementation/ForceRendererTransformation.h @@ -0,0 +1,61 @@ +#ifndef Magnum_DebugTools_Implementation_ForceRendererTransformation_h +#define Magnum_DebugTools_Implementation_ForceRendererTransformation_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Math/Matrix3.h" +#include "Math/Matrix4.h" +#include "Magnum.h" +#include "DimensionTraits.h" + +namespace Magnum { namespace DebugTools { namespace Implementation { + +template typename DimensionTraits::MatrixType forceRendererTransformation(const typename DimensionTraits::VectorType& forcePosition, const typename DimensionTraits::VectorType& force); + +template<> inline Matrix3 forceRendererTransformation<2>(const Vector2& forcePosition, const Vector2& force) { + return Matrix3::from({force, Vector2(-force.y(), force.x())}, forcePosition); +} + +template<> inline Matrix4 forceRendererTransformation<3>(const Vector3& forcePosition, const Vector3& force) { + const Matrix4 translation = Matrix4::translation(forcePosition); + const Float forceLength = force.length(); + + /* Zero length, zero scaling */ + if(forceLength < Math::MathTypeTraits::epsilon()) + return translation*Matrix4::scaling(Vector3(0.0f)); + + const Float dot = Vector3::dot(force/forceLength, Vector3::xAxis()); + + /* Force is parallel to X axis, just scaling */ + if(dot > 1.0f - Math::MathTypeTraits::epsilon()) + return translation*Matrix4::scaling(Vector3(forceLength)); + + /* Force is antiparallel to X axis, scaling inverted on X */ + if(-dot > 1.0f - Math::MathTypeTraits::epsilon()) + return translation*Matrix4::scaling({-forceLength, forceLength, forceLength}); + + /* Normal of plane going through force vector and X axis vector */ + const Vector3 normal = Vector3::cross(Vector3::xAxis(), force).normalized(); + + /* Third base vector, orthogonal to force and normal */ + const Vector3 binormal = Vector3::cross(normal, force).normalized(); + + /* Transformation matrix from scaled base vectors and translation vector */ + return Matrix4::from({force, normal*forceLength, binormal*forceLength}, forcePosition); +} + +}}} + +#endif diff --git a/src/DebugTools/ResourceManager.cpp b/src/DebugTools/ResourceManager.cpp index fccdd75b3..90123e984 100644 --- a/src/DebugTools/ResourceManager.cpp +++ b/src/DebugTools/ResourceManager.cpp @@ -19,16 +19,18 @@ #include "Buffer.h" #include "Mesh.h" +#include "DebugTools/ForceRenderer.h" #include "DebugTools/ObjectRenderer.h" #include "DebugTools/ShapeRenderer.h" namespace Magnum { -template class ResourceManager; +template class ResourceManager; namespace DebugTools { ResourceManager::ResourceManager() { + setFallback(new ForceRendererOptions); setFallback(new ObjectRendererOptions); setFallback(new ShapeRendererOptions); } diff --git a/src/DebugTools/ResourceManager.h b/src/DebugTools/ResourceManager.h index 3e90d8526..43429e954 100644 --- a/src/DebugTools/ResourceManager.h +++ b/src/DebugTools/ResourceManager.h @@ -34,16 +34,17 @@ namespace Magnum { -extern template ResourceManager MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager::internalInstance(); +extern template ResourceManager MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager::internalInstance(); namespace DebugTools { /** @brief %Resource manager for debug tools -Stores various data used by debug renderers. +Stores various data used by debug renderers. See @ref debug-tools for more +information. */ -class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager { +class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager { public: explicit ResourceManager(); ~ResourceManager(); diff --git a/src/DebugTools/Test/CMakeLists.txt b/src/DebugTools/Test/CMakeLists.txt new file mode 100644 index 000000000..76dcebb5e --- /dev/null +++ b/src/DebugTools/Test/CMakeLists.txt @@ -0,0 +1 @@ +corrade_add_test(MagnumDebugToolsForceRendererTest ForceRendererTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/DebugTools/Test/ForceRendererTest.cpp b/src/DebugTools/Test/ForceRendererTest.cpp new file mode 100644 index 000000000..89b8f4131 --- /dev/null +++ b/src/DebugTools/Test/ForceRendererTest.cpp @@ -0,0 +1,114 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "DebugTools/Implementation/ForceRendererTransformation.h" + +namespace Magnum { namespace DebugTools { namespace Implementation { namespace Test { + +class ForceRendererTest: public Corrade::TestSuite::Tester { + public: + explicit ForceRendererTest(); + + void zero2D(); + void parallel2D(); + void antiParallel2D(); + void arbitrary2D(); + + void zero3D(); + void parallel3D(); + void antiParallel3D(); + void arbitrary3D(); +}; + +ForceRendererTest::ForceRendererTest() { + addTests({&ForceRendererTest::zero2D, + &ForceRendererTest::parallel2D, + &ForceRendererTest::antiParallel2D, + &ForceRendererTest::arbitrary2D, + + &ForceRendererTest::zero3D, + &ForceRendererTest::parallel3D, + &ForceRendererTest::antiParallel3D, + &ForceRendererTest::arbitrary3D}); +} + +void ForceRendererTest::zero2D() { + CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2()), + Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(0.0f))); +} + +void ForceRendererTest::parallel2D() { + CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2::xAxis(2.5f)), + Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(2.5f))); +} + +void ForceRendererTest::antiParallel2D() { + CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2::xAxis(-2.5f)), + Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(-2.5f))); +} + +void ForceRendererTest::arbitrary2D() { + Vector2 force(2.7f, -11.5f); + Matrix3 m = Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, force); + + /* Translation, right-pointing base vector is the same as force */ + CORRADE_COMPARE(m.translation(), Vector2(0.5f, -3.0f)); + CORRADE_COMPARE(m.right(), force); + + /* All vectors have the same length */ + CORRADE_COMPARE(m.up().length(), force.length()); + + /* All vectors are parallel */ + CORRADE_COMPARE(Vector2::dot(m.right(), m.up()), 0.0f); +} + +void ForceRendererTest::zero3D() { + CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3()), + Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling(Vector3(0.0f))); +} + +void ForceRendererTest::parallel3D() { + CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3::xAxis(2.5f)), + Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling(Vector3(2.5f))); +} + +void ForceRendererTest::antiParallel3D() { + CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3::xAxis(-2.5f)), + Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling({-2.5f, 2.5f, 2.5f})); +} + +void ForceRendererTest::arbitrary3D() { + Vector3 force(3.7f, -5.7f, -11.5f); + Matrix4 m = Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, force); + + /* Translation, right-pointing base vector is the same as force */ + CORRADE_COMPARE(m.translation(), Vector3(0.5f, -3.0f, 1.0f)); + CORRADE_COMPARE(m.right(), force); + + /* All vectors have the same length */ + CORRADE_COMPARE(m.up().length(), force.length()); + CORRADE_COMPARE(m.backward().length(), force.length()); + + /* All vectors are parallel */ + CORRADE_COMPARE(Vector3::dot(m.right(), m.up()), 0.0f); + CORRADE_COMPARE(Vector3::dot(m.right(), m.backward()), 0.0f); + CORRADE_COMPARE(Vector3::dot(m.up(), m.backward()), 0.0f); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::DebugTools::Implementation::Test::ForceRendererTest) From 600a03b0e606d47878eefba03ebd7190e6870766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 00:07:39 +0100 Subject: [PATCH 529/567] Disable optimization in development PKGBUILD. Saves a lot of compilation time (5:50 before, 3:40 now). --- PKGBUILD | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PKGBUILD b/PKGBUILD index 532445d6f..f99919dcc 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -15,6 +15,10 @@ build() { mkdir -p "$startdir/build" cd "$startdir/build/" + # Disable optimization (saves A LOT of compilation time) + newcxxflags=$(echo $CXXFLAGS | sed s/-O.//g | sed s/-D_FORTIFY_SOURCE=.//g) + export CXXFLAGS="$newcxxflags" + if [ "$CXX" = clang++ ] ; then newcxxflags=$(echo $CXXFLAGS | sed s/--param=ssp-buffer-size=4//g) export CXXFLAGS="$newcxxflags" From 005ae96cf31a26a0f4bf331b33bcb4b63adb63c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 12:10:48 +0100 Subject: [PATCH 530/567] FindMagnum: fixed formatting with `cmake --help-module`. --- modules/FindMagnum.cmake | 45 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 081fbfa75..744f56803 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -15,24 +15,25 @@ # components. The base library depends on Corrade, OpenGL and GLEW # libraries. Additional dependencies are specified by the components. The # optional components are: -# DebugTools - DebugTools library (depends on MeshTools, Physics, -# Primitives, SceneGraph and Shaders components) -# MeshTools - MeshTools library -# Physics - Physics library -# Primitives - Library with stock geometric primitives (static) -# SceneGraph - Scene graph library -# Shaders - Library with stock shaders -# Text - Text rendering library (depends on TextureTools component, -# FreeType library and possibly HarfBuzz library, see below) -# TextureTools - TextureTools library -# GlxApplication - GLX application (depends on X11 libraries) -# XEglApplication - X/EGL application (depends on EGL and X11 libraries) +# DebugTools - DebugTools library (depends on MeshTools, Physics, +# Primitives, SceneGraph and Shaders components) +# MeshTools - MeshTools library +# Physics - Physics library +# Primitives - Library with stock geometric primitives (static) +# SceneGraph - Scene graph library +# Shaders - Library with stock shaders +# Text - Text rendering library (depends on TextureTools +# component, FreeType library and possibly HarfBuzz +# library, see below) +# TextureTools - TextureTools library +# GlxApplication - GLX application (depends on X11 libraries) +# XEglApplication - X/EGL application (depends on EGL and X11 libraries) # WindowlessGlxApplication - Windowless GLX application (depends on X11 -# libraries) -# GlutApplication - GLUT application (depends on GLUT library) -# Sdl2Application - SDL2 application (depends on SDL2 library) -# NaClApplication - NaCl application (only if targetting Google Chrome -# Native Client) +# libraries) +# GlutApplication - GLUT application (depends on GLUT library) +# Sdl2Application - SDL2 application (depends on SDL2 library) +# NaClApplication - NaCl application (only if targetting Google Chrome +# Native Client) # Example usage with specifying additional components is: # find_package(Magnum [REQUIRED|COMPONENTS] # MeshTools Primitives GlutApplication) @@ -44,10 +45,12 @@ # Features of found Magnum library are exposed in these variables: # MAGNUM_TARGET_GLES - Defined if compiled for OpenGL ES # MAGNUM_TARGET_GLES2 - Defined if compiled for OpenGL ES 2.0 -# MAGNUM_TARGET_DESKTOP_GLES - Defined if compiled with OpenGL ES emulation -# on desktop OpenGL -# MAGNUM_TARGET_NACL - Defined if compiled for Google Chrome Native Client -# MAGNUM_USE_HARFBUZZ - Defined if HarfBuzz library is used for text rendering +# MAGNUM_TARGET_DESKTOP_GLES - Defined if compiled with OpenGL ES +# emulation on desktop OpenGL +# MAGNUM_TARGET_NACL - Defined if compiled for Google Chrome Native +# Client +# MAGNUM_USE_HARFBUZZ - Defined if HarfBuzz library is used for text +# rendering # # Additionally these variables are defined for internal usage: # MAGNUM_INCLUDE_DIR - Root include dir (w/o From 23f91fe33923eaadfc94947a40102a9ae9359f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 18:13:40 +0100 Subject: [PATCH 531/567] Doc++ --- src/Buffer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Buffer.h b/src/Buffer.h index ef2447cb4..c99600f0f 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -310,7 +310,7 @@ class MAGNUM_EXPORT Buffer { /** * @brief Memory mapping access * - * @deprecated Prefer to use map(GLintptr, GLsizeiptr, MapFlags) + * @deprecated Prefer to use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)" * instead, as it has more complete set of features. * @see map(MapAccess) * @requires_es_extension %Extension @es_extension{OES,mapbuffer} in @@ -622,7 +622,7 @@ class MAGNUM_EXPORT Buffer { * If @extension{EXT,direct_state_access} is not available and the * buffer is not already bound somewhere, it is bound to hinted target * before the operation. - * @deprecated Prefer to use map(GLintptr, GLsizeiptr, MapFlags) + * @deprecated Prefer to use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)" * instead, as it has more complete set of features. * @see unmap(), setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{MapBuffer} * or @fn_gl_extension{MapNamedBuffer,EXT,direct_state_access} From 1f18bdda5f7ff2fe717f0b94a4c2b12fc52e6648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 19:44:48 +0100 Subject: [PATCH 532/567] Updated and polished coding style documentation. --- doc/coding-style.dox | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/doc/coding-style.dox b/doc/coding-style.dox index d7a1ecec8..bec708b0f 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -50,6 +50,25 @@ namespace itself and contain foward declarations for all classes, enums and copies of all meaningful typedefs. See @ref compilation-forward-declarations for more information. +@section compatibility Compatibility with various OpenGL editions + +If any class, function or part of code depends on particular OpenGL edition +(e.g. only for desktop), use conditional compilation to avoid erors on other +platforms (see @ref portability-target for more information). Put related +documentation also into the conditional compilation block and don't forget to +appropriately mark the class/function (@ref documentation-commands-requires "see below"). +Example: +@code +#ifndef MAGNUM_TARGET_GLES +// +// @brief Set polygon mode +// +// @requires_gl Polygon mode is not available in OpenGL ES. +// +void setPolygonMode(PolygonMode mode); +#endif +@endcode + @section documentation Doxygen documentation @subsection documentation-commands Special documentation commands @@ -77,15 +96,17 @@ with @c \@extension command: @code @extension{ARB,timer_query} @endcode -It produces link to the specification of the extension in OpenGL registry, -e.g. @extension{ARB,timer_query}. Similarly for OpenGL ES extensions there is -@c \@es_extension command. Some extensions have slightly different URL, -with command @c \@es_extension2 you can specify extension filename, if the -previous command gives 404 error. The following produces link to -@es_extension2{NV,read_buffer_front,GL_NV_read_buffer} extension: +It produces link to the specification of the extension in OpenGL registry: +> @extension{ARB,timer_query} + +Similarly for OpenGL ES extensions there is @c \@es_extension command. Some +extensions have slightly different URL, with command @c \@es_extension2 you can +specify extension filename, if the previous command gives 404 error. For example @code @es_extension2{NV,read_buffer_front,GL_NV_read_buffer} @endcode +produces this link: +> @es_extension2{NV,read_buffer_front,GL_NV_read_buffer} @subsubsection documentation-commands-ref_gl Links to related OpenGL functions and definitions @@ -98,9 +119,8 @@ inline static void setSeamless(bool enabled) { enabled ? glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) : glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); } @endcode - -It produces link to the online manual, in this case @fn_gl{Enable}/@fn_gl{Disable} -with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS}. +It produces link to the online manual: +> @fn_gl{Enable}/@fn_gl{Disable} with @def_gl{TEXTURE_CUBE_MAP_SEAMLESS}. For functions which are not part of OpenGL core specification, but only as extensions, use @c \@fn_gl_extension command, e.g. @@ -109,8 +129,8 @@ extensions, use @c \@fn_gl_extension command, e.g. @endcode First parameter is function name without the suffix, the second two parameters are the same as in @c \@extension command. It produced link to extension -specification, with function name as link text, in this case -@fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access}. +specification, with function name as link text: +> @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access}. @subsubsection documentation-commands-requires Classes and functions requiring specific OpenGL version or extensions From 6a1d061a3a2faf9c19de161f9f79a349096b1aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 23:54:36 +0100 Subject: [PATCH 533/567] Updated FindCorrade.cmake from Corrade repository. --- modules/FindCorrade.cmake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index 5b28be5db..fee294752 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -85,6 +85,31 @@ # DLL is not found, fatal error message is printed. # +# +# This file is part of Corrade. +# +# Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Libraries find_library(CORRADE_INTERCONNECT_LIBRARY CorradeInterconnect) find_library(CORRADE_UTILITY_LIBRARY CorradeUtility) From c3a7ddcc9aa1ae92c5ce36f18b95ec519e325240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 19:45:49 +0100 Subject: [PATCH 534/567] Relicensing to MIT/Expat license, part 1: new license document. --- COPYING | 693 ++----------------------------------------------- COPYING.LESSER | 165 ------------ 2 files changed, 19 insertions(+), 839 deletions(-) delete mode 100644 COPYING.LESSER diff --git a/COPYING b/COPYING index 94a9ed024..06646e0a9 100644 --- a/COPYING +++ b/COPYING @@ -1,674 +1,19 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/COPYING.LESSER b/COPYING.LESSER deleted file mode 100644 index 65c5ca88a..000000000 --- a/COPYING.LESSER +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. From 6a5d75d1e491622ccbd3352b937abf62aa46b9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 23:19:40 +0100 Subject: [PATCH 535/567] Relicensing to MIT/Expat license, part 2: headers. --- src/AbstractFramebuffer.h | 29 ++++++++++++------- src/AbstractImage.h | 29 ++++++++++++------- src/AbstractResourceLoader.h | 29 ++++++++++++------- src/AbstractShaderProgram.h | 29 ++++++++++++------- src/AbstractTexture.h | 29 ++++++++++++------- src/Array.h | 29 ++++++++++++------- src/Buffer.h | 29 ++++++++++++------- src/BufferImage.h | 29 ++++++++++++------- src/BufferTexture.h | 29 ++++++++++++------- src/Color.h | 29 ++++++++++++------- src/Context.h | 29 ++++++++++++------- src/CubeMapTexture.h | 29 ++++++++++++------- src/CubeMapTextureArray.h | 29 ++++++++++++------- src/DebugMarker.h | 29 ++++++++++++------- src/DebugTools/DebugTools.h | 29 ++++++++++++------- src/DebugTools/ForceRenderer.h | 29 ++++++++++++------- .../Implementation/AbstractBoxRenderer.h | 29 ++++++++++++------- .../Implementation/AbstractShapeRenderer.h | 29 ++++++++++++------- .../Implementation/AxisAlignedBoxRenderer.h | 29 ++++++++++++------- src/DebugTools/Implementation/BoxRenderer.h | 29 ++++++++++++------- .../ForceRendererTransformation.h | 29 ++++++++++++------- src/DebugTools/Implementation/PointRenderer.h | 29 ++++++++++++------- src/DebugTools/ObjectRenderer.h | 29 ++++++++++++------- src/DebugTools/Profiler.h | 29 ++++++++++++------- src/DebugTools/ResourceManager.h | 27 +++++++++++------ src/DebugTools/ShapeRenderer.h | 29 ++++++++++++------- src/DebugTools/magnumDebugToolsVisibility.h | 27 +++++++++++------ src/DefaultFramebuffer.h | 29 ++++++++++++------- src/DimensionTraits.h | 29 ++++++++++++------- src/Extensions.h | 27 +++++++++++------ src/Framebuffer.h | 29 ++++++++++++------- src/Image.h | 29 ++++++++++++------- src/ImageWrapper.h | 29 ++++++++++++------- src/Implementation/BufferState.h | 29 ++++++++++++------- src/Implementation/FramebufferState.h | 29 ++++++++++++------- src/Implementation/MeshState.h | 29 ++++++++++++------- src/Implementation/ShaderProgramState.h | 29 ++++++++++++------- src/Implementation/State.h | 29 ++++++++++++------- src/Implementation/TextureState.h | 29 ++++++++++++------- src/Magnum.h | 29 ++++++++++++------- src/Math/Algorithms/GaussJordan.h | 29 ++++++++++++------- src/Math/Algorithms/GramSchmidt.h | 27 +++++++++++------ src/Math/Algorithms/Svd.h | 29 ++++++++++++------- src/Math/Angle.h | 29 ++++++++++++------- src/Math/BoolVector.h | 29 ++++++++++++------- src/Math/Complex.h | 29 ++++++++++++------- src/Math/Constants.h | 27 +++++++++++------ src/Math/Dual.h | 29 ++++++++++++------- src/Math/DualComplex.h | 29 ++++++++++++------- src/Math/DualQuaternion.h | 29 ++++++++++++------- src/Math/Functions.h | 29 ++++++++++++------- src/Math/Geometry/Distance.h | 29 ++++++++++++------- src/Math/Geometry/Intersection.h | 27 +++++++++++------ src/Math/Geometry/Rectangle.h | 29 ++++++++++++------- src/Math/Math.h | 29 ++++++++++++------- src/Math/MathTypeTraits.h | 29 ++++++++++++------- src/Math/Matrix.h | 29 ++++++++++++------- src/Math/Matrix3.h | 29 ++++++++++++------- src/Math/Matrix4.h | 29 ++++++++++++------- src/Math/Quaternion.h | 29 ++++++++++++------- src/Math/RectangularMatrix.h | 29 ++++++++++++------- src/Math/Swizzle.h | 29 ++++++++++++------- src/Math/Unit.h | 29 ++++++++++++------- src/Math/Vector.h | 29 ++++++++++++------- src/Math/Vector2.h | 29 ++++++++++++------- src/Math/Vector3.h | 29 ++++++++++++------- src/Math/Vector4.h | 29 ++++++++++++------- src/Mesh.h | 29 ++++++++++++------- src/MeshTools/Clean.h | 29 ++++++++++++------- src/MeshTools/CombineIndexedArrays.h | 29 ++++++++++++------- src/MeshTools/CompressIndices.h | 29 ++++++++++++------- src/MeshTools/FlipNormals.h | 29 ++++++++++++------- src/MeshTools/GenerateFlatNormals.h | 27 +++++++++++------ src/MeshTools/Interleave.h | 29 ++++++++++++------- src/MeshTools/Subdivide.h | 29 ++++++++++++------- src/MeshTools/Test/SubdivideCleanBenchmark.h | 29 ++++++++++++------- src/MeshTools/Tipsify.h | 29 ++++++++++++------- src/MeshTools/Transform.h | 29 ++++++++++++------- src/MeshTools/magnumMeshToolsVisibility.h | 27 +++++++++++------ src/OpenGL.h | 27 +++++++++++------ src/Physics/AbstractShape.h | 29 ++++++++++++------- src/Physics/AxisAlignedBox.h | 29 ++++++++++++------- src/Physics/Box.h | 29 ++++++++++++------- src/Physics/Capsule.h | 29 ++++++++++++------- src/Physics/Line.h | 29 ++++++++++++------- src/Physics/LineSegment.h | 29 ++++++++++++------- src/Physics/ObjectShape.h | 29 ++++++++++++------- src/Physics/ObjectShapeGroup.h | 29 ++++++++++++------- src/Physics/Physics.h | 29 ++++++++++++------- src/Physics/Plane.h | 29 ++++++++++++------- src/Physics/Point.h | 29 ++++++++++++------- src/Physics/ShapeGroup.h | 29 ++++++++++++------- src/Physics/Sphere.h | 29 ++++++++++++------- src/Physics/Test/ShapeTestBase.h | 29 ++++++++++++------- src/Physics/magnumPhysicsVisibility.h | 27 +++++++++++------ src/Platform/AbstractContextHandler.h | 29 ++++++++++++------- src/Platform/AbstractXApplication.h | 29 ++++++++++++------- src/Platform/EglContextHandler.h | 29 ++++++++++++------- src/Platform/ExtensionWrangler.h | 29 ++++++++++++------- src/Platform/GlutApplication.h | 29 ++++++++++++------- src/Platform/GlxApplication.h | 27 +++++++++++------ src/Platform/GlxContextHandler.h | 29 ++++++++++++------- src/Platform/NaClApplication.h | 29 ++++++++++++------- src/Platform/Sdl2Application.h | 29 ++++++++++++------- src/Platform/WindowlessGlxApplication.h | 29 ++++++++++++------- src/Platform/XEglApplication.h | 27 +++++++++++------ src/Primitives/Capsule.h | 29 ++++++++++++------- src/Primitives/Crosshair.h | 27 +++++++++++------ src/Primitives/Cube.h | 29 ++++++++++++------- src/Primitives/Cylinder.h | 29 ++++++++++++------- src/Primitives/Icosphere.h | 27 +++++++++++------ src/Primitives/Plane.h | 27 +++++++++++------ src/Primitives/Square.h | 29 ++++++++++++------- src/Primitives/UVSphere.h | 29 ++++++++++++------- src/Primitives/magnumPrimitivesVisibility.h | 27 +++++++++++------ src/Query.h | 29 ++++++++++++------- src/Renderbuffer.h | 29 ++++++++++++------- src/Renderer.h | 29 ++++++++++++------- src/Resource.h | 29 ++++++++++++------- src/ResourceManager.h | 29 ++++++++++++------- src/SceneGraph/AbstractCamera.h | 29 ++++++++++++------- src/SceneGraph/AbstractCamera.hpp | 29 ++++++++++++------- src/SceneGraph/AbstractFeature.h | 29 ++++++++++++------- src/SceneGraph/AbstractGroupedFeature.h | 29 ++++++++++++------- src/SceneGraph/AbstractObject.h | 29 ++++++++++++------- src/SceneGraph/AbstractTransformation.h | 29 ++++++++++++------- .../AbstractTranslationRotation2D.h | 27 +++++++++++------ .../AbstractTranslationRotation3D.h | 27 +++++++++++------ .../AbstractTranslationRotationScaling2D.h | 29 ++++++++++++------- .../AbstractTranslationRotationScaling3D.h | 29 ++++++++++++------- src/SceneGraph/Animable.h | 29 ++++++++++++------- src/SceneGraph/Animable.hpp | 29 ++++++++++++------- src/SceneGraph/AnimableGroup.h | 29 ++++++++++++------- src/SceneGraph/Camera2D.h | 29 ++++++++++++------- src/SceneGraph/Camera2D.hpp | 29 ++++++++++++------- src/SceneGraph/Camera3D.h | 29 ++++++++++++------- src/SceneGraph/Camera3D.hpp | 27 +++++++++++------ src/SceneGraph/Drawable.h | 29 ++++++++++++------- .../EuclideanMatrixTransformation2D.h | 29 ++++++++++++------- .../EuclideanMatrixTransformation3D.h | 29 ++++++++++++------- src/SceneGraph/FeatureGroup.h | 29 ++++++++++++------- src/SceneGraph/MatrixTransformation2D.h | 29 ++++++++++++------- src/SceneGraph/MatrixTransformation3D.h | 29 ++++++++++++------- src/SceneGraph/Object.h | 29 ++++++++++++------- src/SceneGraph/Object.hpp | 29 ++++++++++++------- src/SceneGraph/Scene.h | 29 ++++++++++++------- src/SceneGraph/SceneGraph.h | 29 ++++++++++++------- src/SceneGraph/magnumSceneGraphVisibility.h | 27 +++++++++++------ src/Shader.h | 29 ++++++++++++------- src/Shaders/AbstractVectorShader.h | 29 ++++++++++++------- src/Shaders/DistanceFieldVectorShader.h | 29 ++++++++++++------- src/Shaders/FlatShader.h | 29 ++++++++++++------- src/Shaders/PhongShader.h | 29 ++++++++++++------- src/Shaders/Shaders.h | 29 ++++++++++++------- src/Shaders/VectorShader.h | 29 ++++++++++++------- src/Shaders/VertexColorShader.h | 29 ++++++++++++------- src/Shaders/magnumShadersVisibility.h | 27 +++++++++++------ src/Swizzle.h | 27 +++++++++++------ src/Text/AbstractFont.h | 29 ++++++++++++------- src/Text/FreeTypeFont.h | 29 ++++++++++++------- src/Text/HarfBuzzFont.h | 29 ++++++++++++------- src/Text/Text.h | 29 ++++++++++++------- src/Text/TextRenderer.h | 29 ++++++++++++------- src/Text/magnumTextVisibility.h | 27 +++++++++++------ src/Texture.h | 29 ++++++++++++------- src/TextureTools/Atlas.h | 29 ++++++++++++------- src/TextureTools/DistanceField.h | 27 +++++++++++------ .../magnumTextureToolsVisibility.h | 27 +++++++++++------ src/Timeline.h | 29 ++++++++++++------- src/Trade/AbstractImporter.h | 29 ++++++++++++------- src/Trade/AbstractMaterialData.h | 29 ++++++++++++------- src/Trade/CameraData.h | 29 ++++++++++++------- src/Trade/ImageData.h | 29 ++++++++++++------- src/Trade/LightData.h | 29 ++++++++++++------- src/Trade/MeshData2D.h | 29 ++++++++++++------- src/Trade/MeshData3D.h | 29 ++++++++++++------- src/Trade/MeshObjectData2D.h | 27 +++++++++++------ src/Trade/MeshObjectData3D.h | 27 +++++++++++------ src/Trade/ObjectData2D.h | 29 ++++++++++++------- src/Trade/ObjectData3D.h | 29 ++++++++++++------- src/Trade/PhongMaterialData.h | 27 +++++++++++------ src/Trade/SceneData.h | 27 +++++++++++------ src/Trade/TextureData.h | 29 ++++++++++++------- src/Trade/Trade.h | 29 ++++++++++++------- src/Types.h | 29 ++++++++++++------- src/magnumVisibility.h | 27 +++++++++++------ 186 files changed, 3504 insertions(+), 1830 deletions(-) diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 53b7b0738..34615da53 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -1,18 +1,27 @@ #ifndef Magnum_AbstractFramebuffer_h #define Magnum_AbstractFramebuffer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/AbstractImage.h b/src/AbstractImage.h index ba74fbb78..6de9cd7cc 100644 --- a/src/AbstractImage.h +++ b/src/AbstractImage.h @@ -1,18 +1,27 @@ #ifndef Magnum_AbstractImage_h #define Magnum_AbstractImage_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h index 47a8215da..194157607 100644 --- a/src/AbstractResourceLoader.h +++ b/src/AbstractResourceLoader.h @@ -1,18 +1,27 @@ #ifndef Magnum_AbstractResourceLoader_h #define Magnum_AbstractResourceLoader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index f501557bd..02e161d58 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -1,18 +1,27 @@ #ifndef Magnum_AbstractShaderProgram_h #define Magnum_AbstractShaderProgram_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index f979af4b2..19a5fe974 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -1,18 +1,27 @@ #ifndef Magnum_AbstractTexture_h #define Magnum_AbstractTexture_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Array.h b/src/Array.h index 81ccb02b0..5c79267e2 100644 --- a/src/Array.h +++ b/src/Array.h @@ -1,18 +1,27 @@ #ifndef Magnum_Array_h #define Magnum_Array_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Buffer.h b/src/Buffer.h index c99600f0f..c1f41a2f7 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -1,18 +1,27 @@ #ifndef Magnum_Buffer_h #define Magnum_Buffer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/BufferImage.h b/src/BufferImage.h index 1e5998c07..ae4910eca 100644 --- a/src/BufferImage.h +++ b/src/BufferImage.h @@ -1,18 +1,27 @@ #ifndef Magnum_BufferImage_h #define Magnum_BufferImage_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifndef MAGNUM_TARGET_GLES2 diff --git a/src/BufferTexture.h b/src/BufferTexture.h index cf697b094..1f0fdeb52 100644 --- a/src/BufferTexture.h +++ b/src/BufferTexture.h @@ -1,18 +1,27 @@ #ifndef Magnum_BufferTexture_h #define Magnum_BufferTexture_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifndef MAGNUM_TARGET_GLES diff --git a/src/Color.h b/src/Color.h index 041b4be22..c3554e1ae 100644 --- a/src/Color.h +++ b/src/Color.h @@ -1,18 +1,27 @@ #ifndef Magnum_Color_h #define Magnum_Color_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Context.h b/src/Context.h index f9b8c18d4..b5e63df5e 100644 --- a/src/Context.h +++ b/src/Context.h @@ -1,18 +1,27 @@ #ifndef Magnum_Context_h #define Magnum_Context_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index bbb54814d..64d72cc99 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -1,18 +1,27 @@ #ifndef Magnum_CubeMapTexture_h #define Magnum_CubeMapTexture_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index a7dad46cd..619e232cc 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -1,18 +1,27 @@ #ifndef Magnum_CubeMapTextureArray_h #define Magnum_CubeMapTextureArray_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifndef MAGNUM_TARGET_GLES diff --git a/src/DebugMarker.h b/src/DebugMarker.h index 54e1e1479..3429c3c53 100644 --- a/src/DebugMarker.h +++ b/src/DebugMarker.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugMarker_h #define Magnum_DebugMarker_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h index 15f1e786b..64f42a4e1 100644 --- a/src/DebugTools/DebugTools.h +++ b/src/DebugTools/DebugTools.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_DebugTools_h #define Magnum_DebugTools_DebugTools_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/ForceRenderer.h b/src/DebugTools/ForceRenderer.h index 56af0c141..2a947e8aa 100644 --- a/src/DebugTools/ForceRenderer.h +++ b/src/DebugTools/ForceRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_ForceRenderer_h #define Magnum_DebugTools_ForceRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.h b/src/DebugTools/Implementation/AbstractBoxRenderer.h index f5d494e8f..0996a20f7 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.h +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Implementation_AbstractBoxRenderer_h #define Magnum_DebugTools_Implementation_AbstractBoxRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractShapeRenderer.h" diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index 6e3b80be1..16f7f6606 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Implementation_AbstractShapeRenderer_h #define Magnum_DebugTools_Implementation_AbstractShapeRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "DimensionTraits.h" diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index 75d6a93af..9247fa2a1 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h #define Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractBoxRenderer.h" diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index 7225471fa..90b459113 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Implementation_BoxRenderer_h #define Magnum_DebugTools_Implementation_BoxRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractBoxRenderer.h" diff --git a/src/DebugTools/Implementation/ForceRendererTransformation.h b/src/DebugTools/Implementation/ForceRendererTransformation.h index 432ca276a..75c3896fc 100644 --- a/src/DebugTools/Implementation/ForceRendererTransformation.h +++ b/src/DebugTools/Implementation/ForceRendererTransformation.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Implementation_ForceRendererTransformation_h #define Magnum_DebugTools_Implementation_ForceRendererTransformation_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Math/Matrix3.h" diff --git a/src/DebugTools/Implementation/PointRenderer.h b/src/DebugTools/Implementation/PointRenderer.h index 820098191..4ac4c78c7 100644 --- a/src/DebugTools/Implementation/PointRenderer.h +++ b/src/DebugTools/Implementation/PointRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Implementation_PointRenderer_h #define Magnum_DebugTools_Implementation_PointRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractShapeRenderer.h" diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h index 3391d4e7e..e1c86cab8 100644 --- a/src/DebugTools/ObjectRenderer.h +++ b/src/DebugTools/ObjectRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_ObjectRenderer_h #define Magnum_DebugTools_ObjectRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/Profiler.h b/src/DebugTools/Profiler.h index 03cb85e16..1477d65d9 100644 --- a/src/DebugTools/Profiler.h +++ b/src/DebugTools/Profiler.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_Profiler_h #define Magnum_DebugTools_Profiler_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/ResourceManager.h b/src/DebugTools/ResourceManager.h index 43429e954..3820cbcea 100644 --- a/src/DebugTools/ResourceManager.h +++ b/src/DebugTools/ResourceManager.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_ResourceManager_h #define Magnum_DebugTools_ResourceManager_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index 15db2c090..354286c02 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_ShapeRenderer_h #define Magnum_DebugTools_ShapeRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DebugTools/magnumDebugToolsVisibility.h b/src/DebugTools/magnumDebugToolsVisibility.h index 6032af2d1..46eda28fd 100644 --- a/src/DebugTools/magnumDebugToolsVisibility.h +++ b/src/DebugTools/magnumDebugToolsVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_DebugTools_magnumDebugToolsVisibility_h #define Magnum_DebugTools_magnumDebugToolsVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index a6fd57dc1..3f37969cc 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -1,18 +1,27 @@ #ifndef Magnum_DefaultFramebuffer_h #define Magnum_DefaultFramebuffer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index b9cfba286..3ce74b5d7 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -1,18 +1,27 @@ #ifndef Magnum_DimensionTraits_h #define Magnum_DimensionTraits_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Math/Math.h" diff --git a/src/Extensions.h b/src/Extensions.h index d0d7f2fc4..aa570bef3 100644 --- a/src/Extensions.h +++ b/src/Extensions.h @@ -1,18 +1,27 @@ #ifndef Magnum_Extensions_h #define Magnum_Extensions_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 78ebbcc95..26a2029ea 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -1,18 +1,27 @@ #ifndef Magnum_Framebuffer_h #define Magnum_Framebuffer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Image.h b/src/Image.h index 20c30cd13..37e4d80bd 100644 --- a/src/Image.h +++ b/src/Image.h @@ -1,18 +1,27 @@ #ifndef Magnum_Image_h #define Magnum_Image_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 739bb810a..132b2526f 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -1,18 +1,27 @@ #ifndef Magnum_ImageWrapper_h #define Magnum_ImageWrapper_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Implementation/BufferState.h b/src/Implementation/BufferState.h index fd4bdebec..0378d8d6b 100644 --- a/src/Implementation/BufferState.h +++ b/src/Implementation/BufferState.h @@ -1,18 +1,27 @@ #ifndef Magnum_Implementation_BufferState_h #define Magnum_Implementation_BufferState_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Buffer.h" diff --git a/src/Implementation/FramebufferState.h b/src/Implementation/FramebufferState.h index b5d7cf891..4d213425c 100644 --- a/src/Implementation/FramebufferState.h +++ b/src/Implementation/FramebufferState.h @@ -1,18 +1,27 @@ #ifndef Magnum_Implementation_FramebufferState_h #define Magnum_Implementation_FramebufferState_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Math/Geometry/Rectangle.h" diff --git a/src/Implementation/MeshState.h b/src/Implementation/MeshState.h index 1e0b24328..b2a18d756 100644 --- a/src/Implementation/MeshState.h +++ b/src/Implementation/MeshState.h @@ -1,18 +1,27 @@ #ifndef Magnum_Implementation_MeshState_h #define Magnum_Implementation_MeshState_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Magnum.h" diff --git a/src/Implementation/ShaderProgramState.h b/src/Implementation/ShaderProgramState.h index 3aeb48310..5313d7d6c 100644 --- a/src/Implementation/ShaderProgramState.h +++ b/src/Implementation/ShaderProgramState.h @@ -1,18 +1,27 @@ #ifndef Magnum_Implementation_ShaderProgramState_h #define Magnum_Implementation_ShaderProgramState_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Magnum.h" diff --git a/src/Implementation/State.h b/src/Implementation/State.h index 738acb31d..16b5b59c9 100644 --- a/src/Implementation/State.h +++ b/src/Implementation/State.h @@ -1,18 +1,27 @@ #ifndef Magnum_Implementation_State_h #define Magnum_Implementation_State_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ namespace Magnum { namespace Implementation { diff --git a/src/Implementation/TextureState.h b/src/Implementation/TextureState.h index b35ae25a6..25d0d0500 100644 --- a/src/Implementation/TextureState.h +++ b/src/Implementation/TextureState.h @@ -1,18 +1,27 @@ #ifndef Magnum_Implementation_TextureState_h #define Magnum_Implementation_TextureState_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Magnum.h b/src/Magnum.h index 1466bbde7..c93a6ce1d 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -1,18 +1,27 @@ #ifndef Magnum_Magnum_h #define Magnum_Magnum_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index 130403216..1bdbef2b8 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Algorithms_GaussJordan_h #define Magnum_Math_Algorithms_GaussJordan_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h index 189fd3de6..5346fe9ee 100644 --- a/src/Math/Algorithms/GramSchmidt.h +++ b/src/Math/Algorithms/GramSchmidt.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Algorithms_GramSchmidt_h #define Magnum_Math_Algorithms_GramSchmidt_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h index ebdc7591e..fdf22703a 100644 --- a/src/Math/Algorithms/Svd.h +++ b/src/Math/Algorithms/Svd.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Algorithms_Svd_h #define Magnum_Math_Algorithms_Svd_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Angle.h b/src/Math/Angle.h index 2614453b6..8c95d20d4 100644 --- a/src/Math/Angle.h +++ b/src/Math/Angle.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Angle_h #define Magnum_Math_Angle_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/BoolVector.h b/src/Math/BoolVector.h index 2ef2495ce..bb1433091 100644 --- a/src/Math/BoolVector.h +++ b/src/Math/BoolVector.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_BoolVector_h #define Magnum_Math_BoolVector_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 97a4c38fb..cd3ed3cb5 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Complex_h #define Magnum_Math_Complex_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 98057ef5f..358a246da 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Constants_h #define Magnum_Math_Constants_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 5ee1ecdc0..4f6135f30 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Dual_h #define Magnum_Math_Dual_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index e25babc85..bc2672234 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_DualComplex_h #define Magnum_Math_DualComplex_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index c6f82a1e4..6a5653224 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_DualQuaternion_h #define Magnum_Math_DualQuaternion_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Functions.h b/src/Math/Functions.h index 5d294aa02..d324983a5 100644 --- a/src/Math/Functions.h +++ b/src/Math/Functions.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Functions_h #define Magnum_Math_Functions_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Geometry/Distance.h b/src/Math/Geometry/Distance.h index 0433887d4..f4868a601 100644 --- a/src/Math/Geometry/Distance.h +++ b/src/Math/Geometry/Distance.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Geometry_Distance_h #define Magnum_Math_Geometry_Distance_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Geometry/Intersection.h b/src/Math/Geometry/Intersection.h index c3b13785c..9d3bff5c7 100644 --- a/src/Math/Geometry/Intersection.h +++ b/src/Math/Geometry/Intersection.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Geometry_Intersection_h #define Magnum_Math_Geometry_Intersection_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Geometry/Rectangle.h b/src/Math/Geometry/Rectangle.h index 1b122497f..c832ecf36 100644 --- a/src/Math/Geometry/Rectangle.h +++ b/src/Math/Geometry/Rectangle.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Geometry_Rectangle_h #define Magnum_Math_Geometry_Rectangle_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Math.h b/src/Math/Math.h index 11915afd7..081d7acdf 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Math_h #define Magnum_Math_Math_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index a8f72e114..7a8dbe0e8 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_MathTypeTraits_h #define Magnum_Math_MathTypeTraits_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 9e7185af0..ae01c1c22 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Matrix_h #define Magnum_Math_Matrix_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 4d7ba282d..b8b6c1913 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Matrix3_h #define Magnum_Math_Matrix3_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 5a073f55a..13a96d7bb 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Matrix4_h #define Magnum_Math_Matrix4_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index cd4f4b07e..e57bc0023 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Quaternion_h #define Magnum_Math_Quaternion_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index af38a25d2..5e867c9cb 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_RectangularMatrix_h #define Magnum_Math_RectangularMatrix_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Swizzle.h b/src/Math/Swizzle.h index b0010fab0..a36234206 100644 --- a/src/Math/Swizzle.h +++ b/src/Math/Swizzle.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Swizzle_h #define Magnum_Math_Swizzle_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Unit.h b/src/Math/Unit.h index 5d2d0ecc3..4b9c5aad3 100644 --- a/src/Math/Unit.h +++ b/src/Math/Unit.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Unit_h #define Magnum_Math_Unit_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 37be813b6..df51b6a7f 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Vector_h #define Magnum_Math_Vector_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Vector2.h b/src/Math/Vector2.h index 8abef7731..148174cfb 100644 --- a/src/Math/Vector2.h +++ b/src/Math/Vector2.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Vector2_h #define Magnum_Math_Vector2_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 2 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 2 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Vector3.h b/src/Math/Vector3.h index ff268d8b7..cbab75330 100644 --- a/src/Math/Vector3.h +++ b/src/Math/Vector3.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Vector3_h #define Magnum_Math_Vector3_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Math/Vector4.h b/src/Math/Vector4.h index 7e36c86de..6e40b12be 100644 --- a/src/Math/Vector4.h +++ b/src/Math/Vector4.h @@ -1,18 +1,27 @@ #ifndef Magnum_Math_Vector4_h #define Magnum_Math_Vector4_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Mesh.h b/src/Mesh.h index f2a7c509c..7f7d47b8d 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -1,18 +1,27 @@ #ifndef Magnum_Mesh_h #define Magnum_Mesh_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index df6f1f5c2..288fc5992 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_Clean_h #define Magnum_MeshTools_Clean_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/CombineIndexedArrays.h b/src/MeshTools/CombineIndexedArrays.h index 528d3cd43..1650b443d 100644 --- a/src/MeshTools/CombineIndexedArrays.h +++ b/src/MeshTools/CombineIndexedArrays.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_CombineIndexedArrays_h #define Magnum_MeshTools_CombineIndexedArrays_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index 2b5d029ad..80cd544ef 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_CompressIndices_h #define Magnum_MeshTools_CompressIndices_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index 2b89892de..6bdbe705b 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_FlipNormals_h #define Magnum_MeshTools_FlipNormals_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index 9198d9bc4..ed0a801ea 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_GenerateFlatNormals_h #define Magnum_MeshTools_GenerateFlatNormals_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/Interleave.h b/src/MeshTools/Interleave.h index 90105318c..42c907cdc 100644 --- a/src/MeshTools/Interleave.h +++ b/src/MeshTools/Interleave.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_Interleave_h #define Magnum_MeshTools_Interleave_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/Subdivide.h b/src/MeshTools/Subdivide.h index d98823267..371aeca24 100644 --- a/src/MeshTools/Subdivide.h +++ b/src/MeshTools/Subdivide.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_Subdivide_h #define Magnum_MeshTools_Subdivide_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/Test/SubdivideCleanBenchmark.h b/src/MeshTools/Test/SubdivideCleanBenchmark.h index 390cb54e2..fe3af344e 100644 --- a/src/MeshTools/Test/SubdivideCleanBenchmark.h +++ b/src/MeshTools/Test/SubdivideCleanBenchmark.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_Test_SubdivideCleanBenchmark_h #define Magnum_MeshTools_Test_SubdivideCleanBenchmark_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Tipsify.h b/src/MeshTools/Tipsify.h index 30ef00526..057b76b96 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_Tipsify_h #define Magnum_MeshTools_Tipsify_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h index 7ecd1e8f4..d04260275 100644 --- a/src/MeshTools/Transform.h +++ b/src/MeshTools/Transform.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_Transform_h #define Magnum_MeshTools_Transform_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/MeshTools/magnumMeshToolsVisibility.h b/src/MeshTools/magnumMeshToolsVisibility.h index ebef4ae43..2c4934962 100644 --- a/src/MeshTools/magnumMeshToolsVisibility.h +++ b/src/MeshTools/magnumMeshToolsVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_MeshTools_magnumMeshToolsVisibility_h #define Magnum_MeshTools_magnumMeshToolsVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/OpenGL.h b/src/OpenGL.h index 100b85ca7..c166dea07 100644 --- a/src/OpenGL.h +++ b/src/OpenGL.h @@ -1,18 +1,27 @@ #ifndef Magnum_OpenGL_h #define Magnum_OpenGL_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 9cd1cb1a4..ea5083982 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_AbstractShape_h #define Magnum_Physics_AbstractShape_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 15137238c..bcb164434 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_AxisAlignedBox_h #define Magnum_Physics_AxisAlignedBox_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 9507e66e8..e442e915d 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Box_h #define Magnum_Physics_Box_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index a2a7a0529..bdb9975d7 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Capsule_h #define Magnum_Physics_Capsule_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 0e9c949f9..0c9abb333 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Line_h #define Magnum_Physics_Line_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index d057257bf..ab1684480 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_LineSegment_h #define Magnum_Physics_LineSegment_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 6c0b13ca9..b940c23e1 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_ObjectShape_h #define Magnum_Physics_ObjectShape_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 0e3ca7d28..9d674b0be 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_ObjectShapeGroup_h #define Magnum_Physics_ObjectShapeGroup_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Physics.h b/src/Physics/Physics.h index ac9712de0..d0a297bc5 100644 --- a/src/Physics/Physics.h +++ b/src/Physics/Physics.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Physics_h #define Magnum_Physics_Physics_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 38dca5670..7dbf76e22 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Plane_h #define Magnum_Physics_Plane_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 406197023..2ab8f362e 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Point_h #define Magnum_Physics_Point_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 132686f77..40e222936 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_ShapeGroup_h #define Magnum_Physics_ShapeGroup_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index ed84b3b59..c1324c550 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Sphere_h #define Magnum_Physics_Sphere_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Physics/Test/ShapeTestBase.h b/src/Physics/Test/ShapeTestBase.h index 099fb20c0..9e9f52304 100644 --- a/src/Physics/Test/ShapeTestBase.h +++ b/src/Physics/Test/ShapeTestBase.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_Test_ShapeTestBase_h #define Magnum_Physics_Test_ShapeTestBase_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/magnumPhysicsVisibility.h b/src/Physics/magnumPhysicsVisibility.h index a2e487560..07d22128b 100644 --- a/src/Physics/magnumPhysicsVisibility.h +++ b/src/Physics/magnumPhysicsVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_Physics_magnumPhysicsVisibility_h #define Magnum_Physics_magnumPhysicsVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/Platform/AbstractContextHandler.h b/src/Platform/AbstractContextHandler.h index 9c6376342..e4bb876a9 100644 --- a/src/Platform/AbstractContextHandler.h +++ b/src/Platform/AbstractContextHandler.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_AbstractContextHandler_h #define Magnum_Platform_AbstractContextHandler_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 9f0b3f3fa..1de097e9a 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_AbstractXApplication_h #define Magnum_Platform_AbstractXApplication_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/EglContextHandler.h b/src/Platform/EglContextHandler.h index 26d12ba1a..a67d709e0 100644 --- a/src/Platform/EglContextHandler.h +++ b/src/Platform/EglContextHandler.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_EglContextHandler_h #define Magnum_Platform_EglContextHandler_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/ExtensionWrangler.h b/src/Platform/ExtensionWrangler.h index 5dc8d8147..39ad83bce 100644 --- a/src/Platform/ExtensionWrangler.h +++ b/src/Platform/ExtensionWrangler.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_ExtensionWrangler_h #define Magnum_Platform_ExtensionWrangler_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 8d1030eec..15921fb12 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_GlutApplication_h #define Magnum_Platform_GlutApplication_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index 919fc7dea..1f1f4ea5f 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_GlxApplication_h #define Magnum_Platform_GlxApplication_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/GlxContextHandler.h b/src/Platform/GlxContextHandler.h index fd9e3adcf..d5455c5d0 100644 --- a/src/Platform/GlxContextHandler.h +++ b/src/Platform/GlxContextHandler.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_GlxContextHandler_h #define Magnum_Platform_GlxContextHandler_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 050e93164..bd3145b0d 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_NaClApplication_h #define Magnum_Platform_NaClApplication_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index ec1b85058..7a4d783cf 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_Sdl2Application_h #define Magnum_Platform_Sdl2Application_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index 8e35d4492..71569af0a 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_WindowlessGlxApplication_h #define Magnum_Platform_WindowlessGlxApplication_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index fab076393..b37ac0328 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -1,18 +1,27 @@ #ifndef Magnum_Platform_XEglApplication_h #define Magnum_Platform_XEglApplication_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index 461478796..00111ae74 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Capsule_h #define Magnum_Primitives_Capsule_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Crosshair.h b/src/Primitives/Crosshair.h index 22b7e2e09..b8d1a2783 100644 --- a/src/Primitives/Crosshair.h +++ b/src/Primitives/Crosshair.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Cube_h #define Magnum_Primitives_Cube_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index ed6cb1669..52cdee061 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Cube_h #define Magnum_Primitives_Cube_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index 1e8be915c..eac16de9d 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Cylinder_h #define Magnum_Primitives_Cylinder_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 79f5583e3..ff57f0255 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Icosphere_h #define Magnum_Primitives_Icosphere_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index 72970ed66..163d2cdf8 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Plane_h #define Magnum_Primitives_Plane_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index 4d81f9b90..5ba34f1ec 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_Square_h #define Magnum_Primitives_Square_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index b23c6f702..8b6266c45 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_UVSphere_h #define Magnum_Primitives_UVSphere_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Primitives/magnumPrimitivesVisibility.h b/src/Primitives/magnumPrimitivesVisibility.h index cf8191277..13a5c93cb 100644 --- a/src/Primitives/magnumPrimitivesVisibility.h +++ b/src/Primitives/magnumPrimitivesVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_Primitives_magnumPrimitivesVisibility_h #define Magnum_Primitives_magnumPrimitivesVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/Query.h b/src/Query.h index 7b3e9ebc2..76ad04a55 100644 --- a/src/Query.h +++ b/src/Query.h @@ -1,18 +1,27 @@ #ifndef Magnum_Query_h #define Magnum_Query_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Renderbuffer.h b/src/Renderbuffer.h index 20f53aa6a..20420056b 100644 --- a/src/Renderbuffer.h +++ b/src/Renderbuffer.h @@ -1,18 +1,27 @@ #ifndef Magnum_Renderbuffer_h #define Magnum_Renderbuffer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Renderer.h b/src/Renderer.h index f91144556..5edbd0db2 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_Renderer_h #define Magnum_Renderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Resource.h b/src/Resource.h index 71e00d856..6848bbb12 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -1,18 +1,27 @@ #ifndef Magnum_Resource_h #define Magnum_Resource_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file /Resource.h diff --git a/src/ResourceManager.h b/src/ResourceManager.h index e33687c58..41d8a2105 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -1,18 +1,27 @@ #ifndef Magnum_ResourceManager_h #define Magnum_ResourceManager_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file /ResourceManager.h diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index fff05d28d..f1128651a 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractCamera_h #define Magnum_SceneGraph_AbstractCamera_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractCamera.hpp b/src/SceneGraph/AbstractCamera.hpp index 89840d11d..f2ecd960b 100644 --- a/src/SceneGraph/AbstractCamera.hpp +++ b/src/SceneGraph/AbstractCamera.hpp @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractCamera_hpp #define Magnum_SceneGraph_AbstractCamera_hpp /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index 4d119f2a7..e77137611 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractFeature_h #define Magnum_SceneGraph_AbstractFeature_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index 2672e5d73..e0273d3a0 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractGroupedFeature_h #define Magnum_SceneGraph_AbstractGroupedFeature_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 90ad22a96..41c751230 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractObject_h #define Magnum_SceneGraph_AbstractObject_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 10b26f9ee..1e27b1682 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractTransformation_h #define Magnum_SceneGraph_AbstractTransformation_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index c3d17321c..4186fee24 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractTranslationRotation2D_h #define Magnum_SceneGraph_AbstractTranslationRotation2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index c9cca2ecc..99f735d58 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractTranslationRotation3D_h #define Magnum_SceneGraph_AbstractTranslationRotation3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractTranslationRotationScaling2D.h b/src/SceneGraph/AbstractTranslationRotationScaling2D.h index e0318157b..4b9458631 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling2D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractTranslationRotationScaling2D_h #define Magnum_SceneGraph_AbstractTranslationRotationScaling2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AbstractTranslationRotationScaling3D.h b/src/SceneGraph/AbstractTranslationRotationScaling3D.h index 21be3a012..60049e776 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling3D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AbstractTranslationRotationScaling3D_h #define Magnum_SceneGraph_AbstractTranslationRotationScaling3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index ef0c9c323..1d5cba5a9 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Animable_h #define Magnum_SceneGraph_Animable_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp index 4b2789cee..598959bac 100644 --- a/src/SceneGraph/Animable.hpp +++ b/src/SceneGraph/Animable.hpp @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Animable_hpp #define Magnum_SceneGraph_Animable_hpp /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/AnimableGroup.h b/src/SceneGraph/AnimableGroup.h index 3b7081867..e70069d8a 100644 --- a/src/SceneGraph/AnimableGroup.h +++ b/src/SceneGraph/AnimableGroup.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_AnimableGroup_h #define Magnum_SceneGraph_AnimableGroup_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 1e3ee9400..68fea359e 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Camera2D_h #define Magnum_SceneGraph_Camera2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Camera2D.hpp b/src/SceneGraph/Camera2D.hpp index 0241ec8b4..900d976b1 100644 --- a/src/SceneGraph/Camera2D.hpp +++ b/src/SceneGraph/Camera2D.hpp @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Camera2D_hpp #define Magnum_SceneGraph_Camera2D_hpp /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 6c62a893f..bb040ebab 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Camera3D_h #define Magnum_SceneGraph_Camera3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index a64537345..732cba3f7 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Camera3D_hpp #define Magnum_SceneGraph_Camera3D_hpp /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 27e49f13b..be31aad84 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Drawable_h #define Magnum_SceneGraph_Drawable_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index 2ea810c5c..f3e81f9d9 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_EuclideanMatrixTransformation2D_h #define Magnum_SceneGraph_EuclideanMatrixTransformation2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index 4a94b9fe4..751f5f0b3 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_EuclideanMatrixTransformation3D_h #define Magnum_SceneGraph_EuclideanMatrixTransformation3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 2f1856942..36da1d463 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_FeatureGroup_h #define Magnum_SceneGraph_FeatureGroup_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index 032246a74..a3300a504 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_MatrixTransformation2D_h #define Magnum_SceneGraph_MatrixTransformation2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 1e98d447d..d6a40cbe6 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_MatrixTransformation3D_h #define Magnum_SceneGraph_MatrixTransformation3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index e2d0f8694..07c798249 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Object_h #define Magnum_SceneGraph_Object_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index 88141f3f0..1a7a48d5a 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Object_hpp #define Magnum_SceneGraph_Object_hpp /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 9f06d3f8a..2ba3a552e 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_Scene_h #define Magnum_SceneGraph_Scene_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index 4b9a3aeb8..196a5572e 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_SceneGraph_h #define Magnum_SceneGraph_SceneGraph_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/SceneGraph/magnumSceneGraphVisibility.h b/src/SceneGraph/magnumSceneGraphVisibility.h index fca3dc0bc..b4b023eef 100644 --- a/src/SceneGraph/magnumSceneGraphVisibility.h +++ b/src/SceneGraph/magnumSceneGraphVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_SceneGraph_magnumSceneGraphVisibility_h #define Magnum_SceneGraph_magnumSceneGraphVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/Shader.h b/src/Shader.h index 3fb8d6c3d..5332b0e7b 100644 --- a/src/Shader.h +++ b/src/Shader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shader_h #define Magnum_Shader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/AbstractVectorShader.h b/src/Shaders/AbstractVectorShader.h index b0ced8634..75d2f6e23 100644 --- a/src/Shaders/AbstractVectorShader.h +++ b/src/Shaders/AbstractVectorShader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_AbstractVectorShader_h #define Magnum_Shaders_AbstractVectorShader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/DistanceFieldVectorShader.h b/src/Shaders/DistanceFieldVectorShader.h index 40f58ab49..e938ee695 100644 --- a/src/Shaders/DistanceFieldVectorShader.h +++ b/src/Shaders/DistanceFieldVectorShader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_DistanceFieldVectorShader_h #define Magnum_Shaders_DistanceFieldVectorShader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index ea0922816..e2ff47e63 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_FlatShader_h #define Magnum_Shaders_FlatShader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 3e7f84bc3..98b3312d6 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_PhongShader_h #define Magnum_Shaders_PhongShader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/Shaders.h b/src/Shaders/Shaders.h index f5e8f2a40..855c3d0c3 100644 --- a/src/Shaders/Shaders.h +++ b/src/Shaders/Shaders.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_Shader_h #define Magnum_Shaders_Shader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/VectorShader.h b/src/Shaders/VectorShader.h index f2dee2480..64ebba832 100644 --- a/src/Shaders/VectorShader.h +++ b/src/Shaders/VectorShader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_VectorShader_h #define Magnum_Shaders_VectorShader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 6e97d4fe5..87c6a5c88 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_VertexColorShader_h #define Magnum_Shaders_VertexColorShader_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Shaders/magnumShadersVisibility.h b/src/Shaders/magnumShadersVisibility.h index 047ee9eca..238ddeb04 100644 --- a/src/Shaders/magnumShadersVisibility.h +++ b/src/Shaders/magnumShadersVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_Shaders_magnumShadersVisibility_h #define Magnum_Shaders_magnumShadersVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/Swizzle.h b/src/Swizzle.h index f3befdf78..972cf70cc 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -1,18 +1,27 @@ #ifndef Magnum_Swizzle_h #define Magnum_Swizzle_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file /Swizzle.h diff --git a/src/Text/AbstractFont.h b/src/Text/AbstractFont.h index 561133bcc..aa22df3c1 100644 --- a/src/Text/AbstractFont.h +++ b/src/Text/AbstractFont.h @@ -1,18 +1,27 @@ #ifndef Magnum_Text_AbstractFont_h #define Magnum_Text_AbstractFont_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Text/FreeTypeFont.h b/src/Text/FreeTypeFont.h index f75285844..223698995 100644 --- a/src/Text/FreeTypeFont.h +++ b/src/Text/FreeTypeFont.h @@ -1,18 +1,27 @@ #ifndef Magnum_Text_FreeTypeFont_h #define Magnum_Text_FreeTypeFont_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Text/HarfBuzzFont.h b/src/Text/HarfBuzzFont.h index 01a264b5c..b34b8ab77 100644 --- a/src/Text/HarfBuzzFont.h +++ b/src/Text/HarfBuzzFont.h @@ -1,18 +1,27 @@ #ifndef Magnum_Text_HarfBuzzFont_h #define Magnum_Text_HarfBuzzFont_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Text/Text.h b/src/Text/Text.h index 1beb1ee51..7f18557d9 100644 --- a/src/Text/Text.h +++ b/src/Text/Text.h @@ -1,18 +1,27 @@ #ifndef Magnum_Text_Text_h #define Magnum_Text_Text_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 0cbefe4af..998c30bdb 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -1,18 +1,27 @@ #ifndef Magnum_Text_TextRenderer_h #define Magnum_Text_TextRenderer_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Text/magnumTextVisibility.h b/src/Text/magnumTextVisibility.h index 4d70506c9..a5608044a 100644 --- a/src/Text/magnumTextVisibility.h +++ b/src/Text/magnumTextVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_Text_magnumTextVisibility_h #define Magnum_Text_magnumTextVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/Texture.h b/src/Texture.h index 05e706623..e68ecaf56 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -1,18 +1,27 @@ #ifndef Magnum_Texture_h #define Magnum_Texture_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/TextureTools/Atlas.h b/src/TextureTools/Atlas.h index 3595b32bc..548eb9921 100644 --- a/src/TextureTools/Atlas.h +++ b/src/TextureTools/Atlas.h @@ -1,18 +1,27 @@ #ifndef Magnum_TextureTools_Atlas_h #define Magnum_TextureTools_Atlas_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/TextureTools/DistanceField.h b/src/TextureTools/DistanceField.h index 85bd4ab6d..a88ab940e 100644 --- a/src/TextureTools/DistanceField.h +++ b/src/TextureTools/DistanceField.h @@ -1,18 +1,27 @@ #ifndef Magnum_TextureTools_DistanceField_h #define Magnum_TextureTools_DistanceField_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/TextureTools/magnumTextureToolsVisibility.h b/src/TextureTools/magnumTextureToolsVisibility.h index 725041d71..ad0dbb333 100644 --- a/src/TextureTools/magnumTextureToolsVisibility.h +++ b/src/TextureTools/magnumTextureToolsVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_TextureTools_magnumTextureToolsVisibility_h #define Magnum_TextureTools_magnumTextureToolsVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 diff --git a/src/Timeline.h b/src/Timeline.h index 8b8b2b2d6..a74efe154 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -1,18 +1,27 @@ #ifndef Magnum_Timeline_h #define Magnum_Timeline_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Trade/AbstractImporter.h b/src/Trade/AbstractImporter.h index 544726b12..566a9ae46 100644 --- a/src/Trade/AbstractImporter.h +++ b/src/Trade/AbstractImporter.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_AbstractImporter_h #define Magnum_Trade_AbstractImporter_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/AbstractMaterialData.h b/src/Trade/AbstractMaterialData.h index 483625742..311644a1e 100644 --- a/src/Trade/AbstractMaterialData.h +++ b/src/Trade/AbstractMaterialData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_AbstractMaterialData_h #define Magnum_Trade_AbstractMaterialData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/CameraData.h b/src/Trade/CameraData.h index 4fcf2e7e1..a8bfad918 100644 --- a/src/Trade/CameraData.h +++ b/src/Trade/CameraData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_CameraData_h #define Magnum_Trade_CameraData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index d1c4d9094..fbe6d8c4c 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_ImageData_h #define Magnum_Trade_ImageData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/LightData.h b/src/Trade/LightData.h index 51e93998d..b06e16773 100644 --- a/src/Trade/LightData.h +++ b/src/Trade/LightData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_LightData_h #define Magnum_Trade_LightData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index 08dbc9911..4c52fa326 100644 --- a/src/Trade/MeshData2D.h +++ b/src/Trade/MeshData2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_MeshData2D_h #define Magnum_Trade_MeshData2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 94c60def4..0a41f02d6 100644 --- a/src/Trade/MeshData3D.h +++ b/src/Trade/MeshData3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_MeshData3D_h #define Magnum_Trade_MeshData3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/MeshObjectData2D.h b/src/Trade/MeshObjectData2D.h index 14dabdd4e..e144880c9 100644 --- a/src/Trade/MeshObjectData2D.h +++ b/src/Trade/MeshObjectData2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_MeshObjectData2D_h #define Magnum_Trade_MeshObjectData2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/MeshObjectData3D.h b/src/Trade/MeshObjectData3D.h index 05dbf10e2..348b3f4a4 100644 --- a/src/Trade/MeshObjectData3D.h +++ b/src/Trade/MeshObjectData3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_MeshObjectData3D_h #define Magnum_Trade_MeshObjectData3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/ObjectData2D.h b/src/Trade/ObjectData2D.h index a40f305ce..7e934486b 100644 --- a/src/Trade/ObjectData2D.h +++ b/src/Trade/ObjectData2D.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_ObjectData2D_h #define Magnum_Trade_ObjectData2D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/ObjectData3D.h b/src/Trade/ObjectData3D.h index 3884c2a12..c1ff82db4 100644 --- a/src/Trade/ObjectData3D.h +++ b/src/Trade/ObjectData3D.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_ObjectData3D_h #define Magnum_Trade_ObjectData3D_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/PhongMaterialData.h b/src/Trade/PhongMaterialData.h index 3d80f83e1..fed9fd310 100644 --- a/src/Trade/PhongMaterialData.h +++ b/src/Trade/PhongMaterialData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_PhongMaterialData_h #define Magnum_Trade_PhongMaterialData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/SceneData.h b/src/Trade/SceneData.h index ada693798..cdf3718b5 100644 --- a/src/Trade/SceneData.h +++ b/src/Trade/SceneData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_SceneData_h #define Magnum_Trade_SceneData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/TextureData.h b/src/Trade/TextureData.h index ad2c70003..dd35fc191 100644 --- a/src/Trade/TextureData.h +++ b/src/Trade/TextureData.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_TextureData_h #define Magnum_Trade_TextureData_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Trade/Trade.h b/src/Trade/Trade.h index 5ac365db3..37dc2ba1a 100644 --- a/src/Trade/Trade.h +++ b/src/Trade/Trade.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_Trade_h #define Magnum_Trade_Trade_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/Types.h b/src/Types.h index ee76b421f..d8e04bb65 100644 --- a/src/Types.h +++ b/src/Types.h @@ -1,18 +1,27 @@ #ifndef Magnum_Types_h #define Magnum_Types_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file diff --git a/src/magnumVisibility.h b/src/magnumVisibility.h index e37af8242..c23a8066b 100644 --- a/src/magnumVisibility.h +++ b/src/magnumVisibility.h @@ -1,18 +1,27 @@ #ifndef Magnum_magnumVisibility_h #define Magnum_magnumVisibility_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #ifdef _WIN32 From c5ab86794b34388775f3fc808329da2a03f36df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 23:21:11 +0100 Subject: [PATCH 536/567] Relicensing to MIT/Expat license, part 3: source files. Added license header also to shader sources. Hopefully it won't harm compilation times too much. --- src/AbstractFramebuffer.cpp | 29 +++++++++++------- src/AbstractImage.cpp | 29 +++++++++++------- src/AbstractShaderProgram.cpp | 29 +++++++++++------- src/AbstractTexture.cpp | 29 +++++++++++------- src/Buffer.cpp | 29 +++++++++++------- src/BufferImage.cpp | 29 +++++++++++------- src/BufferTexture.cpp | 27 +++++++++++------ src/Context.cpp | 27 +++++++++++------ src/DebugMarker.cpp | 27 +++++++++++------ src/DebugTools/ForceRenderer.cpp | 29 +++++++++++------- .../Implementation/AbstractBoxRenderer.cpp | 29 +++++++++++------- .../Implementation/AbstractShapeRenderer.cpp | 29 +++++++++++------- .../Implementation/AxisAlignedBoxRenderer.cpp | 29 +++++++++++------- src/DebugTools/Implementation/BoxRenderer.cpp | 29 +++++++++++------- .../Implementation/PointRenderer.cpp | 27 +++++++++++------ src/DebugTools/ObjectRenderer.cpp | 29 +++++++++++------- src/DebugTools/Profiler.cpp | 29 +++++++++++------- src/DebugTools/ResourceManager.cpp | 29 +++++++++++------- src/DebugTools/ShapeRenderer.cpp | 29 +++++++++++------- src/DebugTools/Test/ForceRendererTest.cpp | 29 +++++++++++------- src/DefaultFramebuffer.cpp | 29 +++++++++++------- src/Framebuffer.cpp | 29 +++++++++++------- src/Image.cpp | 29 +++++++++++------- src/Implementation/BufferState.cpp | 27 +++++++++++------ src/Implementation/State.cpp | 29 +++++++++++------- src/Math/Algorithms/Test/GaussJordanTest.cpp | 29 +++++++++++------- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 29 +++++++++++------- src/Math/Algorithms/Test/SvdTest.cpp | 29 +++++++++++------- src/Math/Angle.cpp | 27 +++++++++++------ src/Math/Complex.cpp | 27 +++++++++++------ src/Math/DualComplex.cpp | 27 +++++++++++------ src/Math/DualQuaternion.cpp | 27 +++++++++++------ src/Math/Functions.cpp | 29 +++++++++++------- src/Math/Geometry/Test/DistanceTest.cpp | 29 +++++++++++------- src/Math/Geometry/Test/IntersectionTest.cpp | 29 +++++++++++------- src/Math/Geometry/Test/RectangleTest.cpp | 29 +++++++++++------- src/Math/Quaternion.cpp | 27 +++++++++++------ src/Math/RectangularMatrix.cpp | 27 +++++++++++------ src/Math/Test/AngleTest.cpp | 29 +++++++++++------- src/Math/Test/BoolVectorTest.cpp | 29 +++++++++++------- src/Math/Test/ComplexTest.cpp | 29 +++++++++++------- src/Math/Test/ConstantsTest.cpp | 29 +++++++++++------- src/Math/Test/DualComplexTest.cpp | 29 +++++++++++------- src/Math/Test/DualQuaternionTest.cpp | 29 +++++++++++------- src/Math/Test/DualTest.cpp | 29 +++++++++++------- src/Math/Test/FunctionsTest.cpp | 29 +++++++++++------- src/Math/Test/MathTypeTraitsTest.cpp | 29 +++++++++++------- src/Math/Test/Matrix3Test.cpp | 29 +++++++++++------- src/Math/Test/Matrix4Test.cpp | 29 +++++++++++------- src/Math/Test/MatrixTest.cpp | 29 +++++++++++------- src/Math/Test/QuaternionTest.cpp | 29 +++++++++++------- src/Math/Test/RectangularMatrixTest.cpp | 29 +++++++++++------- src/Math/Test/SwizzleTest.cpp | 29 +++++++++++------- src/Math/Test/UnitTest.cpp | 29 +++++++++++------- src/Math/Test/Vector2Test.cpp | 29 +++++++++++------- src/Math/Test/Vector3Test.cpp | 29 +++++++++++------- src/Math/Test/Vector4Test.cpp | 29 +++++++++++------- src/Math/Test/VectorTest.cpp | 29 +++++++++++------- src/Math/Vector.cpp | 27 +++++++++++------ src/Mesh.cpp | 29 +++++++++++------- src/MeshTools/CompressIndices.cpp | 29 +++++++++++------- src/MeshTools/FlipNormals.cpp | 29 +++++++++++------- src/MeshTools/GenerateFlatNormals.cpp | 29 +++++++++++------- src/MeshTools/Test/CleanTest.cpp | 29 +++++++++++------- .../Test/CombineIndexedArraysTest.cpp | 29 +++++++++++------- src/MeshTools/Test/CompressIndicesTest.cpp | 29 +++++++++++------- src/MeshTools/Test/FlipNormalsTest.cpp | 29 +++++++++++------- .../Test/GenerateFlatNormalsTest.cpp | 27 +++++++++++------ src/MeshTools/Test/InterleaveTest.cpp | 29 +++++++++++------- .../Test/SubdivideCleanBenchmark.cpp | 29 +++++++++++------- src/MeshTools/Test/SubdivideTest.cpp | 29 +++++++++++------- src/MeshTools/Test/TipsifyTest.cpp | 29 +++++++++++------- src/MeshTools/Test/TransformTest.cpp | 29 +++++++++++------- src/MeshTools/Tipsify.cpp | 29 +++++++++++------- src/OpenGL.cpp | 29 +++++++++++------- src/Physics/AbstractShape.cpp | 29 +++++++++++------- src/Physics/AxisAlignedBox.cpp | 29 +++++++++++------- src/Physics/Box.cpp | 29 +++++++++++------- src/Physics/Capsule.cpp | 27 +++++++++++------ src/Physics/Line.cpp | 29 +++++++++++------- src/Physics/ObjectShape.cpp | 29 +++++++++++------- src/Physics/ObjectShapeGroup.cpp | 29 +++++++++++------- src/Physics/Plane.cpp | 29 +++++++++++------- src/Physics/Point.cpp | 29 +++++++++++------- src/Physics/ShapeGroup.cpp | 29 +++++++++++------- src/Physics/Sphere.cpp | 29 +++++++++++------- src/Physics/Test/AbstractShapeTest.cpp | 29 +++++++++++------- src/Physics/Test/AxisAlignedBoxTest.cpp | 29 +++++++++++------- src/Physics/Test/BoxTest.cpp | 29 +++++++++++------- src/Physics/Test/CapsuleTest.cpp | 29 +++++++++++------- src/Physics/Test/LineTest.cpp | 29 +++++++++++------- src/Physics/Test/ObjectShapeTest.cpp | 29 +++++++++++------- src/Physics/Test/PlaneTest.cpp | 29 +++++++++++------- src/Physics/Test/PointTest.cpp | 29 +++++++++++------- src/Physics/Test/ShapeGroupTest.cpp | 29 +++++++++++------- src/Physics/Test/SphereTest.cpp | 29 +++++++++++------- src/Platform/AbstractXApplication.cpp | 29 +++++++++++------- src/Platform/EglContextHandler.cpp | 29 +++++++++++------- src/Platform/ExtensionWrangler.cpp | 29 +++++++++++------- src/Platform/GlutApplication.cpp | 29 +++++++++++------- src/Platform/GlxContextHandler.cpp | 29 +++++++++++------- src/Platform/NaClApplication.cpp | 29 +++++++++++------- src/Platform/Sdl2Application.cpp | 29 +++++++++++------- src/Platform/WindowlessGlxApplication.cpp | 29 +++++++++++------- src/Platform/magnum-info.cpp | 29 +++++++++++------- src/Primitives/Capsule.cpp | 29 +++++++++++------- src/Primitives/Crosshair.cpp | 29 +++++++++++------- src/Primitives/Cube.cpp | 29 +++++++++++------- src/Primitives/Cylinder.cpp | 29 +++++++++++------- src/Primitives/Icosphere.cpp | 27 +++++++++++------ src/Primitives/Plane.cpp | 29 +++++++++++------- src/Primitives/Square.cpp | 29 +++++++++++------- src/Primitives/Test/CapsuleTest.cpp | 29 +++++++++++------- src/Primitives/Test/CylinderTest.cpp | 29 +++++++++++------- src/Primitives/Test/UVSphereTest.cpp | 29 +++++++++++------- src/Primitives/UVSphere.cpp | 29 +++++++++++------- src/Query.cpp | 29 +++++++++++------- src/Renderbuffer.cpp | 29 +++++++++++------- src/Resource.cpp | 29 +++++++++++------- src/SceneGraph/Animable.cpp | 29 +++++++++++------- src/SceneGraph/Camera.cpp | 27 +++++++++++------ .../EuclideanMatrixTransformation2D.cpp | 29 +++++++++++------- .../EuclideanMatrixTransformation3D.cpp | 29 +++++++++++------- src/SceneGraph/MatrixTransformation2D.cpp | 29 +++++++++++------- src/SceneGraph/MatrixTransformation3D.cpp | 29 +++++++++++------- src/SceneGraph/Object.cpp | 27 +++++++++++------ src/SceneGraph/Test/AnimableTest.cpp | 29 +++++++++++------- src/SceneGraph/Test/CameraTest.cpp | 29 +++++++++++------- .../EuclideanMatrixTransformation2DTest.cpp | 29 +++++++++++------- .../EuclideanMatrixTransformation3DTest.cpp | 29 +++++++++++------- .../Test/MatrixTransformation2DTest.cpp | 29 +++++++++++------- .../Test/MatrixTransformation3DTest.cpp | 29 +++++++++++------- src/SceneGraph/Test/ObjectTest.cpp | 29 +++++++++++------- src/SceneGraph/Test/SceneTest.cpp | 29 +++++++++++------- src/Shader.cpp | 29 +++++++++++------- src/Shaders/AbstractVectorShader2D.vert | 24 +++++++++++++++ src/Shaders/AbstractVectorShader3D.vert | 24 +++++++++++++++ src/Shaders/DistanceFieldVectorShader.cpp | 29 +++++++++++------- src/Shaders/DistanceFieldVectorShader.frag | 24 +++++++++++++++ src/Shaders/FlatShader.cpp | 29 +++++++++++------- src/Shaders/FlatShader.frag | 24 +++++++++++++++ src/Shaders/FlatShader2D.vert | 24 +++++++++++++++ src/Shaders/FlatShader3D.vert | 24 +++++++++++++++ src/Shaders/PhongShader.cpp | 29 +++++++++++------- src/Shaders/PhongShader.frag | 24 +++++++++++++++ src/Shaders/PhongShader.vert | 24 +++++++++++++++ src/Shaders/VectorShader.cpp | 29 +++++++++++------- src/Shaders/VectorShader.frag | 24 +++++++++++++++ src/Shaders/VertexColorShader.cpp | 29 +++++++++++------- src/Shaders/VertexColorShader.frag | 24 +++++++++++++++ src/Shaders/VertexColorShader2D.vert | 24 +++++++++++++++ src/Shaders/VertexColorShader3D.vert | 24 +++++++++++++++ src/Shaders/compatibility.glsl | 24 +++++++++++++++ src/Test/AbstractImageTest.cpp | 29 +++++++++++------- src/Test/AbstractShaderProgramTest.cpp | 29 +++++++++++------- src/Test/ArrayTest.cpp | 29 +++++++++++------- src/Test/ColorTest.cpp | 29 +++++++++++------- src/Test/MeshTest.cpp | 29 +++++++++++------- src/Test/ResourceManagerTest.cpp | 29 +++++++++++------- src/Test/SwizzleTest.cpp | 27 +++++++++++------ src/Text/AbstractFont.cpp | 29 +++++++++++------- src/Text/FreeTypeFont.cpp | 29 +++++++++++------- src/Text/HarfBuzzFont.cpp | 29 +++++++++++------- src/Text/TextRenderer.cpp | 29 +++++++++++------- src/TextureTools/Atlas.cpp | 29 +++++++++++------- src/TextureTools/DistanceField.cpp | 29 +++++++++++------- src/TextureTools/DistanceFieldShader.frag | 24 +++++++++++++++ src/TextureTools/DistanceFieldShader.vert | 24 +++++++++++++++ src/TextureTools/Test/AtlasTest.cpp | 29 +++++++++++------- src/Timeline.cpp | 30 ++++++++++++------- src/Trade/AbstractImporter.cpp | 29 +++++++++++------- src/Trade/MeshData2D.cpp | 29 +++++++++++------- src/Trade/MeshData3D.cpp | 29 +++++++++++------- src/Trade/ObjectData2D.cpp | 29 +++++++++++------- src/Trade/ObjectData3D.cpp | 29 +++++++++++------- src/Trade/Test/ObjectData2DTest.cpp | 29 +++++++++++------- src/Trade/Test/ObjectData3DTest.cpp | 29 +++++++++++------- 177 files changed, 3421 insertions(+), 1602 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index ef5761a97..ac57b4402 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractFramebuffer.h" diff --git a/src/AbstractImage.cpp b/src/AbstractImage.cpp index 5a0c320d5..6d34289e3 100644 --- a/src/AbstractImage.cpp +++ b/src/AbstractImage.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractImage.h" diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 88f30d040..b353ca475 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractShaderProgram.h" diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index aa2a497ab..cdb5a305b 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractTexture.h" diff --git a/src/Buffer.cpp b/src/Buffer.cpp index f37079450..dd108bd2e 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Buffer.h" diff --git a/src/BufferImage.cpp b/src/BufferImage.cpp index ff2b8f5d9..db8d13069 100644 --- a/src/BufferImage.cpp +++ b/src/BufferImage.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "BufferImage.h" diff --git a/src/BufferTexture.cpp b/src/BufferTexture.cpp index 621d4feee..c06e62ec6 100644 --- a/src/BufferTexture.cpp +++ b/src/BufferTexture.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "BufferTexture.h" diff --git a/src/Context.cpp b/src/Context.cpp index bcc9518ec..b30f2b251 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Context.h" diff --git a/src/DebugMarker.cpp b/src/DebugMarker.cpp index e4ec3d21a..44b2e6919 100644 --- a/src/DebugMarker.cpp +++ b/src/DebugMarker.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "DebugMarker.h" diff --git a/src/DebugTools/ForceRenderer.cpp b/src/DebugTools/ForceRenderer.cpp index 8ac198796..9b9fdd25a 100644 --- a/src/DebugTools/ForceRenderer.cpp +++ b/src/DebugTools/ForceRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ForceRenderer.h" diff --git a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp index 90a3ed261..011997e4f 100644 --- a/src/DebugTools/Implementation/AbstractBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractBoxRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractBoxRenderer.h" diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index b461cac31..06f9b30cd 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractShapeRenderer.h" diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index cfbda116a..903cfbf57 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AxisAlignedBoxRenderer.h" diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index fa42567c4..e838b67f1 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "BoxRenderer.h" diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp index 3a658bbcb..c414813f2 100644 --- a/src/DebugTools/Implementation/PointRenderer.cpp +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "PointRenderer.h" diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 65c320a09..240febe45 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ObjectRenderer.h" diff --git a/src/DebugTools/Profiler.cpp b/src/DebugTools/Profiler.cpp index 00602f9a8..465833b96 100644 --- a/src/DebugTools/Profiler.cpp +++ b/src/DebugTools/Profiler.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Profiler.h" diff --git a/src/DebugTools/ResourceManager.cpp b/src/DebugTools/ResourceManager.cpp index 90123e984..204c28357 100644 --- a/src/DebugTools/ResourceManager.cpp +++ b/src/DebugTools/ResourceManager.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 5b7cfb4a4..1987e529b 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ShapeRenderer.h" diff --git a/src/DebugTools/Test/ForceRendererTest.cpp b/src/DebugTools/Test/ForceRendererTest.cpp index 89b8f4131..5dcf4022c 100644 --- a/src/DebugTools/Test/ForceRendererTest.cpp +++ b/src/DebugTools/Test/ForceRendererTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 6b1f61b69..895a12e74 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "DefaultFramebuffer.h" diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index a4f5e0102..01c0a7d5f 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Framebuffer.h" diff --git a/src/Image.cpp b/src/Image.cpp index b6c6921e2..06f8cde86 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Image.h" diff --git a/src/Implementation/BufferState.cpp b/src/Implementation/BufferState.cpp index 949c3bdb1..15ecc9a9e 100644 --- a/src/Implementation/BufferState.cpp +++ b/src/Implementation/BufferState.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "BufferState.h" diff --git a/src/Implementation/State.cpp b/src/Implementation/State.cpp index 152e02450..c4d00e811 100644 --- a/src/Implementation/State.cpp +++ b/src/Implementation/State.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "State.h" diff --git a/src/Math/Algorithms/Test/GaussJordanTest.cpp b/src/Math/Algorithms/Test/GaussJordanTest.cpp index 2f1383197..80ef9c1e5 100644 --- a/src/Math/Algorithms/Test/GaussJordanTest.cpp +++ b/src/Math/Algorithms/Test/GaussJordanTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 80ad62ab2..28700089d 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Algorithms/Test/SvdTest.cpp b/src/Math/Algorithms/Test/SvdTest.cpp index aebea8cfb..ca1a1219b 100644 --- a/src/Math/Algorithms/Test/SvdTest.cpp +++ b/src/Math/Algorithms/Test/SvdTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Angle.cpp b/src/Math/Angle.cpp index 07f77b4e6..bae169c3f 100644 --- a/src/Math/Angle.cpp +++ b/src/Math/Angle.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Angle.h" diff --git a/src/Math/Complex.cpp b/src/Math/Complex.cpp index 84cdf2c3e..0b234116c 100644 --- a/src/Math/Complex.cpp +++ b/src/Math/Complex.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Complex.h" diff --git a/src/Math/DualComplex.cpp b/src/Math/DualComplex.cpp index e0e83ca08..9b18e9abc 100644 --- a/src/Math/DualComplex.cpp +++ b/src/Math/DualComplex.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "DualComplex.h" diff --git a/src/Math/DualQuaternion.cpp b/src/Math/DualQuaternion.cpp index fe330c6b6..0070e50ac 100644 --- a/src/Math/DualQuaternion.cpp +++ b/src/Math/DualQuaternion.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "DualQuaternion.h" diff --git a/src/Math/Functions.cpp b/src/Math/Functions.cpp index afcb2ad76..d562bd8f4 100644 --- a/src/Math/Functions.cpp +++ b/src/Math/Functions.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Functions.h" diff --git a/src/Math/Geometry/Test/DistanceTest.cpp b/src/Math/Geometry/Test/DistanceTest.cpp index 01053098d..3170265e7 100644 --- a/src/Math/Geometry/Test/DistanceTest.cpp +++ b/src/Math/Geometry/Test/DistanceTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Geometry/Test/IntersectionTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp index 4004dacf6..c70f48747 100644 --- a/src/Math/Geometry/Test/IntersectionTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Geometry/Test/RectangleTest.cpp b/src/Math/Geometry/Test/RectangleTest.cpp index 1ef1de127..0120168ea 100644 --- a/src/Math/Geometry/Test/RectangleTest.cpp +++ b/src/Math/Geometry/Test/RectangleTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Quaternion.cpp b/src/Math/Quaternion.cpp index 9939dc854..8ec3c0b13 100644 --- a/src/Math/Quaternion.cpp +++ b/src/Math/Quaternion.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Quaternion.h" diff --git a/src/Math/RectangularMatrix.cpp b/src/Math/RectangularMatrix.cpp index 76d8e9cdf..7fcd9a6c7 100644 --- a/src/Math/RectangularMatrix.cpp +++ b/src/Math/RectangularMatrix.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "RectangularMatrix.h" diff --git a/src/Math/Test/AngleTest.cpp b/src/Math/Test/AngleTest.cpp index 9cc2ca081..cac78bda1 100644 --- a/src/Math/Test/AngleTest.cpp +++ b/src/Math/Test/AngleTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/BoolVectorTest.cpp b/src/Math/Test/BoolVectorTest.cpp index 312be39b3..1063726e6 100644 --- a/src/Math/Test/BoolVectorTest.cpp +++ b/src/Math/Test/BoolVectorTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 1910, 1911, 1912 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 7f7bd484a..d35efe979 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index a6e244b89..98211496b 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 025c3d72b..31ffb6385 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index fcbe9e021..75300f1d6 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index 74c7588b6..3bc8057d1 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 69b61296f..55191dd1b 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index 42616fb6e..f1239ce50 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index f10efb385..ce0423c6e 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index 3cd612692..c201a5688 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 6d5567731..207580b65 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index b7ba2aad9..75d4ddf46 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index bfdd0f3b4..05af6ccc8 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp index 4ce3dfca9..cb7596beb 100644 --- a/src/Math/Test/SwizzleTest.cpp +++ b/src/Math/Test/SwizzleTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index b575342ed..18dc1179d 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/Vector2Test.cpp b/src/Math/Test/Vector2Test.cpp index 1d0b4b17d..1a4183445 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/Vector3Test.cpp b/src/Math/Test/Vector3Test.cpp index 76dc9b863..05d5a697d 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/Vector4Test.cpp b/src/Math/Test/Vector4Test.cpp index 53467e4a4..8e09b296c 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index b874e64da..8cc307a5b 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Math/Vector.cpp b/src/Math/Vector.cpp index c01650c88..615eeba28 100644 --- a/src/Math/Vector.cpp +++ b/src/Math/Vector.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Vector.h" diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 566f3dee2..169a78ffd 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Mesh.h" diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index e100078c3..2506fb346 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "CompressIndices.h" diff --git a/src/MeshTools/FlipNormals.cpp b/src/MeshTools/FlipNormals.cpp index 5dda1adc2..0a2172b32 100644 --- a/src/MeshTools/FlipNormals.cpp +++ b/src/MeshTools/FlipNormals.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "FlipNormals.h" diff --git a/src/MeshTools/GenerateFlatNormals.cpp b/src/MeshTools/GenerateFlatNormals.cpp index dcc00bc5f..64e152d1c 100644 --- a/src/MeshTools/GenerateFlatNormals.cpp +++ b/src/MeshTools/GenerateFlatNormals.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "GenerateFlatNormals.h" diff --git a/src/MeshTools/Test/CleanTest.cpp b/src/MeshTools/Test/CleanTest.cpp index 2e6372fc8..8e15281c9 100644 --- a/src/MeshTools/Test/CleanTest.cpp +++ b/src/MeshTools/Test/CleanTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/CombineIndexedArraysTest.cpp b/src/MeshTools/Test/CombineIndexedArraysTest.cpp index ee704b1c7..9473a4123 100644 --- a/src/MeshTools/Test/CombineIndexedArraysTest.cpp +++ b/src/MeshTools/Test/CombineIndexedArraysTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/CompressIndicesTest.cpp b/src/MeshTools/Test/CompressIndicesTest.cpp index f18cfc712..a433c1413 100644 --- a/src/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/MeshTools/Test/CompressIndicesTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/FlipNormalsTest.cpp b/src/MeshTools/Test/FlipNormalsTest.cpp index 8cfa4c73f..47c648827 100644 --- a/src/MeshTools/Test/FlipNormalsTest.cpp +++ b/src/MeshTools/Test/FlipNormalsTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp index 5859ff549..00b661266 100644 --- a/src/MeshTools/Test/GenerateFlatNormalsTest.cpp +++ b/src/MeshTools/Test/GenerateFlatNormalsTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index 4b10121ec..fe525edda 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/SubdivideCleanBenchmark.cpp b/src/MeshTools/Test/SubdivideCleanBenchmark.cpp index fd56ef292..01f3ebd36 100644 --- a/src/MeshTools/Test/SubdivideCleanBenchmark.cpp +++ b/src/MeshTools/Test/SubdivideCleanBenchmark.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "SubdivideCleanBenchmark.h" diff --git a/src/MeshTools/Test/SubdivideTest.cpp b/src/MeshTools/Test/SubdivideTest.cpp index 35919bd16..9271e3d60 100644 --- a/src/MeshTools/Test/SubdivideTest.cpp +++ b/src/MeshTools/Test/SubdivideTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index 98c32b98b..096b2fe2e 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Test/TransformTest.cpp b/src/MeshTools/Test/TransformTest.cpp index a0ad8184c..7d632c879 100644 --- a/src/MeshTools/Test/TransformTest.cpp +++ b/src/MeshTools/Test/TransformTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/MeshTools/Tipsify.cpp b/src/MeshTools/Tipsify.cpp index 497f74890..fea4ddd21 100644 --- a/src/MeshTools/Tipsify.cpp +++ b/src/MeshTools/Tipsify.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Tipsify.h" diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index ec410cee2..7a0dbeee2 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index adedf7f85..2321bd481 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractShape.h" diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 68f28ca11..5b7a5d7bb 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AxisAlignedBox.h" diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 189625c6f..3f724793e 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Box.h" diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 18bf0fab9..09823df5d 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Capsule.h" diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index d3835441e..bcb5f9a15 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Line.h" diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index a34f46e3e..a5eb93791 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ObjectShape.h" diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index 16580d012..994f71a02 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ObjectShapeGroup.h" diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index 098c0e071..8c3ae2b50 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Plane.h" diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 880c91edb..fb52d3b7e 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Point.h" diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index 5c5a957b9..5d6777c4b 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ShapeGroup.h" diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 2bf35b7f8..4eebd8c49 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Sphere.h" diff --git a/src/Physics/Test/AbstractShapeTest.cpp b/src/Physics/Test/AbstractShapeTest.cpp index 1a44f46a6..0b451e78d 100644 --- a/src/Physics/Test/AbstractShapeTest.cpp +++ b/src/Physics/Test/AbstractShapeTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index 097c0f704..cf45bf009 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp index 880f497d6..33bc2781b 100644 --- a/src/Physics/Test/BoxTest.cpp +++ b/src/Physics/Test/BoxTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 88636f4e6..8f1bc43d3 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Physics/Capsule.h" diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 05a2076c7..6f0f2cd9d 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/ObjectShapeTest.cpp b/src/Physics/Test/ObjectShapeTest.cpp index 8e978c813..056c680f1 100644 --- a/src/Physics/Test/ObjectShapeTest.cpp +++ b/src/Physics/Test/ObjectShapeTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/PlaneTest.cpp b/src/Physics/Test/PlaneTest.cpp index 877c1d01d..028ccb770 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Physics/LineSegment.h" diff --git a/src/Physics/Test/PointTest.cpp b/src/Physics/Test/PointTest.cpp index d751d2b23..f2e10188c 100644 --- a/src/Physics/Test/PointTest.cpp +++ b/src/Physics/Test/PointTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index c5140db92..6650405ca 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index 225d31072..ba50a5b15 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Physics/LineSegment.h" diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index d96e9bd70..37aa4fcc1 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractXApplication.h" diff --git a/src/Platform/EglContextHandler.cpp b/src/Platform/EglContextHandler.cpp index a002feace..75a1f05d4 100644 --- a/src/Platform/EglContextHandler.cpp +++ b/src/Platform/EglContextHandler.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "EglContextHandler.h" diff --git a/src/Platform/ExtensionWrangler.cpp b/src/Platform/ExtensionWrangler.cpp index b5fdce9f0..4db476384 100644 --- a/src/Platform/ExtensionWrangler.cpp +++ b/src/Platform/ExtensionWrangler.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ExtensionWrangler.h" diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 6a8b6dabc..cdf7dd5c9 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "GlutApplication.h" diff --git a/src/Platform/GlxContextHandler.cpp b/src/Platform/GlxContextHandler.cpp index a7e2b810d..f39cd2db4 100644 --- a/src/Platform/GlxContextHandler.cpp +++ b/src/Platform/GlxContextHandler.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "GlxContextHandler.h" diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index 20da70355..87a442ccc 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "NaClApplication.h" diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 41a1b3876..6ed239158 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Sdl2Application.h" diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index b109a7108..36370c686 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "WindowlessGlxApplication.h" diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index f3477c265..7aa18126b 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 6ac9a6317..fdab14a66 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Capsule.h" diff --git a/src/Primitives/Crosshair.cpp b/src/Primitives/Crosshair.cpp index e38084498..c20fe61fe 100644 --- a/src/Primitives/Crosshair.cpp +++ b/src/Primitives/Crosshair.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Crosshair.h" diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 9319d341c..eb369ce23 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Cube.h" diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index b51e991f5..1a924b0d3 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Cylinder.h" diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 0dbd56845..b5ddc86ea 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Icosphere.h" diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 3bf69aca2..3ff7488a5 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Plane.h" diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index 9a20cc4d0..f17646966 100644 --- a/src/Primitives/Square.cpp +++ b/src/Primitives/Square.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Square.h" diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index bebcb9f4e..3d74a2680 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/src/Primitives/Test/CapsuleTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /* Less precision */ diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index 351d5e28f..938162fab 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/src/Primitives/Test/CylinderTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 65ce46088..beaa6b46f 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/src/Primitives/Test/UVSphereTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 5e898d9ce..91fa8c2bc 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "UVSphere.h" diff --git a/src/Query.cpp b/src/Query.cpp index 12cf4e527..072fad307 100644 --- a/src/Query.cpp +++ b/src/Query.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Query.h" diff --git a/src/Renderbuffer.cpp b/src/Renderbuffer.cpp index afb9d1f26..0ca1a724c 100644 --- a/src/Renderbuffer.cpp +++ b/src/Renderbuffer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Renderbuffer.h" diff --git a/src/Resource.cpp b/src/Resource.cpp index 6093091d4..ac0c89ffa 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Resource.h" diff --git a/src/SceneGraph/Animable.cpp b/src/SceneGraph/Animable.cpp index 8af96cd96..a424ef9bd 100644 --- a/src/SceneGraph/Animable.cpp +++ b/src/SceneGraph/Animable.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Animable.hpp" diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index a62f75548..982d76a01 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Camera2D.hpp" diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.cpp b/src/SceneGraph/EuclideanMatrixTransformation2D.cpp index 589b0f569..cbf5bccfe 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.cpp +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "EuclideanMatrixTransformation2D.h" diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.cpp b/src/SceneGraph/EuclideanMatrixTransformation3D.cpp index f670329ce..d42cab0ad 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.cpp +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "EuclideanMatrixTransformation3D.h" diff --git a/src/SceneGraph/MatrixTransformation2D.cpp b/src/SceneGraph/MatrixTransformation2D.cpp index 7850ca48c..c546bd302 100644 --- a/src/SceneGraph/MatrixTransformation2D.cpp +++ b/src/SceneGraph/MatrixTransformation2D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "MatrixTransformation2D.h" diff --git a/src/SceneGraph/MatrixTransformation3D.cpp b/src/SceneGraph/MatrixTransformation3D.cpp index bbcc227e8..d2e7e82b3 100644 --- a/src/SceneGraph/MatrixTransformation3D.cpp +++ b/src/SceneGraph/MatrixTransformation3D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "MatrixTransformation3D.h" diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index 8bfe038a2..0a4c679c8 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Object.hpp" diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index 493a57739..fb0ebb643 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 6ab6446ff..8c0c91e9e 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp index 0be0e4795..6f5cb9fba 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp index b3182236b..840b7c590 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp index eca05d982..976fb46b2 100644 --- a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index 03c037fbb..ce624065f 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 61988025f..51f1187f2 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/SceneGraph/Test/SceneTest.cpp b/src/SceneGraph/Test/SceneTest.cpp index 64d9cff35..d3731a11d 100644 --- a/src/SceneGraph/Test/SceneTest.cpp +++ b/src/SceneGraph/Test/SceneTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Shader.cpp b/src/Shader.cpp index b66a72742..741d2b3c3 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Shader.h" diff --git a/src/Shaders/AbstractVectorShader2D.vert b/src/Shaders/AbstractVectorShader2D.vert index 9b3816650..6f0f9baa4 100644 --- a/src/Shaders/AbstractVectorShader2D.vert +++ b/src/Shaders/AbstractVectorShader2D.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #define out varying diff --git a/src/Shaders/AbstractVectorShader3D.vert b/src/Shaders/AbstractVectorShader3D.vert index 5204e41b4..f74fb0989 100644 --- a/src/Shaders/AbstractVectorShader3D.vert +++ b/src/Shaders/AbstractVectorShader3D.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #define out varying diff --git a/src/Shaders/DistanceFieldVectorShader.cpp b/src/Shaders/DistanceFieldVectorShader.cpp index 6631a0ddf..5d39f356c 100644 --- a/src/Shaders/DistanceFieldVectorShader.cpp +++ b/src/Shaders/DistanceFieldVectorShader.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "DistanceFieldVectorShader.h" diff --git a/src/Shaders/DistanceFieldVectorShader.frag b/src/Shaders/DistanceFieldVectorShader.frag index 7ec900bf1..1e0ae9f1f 100644 --- a/src/Shaders/DistanceFieldVectorShader.frag +++ b/src/Shaders/DistanceFieldVectorShader.frag @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in varying #define fragmentColor gl_FragColor diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index d8ea1b039..7ee89d254 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "FlatShader.h" diff --git a/src/Shaders/FlatShader.frag b/src/Shaders/FlatShader.frag index ce2c5867a..d27192d22 100644 --- a/src/Shaders/FlatShader.frag +++ b/src/Shaders/FlatShader.frag @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define fragmentColor gl_FragColor #endif diff --git a/src/Shaders/FlatShader2D.vert b/src/Shaders/FlatShader2D.vert index a976a1c7f..9e983a978 100644 --- a/src/Shaders/FlatShader2D.vert +++ b/src/Shaders/FlatShader2D.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #endif diff --git a/src/Shaders/FlatShader3D.vert b/src/Shaders/FlatShader3D.vert index 69eaead28..2f4b875c5 100644 --- a/src/Shaders/FlatShader3D.vert +++ b/src/Shaders/FlatShader3D.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #endif diff --git a/src/Shaders/PhongShader.cpp b/src/Shaders/PhongShader.cpp index aec592bdb..cbba095c0 100644 --- a/src/Shaders/PhongShader.cpp +++ b/src/Shaders/PhongShader.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "PhongShader.h" diff --git a/src/Shaders/PhongShader.frag b/src/Shaders/PhongShader.frag index 4b00f8cd5..c3411f0ea 100644 --- a/src/Shaders/PhongShader.frag +++ b/src/Shaders/PhongShader.frag @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in varying #define color gl_FragColor diff --git a/src/Shaders/PhongShader.vert b/src/Shaders/PhongShader.vert index 99d3a3fe7..c52eb30f9 100644 --- a/src/Shaders/PhongShader.vert +++ b/src/Shaders/PhongShader.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #define out varying diff --git a/src/Shaders/VectorShader.cpp b/src/Shaders/VectorShader.cpp index da1706824..af1c7ba2f 100644 --- a/src/Shaders/VectorShader.cpp +++ b/src/Shaders/VectorShader.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "VectorShader.h" diff --git a/src/Shaders/VectorShader.frag b/src/Shaders/VectorShader.frag index eb1238fb1..8384499a7 100644 --- a/src/Shaders/VectorShader.frag +++ b/src/Shaders/VectorShader.frag @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in varying #define fragmentColor gl_FragColor diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index e73c2335e..8c6b4699e 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "VertexColorShader.h" diff --git a/src/Shaders/VertexColorShader.frag b/src/Shaders/VertexColorShader.frag index 641dd081e..caa13dbf4 100644 --- a/src/Shaders/VertexColorShader.frag +++ b/src/Shaders/VertexColorShader.frag @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in varying #define fragmentColor gl_FragColor diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index 1272488e2..f7d2c879e 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/src/Shaders/VertexColorShader2D.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #define out varying diff --git a/src/Shaders/VertexColorShader3D.vert b/src/Shaders/VertexColorShader3D.vert index 8a871000f..9cf727389 100644 --- a/src/Shaders/VertexColorShader3D.vert +++ b/src/Shaders/VertexColorShader3D.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #ifndef NEW_GLSL #define in attribute #define out varying diff --git a/src/Shaders/compatibility.glsl b/src/Shaders/compatibility.glsl index 2d3994a68..3534b4187 100644 --- a/src/Shaders/compatibility.glsl +++ b/src/Shaders/compatibility.glsl @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #if (!defined(GL_ES) && __VERSION__ >= 130) || (defined(GL_ES) && __VERSION__ >= 300) #define NEW_GLSL #endif diff --git a/src/Test/AbstractImageTest.cpp b/src/Test/AbstractImageTest.cpp index e2007d9f0..2f1e475ec 100644 --- a/src/Test/AbstractImageTest.cpp +++ b/src/Test/AbstractImageTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Test/AbstractShaderProgramTest.cpp b/src/Test/AbstractShaderProgramTest.cpp index a7af82851..4dc11e31b 100644 --- a/src/Test/AbstractShaderProgramTest.cpp +++ b/src/Test/AbstractShaderProgramTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Test/ArrayTest.cpp b/src/Test/ArrayTest.cpp index 8743a9526..dcf4de7bd 100644 --- a/src/Test/ArrayTest.cpp +++ b/src/Test/ArrayTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index e54fbf2ef..773913454 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp index 8733bf7ca..10c91fcc8 100644 --- a/src/Test/MeshTest.cpp +++ b/src/Test/MeshTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 9f1bbe4ff..ac3a89747 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 7994c6eb8..75d281c44 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Text/AbstractFont.cpp b/src/Text/AbstractFont.cpp index 5daef1fa2..31214e636 100644 --- a/src/Text/AbstractFont.cpp +++ b/src/Text/AbstractFont.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Text/AbstractFont.h" diff --git a/src/Text/FreeTypeFont.cpp b/src/Text/FreeTypeFont.cpp index 2078db100..4cd54b78c 100644 --- a/src/Text/FreeTypeFont.cpp +++ b/src/Text/FreeTypeFont.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "FreeTypeFont.h" diff --git a/src/Text/HarfBuzzFont.cpp b/src/Text/HarfBuzzFont.cpp index 31b1ba1f8..6adf781e7 100644 --- a/src/Text/HarfBuzzFont.cpp +++ b/src/Text/HarfBuzzFont.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "HarfBuzzFont.h" diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 5de5724f1..e471b968d 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "TextRenderer.h" diff --git a/src/TextureTools/Atlas.cpp b/src/TextureTools/Atlas.cpp index 2d4b87b30..08398437c 100644 --- a/src/TextureTools/Atlas.cpp +++ b/src/TextureTools/Atlas.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "Atlas.h" diff --git a/src/TextureTools/DistanceField.cpp b/src/TextureTools/DistanceField.cpp index e67146ef0..7b5e0a6f6 100644 --- a/src/TextureTools/DistanceField.cpp +++ b/src/TextureTools/DistanceField.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "TextureTools/DistanceField.h" diff --git a/src/TextureTools/DistanceFieldShader.frag b/src/TextureTools/DistanceFieldShader.frag index e47f0447f..9191f9525 100644 --- a/src/TextureTools/DistanceFieldShader.frag +++ b/src/TextureTools/DistanceFieldShader.frag @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + layout(location = 0) uniform int radius; layout(location = 1) uniform vec2 scaling; layout(binding = 8) uniform sampler2D texture; diff --git a/src/TextureTools/DistanceFieldShader.vert b/src/TextureTools/DistanceFieldShader.vert index 325b2e733..a412a0a20 100644 --- a/src/TextureTools/DistanceFieldShader.vert +++ b/src/TextureTools/DistanceFieldShader.vert @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + void main() { gl_Position = vec4((gl_VertexID == 2) ? 3.0 : -1.0, (gl_VertexID == 1) ? -3.0 : 1.0, 0.0, 1.0); diff --git a/src/TextureTools/Test/AtlasTest.cpp b/src/TextureTools/Test/AtlasTest.cpp index a5b9cc311..aa653ad28 100644 --- a/src/TextureTools/Test/AtlasTest.cpp +++ b/src/TextureTools/Test/AtlasTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Timeline.cpp b/src/Timeline.cpp index a94d19376..2df6f5e74 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -1,19 +1,29 @@ -#include "Timeline.h" /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ +#include "Timeline.h" + #include #include diff --git a/src/Trade/AbstractImporter.cpp b/src/Trade/AbstractImporter.cpp index 9c0419253..79f7a9098 100644 --- a/src/Trade/AbstractImporter.cpp +++ b/src/Trade/AbstractImporter.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "AbstractImporter.h" diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp index 810fc0c96..dc665bc37 100644 --- a/src/Trade/MeshData2D.cpp +++ b/src/Trade/MeshData2D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "MeshData2D.h" diff --git a/src/Trade/MeshData3D.cpp b/src/Trade/MeshData3D.cpp index bfca98c39..cd85af98d 100644 --- a/src/Trade/MeshData3D.cpp +++ b/src/Trade/MeshData3D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "MeshData3D.h" diff --git a/src/Trade/ObjectData2D.cpp b/src/Trade/ObjectData2D.cpp index bf71a36cc..4c44c12f6 100644 --- a/src/Trade/ObjectData2D.cpp +++ b/src/Trade/ObjectData2D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ObjectData2D.h" diff --git a/src/Trade/ObjectData3D.cpp b/src/Trade/ObjectData3D.cpp index ee4fc9fae..b021b4305 100644 --- a/src/Trade/ObjectData3D.cpp +++ b/src/Trade/ObjectData3D.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "ObjectData3D.h" diff --git a/src/Trade/Test/ObjectData2DTest.cpp b/src/Trade/Test/ObjectData2DTest.cpp index c2bdd6a6c..75c377943 100644 --- a/src/Trade/Test/ObjectData2DTest.cpp +++ b/src/Trade/Test/ObjectData2DTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Trade/Test/ObjectData3DTest.cpp b/src/Trade/Test/ObjectData3DTest.cpp index d6bcdafb9..f723262c5 100644 --- a/src/Trade/Test/ObjectData3DTest.cpp +++ b/src/Trade/Test/ObjectData3DTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include From a0b83edd2b94fe45e3d310b4c9552af1493ea1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 23:50:35 +0100 Subject: [PATCH 537/567] Relicensing to MIT/Expat license, part 4: CMake and documentation files. They didn't contain license header before, but I think adding it also there wouldn't do any harm. Documentation is also integral part of the codebase. --- CMakeLists.txt | 24 ++++++++++++++++++++++++ doc/best-practices.dox | 24 ++++++++++++++++++++++++ doc/building.dox | 24 ++++++++++++++++++++++++ doc/coding-style.dox | 24 ++++++++++++++++++++++++ doc/collision-detection.dox | 24 ++++++++++++++++++++++++ doc/compilation-speedup.dox | 24 ++++++++++++++++++++++++ doc/debug-tools.dox | 24 ++++++++++++++++++++++++ doc/features.dox | 24 ++++++++++++++++++++++++ doc/mainpage.dox | 24 ++++++++++++++++++++++++ doc/matrix-vector.dox | 24 ++++++++++++++++++++++++ doc/method-chaining.dox | 24 ++++++++++++++++++++++++ doc/namespaces.dox | 24 ++++++++++++++++++++++++ doc/portability.dox | 24 ++++++++++++++++++++++++ doc/required-extensions.dox | 24 ++++++++++++++++++++++++ doc/scenegraph.dox | 24 ++++++++++++++++++++++++ doc/tips.dox | 24 ++++++++++++++++++++++++ doc/transformations.dox | 24 ++++++++++++++++++++++++ doc/types.dox | 24 ++++++++++++++++++++++++ doc/unsupported.dox | 24 ++++++++++++++++++++++++ external/CMakeLists.txt | 24 ++++++++++++++++++++++++ external/GL/CMakeLists.txt | 24 ++++++++++++++++++++++++ external/GLES3/CMakeLists.txt | 24 ++++++++++++++++++++++++ external/KHR/CMakeLists.txt | 24 ++++++++++++++++++++++++ modules/CMakeLists.txt | 24 ++++++++++++++++++++++++ modules/FindEGL.cmake | 24 ++++++++++++++++++++++++ modules/FindGLEW.cmake | 24 ++++++++++++++++++++++++ modules/FindHarfBuzz.cmake | 24 ++++++++++++++++++++++++ modules/FindMagnum.cmake | 24 ++++++++++++++++++++++++ modules/FindOpenGLES2.cmake | 24 ++++++++++++++++++++++++ modules/FindSDL2.cmake | 24 ++++++++++++++++++++++++ src/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/DebugTools/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/DebugTools/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Math/Algorithms/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Math/Algorithms/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Math/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Math/Geometry/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Math/Geometry/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Math/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/MeshTools/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/MeshTools/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Physics/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Physics/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Platform/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Primitives/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Primitives/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/SceneGraph/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/SceneGraph/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Shaders/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Text/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/TextureTools/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/TextureTools/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Trade/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/Trade/Test/CMakeLists.txt | 24 ++++++++++++++++++++++++ src/magnumConfigure.h.cmake | 24 ++++++++++++++++++++++++ 56 files changed, 1344 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28d4834fc..7b8353fe0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # CMake 2.8.8 required for OBJECT library target cmake_minimum_required(VERSION 2.8.8) project(Magnum) diff --git a/doc/best-practices.dox b/doc/best-practices.dox index e406f70ef..7517541ca 100644 --- a/doc/best-practices.dox +++ b/doc/best-practices.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page best-practices Best practices and platform-specific information diff --git a/doc/building.dox b/doc/building.dox index da7cdeb9f..2f453590c 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page building Downloading and building @brief Guide how to download and build %Magnum on different platforms. diff --git a/doc/coding-style.dox b/doc/coding-style.dox index bec708b0f..68a8ea39f 100644 --- a/doc/coding-style.dox +++ b/doc/coding-style.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page coding-style Coding style @brief Coding style and best practices to preserve maintainability and diff --git a/doc/collision-detection.dox b/doc/collision-detection.dox index 033f7607d..e263492a0 100644 --- a/doc/collision-detection.dox +++ b/doc/collision-detection.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { namespace Physics { /** @page collision-detection Collision detection @brief Collection of simple shapes for high performance collision detection. diff --git a/doc/compilation-speedup.dox b/doc/compilation-speedup.dox index 8d86d3bb3..f05196e0a 100644 --- a/doc/compilation-speedup.dox +++ b/doc/compilation-speedup.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page compilation-speedup Speeding up compilation @brief Techniques for reducing compilation times. diff --git a/doc/debug-tools.dox b/doc/debug-tools.dox index d09612c4f..916df7408 100644 --- a/doc/debug-tools.dox +++ b/doc/debug-tools.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page debug-tools Debugging helpers diff --git a/doc/features.dox b/doc/features.dox index 137c52c9a..2e0813e95 100644 --- a/doc/features.dox +++ b/doc/features.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page features Feature overview @brief Fundamental principles and design goals diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 27a0ec6db..03ca9e2d3 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @mainpage diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index b601cb5a8..ea2421c60 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { namespace Math { /** @page matrix-vector Operations with matrices and vectors diff --git a/doc/method-chaining.dox b/doc/method-chaining.dox index 9ed291b49..798830984 100644 --- a/doc/method-chaining.dox +++ b/doc/method-chaining.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page method-chaining Method chaining diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 654ff8540..179c15fc5 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + /** @dir magnum * @brief %Magnum library */ diff --git a/doc/portability.dox b/doc/portability.dox index f483e10dd..113177123 100644 --- a/doc/portability.dox +++ b/doc/portability.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page portability Writing portable applications @brief How to support different platforms and different OpenGL capabilities within one codebase. diff --git a/doc/required-extensions.dox b/doc/required-extensions.dox index 58a47ebfc..554359a1f 100644 --- a/doc/required-extensions.dox +++ b/doc/required-extensions.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + /** @page required-extensions Functionality requiring specific OpenGL version or extensions @brief List of functions not available on OpenGL 2.1 / OpenGL ES 2. diff --git a/doc/scenegraph.dox b/doc/scenegraph.dox index 857f9c4d9..6588fe109 100644 --- a/doc/scenegraph.dox +++ b/doc/scenegraph.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { namespace SceneGraph { /** @page scenegraph Using scene graph @brief Overview of scene management capabilities. diff --git a/doc/tips.dox b/doc/tips.dox index 88800e65d..3931ccd7f 100644 --- a/doc/tips.dox +++ b/doc/tips.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page tips Tips and tricks @brief Hints for better productivity and performance. diff --git a/doc/transformations.dox b/doc/transformations.dox index 43bba0457..4ead3685b 100644 --- a/doc/transformations.dox +++ b/doc/transformations.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { namespace Math { /** @page transformations 2D and 3D transformations diff --git a/doc/types.dox b/doc/types.dox index f0a721938..99d6f8755 100644 --- a/doc/types.dox +++ b/doc/types.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + namespace Magnum { /** @page types Type system diff --git a/doc/unsupported.dox b/doc/unsupported.dox index 4d6ae1232..85a52c830 100644 --- a/doc/unsupported.dox +++ b/doc/unsupported.dox @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + /** @page unsupported Unsupported OpenGL features Some functionality, which is either soon-to-be deprecated or isn't proven to diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index a24503e8b..e4e61ff4a 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + if(NOT TARGET_GLES) add_subdirectory(GL) else() diff --git a/external/GL/CMakeLists.txt b/external/GL/CMakeLists.txt index a24337831..0cfe57d4e 100644 --- a/external/GL/CMakeLists.txt +++ b/external/GL/CMakeLists.txt @@ -1 +1,25 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + install(FILES glcorearb.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GL) diff --git a/external/GLES3/CMakeLists.txt b/external/GLES3/CMakeLists.txt index 420ee834b..ccb237ced 100644 --- a/external/GLES3/CMakeLists.txt +++ b/external/GLES3/CMakeLists.txt @@ -1 +1,25 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + install(FILES gl3.h gl3platform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GLES3) diff --git a/external/KHR/CMakeLists.txt b/external/KHR/CMakeLists.txt index 19c9ed8d8..ba1402551 100644 --- a/external/KHR/CMakeLists.txt +++ b/external/KHR/CMakeLists.txt @@ -1 +1,25 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + install(FILES khrplatform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/KHR) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 7fbed6775..c4a1b4638 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + if(NOT CMAKE_CROSSCOMPILING) install(FILES FindMagnum.cmake DESTINATION ${MAGNUM_CMAKE_MODULE_INSTALL_DIR}) endif() diff --git a/modules/FindEGL.cmake b/modules/FindEGL.cmake index fa7ee7cda..2550a03b7 100644 --- a/modules/FindEGL.cmake +++ b/modules/FindEGL.cmake @@ -7,6 +7,30 @@ # EGL_INCLUDE_DIR - Include dir # +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Library find_library(EGL_LIBRARY EGL) diff --git a/modules/FindGLEW.cmake b/modules/FindGLEW.cmake index ef623d969..71f02394c 100644 --- a/modules/FindGLEW.cmake +++ b/modules/FindGLEW.cmake @@ -7,6 +7,30 @@ # GLEW_INCLUDE_DIR - Include dir # +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Include dir find_path(GLEW_INCLUDE_DIR NAMES GL/glew.h) diff --git a/modules/FindHarfBuzz.cmake b/modules/FindHarfBuzz.cmake index bf2c71e7e..f4b0139f5 100644 --- a/modules/FindHarfBuzz.cmake +++ b/modules/FindHarfBuzz.cmake @@ -10,6 +10,30 @@ # HARFBUZZ_LIBRARY - HarfBuzz library (w/o dependencies) # +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Library find_library(HARFBUZZ_LIBRARY NAMES harfbuzz) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 744f56803..b94183bcb 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -70,6 +70,30 @@ # directory # +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Dependencies find_package(Corrade REQUIRED) diff --git a/modules/FindOpenGLES2.cmake b/modules/FindOpenGLES2.cmake index 414db8368..3bc3865a3 100644 --- a/modules/FindOpenGLES2.cmake +++ b/modules/FindOpenGLES2.cmake @@ -7,6 +7,30 @@ # OPENGLES2_INCLUDE_DIR - Include dir # +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Library find_library(OPENGLES2_LIBRARY NAMES GLESv2 diff --git a/modules/FindSDL2.cmake b/modules/FindSDL2.cmake index 9ac6e9020..f352a7b58 100644 --- a/modules/FindSDL2.cmake +++ b/modules/FindSDL2.cmake @@ -7,6 +7,30 @@ # SDL2_INCLUDE_DIR - Include dir # +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Library find_library(SDL2_LIBRARY SDL2) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7390c753f..704b6d1a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}") include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CORRADE_INCLUDE_DIR}) diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 6e91b9f05..55081223a 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumDebugTools_SRCS ForceRenderer.cpp ObjectRenderer.cpp diff --git a/src/DebugTools/Test/CMakeLists.txt b/src/DebugTools/Test/CMakeLists.txt index 76dcebb5e..68a6ddae3 100644 --- a/src/DebugTools/Test/CMakeLists.txt +++ b/src/DebugTools/Test/CMakeLists.txt @@ -1 +1,25 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(MagnumDebugToolsForceRendererTest ForceRendererTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Algorithms/CMakeLists.txt b/src/Math/Algorithms/CMakeLists.txt index df7bdf1f4..3cc642da9 100644 --- a/src/Math/Algorithms/CMakeLists.txt +++ b/src/Math/Algorithms/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumMathAlgorithms_HEADERS GaussJordan.h GramSchmidt.h diff --git a/src/Math/Algorithms/Test/CMakeLists.txt b/src/Math/Algorithms/Test/CMakeLists.txt index 15166b9b7..8149a43f8 100644 --- a/src/Math/Algorithms/Test/CMakeLists.txt +++ b/src/Math/Algorithms/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(MathAlgorithmsGaussJordanTest GaussJordanTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathAlgorithmsGramSchmidtTest GramSchmidtTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathAlgorithmsSvdTest SvdTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 602896ef5..5455c492a 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumMath_HEADERS Angle.h BoolVector.h diff --git a/src/Math/Geometry/CMakeLists.txt b/src/Math/Geometry/CMakeLists.txt index 811821db3..bd64aff42 100644 --- a/src/Math/Geometry/CMakeLists.txt +++ b/src/Math/Geometry/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumMathGeometry_HEADERS Distance.h Intersection.h diff --git a/src/Math/Geometry/Test/CMakeLists.txt b/src/Math/Geometry/Test/CMakeLists.txt index 46ad2a19e..e60e23aa3 100644 --- a/src/Math/Geometry/Test/CMakeLists.txt +++ b/src/Math/Geometry/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(MathGeometryDistanceTest DistanceTest.cpp) corrade_add_test(MathGeometryIntersectionTest IntersectionTest.cpp) corrade_add_test(MathGeometryRectangleTest RectangleTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 1e1570ddd..4e2a1a990 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(MathBoolVectorTest BoolVectorTest.cpp) corrade_add_test(MathConstantsTest ConstantsTest.cpp) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index 4e20509b2..b28bd7c77 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Files shared between main library and unit test library set(MagnumMeshTools_SRCS CompressIndices.cpp diff --git a/src/MeshTools/Test/CMakeLists.txt b/src/MeshTools/Test/CMakeLists.txt index 6cd555f0b..a0a5626e5 100644 --- a/src/MeshTools/Test/CMakeLists.txt +++ b/src/MeshTools/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(MeshToolsCleanTest CleanTest.cpp) corrade_add_test(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp) corrade_add_test(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES MagnumMeshTools) diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index 36b9a0e24..aa4a2afe2 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumPhysics_SRCS AbstractShape.cpp AxisAlignedBox.cpp diff --git a/src/Physics/Test/CMakeLists.txt b/src/Physics/Test/CMakeLists.txt index 4477fdda6..2467787cc 100644 --- a/src/Physics/Test/CMakeLists.txt +++ b/src/Physics/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(PhysicsAbstractShapeTest AbstractShapeTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index 2123e9120..378c14cbc 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumPlatform_HEADERS AbstractContextHandler.h ExtensionWrangler.h) diff --git a/src/Primitives/CMakeLists.txt b/src/Primitives/CMakeLists.txt index 9c8ac8a6d..a3c2efd95 100644 --- a/src/Primitives/CMakeLists.txt +++ b/src/Primitives/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumPrimitives_SRCS Capsule.cpp Crosshair.cpp diff --git a/src/Primitives/Test/CMakeLists.txt b/src/Primitives/Test/CMakeLists.txt index cf9d61c75..987d1e01e 100644 --- a/src/Primitives/Test/CMakeLists.txt +++ b/src/Primitives/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesUVSphereTest UVSphereTest.cpp LIBRARIES MagnumPrimitives) corrade_add_test(PrimitivesCylinderTest CylinderTest.cpp LIBRARIES MagnumPrimitives) diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 1b2df1a34..e1b68c04e 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + # Files shared between main library and unit test library set(MagnumSceneGraph_SRCS Animable.cpp diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index 86f50974f..c587cd07a 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphEuclideanMatrixTr___2DTest EuclideanMatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) diff --git a/src/Shaders/CMakeLists.txt b/src/Shaders/CMakeLists.txt index e8e96d25b..225b1b0c0 100644 --- a/src/Shaders/CMakeLists.txt +++ b/src/Shaders/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_resource(MagnumShaders_RCS MagnumShaders AbstractVectorShader2D.vert AbstractVectorShader3D.vert FlatShader2D.vert FlatShader3D.vert FlatShader.frag diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 5b4b97791..78495259d 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(AbstractImageTest AbstractImageTest.cpp LIBRARIES Magnum) corrade_add_test(AbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARIES Magnum) corrade_add_test(ArrayTest ArrayTest.cpp) diff --git a/src/Text/CMakeLists.txt b/src/Text/CMakeLists.txt index 92ea20ce9..517ebbea2 100644 --- a/src/Text/CMakeLists.txt +++ b/src/Text/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + find_package(Freetype REQUIRED) include_directories(${FREETYPE_INCLUDE_DIRS}) diff --git a/src/TextureTools/CMakeLists.txt b/src/TextureTools/CMakeLists.txt index 36eb6dae7..701f299e5 100644 --- a/src/TextureTools/CMakeLists.txt +++ b/src/TextureTools/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_resource(MagnumTextureTools_RCS MagnumTextureTools DistanceFieldShader.vert DistanceFieldShader.frag ../Shaders/compatibility.glsl ALIAS compatibility.glsl) diff --git a/src/TextureTools/Test/CMakeLists.txt b/src/TextureTools/Test/CMakeLists.txt index 4c4610b50..f1849c53e 100644 --- a/src/TextureTools/Test/CMakeLists.txt +++ b/src/TextureTools/Test/CMakeLists.txt @@ -1 +1,25 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(TextureToolsAtlasTest AtlasTest.cpp LIBRARIES MagnumTextureTools) diff --git a/src/Trade/CMakeLists.txt b/src/Trade/CMakeLists.txt index 6e8a1efd2..3e541fe28 100644 --- a/src/Trade/CMakeLists.txt +++ b/src/Trade/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(MagnumTrade_HEADERS AbstractImporter.h AbstractMaterialData.h diff --git a/src/Trade/Test/CMakeLists.txt b/src/Trade/Test/CMakeLists.txt index 84ba62f24..1581379f4 100644 --- a/src/Trade/Test/CMakeLists.txt +++ b/src/Trade/Test/CMakeLists.txt @@ -1,2 +1,26 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(TradeObjectData2DTest ObjectData2DTest.cpp LIBRARIES Magnum) corrade_add_test(TradeObjectData3DTest ObjectData3DTest.cpp LIBRARIES Magnum) diff --git a/src/magnumConfigure.h.cmake b/src/magnumConfigure.h.cmake index 61279ff38..303ffee2d 100644 --- a/src/magnumConfigure.h.cmake +++ b/src/magnumConfigure.h.cmake @@ -1,3 +1,27 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + #cmakedefine MAGNUM_TARGET_GLES #cmakedefine MAGNUM_TARGET_GLES2 #cmakedefine MAGNUM_TARGET_DESKTOP_GLES From a7ff819dd87f4c69b53086d3072e919e2b54411e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 23:53:16 +0100 Subject: [PATCH 538/567] Relicensing to MIT/Expat license, part 5: updated package files. --- PKGBUILD | 2 +- PKGBUILD-mingw32 | 2 +- PKGBUILD-nacl | 2 +- PKGBUILD-release | 2 +- package/archlinux/magnum-git/PKGBUILD | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index f99919dcc..ca4a64126 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -5,7 +5,7 @@ pkgrel=1 pkgdesc="OpenGL 3 graphics engine" arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" -license=('LGPLv3') +license=('MIT') depends=('corrade' 'glew') makedepends=('cmake') options=(!strip) diff --git a/PKGBUILD-mingw32 b/PKGBUILD-mingw32 index 106fd8f2f..42b3835c3 100644 --- a/PKGBUILD-mingw32 +++ b/PKGBUILD-mingw32 @@ -5,7 +5,7 @@ pkgrel=1 pkgdesc="OpenGL 3 graphics engine (mingw32)" arch=('any') url="https://github.com/mosra/magnum" -license=('LGPLv3') +license=('MIT') depends=('mingw32-runtime' 'mingw32-corrade' 'mingw32-glew') makedepends=('mingw32-gcc' 'cmake' 'corrade') options=(!buildflags !strip) diff --git a/PKGBUILD-nacl b/PKGBUILD-nacl index 344e53f7b..668cafd4c 100644 --- a/PKGBUILD-nacl +++ b/PKGBUILD-nacl @@ -5,7 +5,7 @@ pkgrel=1 pkgdesc="OpenGL 3 graphics engine (NaCl x86-64 version)" arch=('any') url="https://github.com/mosra/magnum" -license=('LGPLv3') +license=('MIT') depends=('nacl-corrade') makedepends=('nacl-sdk' 'cmake') options=(!buildflags !strip) diff --git a/PKGBUILD-release b/PKGBUILD-release index 3409b26e2..a09e48d39 100644 --- a/PKGBUILD-release +++ b/PKGBUILD-release @@ -5,7 +5,7 @@ pkgrel=1 pkgdesc="OpenGL 3 graphics engine" arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" -license=('LGPLv3') +license=('MIT') depends=('corrade' 'glew') makedepends=('cmake' 'qt') provides=('magnum-git') diff --git a/package/archlinux/magnum-git/PKGBUILD b/package/archlinux/magnum-git/PKGBUILD index f4931acf7..5e3128719 100644 --- a/package/archlinux/magnum-git/PKGBUILD +++ b/package/archlinux/magnum-git/PKGBUILD @@ -5,7 +5,7 @@ pkgrel=1 pkgdesc="OpenGL 3 graphics engine (Git version)" arch=('i686' 'x86_64') url="https://github.com/mosra/magnum" -license=('LGPLv3') +license=('MIT') depends=('corrade-git' 'glew') makedepends=('cmake' 'git') From b6ae293b24639d824168b9fa0b1e86d9bc3b19fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 10 Mar 2013 23:54:02 +0100 Subject: [PATCH 539/567] Relicensing to MIT/Expat license, part 6: mention it in documentation. --- CONTRIBUTING.md | 72 +++++++++++++++++++++++++++--------------------- README.md | 6 ++++ doc/mainpage.dox | 26 +++++++++++++++++ 3 files changed, 73 insertions(+), 31 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d55a03a71..ec263025d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,41 +4,51 @@ To make things easier, here are a few tips: Reporting bugs, requesting features ----------------------------------- -- Best way to report bugs and request new features is to use GitHub - [issues](https://github.com/mosra/magnum/issues), but you can contact me - also any other way. +* Best way to report bugs and request new features is to use GitHub + [issues](https://github.com/mosra/magnum/issues), but you can contact me + also any other way. Code contribution ----------------- -- Building and installing Magnum is described in the - [documentation](http://mosra.cz/blog/magnum-doc/building.html). -- Follow the project coding guidelines. In short - try to match style of - surrounding code and avoid any trailing whitespace. When in doubt, consult - coding guidelines, which are available also - [online](http://mosra.cz/blog/magnum-doc/coding-style.html). -- Document your code. When updating or adding new API, make sure that Doxygen - documentation is up to date. Run - - doxygen - - in project root to generate the documentation and check that your - modifications didn't add any warnings. -- Build unit tests (`-DBUILD_TESTS=ON` parameter to CMake) and run them - using - - ctest --output-on-failure - - in build directory. All tests should always pass. Add new tests or modify - the existing to make sure new code is properly covered (if possible). Here - is a [short tutorial](http://mosra.cz/blog/corrade-doc/unit-testing.html) to - help you with creating unit tests. -- Best way to contribute is by using GitHub - [pull requests](https://github.com/mosra/magnum/pulls) - fork the repository - and make pull request from feature branch. You can also send patches via - e-mail or contact me any other way. -- All your code will be released under license of the project, so make sure - you (or your employers) have no problems with it. +* Building and installing Magnum is described in the [documentation](http://mosra.cz/blog/magnum-doc/building.html). +* Follow the project coding guidelines. In short -- try to match style of the + surrounding code and avoid any trailing whitespace. When in doubt, consult + coding guidelines, which are available also [online](http://mosra.cz/blog/magnum-doc/coding-style.html). +* Document your code. When updating or adding new API, make sure that Doxygen + documentation is up to date. Run + + doxygen + + in project root to generate the documentation and check that your + modifications didn't add any warnings. +* Build unit tests (`-DBUILD_TESTS=ON` parameter to CMake) and run them + using + + ctest --output-on-failure + + in build directory. All tests should *always* pass. Add new tests or modify + the existing to make sure new code is properly covered (if possible). Here + is a [short tutorial](http://mosra.cz/blog/corrade-doc/unit-testing.html) + to help you with creating unit tests. +* Best way to contribute is by using GitHub [pull requests](https://github.com/mosra/magnum/pulls) + -- fork the repository and make pull request from feature branch. You can + also send patches via e-mail or contact me any other way. +* All your code will be released under license of the project (see [COPYING](COPYING) + file for details), so make sure you and your collaborators (or employers) + have no problems with it. If you create new files, don't forget to add + license header (verbatim copied from other files) and don't forget to add + yourself to license header of files you added or significantly modified, + for example: + + /* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + Copyright © YEAR YOUR_NAME + + Permission is hereby granted, free of charge, to any person obtaining a + ... Contact ------- diff --git a/README.md b/README.md index 5b378b3aa..1164a9484 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,9 @@ awesome idea? Feel free to visit my website or contact me at: * GitHub - https://github.com/mosra/magnum * E-mail - mosra@centrum.cz * Jabber - mosra@jabbim.cz + +LICENSE +======= + +Magnum is licensed under MIT/Expat license, see [COPYING](COPYING) file for +details. diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 03ca9e2d3..d9233a841 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -93,5 +93,31 @@ Feel free to get more information or contact the author at: - E-mail - mosra@centrum.cz - Jabber - mosra@jabbim.cz +@section license License + +%Magnum is licensed under MIT/Expat license: + +> +> Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> +> +> Permission is hereby granted, free of charge, to any person obtaining a +> copy of this software and associated documentation files (the "Software"), +> to deal in the Software without restriction, including without limitation +> the rights to use, copy, modify, merge, publish, distribute, sublicense, +> and/or sell copies of the Software, and to permit persons to whom the +> Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included +> in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +> THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +> FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +> DEALINGS IN THE SOFTWARE. +> + */ } From efab88fb5744a704dfc61d4431fadd885f055165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Mar 2013 14:41:29 +0100 Subject: [PATCH 540/567] Removed WITH_EVERYTHING compilation switch. Simplifies many things a lot. --- CMakeLists.txt | 21 +++++++-------- doc/building.dox | 68 +++++++++++++++++++++++++----------------------- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b8353fe0..799488f4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,21 +33,20 @@ cmake_dependent_option(TARGET_GLES2 "Build for OpenGL ES 2" ON "TARGET_GLES" OFF cmake_dependent_option(TARGET_DESKTOP_GLES "Build for OpenGL ES on desktop" OFF "TARGET_GLES" OFF) # Parts of the library -option(WITH_EVERYTHING "Build everything (doesn't include *Application libraries)" ON) -cmake_dependent_option(WITH_DEBUGTOOLS "Build DebugTools library" OFF "NOT WITH_EVERYTHING" ON) -cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) -cmake_dependent_option(WITH_PHYSICS "Build Physics library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) -cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) -cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) -cmake_dependent_option(WITH_SHADERS "Build Shaders library" OFF "NOT WITH_EVERYTHING;NOT WITH_DEBUGTOOLS" ON) -cmake_dependent_option(WITH_TEXT "Build Text library" OFF "NOT WITH_EVERYTHING" ON) -cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" OFF "NOT WITH_EVERYTHING;NOT WITH_TEXT" ON) - -cmake_dependent_option(WITH_MAGNUMINFO "Build magnum-info utility" OFF "NOT WITH_EVERYTHING" ON) +option(WITH_DEBUGTOOLS "Build DebugTools library" ON) +cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" ON "NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_PHYSICS "Build Physics library" ON "NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" ON "NOT WITH_DEBUGTOOLS" ON) +cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" ON "NOT WITH_DEBUGTOOLS;NOT WITH_PHYSICS" ON) +cmake_dependent_option(WITH_SHADERS "Build Shaders library" ON "NOT WITH_DEBUGTOOLS" ON) +option(WITH_TEXT "Build Text library" ON) +cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" ON "NOT WITH_TEXT" ON) +option(WITH_MAGNUMINFO "Build magnum-info utility" ON) # Library features cmake_dependent_option(USE_HARFBUZZ "Use HarfBuzz in Text library" ON "WITH_TEXT" OFF) +# Application libraries if(${CMAKE_SYSTEM_NAME} STREQUAL NaCl) option(WITH_NACLAPPLICATION "Build NaClApplication library" OFF) else() diff --git a/doc/building.dox b/doc/building.dox index 2f453590c..df562d963 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -80,7 +80,8 @@ If you want to build with another compiler (e.g. Clang), pass @subsection building-optional Enabling or disabling features By default the engine is built for desktop OpenGL. Using `TARGET_*` CMake -parameters you can target other platforms: +parameters you can target other platforms. Note that some features are available +for desktop OpenGL only, see @ref requires-gl. - `TARGET_GLES` - Target OpenGL ES. - `TARGET_GLES2` - Target OpenGL ES 2.0. Currently enabled by default when @@ -88,28 +89,28 @@ parameters you can target other platforms: - `TARGET_DESKTOP_GLES` - Target OpenGL ES on desktop, i.e. use OpenGL ES emulation in desktop OpenGL library. Might not be supported in all drivers. -Note that some features are available for desktop OpenGL only, see -@ref requires-gl. +By default the engine is built with everything except application libraries (see +below). Using `WITH_*` CMake parameters you can specify which parts will be built +and which not: -By default the engine is built with everything except -@ref Platform "application libraries". Using `WITH_*` CMake parameters you can -specify which parts will be built and which not: - - - `WITH_EVERYTHING` - Defaults to `ON`, builds everything except application - libraries. If set to `OFF`, only the main library is built and you can - select additional components with the following: - `WITH_DEBUGTOOLS` - DebugTools library. Enables also building of MeshTools, Physics, Primitives, SceneGraph and Shaders libraries. - - `WITH_MESHTOOLS` - MeshTools library. - - `WITH_PHYSICS` - Physics library. - - `WITH_PRIMITIVES` - Primitives library. - - `WITH_SCENEGRAPH` - SceneGraph library. - - `WITH_SHADERS` - Shaders library. - - `WITH_TEXT` - Text library. Enables also building of TextureTools. Requires - **FreeType** and possibly **HarfBuzz** library (see below). - - `WITH_TEXTURETOOLS` - TextureTools library. - - `WITH_MAGNUMINFO` - `magnum-info` executable, provides information about - Magnum engine and OpenGL capabilities. + - `WITH_MESHTOOLS` - MeshTools library. Enabled automatically if `WITH_DEBUGTOOLS` + is enabled. + - `WITH_PHYSICS` - Physics library. Enables also building of SceneGraph + library. Enabled automatically if `WITH_DEBUGTOOLS` is enabled. + - `WITH_PRIMITIVES` - Primitives library. Enabled automatically if `WITH_DEBUGTOOLS` + is enabled. + - `WITH_SCENEGRAPH` - SceneGraph library. Enabled automatically if `WITH_DEBUGTOOLS` + or `WITH_PHYSICS` is enabled. + - `WITH_SHADERS` - Shaders library. Enabled automatically if `WITH_DEBUGTOOLS` + is enabled. + - `WITH_TEXT` - Text library. Enables also building of TextureTools library. + Requires **FreeType** and possibly **HarfBuzz** library (see below). + - `WITH_TEXTURETOOLS` - TextureTools library. Enabled automatically if `WITH_TEXT` + is enabled. + - `WITH_MAGNUMINFO` - `magnum-info` executable, provides information about the + engine and OpenGL capabilities. Some dependencies are optional, although disabling them might reduce some functionality: @@ -117,18 +118,21 @@ functionality: - `USE_HARFBUZZ` - Defaults to `ON`, disabling it will result in worse text rendering (no kerning & ligatures) and possible issues with non-Latin text. -None of the application libraries is built by default, regardless to -`WITH_EVERYTHING` is enabled or not: - - - `WITH_XEGLAPPLICATION` - XEglApplication, available only if targeting - OpenGL ES (see above). Requires **X11** and **EGL** libraries. - - `WITH_GLXAPPLICATION` - GlxApplication. Requires **X11** and **GLX** - libraries. - - `WITH_WINDOWLESSGLXAPPLICATION` - Windowless GLX application. Requires - **X11** and **GLX** libraries. - - `WITH_GLUTAPPLICATION` - GlutApplication, available only if targeting - desktop OpenGL. Requires **GLUT** library. - - `WITH_SDL2APPLICATION` - Sdl2Application. Requires **SDL2** library. +None of the @ref Platform "application libraries" is built by default (and you +need at least one). Choose the one which suits your requirements and your +platform best: + + - `WITH_XEGLAPPLICATION` - @ref Platform::XEglApplication "XEglApplication", + available only if targeting OpenGL ES (see above). Requires **X11** and + **EGL** libraries. + - `WITH_GLXAPPLICATION` - @ref Platform::GlxApplication "GlxApplication". + Requires **X11** and **GLX** libraries. + - `WITH_WINDOWLESSGLXAPPLICATION` - @ref Platform::WindowlessGlxApplication "WindowlessGlxApplication". + Requires **X11** and **GLX** libraries. + - `WITH_GLUTAPPLICATION` - @ref Platform::GlutApplication "GlutApplication", + available only if targeting desktop OpenGL. Requires **GLUT** library. + - `WITH_SDL2APPLICATION` - @ref Platform::Sdl2Application "Sdl2Application". + Requires **SDL2** library. @subsection building-tests Building and running unit tests From 75d8fefdde65968685ee835f7e779757a8cdafd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Mar 2013 15:34:10 +0100 Subject: [PATCH 541/567] Math: ability to access also matrix row vectors. --- doc/matrix-vector.dox | 6 ++++++ src/Math/Matrix.h | 3 +++ src/Math/RectangularMatrix.h | 24 ++++++++++++++++++++++-- src/Math/Test/RectangularMatrixTest.cpp | 12 ++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index ea2421c60..82ab2d98b 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -129,6 +129,12 @@ Vector<3, Int> b; b[1] = 1; // second element @endcode +Row vectors can be accessed too, but only for reading, and the access is slower +due to the way the matrix is stored (see explanation below): +@code +Vector<2, Int> c = a.row(2); // third row +@endcode + Fixed-size vector subclasses have functions for accessing named components and subparts: @code diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index ae01c1c22..1fe7c40d0 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -199,6 +199,9 @@ template inline Corrade::Utility::Debug operator<<(Co } \ inline constexpr const VectorType operator[](std::size_t col) const { \ return VectorType(Matrix::operator[](col)); \ + } \ + inline VectorType row(std::size_t row) const { \ + return VectorType(Matrix::row(row)); \ } \ \ inline Type operator*(const Matrix& other) const { \ diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 5e867c9cb..fb869992d 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -154,7 +154,7 @@ template class RectangularMatrix { * Float a = m[2][1]; * @endcode * - * @see data() + * @see row(), data() */ inline Vector& operator[](std::size_t col) { return _data[col]; @@ -164,6 +164,22 @@ template class RectangularMatrix { return _data[col]; } + /** + * @brief %Matrix row + * + * Consider using transposed() when accessing rows frequently, as this + * is slower than accessing columns due to the way the matrix is stored. + * @see operator[]() + */ + inline Vector row(std::size_t row) const { + Vector out; + + for(std::size_t i = 0; i != cols; ++i) + out[i] = _data[i][row]; + + return out; + } + /** @brief Equality comparison */ inline bool operator==(const RectangularMatrix& other) const { for(std::size_t i = 0; i != cols; ++i) @@ -336,7 +352,11 @@ template class RectangularMatrix { return operator*(RectangularMatrix<1, rows, T>(other))[0]; } - /** @brief Transposed matrix */ + /** + * @brief Transposed matrix + * + * @see row() + */ RectangularMatrix transposed() const { RectangularMatrix out; diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 05af6ccc8..7c2c22289 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -40,7 +40,9 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester { void constructFromData(); void constructFromDiagonal(); void constructCopy(); + void data(); + void row(); void compare(); @@ -79,7 +81,9 @@ RectangularMatrixTest::RectangularMatrixTest() { &RectangularMatrixTest::constructFromData, &RectangularMatrixTest::constructFromDiagonal, &RectangularMatrixTest::constructCopy, + &RectangularMatrixTest::data, + &RectangularMatrixTest::row, &RectangularMatrixTest::compare, @@ -199,6 +203,14 @@ void RectangularMatrixTest::data() { CORRADE_COMPARE(d, 3.0f); } +void RectangularMatrixTest::row() { + const Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); + + CORRADE_COMPARE(a.row(1), Vector3(2.0f, 6.0f, 10.0f)); +} + void RectangularMatrixTest::compare() { Matrix2 a(Vector2(1.0f, -3.0f), Vector2(5.0f, -10.0f)); From 408f40a908b3b463d176759ab0db493798ed3444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 14 Mar 2013 16:12:11 +0100 Subject: [PATCH 542/567] Math: renamed MathTypeTraits to TypeTraits. As there is no Magnum::TypeTraits struct anymore, there is no need to have redundant name in it. Hopefully Doxygen will handle the difference between this and Corrade's TypeTraits.h properly. --- src/Color.h | 2 +- .../ForceRendererTransformation.h | 6 +-- src/Math/Algorithms/GaussJordan.h | 2 +- src/Math/Algorithms/Svd.h | 6 +-- src/Math/CMakeLists.txt | 2 +- src/Math/Complex.h | 8 ++-- src/Math/Constants.h | 2 +- src/Math/Dual.h | 6 +-- src/Math/Matrix3.h | 2 +- src/Math/Matrix4.h | 4 +- src/Math/Quaternion.h | 20 ++++----- src/Math/Test/CMakeLists.txt | 2 +- src/Math/Test/ComplexTest.cpp | 8 ++-- src/Math/Test/DualTest.cpp | 8 ++-- src/Math/Test/QuaternionTest.cpp | 8 ++-- src/Math/Test/RectangularMatrixTest.cpp | 4 +- ...hTypeTraitsTest.cpp => TypeTraitsTest.cpp} | 32 +++++++------- src/Math/Test/UnitTest.cpp | 4 +- src/Math/Test/VectorTest.cpp | 4 +- src/Math/{MathTypeTraits.h => TypeTraits.h} | 42 +++++++++---------- src/Math/Unit.h | 4 +- src/Math/Vector.h | 8 ++-- src/MeshTools/Clean.h | 4 +- 23 files changed, 94 insertions(+), 94 deletions(-) rename src/Math/Test/{MathTypeTraitsTest.cpp => TypeTraitsTest.cpp} (67%) rename src/Math/{MathTypeTraits.h => TypeTraits.h} (73%) diff --git a/src/Color.h b/src/Color.h index c3554e1ae..74b634d84 100644 --- a/src/Color.h +++ b/src/Color.h @@ -158,7 +158,7 @@ template class Color3: public Math::Vector3 { public: /** @brief Corresponding floating-point type for HSV computation */ - typedef typename Math::MathTypeTraits::FloatingPointType FloatingPointType; + typedef typename Math::TypeTraits::FloatingPointType FloatingPointType; /** * @brief Type for storing HSV values diff --git a/src/DebugTools/Implementation/ForceRendererTransformation.h b/src/DebugTools/Implementation/ForceRendererTransformation.h index 75c3896fc..067df4960 100644 --- a/src/DebugTools/Implementation/ForceRendererTransformation.h +++ b/src/DebugTools/Implementation/ForceRendererTransformation.h @@ -42,17 +42,17 @@ template<> inline Matrix4 forceRendererTransformation<3>(const Vector3& forcePos const Float forceLength = force.length(); /* Zero length, zero scaling */ - if(forceLength < Math::MathTypeTraits::epsilon()) + if(forceLength < Math::TypeTraits::epsilon()) return translation*Matrix4::scaling(Vector3(0.0f)); const Float dot = Vector3::dot(force/forceLength, Vector3::xAxis()); /* Force is parallel to X axis, just scaling */ - if(dot > 1.0f - Math::MathTypeTraits::epsilon()) + if(dot > 1.0f - Math::TypeTraits::epsilon()) return translation*Matrix4::scaling(Vector3(forceLength)); /* Force is antiparallel to X axis, scaling inverted on X */ - if(-dot > 1.0f - Math::MathTypeTraits::epsilon()) + if(-dot > 1.0f - Math::TypeTraits::epsilon()) return translation*Matrix4::scaling({-forceLength, forceLength, forceLength}); /* Normal of plane going through force vector and X axis vector */ diff --git a/src/Math/Algorithms/GaussJordan.h b/src/Math/Algorithms/GaussJordan.h index 1bdbef2b8..37bacfe51 100644 --- a/src/Math/Algorithms/GaussJordan.h +++ b/src/Math/Algorithms/GaussJordan.h @@ -64,7 +64,7 @@ template bool gaussJordanInPlaceTra std::swap(t[row], t[rowMax]); /* Singular */ - if(MathTypeTraits::equals(a[row][row], T(0))) + if(TypeTraits::equals(a[row][row], T(0))) return false; /* Eliminate column */ diff --git a/src/Math/Algorithms/Svd.h b/src/Math/Algorithms/Svd.h index fdf22703a..9c4200515 100644 --- a/src/Math/Algorithms/Svd.h +++ b/src/Math/Algorithms/Svd.h @@ -96,8 +96,8 @@ decomposition and least squares solutions"*. /* The matrix is passed by value because it is changed inside */ template std::tuple, Vector, Matrix> svd(RectangularMatrix m) { static_assert(rows >= cols, "Unsupported matrix aspect ratio"); - static_assert(T(1)+MathTypeTraits::epsilon() > T(1), "Epsilon too small"); - constexpr T tol = Implementation::smallestDelta()/MathTypeTraits::epsilon(); + static_assert(T(1)+TypeTraits::epsilon() > T(1), "Epsilon too small"); + constexpr T tol = Implementation::smallestDelta()/TypeTraits::epsilon(); static_assert(tol > T(0), "Tol too small"); constexpr std::size_t maxIterations = 50; @@ -212,7 +212,7 @@ template std::tuple::epsilon()*epsilonX; + const T epsilon = TypeTraits::epsilon()*epsilonX; for(std::size_t k2 = cols; k2 != 0; --k2) { const std::size_t k = k2 - 1; diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 5455c492a..9552fd85c 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -32,7 +32,7 @@ set(MagnumMath_HEADERS DualQuaternion.h Functions.h Math.h - MathTypeTraits.h + TypeTraits.h Matrix.h Matrix3.h Matrix4.h diff --git a/src/Math/Complex.h b/src/Math/Complex.h index cd3ed3cb5..7f7d741bb 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -69,7 +69,7 @@ template class Complex { * @see Quaternion::angle(), Vector::angle() */ inline static Rad angle(const Complex& normalizedA, const Complex& normalizedB) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Complex::angle(): complex numbers must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(std::acos(normalizedA._real*normalizedB._real + normalizedA._imaginary*normalizedB._imaginary)); } @@ -117,8 +117,8 @@ template class Complex { /** @brief Equality comparison */ inline bool operator==(const Complex& other) const { - return MathTypeTraits::equals(_real, other._real) && - MathTypeTraits::equals(_imaginary, other._imaginary); + return TypeTraits::equals(_real, other._real) && + TypeTraits::equals(_imaginary, other._imaginary); } /** @brief Non-equality comparison */ @@ -345,7 +345,7 @@ template class Complex { * @see inverted() */ inline Complex invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Complex::invertedNormalized(): complex number must be normalized", Complex(std::numeric_limits::quiet_NaN(), {})); return conjugated(); diff --git a/src/Math/Constants.h b/src/Math/Constants.h index 358a246da..9f7402da6 100644 --- a/src/Math/Constants.h +++ b/src/Math/Constants.h @@ -40,7 +40,7 @@ namespace Magnum { namespace Math { template struct Constants { Constants() = delete; - /* See MathTypeTraits for answer why these are functions and not constants. */ + /* See TypeTraits for answer why these are functions and not constants. */ #ifdef DOXYGEN_GENERATING_OUTPUT /** * @brief Pi diff --git a/src/Math/Dual.h b/src/Math/Dual.h index 4f6135f30..630a6f736 100644 --- a/src/Math/Dual.h +++ b/src/Math/Dual.h @@ -31,7 +31,7 @@ #include #include -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" namespace Magnum { namespace Math { @@ -63,8 +63,8 @@ template class Dual { /** @brief Equality comparison */ inline bool operator==(const Dual& other) const { - return MathTypeTraits::equals(_real, other._real) && - MathTypeTraits::equals(_dual, other._dual); + return TypeTraits::equals(_real, other._real) && + TypeTraits::equals(_dual, other._dual); } /** @brief Non-equality comparison */ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index b8b6c1913..c680c53f7 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -96,7 +96,7 @@ template class Matrix3: public Matrix<3, T> { * @see Matrix4::reflection() */ static Matrix3 reflection(const Vector2& normal) { - CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normal.dot(), T(1)), "Math::Matrix3::reflection(): normal must be normalized", {}); return from(Matrix<2, T>() - T(2)*normal*RectangularMatrix<1, 2, T>(normal).transposed(), {}); } diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 13a96d7bb..3676f5ecc 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -91,7 +91,7 @@ template class Matrix4: public Matrix<4, T> { * Vector3::zAxis() */ static Matrix4 rotation(Rad angle, const Vector3& normalizedAxis) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedAxis.dot(), T(1)), "Math::Matrix4::rotation(): axis must be normalized", {}); T sine = std::sin(T(angle)); @@ -184,7 +184,7 @@ template class Matrix4: public Matrix<4, T> { * @see Matrix3::reflection() */ static Matrix4 reflection(const Vector3& normal) { - CORRADE_ASSERT(MathTypeTraits::equals(normal.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normal.dot(), T(1)), "Math::Matrix4::reflection(): normal must be normalized", {}); return from(Matrix<3, T>() - T(2)*normal*RectangularMatrix<1, 3, T>(normal).transposed(), {}); } diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index e57bc0023..5103de897 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -32,7 +32,7 @@ #include #include -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" #include "Math/Matrix.h" #include "Math/Vector3.h" @@ -71,7 +71,7 @@ template class Quaternion { * @see Complex::angle(), Vector::angle() */ inline static Rad angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::angle(): quaternions must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(angleInternal(normalizedA, normalizedB)); } @@ -88,7 +88,7 @@ template class Quaternion { * @see slerp(), Math::lerp() */ inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::lerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); @@ -108,7 +108,7 @@ template class Quaternion { * @see lerp() */ inline static Quaternion slerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Quaternion::slerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); T a = angleInternal(normalizedA, normalizedB); @@ -128,7 +128,7 @@ template class Quaternion { * Vector3::yAxis(), Vector3::zAxis() */ inline static Quaternion rotation(Rad angle, const Vector3& normalizedAxis) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedAxis.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedAxis.dot(), T(1)), "Math::Quaternion::rotation(): axis must be normalized", {}); return {normalizedAxis*std::sin(T(angle)/2), std::cos(T(angle)/2)}; @@ -164,7 +164,7 @@ template class Quaternion { /** @brief Equality comparison */ inline bool operator==(const Quaternion& other) const { - return _vector == other._vector && MathTypeTraits::equals(_scalar, other._scalar); + return _vector == other._vector && TypeTraits::equals(_scalar, other._scalar); } /** @brief Non-equality comparison */ @@ -187,7 +187,7 @@ template class Quaternion { * @see rotationAxis(), rotation(), DualQuaternion::rotationAngle() */ inline Rad rotationAngle() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAngle(): quaternion must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(T(2)*std::acos(_scalar)); @@ -204,7 +204,7 @@ template class Quaternion { * @see rotationAngle(), rotation() */ inline Vector3 rotationAxis() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::rotationAxis(): quaternion must be normalized", {}); return _vector/std::sqrt(1-pow2(_scalar)); @@ -404,7 +404,7 @@ template class Quaternion { * @see inverted() */ inline Quaternion invertedNormalized() const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::invertedNormalized(): quaternion must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return conjugated(); @@ -435,7 +435,7 @@ template class Quaternion { * DualQuaternion::transformPointNormalized(), Complex::transformVector() */ inline Vector3 transformVectorNormalized(const Vector3& vector) const { - CORRADE_ASSERT(MathTypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), "Math::Quaternion::transformVectorNormalized(): quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*Quaternion(vector)*conjugated()).vector(); diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 4e2a1a990..e071c9da9 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -25,7 +25,7 @@ corrade_add_test(MathBoolVectorTest BoolVectorTest.cpp) corrade_add_test(MathConstantsTest ConstantsTest.cpp) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) +corrade_add_test(MathTypeTraitsTest TypeTraitsTest.cpp) corrade_add_test(MathVectorTest VectorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index d35efe979..1cbc1d8af 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -120,10 +120,10 @@ void ComplexTest::constructFromVector() { } void ComplexTest::compare() { - CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); - CORRADE_VERIFY(Complex(3.7f, -1.0f+MathTypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); - CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); - CORRADE_VERIFY(Complex(1.0f+MathTypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+TypeTraits::epsilon()/2) == Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(3.7f, -1.0f+TypeTraits::epsilon()*2) != Complex(3.7f, -1.0f)); + CORRADE_VERIFY(Complex(1.0f+TypeTraits::epsilon()/2, 3.7f) == Complex(1.0f, 3.7f)); + CORRADE_VERIFY(Complex(1.0f+TypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); } void ComplexTest::constExpressions() { diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index 3bc8057d1..dd6338f0c 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -83,10 +83,10 @@ void DualTest::constructDefault() { } void DualTest::compare() { - CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f, 1.0f+MathTypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); - CORRADE_VERIFY(Dual(1.0f+MathTypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+TypeTraits::epsilon()/2) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f, 1.0f+TypeTraits::epsilon()*2) != Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+TypeTraits::epsilon()/2, 1.0f) == Dual(1.0f, 1.0f)); + CORRADE_VERIFY(Dual(1.0f+TypeTraits::epsilon()*2, 1.0f) != Dual(1.0f, 1.0f)); /* Compare to real part only */ CORRADE_VERIFY(Dual(1.0f, 0.0f) == 1.0f); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 75d4ddf46..6577ea5ab 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -123,10 +123,10 @@ void QuaternionTest::constructFromVector() { } void QuaternionTest::compare() { - CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_VERIFY(Quaternion({1.0f+MathTypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); - CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+MathTypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({1.0f+TypeTraits::epsilon()/2, 2.0f, 3.0f}, -4.0f) == Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({1.0f+TypeTraits::epsilon()*2, 2.0f, 3.0f}, -4.0f) != Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+TypeTraits::epsilon()/2) == Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); + CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+TypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); } void QuaternionTest::constExpressions() { diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index 7c2c22289..d311231c3 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -214,9 +214,9 @@ void RectangularMatrixTest::row() { void RectangularMatrixTest::compare() { Matrix2 a(Vector2(1.0f, -3.0f), Vector2(5.0f, -10.0f)); - Matrix2 b(Vector2(1.0f + MathTypeTraits::epsilon()/2, -3.0f), + Matrix2 b(Vector2(1.0f + TypeTraits::epsilon()/2, -3.0f), Vector2(5.0f, -10.0f)); - Matrix2 c(Vector2(1.0f, -1.0f + MathTypeTraits::epsilon()*2), + Matrix2 c(Vector2(1.0f, -1.0f + TypeTraits::epsilon()*2), Vector2(5.0f, -10.0f)); CORRADE_VERIFY(a == b); CORRADE_VERIFY(a != c); diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/TypeTraitsTest.cpp similarity index 67% rename from src/Math/Test/MathTypeTraitsTest.cpp rename to src/Math/Test/TypeTraitsTest.cpp index f1239ce50..63a6fbace 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/TypeTraitsTest.cpp @@ -25,13 +25,13 @@ #include #include -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" namespace Magnum { namespace Math { namespace Test { -class MathTypeTraitsTest: public Corrade::TestSuite::Tester { +class TypeTraitsTest: public Corrade::TestSuite::Tester { public: - MathTypeTraitsTest(); + TypeTraitsTest(); void equalsFloatingPoint(); void equalsIntegral(); @@ -41,12 +41,12 @@ class MathTypeTraitsTest: public Corrade::TestSuite::Tester { template void _equalsIntegral(); }; -MathTypeTraitsTest::MathTypeTraitsTest() { - addTests({&MathTypeTraitsTest::equalsIntegral, - &MathTypeTraitsTest::equalsFloatingPoint}); +TypeTraitsTest::TypeTraitsTest() { + addTests({&TypeTraitsTest::equalsIntegral, + &TypeTraitsTest::equalsFloatingPoint}); } -void MathTypeTraitsTest::equalsIntegral() { +void TypeTraitsTest::equalsIntegral() { _equalsIntegral(); _equalsIntegral(); _equalsIntegral(); @@ -57,29 +57,29 @@ void MathTypeTraitsTest::equalsIntegral() { _equalsIntegral(); } -void MathTypeTraitsTest::equalsFloatingPoint() { +void TypeTraitsTest::equalsFloatingPoint() { _equalsFloatingPoint(); _equalsFloatingPoint(); } -template void MathTypeTraitsTest::_equalsIntegral() { - CORRADE_VERIFY(!MathTypeTraits::equals(1, 1+MathTypeTraits::epsilon())); +template void TypeTraitsTest::_equalsIntegral() { + CORRADE_VERIFY(!TypeTraits::equals(1, 1+TypeTraits::epsilon())); } -template void MathTypeTraitsTest::_equalsFloatingPoint() { - CORRADE_VERIFY(MathTypeTraits::equals(T(1)+MathTypeTraits::epsilon()/T(2), T(1))); - CORRADE_VERIFY(!MathTypeTraits::equals(T(1)+MathTypeTraits::epsilon()*T(2), T(1))); +template void TypeTraitsTest::_equalsFloatingPoint() { + CORRADE_VERIFY(TypeTraits::equals(T(1)+TypeTraits::epsilon()/T(2), T(1))); + CORRADE_VERIFY(!TypeTraits::equals(T(1)+TypeTraits::epsilon()*T(2), T(1))); { CORRADE_EXPECT_FAIL("Comparing to infinity is broken"); - CORRADE_VERIFY(MathTypeTraits::equals(std::numeric_limits::infinity(), + CORRADE_VERIFY(TypeTraits::equals(std::numeric_limits::infinity(), std::numeric_limits::infinity())); } - CORRADE_VERIFY(!MathTypeTraits::equals(std::numeric_limits::quiet_NaN(), + CORRADE_VERIFY(!TypeTraits::equals(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); } }}} -CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) +CORRADE_TEST_MAIN(Magnum::Math::Test::TypeTraitsTest) diff --git a/src/Math/Test/UnitTest.cpp b/src/Math/Test/UnitTest.cpp index 18dc1179d..d1d687a9a 100644 --- a/src/Math/Test/UnitTest.cpp +++ b/src/Math/Test/UnitTest.cpp @@ -78,8 +78,8 @@ void UnitTest::constructConversion() { } void UnitTest::compare() { - CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()/2) == Sec(25.0f)); - CORRADE_VERIFY(Sec(25.0f + MathTypeTraits::epsilon()*2) != Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()/2) == Sec(25.0f)); + CORRADE_VERIFY(Sec(25.0f + TypeTraits::epsilon()*2) != Sec(25.0f)); constexpr bool c = Sec(3.0f) < Sec(3.0f); constexpr bool d = Sec(3.0f) <= Sec(3.0f); diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 8cc307a5b..7c301cd7e 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -215,8 +215,8 @@ void VectorTest::data() { } void VectorTest::compare() { - CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + MathTypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); - CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + MathTypeTraits::epsilon()*2, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -3.5f, 5.0f, -10.0f) == Vector4(1.0f + TypeTraits::epsilon()/2, -3.5f, 5.0f, -10.0f)); + CORRADE_VERIFY(Vector4(1.0f, -1.0f, 5.0f, -10.0f) != Vector4(1.0f, -1.0f + TypeTraits::epsilon()*2, 5.0f, -10.0f)); CORRADE_VERIFY(Vector4i(1, -3, 5, -10) == Vector4i(1, -3, 5, -10)); CORRADE_VERIFY(Vector4i(1, -3, 5, -10) != Vector4i(1, -2, 5, -10)); diff --git a/src/Math/MathTypeTraits.h b/src/Math/TypeTraits.h similarity index 73% rename from src/Math/MathTypeTraits.h rename to src/Math/TypeTraits.h index 7a8dbe0e8..8897f33c3 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/TypeTraits.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Math_MathTypeTraits_h -#define Magnum_Math_MathTypeTraits_h +#ifndef Magnum_Math_TypeTraits_h +#define Magnum_Math_TypeTraits_h /* This file is part of Magnum. @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::Math::MathTypeTraits + * @brief Class Magnum::Math::TypeTraits */ #include @@ -54,8 +54,8 @@ namespace Magnum { namespace Math { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct MathTypeTraitsDefault { - MathTypeTraitsDefault() = delete; + template struct TypeTraitsDefault { + TypeTraitsDefault() = delete; inline constexpr static bool equals(T a, T b) { return a == b; @@ -71,7 +71,7 @@ Traits classes are usable for detecting type features at compile time without the need for repeated code such as method overloading or template specialization for given types. */ -template struct MathTypeTraits: Implementation::MathTypeTraitsDefault { +template struct TypeTraits: Implementation::TypeTraitsDefault { /* * The following values are implemented as inline functions, not as * static const variables, because the compiler will inline the return @@ -118,58 +118,58 @@ template struct MathTypeTraits: Implementation::MathTypeTraitsDefault struct MathTypeTraitsIntegral: MathTypeTraitsDefault { + template struct TypeTraitsIntegral: TypeTraitsDefault { inline constexpr static T epsilon() { return T(1); } }; } -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Float FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsIntegral { +template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef long double FloatingPointType; }; /* Floating-point scalar types */ namespace Implementation { - template struct MathTypeTraitsFloatingPoint { - MathTypeTraitsFloatingPoint() = delete; + template struct TypeTraitsFloatingPoint { + TypeTraitsFloatingPoint() = delete; inline static bool equals(T a, T b) { - return std::abs(a - b) < MathTypeTraits::epsilon(); + return std::abs(a - b) < TypeTraits::epsilon(); } }; } -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { +template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef Float FloatingPointType; inline constexpr static Float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { +template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef Double FloatingPointType; inline constexpr static Double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; -template<> struct MathTypeTraits: Implementation::MathTypeTraitsFloatingPoint { +template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoint { typedef long double FloatingPointType; inline constexpr static long double epsilon() { return LONG_DOUBLE_EQUALITY_PRECISION; } diff --git a/src/Math/Unit.h b/src/Math/Unit.h index 4b9c5aad3..7a586ec6e 100644 --- a/src/Math/Unit.h +++ b/src/Math/Unit.h @@ -28,7 +28,7 @@ * @brief Class Magnum::Math::Unit */ -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" namespace Magnum { namespace Math { @@ -58,7 +58,7 @@ template class Derived, class T> class Unit { /** @brief Equality comparison */ inline constexpr bool operator==(Unit other) const { - return MathTypeTraits::equals(value, other.value); + return TypeTraits::equals(value, other.value); } /** @brief Non-equality comparison */ diff --git a/src/Math/Vector.h b/src/Math/Vector.h index df51b6a7f..767c79ce0 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -36,7 +36,7 @@ #include "Math/Angle.h" #include "Math/BoolVector.h" -#include "Math/MathTypeTraits.h" +#include "Math/TypeTraits.h" #include "magnumVisibility.h" @@ -102,7 +102,7 @@ template class Vector { * @see Quaternion::angle(), Complex::angle() */ inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { - CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), "Math::Vector::angle(): vectors must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(std::acos(dot(normalizedA, normalizedB))); } @@ -195,7 +195,7 @@ template class Vector { /** @brief Equality comparison */ inline bool operator==(const Vector& other) const { for(std::size_t i = 0; i != size; ++i) - if(!MathTypeTraits::equals(_data[i], other._data[i])) return false; + if(!TypeTraits::equals(_data[i], other._data[i])) return false; return true; } @@ -468,7 +468,7 @@ template class Vector { * @f] */ inline Vector projectedOntoNormalized(const Vector& line) const { - CORRADE_ASSERT(MathTypeTraits::equals(line.dot(), T(1)), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); + CORRADE_ASSERT(TypeTraits::equals(line.dot(), T(1)), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); return line*dot(*this, line); } diff --git a/src/MeshTools/Clean.h b/src/MeshTools/Clean.h index 288fc5992..369fbc680 100644 --- a/src/MeshTools/Clean.h +++ b/src/MeshTools/Clean.h @@ -43,7 +43,7 @@ template class Clean { public: inline Clean(std::vector& indices, std::vector& vertices): indices(indices), vertices(vertices) {} - void operator()(typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { + void operator()(typename Vertex::Type epsilon = Math::TypeTraits::epsilon()) { if(indices.empty()) return; /* Get mesh bounds */ @@ -145,7 +145,7 @@ Removes duplicate vertices from the mesh. @todo Interpolate vertices, not collapse them to first in the cell @todo Ability to specify other attributes for interpolation */ -template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::MathTypeTraits::epsilon()) { +template inline void clean(std::vector& indices, std::vector& vertices, typename Vertex::Type epsilon = Math::TypeTraits::epsilon()) { Implementation::Clean(indices, vertices)(epsilon); } From 4714cafedc6a9aeeec46900b8aab70d78f81b5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 14 Mar 2013 20:18:54 +0100 Subject: [PATCH 543/567] Math: added Matrix::isOrthogonal(). --- src/Math/Matrix.h | 23 +++++++++++++++++++++++ src/Math/Test/MatrixTest.cpp | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 1fe7c40d0..f639cd96a 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -102,6 +102,29 @@ template class Matrix: public RectangularMatrix& other): RectangularMatrix(other) {} + /** + * @brief Whether the matrix is orthogonal + * + * The matrix is orthogonal if its transpose is equal to its inverse: @f[ + * Q^T = Q^{-1} + * @f] + * @see transposed(), inverted() + */ + bool isOrthogonal() const { + /* Normality */ + for(std::size_t i = 0; i != size; ++i) + if(!TypeTraits::equals((*this)[i].dot(), T(1))) + return false; + + /* Orthogonality */ + for(std::size_t i = 0; i != size-1; ++i) + for(std::size_t j = i+1; j != size; ++j) + if(!TypeTraits::equals(Vector::dot((*this)[i], (*this)[j]), T(0))) + return false; + + return true; + } + /** * @brief Trace of the matrix * diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 207580b65..bd7dca4c3 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -40,6 +40,8 @@ class MatrixTest: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void isOrthogonal(); + void trace(); void ij(); void determinant(); @@ -63,6 +65,8 @@ MatrixTest::MatrixTest() { &MatrixTest::constructConversion, &MatrixTest::constructCopy, + &MatrixTest::isOrthogonal, + &MatrixTest::trace, &MatrixTest::ij, &MatrixTest::determinant, @@ -139,6 +143,18 @@ void MatrixTest::constructCopy() { Vector4(7.9f, -1.0f, 8.0f, -1.5f))); } +void MatrixTest::isOrthogonal() { + CORRADE_VERIFY(!Matrix3(Vector3(1.0f, 0.0f, 0.0f), + Vector3(0.0f, 1.0f, 0.0f), + Vector3(0.0f, 0.1f, 1.0f)).isOrthogonal()); + CORRADE_VERIFY(!Matrix3(Vector3(1.0f, 0.0f, 0.0f), + Vector3(0.0f, 1.0f, 0.0f), + Vector3(0.0f, 1.0f, 0.0f)).isOrthogonal()); + CORRADE_VERIFY(Matrix3(Vector3(1.0f, 0.0f, 0.0f), + Vector3(0.0f, 1.0f, 0.0f), + Vector3(0.0f, 0.0f, 1.0f)).isOrthogonal()); +} + void MatrixTest::trace() { Matrix<5, Int> m( Vector<5, Int>(1, 2, 3, 0, 0), From dfe25710478a4d263fff45fb8b66bc4534c3e294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 14 Mar 2013 21:14:16 +0100 Subject: [PATCH 544/567] Math: added Matrix{3,4}::isRigidTransformation(). --- src/Math/Matrix.h | 3 ++- src/Math/Matrix3.h | 11 +++++++++++ src/Math/Matrix4.h | 11 +++++++++++ src/Math/Test/Matrix3Test.cpp | 16 ++++++++++++++++ src/Math/Test/Matrix4Test.cpp | 19 +++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index f639cd96a..11f1c739e 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -108,7 +108,8 @@ template class Matrix: public RectangularMatrix class Matrix3: public Matrix<3, T> { /** @brief Copy constructor */ inline constexpr Matrix3(const RectangularMatrix<3, 3, T>& other): Matrix<3, T>(other) {} + /** + * @brief Check whether the matrix represents rigid transformation + * + * Rigid transformation consists only of rotation and translation (i.e. + * no scaling or projection). + * @see isOrthogonal() + */ + inline bool isRigidTransformation() const { + return rotationScaling().isOrthogonal() && row(2) == Vector3(T(0), T(0), T(1)); + } + /** * @brief 2D rotation and scaling part of the matrix * diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 3676f5ecc..fdefc41b1 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -283,6 +283,17 @@ template class Matrix4: public Matrix<4, T> { /** @brief Copy constructor */ inline constexpr Matrix4(const RectangularMatrix<4, 4, T>& other): Matrix<4, T>(other) {} + /** + * @brief Check whether the matrix represents rigid transformation + * + * Rigid transformation consists only of rotation and translation (i.e. + * no scaling or projection). + * @see isOrthogonal() + */ + inline bool isRigidTransformation() const { + return rotationScaling().isOrthogonal() && row(3) == Vector4(T(0), T(0), T(0), T(1)); + } + /** * @brief 3D rotation and scaling part of the matrix * diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index ce0423c6e..71a14458e 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -40,6 +40,8 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void isRigidTransformation(); + void translation(); void scaling(); void rotation(); @@ -69,6 +71,8 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::constructConversion, &Matrix3Test::constructCopy, + &Matrix3Test::isRigidTransformation, + &Matrix3Test::translation, &Matrix3Test::scaling, &Matrix3Test::rotation, @@ -143,6 +147,18 @@ void Matrix3Test::constructCopy() { {7.9f, -1.0f, 8.0f})); } +void Matrix3Test::isRigidTransformation() { + CORRADE_VERIFY(!Matrix3({1.0f, 0.0f, 0.0f}, + {0.1f, 1.0f, 0.0f}, + {5.0f, 4.0f, 1.0f}).isRigidTransformation()); + CORRADE_VERIFY(!Matrix3({1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 1.0f}, + {5.0f, 4.0f, 0.0f}).isRigidTransformation()); + CORRADE_VERIFY(Matrix3({1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {5.0f, 4.0f, 1.0f}).isRigidTransformation()); +} + void Matrix3Test::translation() { constexpr Matrix3 a = Matrix3::translation({3.0f, 1.0f}); CORRADE_COMPARE(a, Matrix3({1.0f, 0.0f, 0.0f}, diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index c201a5688..c7e2826c9 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -40,6 +40,8 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void isRigidTransformation(); + void translation(); void scaling(); void rotation(); @@ -75,6 +77,8 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::constructConversion, &Matrix4Test::constructCopy, + &Matrix4Test::isRigidTransformation, + &Matrix4Test::translation, &Matrix4Test::scaling, &Matrix4Test::rotation, @@ -164,6 +168,21 @@ void Matrix4Test::constructCopy() { {7.9f, -1.0f, 8.0f, -1.5f})); } +void Matrix4Test::isRigidTransformation() { + CORRADE_VERIFY(!Matrix4({1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.1f, 1.0f, 0.0f}, + {5.0f, 4.0f, 0.5f, 1.0f}).isRigidTransformation()); + CORRADE_VERIFY(!Matrix4({1.0f, 0.0f, 0.0f, 0.0f}, + {0.1f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 1.0f}, + {5.0f, 4.0f, 0.5f, 0.0f}).isRigidTransformation()); + CORRADE_VERIFY(Matrix4({1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {5.0f, 4.0f, 0.5f, 1.0f}).isRigidTransformation()); +} + void Matrix4Test::translation() { constexpr Matrix4 a = Matrix4::translation({3.0f, 1.0f, 2.0f}); CORRADE_COMPARE(a, Matrix4({1.0f, 0.0f, 0.0f, 0.0f}, From 33058aa5b06b029db15e73a732387ffde61f0282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 14 Mar 2013 16:02:41 +0100 Subject: [PATCH 545/567] Math: Matrix::invertedOrthogonal(), Matrix{3,4}::invertedRigid(). Renamed original invertedEuclidean() functions to invertedRigid() and simplified them using isRigidTransformation(). --- doc/transformations.dox | 6 ++-- src/Math/Matrix.h | 23 +++++++++++++-- src/Math/Matrix3.h | 18 +++++------- src/Math/Matrix4.h | 18 +++++------- src/Math/Test/CMakeLists.txt | 1 + src/Math/Test/Matrix3Test.cpp | 28 +++++++----------- src/Math/Test/Matrix4Test.cpp | 29 +++++++------------ src/Math/Test/MatrixTest.cpp | 17 +++++++++++ .../EuclideanMatrixTransformation2D.h | 2 +- .../EuclideanMatrixTransformation3D.h | 2 +- 10 files changed, 79 insertions(+), 65 deletions(-) diff --git a/doc/transformations.dox b/doc/transformations.dox index 4ead3685b..a069e2fe8 100644 --- a/doc/transformations.dox +++ b/doc/transformations.dox @@ -188,9 +188,9 @@ Inverse transformation can be computed using Matrix3::inverted(), Matrix4::inver Complex::inverted(), Quaternion::inverted(), DualComplex::inverted() or DualQuaternion::inverted(). %Matrix inversion is quite costly, so if your transformation involves only translation and rotation, you can use faster -alternatives Matrix3::invertedEuclidean() and Matrix4::invertedEuclidean(). If -you are sure that the (dual) complex number or (dual) quaternion is of unit -length, you can use Complex::invertedNormalized(), Quaternion::invertedNormalized(), +alternatives Matrix3::invertedRigid() and Matrix4::invertedRigid(). If you are +sure that the (dual) complex number or (dual) quaternion is of unit length, you +can use Complex::invertedNormalized(), Quaternion::invertedNormalized(), DualComplex::invertedNormalized() or DualQuaternion::invertedNormalized() which is a little bit faster, because it doesn't need to renormalize the result. diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 11f1c739e..432ded0d8 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -168,8 +168,7 @@ template class Matrix: public RectangularMatrix inverted() const { @@ -184,6 +183,21 @@ template class Matrix: public RectangularMatrix invertedOrthogonal() const { + CORRADE_ASSERT(isOrthogonal(), + "Math::Matrix::invertedOrthogonal(): the matrix is not orthogonal", {}); + return this->transposed(); + } + #ifndef DOXYGEN_GENERATING_OUTPUT /* Reimplementation of functions to return correct type */ inline Matrix operator*(const Matrix& other) const { @@ -239,7 +253,10 @@ template inline Corrade::Utility::Debug operator<<(Co } \ \ inline Type transposed() const { return Matrix::transposed(); } \ - inline Type inverted() const { return Matrix::inverted(); } + inline Type inverted() const { return Matrix::inverted(); } \ + inline Type invertedOrthogonal() const { \ + return Matrix::invertedOrthogonal(); \ + } #define MAGNUM_MATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \ template inline typename std::enable_if::value, Type>::type operator*(U number, const Type& matrix) { \ diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index 6e678eefc..a60e0133e 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -218,20 +218,18 @@ template class Matrix3: public Matrix<3, T> { inline constexpr Vector2 translation() const { return (*this)[2].xy(); } /**< @overload */ /** - * @brief Inverted Euclidean transformation matrix + * @brief Inverted rigid transformation matrix * - * Assumes that the matrix represents Euclidean transformation (i.e. - * only rotation and translation, no scaling) and creates inverted - * matrix from transposed rotation part and negated translation part. + * Expects that the matrix represents rigid transformation. * Significantly faster than the general algorithm in inverted(). - * @see rotationScaling() const, translation() const + * @see isRigidTransformation(), invertedOrthogonal(), + * rotationScaling() const, translation() const */ - inline Matrix3 invertedEuclidean() const { - CORRADE_ASSERT((*this)[0][2] == T(0) && (*this)[1][2] == T(0) && (*this)[2][2] == T(1), - "Math::Matrix3::invertedEuclidean(): unexpected values on last row", {}); + inline Matrix3 invertedRigid() const { + CORRADE_ASSERT(isRigidTransformation(), + "Math::Matrix3::invertedRigid(): the matrix doesn't represent rigid transformation", {}); + Matrix<2, T> inverseRotation = rotationScaling().transposed(); - CORRADE_ASSERT((inverseRotation*rotationScaling() == Matrix<2, T>()), - "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation", {}); return from(inverseRotation, inverseRotation*-translation()); } diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index fdefc41b1..9837bdae7 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -363,20 +363,18 @@ template class Matrix4: public Matrix<4, T> { inline constexpr Vector3 translation() const { return (*this)[3].xyz(); } /**< @overload */ /** - * @brief Inverted Euclidean transformation matrix + * @brief Inverted rigid transformation matrix * - * Expects that the matrix represents Euclidean transformation (i.e. - * only rotation and translation, no scaling) and creates inverted - * matrix from transposed rotation part and negated translation part. + * Expects that the matrix represents rigid transformation. * Significantly faster than the general algorithm in inverted(). - * @see rotationScaling() const, translation() const + * @see isRigidTransformation(), invertedOrthogonal(), + * rotationScaling() const, translation() const */ - inline Matrix4 invertedEuclidean() const { - CORRADE_ASSERT((*this)[0][3] == T(0) && (*this)[1][3] == T(0) && (*this)[2][3] == T(0) && (*this)[3][3] == T(1), - "Math::Matrix4::invertedEuclidean(): unexpected values on last row", {}); + inline Matrix4 invertedRigid() const { + CORRADE_ASSERT(isRigidTransformation(), + "Math::Matrix4::invertedRigid(): the matrix doesn't represent rigid transformation", {}); + Matrix<3, T> inverseRotation = rotationScaling().transposed(); - CORRADE_ASSERT((inverseRotation*rotationScaling() == Matrix<3, T>()), - "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation", {}); return from(inverseRotation, inverseRotation*-translation()); } diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index e071c9da9..65fe5141c 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -49,6 +49,7 @@ corrade_add_test(MathDualQuaternionTest DualQuaternionTest.cpp LIBRARIES MagnumM set_target_properties( MathVectorTest + MathMatrixTest MathMatrix3Test MathMatrix4Test MathComplexTest diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 71a14458e..eeaa8dd8b 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -51,7 +51,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester { void rotationScalingPart(); void rotationPart(); void vectorParts(); - void invertedEuclidean(); + void invertedRigid(); void transform(); void debug(); @@ -82,7 +82,7 @@ Matrix3Test::Matrix3Test() { &Matrix3Test::rotationScalingPart, &Matrix3Test::rotationPart, &Matrix3Test::vectorParts, - &Matrix3Test::invertedEuclidean, + &Matrix3Test::invertedRigid, &Matrix3Test::transform, &Matrix3Test::debug, @@ -271,20 +271,7 @@ void Matrix3Test::vectorParts() { CORRADE_COMPARE(translation, Vector2(-5.0f, 12.0f)); } -void Matrix3Test::invertedEuclidean() { - std::ostringstream o; - Error::setOutput(&o); - - Matrix3 m({3.0f, 5.0f, 8.0f}, - {4.0f, 4.0f, 7.0f}, - {7.0f, -1.0f, 8.0f}); - CORRADE_COMPARE(m.invertedEuclidean(), Matrix3()); - CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): unexpected values on last row\n"); - - o.str({}); - CORRADE_COMPARE(Matrix3::scaling(Vector2(2.0f)).invertedEuclidean(), Matrix3()); - CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); - +void Matrix3Test::invertedRigid() { Matrix3 actual = Matrix3::rotation(Deg(-74.0f))* Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* Matrix3::translation({2.0f, -3.0f}); @@ -292,8 +279,13 @@ void Matrix3Test::invertedEuclidean() { Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* Matrix3::rotation(Deg(74.0f)); - CORRADE_COMPARE(actual.invertedEuclidean(), expected); - CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); + std::ostringstream o; + Error::setOutput(&o); + (2*actual).invertedRigid(); + CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedRigid(): the matrix doesn't represent rigid transformation\n"); + + CORRADE_COMPARE(actual.invertedRigid(), expected); + CORRADE_COMPARE(actual.invertedRigid(), actual.inverted()); } void Matrix3Test::transform() { diff --git a/src/Math/Test/Matrix4Test.cpp b/src/Math/Test/Matrix4Test.cpp index c7e2826c9..771b5dba7 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -56,7 +56,7 @@ class Matrix4Test: public Corrade::TestSuite::Tester { void rotationScalingPart(); void rotationPart(); void vectorParts(); - void invertedEuclidean(); + void invertedRigid(); void transform(); void debug(); @@ -93,7 +93,7 @@ Matrix4Test::Matrix4Test() { &Matrix4Test::rotationScalingPart, &Matrix4Test::rotationPart, &Matrix4Test::vectorParts, - &Matrix4Test::invertedEuclidean, + &Matrix4Test::invertedRigid, &Matrix4Test::transform, &Matrix4Test::debug, @@ -355,21 +355,7 @@ void Matrix4Test::vectorParts() { CORRADE_COMPARE(translation, Vector3(-5.0f, 12.0f, 0.5f)); } -void Matrix4Test::invertedEuclidean() { - std::ostringstream o; - Error::setOutput(&o); - - Matrix4 m({3.0f, 5.0f, 8.0f, 4.0f}, - {4.0f, 4.0f, 7.0f, 3.0f}, - {7.0f, -1.0f, 8.0f, 0.0f}, - {9.0f, 4.0f, 5.0f, 9.0f}); - CORRADE_COMPARE(m.invertedEuclidean(), Matrix4()); - CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): unexpected values on last row\n"); - - o.str({}); - CORRADE_COMPARE(Matrix4::scaling(Vector3(2.0f)).invertedEuclidean(), Matrix4()); - CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); - +void Matrix4Test::invertedRigid() { Matrix4 actual = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized())* Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* Matrix4::translation({1.0f, 2.0f, -3.0f}); @@ -377,8 +363,13 @@ void Matrix4Test::invertedEuclidean() { Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* Matrix4::rotation(Deg(74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized()); - CORRADE_COMPARE(actual.invertedEuclidean(), expected); - CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); + std::ostringstream o; + Error::setOutput(&o); + (2*actual).invertedRigid(); + CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedRigid(): the matrix doesn't represent rigid transformation\n"); + + CORRADE_COMPARE(actual.invertedRigid(), expected); + CORRADE_COMPARE(actual.invertedRigid(), actual.inverted()); } void Matrix4Test::transform() { diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index bd7dca4c3..62973756f 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -46,6 +46,7 @@ class MatrixTest: public Corrade::TestSuite::Tester { void ij(); void determinant(); void inverted(); + void invertedOrthogonal(); void debug(); void configuration(); @@ -57,6 +58,7 @@ typedef Matrix<3, Float> Matrix3; typedef Vector<4, Float> Vector4; typedef Vector<4, Int> Vector4i; typedef Vector<3, Float> Vector3; +typedef Math::Constants Constants; MatrixTest::MatrixTest() { addTests({&MatrixTest::construct, @@ -71,6 +73,7 @@ MatrixTest::MatrixTest() { &MatrixTest::ij, &MatrixTest::determinant, &MatrixTest::inverted, + &MatrixTest::invertedOrthogonal, &MatrixTest::debug, &MatrixTest::configuration}); } @@ -209,6 +212,20 @@ void MatrixTest::inverted() { CORRADE_COMPARE(_inverse*m, Matrix4()); } +void MatrixTest::invertedOrthogonal() { + std::ostringstream o; + Error::setOutput(&o); + + Matrix3 a(Vector3(Constants::sqrt3()/2.0f, 0.5f, 0.0f), + Vector3(-0.5f, Constants::sqrt3()/2.0f, 0.0f), + Vector3(0.0f, 0.0f, 1.0f)); + (a*2).invertedOrthogonal(); + CORRADE_COMPARE(o.str(), "Math::Matrix::invertedOrthogonal(): the matrix is not orthogonal\n"); + + CORRADE_COMPARE(a.invertedOrthogonal()*a, Matrix3()); + CORRADE_COMPARE(a.invertedOrthogonal(), a.inverted()); +} + void MatrixTest::debug() { Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Vector4(4.0f, 4.0f, 7.0f, 3.0f), diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index f3e81f9d9..b5c920e27 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -68,7 +68,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { } inline static Math::Matrix3 inverted(const Math::Matrix3& transformation) { - return transformation.invertedEuclidean(); + return transformation.invertedRigid(); } inline Math::Matrix3 transformation() const { diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index 751f5f0b3..90c32f435 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -68,7 +68,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { } inline static Math::Matrix4 inverted(const Math::Matrix4& transformation) { - return transformation.invertedEuclidean(); + return transformation.invertedRigid(); } inline Math::Matrix4 transformation() const { From 9128820e357ed1b626e95cd4ff7da11b35f3cab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 Mar 2013 15:35:40 +0100 Subject: [PATCH 546/567] Math: ability to create Complex and DualComplex from matrix. --- src/Math/Complex.h | 24 +++++++++++++++++++++++- src/Math/DualComplex.h | 15 ++++++++++++++- src/Math/Test/ComplexTest.cpp | 8 ++++++++ src/Math/Test/DualComplexTest.cpp | 8 ++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 7f7d741bb..65c455b2e 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -37,6 +37,15 @@ namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + /* No assertions fired, for internal use */ + template inline static Complex complexFromMatrix(const Matrix<2, T>& matrix) { + return {matrix[0][0], matrix[0][1]}; + } +} +#endif + /** @brief %Complex number @tparam T Data type @@ -87,6 +96,18 @@ template class Complex { return {std::cos(T(angle)), std::sin(T(angle))}; } + /** + * @brief Create complex number from rotation matrix + * + * Expects that the matrix is orthogonal (i.e. pure rotation). + * @see toMatrix(), DualComplex::fromMatrix(), Matrix::isOrthogonal() + */ + inline static Complex fromMatrix(const Matrix<2, T>& matrix) { + CORRADE_ASSERT(matrix.isOrthogonal(), + "Math::Complex::fromMatrix(): the matrix is not orthogonal", {}); + return Implementation::complexFromMatrix(matrix); + } + /** * @brief Default constructor * @@ -164,7 +185,8 @@ template class Complex { * b & a * \end{pmatrix} * @f] - * @see DualComplex::toMatrix(), Matrix3::from(const Matrix<2, T>&, const Vector2&) + * @see fromMatrix(), DualComplex::toMatrix(), + * Matrix3::from(const Matrix<2, T>&, const Vector2&) */ Matrix<2, T> toMatrix() const { return {Vector<2, T>(_real, _imaginary), diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index bc2672234..f1cce6981 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -76,6 +76,19 @@ template class DualComplex: public Dual> { return {{}, {vector.x(), vector.y()}}; } + /** + * @brief Create dual complex number from rotation matrix + * + * Expects that the matrix represents rigid transformation. + * @see toMatrix(), Complex::fromMatrix(), + * Matrix3::isRigidTransformation() + */ + inline static DualComplex fromMatrix(const Matrix3& matrix) { + CORRADE_ASSERT(matrix.isRigidTransformation(), + "Math::DualComplex::fromMatrix(): the matrix doesn't represent rigid transformation", {}); + return {Implementation::complexFromMatrix(matrix.rotationScaling()), Complex(matrix.translation())}; + } + /** * @brief Default constructor * @@ -140,7 +153,7 @@ template class DualComplex: public Dual> { /** * @brief Convert dual complex number to transformation matrix * - * @see Complex::toMatrix() + * @see fromMatrix(), Complex::toMatrix() */ inline Matrix3 toMatrix() const { return Matrix3::from(this->real().toMatrix(), translation()); diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 1cbc1d8af..75ad05df8 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -280,6 +280,14 @@ void ComplexTest::matrix() { Matrix2 m = Matrix3::rotation(Deg(37.0f)).rotationScaling(); CORRADE_COMPARE(a.toMatrix(), m); + + std::ostringstream o; + Error::setOutput(&o); + Complex::fromMatrix(m*2); + CORRADE_COMPARE(o.str(), "Math::Complex::fromMatrix(): the matrix is not orthogonal\n"); + + Complex b = Complex::fromMatrix(m); + CORRADE_COMPARE(b, a); } void ComplexTest::transformVector() { diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 31ffb6385..b67f69259 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -225,6 +225,14 @@ void DualComplexTest::matrix() { Matrix3 m = Matrix3::rotation(Deg(23.0f))*Matrix3::translation({2.0f, 3.0f}); CORRADE_COMPARE(a.toMatrix(), m); + + std::ostringstream o; + Error::setOutput(&o); + DualComplex::fromMatrix(m*2); + CORRADE_COMPARE(o.str(), "Math::DualComplex::fromMatrix(): the matrix doesn't represent rigid transformation\n"); + + DualComplex b = DualComplex::fromMatrix(m); + CORRADE_COMPARE(b, a); } void DualComplexTest::transformPoint() { From da93b2ad6aafe3237c402b29fa889e61129eeab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 00:30:13 +0100 Subject: [PATCH 547/567] Math: ability to create Quaternion and DualQuaternion from matrix. --- src/Math/DualQuaternion.h | 17 ++++++++- src/Math/Quaternion.h | 54 +++++++++++++++++++++++++++- src/Math/Test/DualQuaternionTest.cpp | 8 +++++ src/Math/Test/QuaternionTest.cpp | 21 +++++++++-- 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 6a5653224..9d3e79902 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -79,6 +79,21 @@ template class DualQuaternion: public Dual> { return {{}, {vector/T(2), T(0)}}; } + /** + * @brief Create dual quaternion from transformation matrix + * + * Expects that the matrix represents rigid transformation. + * @see toMatrix(), Quaternion::fromMatrix(), + * Matrix4::isRigidTransformation() + */ + inline static DualQuaternion fromMatrix(const Matrix4& matrix) { + CORRADE_ASSERT(matrix.isRigidTransformation(), + "Math::DualQuaternion::fromMatrix(): the matrix doesn't represent rigid transformation", {}); + + Quaternion q = Implementation::quaternionFromMatrix(matrix.rotationScaling()); + return {q, Quaternion(matrix.translation()/2)*q}; + } + /** * @brief Default constructor * @@ -158,7 +173,7 @@ template class DualQuaternion: public Dual> { /** * @brief Convert dual quaternion to transformation matrix * - * @see Quaternion::toMatrix() + * @see fromMatrix(), Quaternion::toMatrix() */ Matrix4 toMatrix() const { return Matrix4::from(this->real().toMatrix(), translation()); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 5103de897..aa5614810 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -38,6 +38,45 @@ namespace Magnum { namespace Math { +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + +/* No assertions fired, for internal use */ +template inline Quaternion quaternionFromMatrix(const Matrix<3, T>& m) { + const Vector<3, T> diagonal = m.diagonal(); + const T trace = diagonal.sum(); + + /* Diagonal is positive */ + if(trace > T(0)) { + const T s = std::sqrt(trace + T(1)); + const T t = T(0.5)/s; + return {Vector3(m[1][2] - m[2][1], + m[2][0] - m[0][2], + m[0][1] - m[1][0])*t, s*T(0.5)}; + } + + /* Diagonal is negative */ + std::size_t i = 0; + if(diagonal[1] > diagonal[0]) i = 1; + if(diagonal[2] > diagonal[i]) i = 2; + + const std::size_t j = (i + 1) % 3; + const std::size_t k = (i + 2) % 3; + + const T s = std::sqrt(diagonal[i] - diagonal[j] - diagonal[k] + T(1)); + const T t = (s == T(0) ? T(0) : T(0.5)/s); + + Vector3 vec; + vec[i] = s*T(0.5); + vec[j] = (m[i][j] + m[j][i])*t; + vec[k] = (m[i][k] + m[k][i])*t; + + return {vec, (m[j][k] - m[k][j])*t}; +} + +} +#endif + /** @brief %Quaternion @tparam T Underlying data type @@ -134,6 +173,18 @@ template class Quaternion { return {normalizedAxis*std::sin(T(angle)/2), std::cos(T(angle)/2)}; } + /** + * @brief Create quaternion from rotation matrix + * + * Expects that the matrix is orthogonal (i.e. pure rotation). + * @see toMatrix(), DualComplex::fromMatrix(), Matrix::isOrthogonal() + */ + inline static Quaternion fromMatrix(const Matrix<3, T>& matrix) { + CORRADE_ASSERT(matrix.isOrthogonal(), + "Math::Quaternion::fromMatrix(): the matrix is not orthogonal", {}); + return Implementation::quaternionFromMatrix(matrix); + } + /** * @brief Default constructor * @@ -213,7 +264,8 @@ template class Quaternion { /** * @brief Convert quaternion to rotation matrix * - * @see DualQuaternion::toMatrix(), Matrix4::from(const Matrix<3, T>&, const Vector3&) + * @see fromMatrix(), DualQuaternion::toMatrix(), + * Matrix4::from(const Matrix<3, T>&, const Vector3&) */ Matrix<3, T> toMatrix() const { return { diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index 75300f1d6..cb5011d94 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -234,6 +234,14 @@ void DualQuaternionTest::matrix() { /* Verify that negated dual quaternion gives the same transformation */ CORRADE_COMPARE(q.toMatrix(), m); CORRADE_COMPARE((-q).toMatrix(), m); + + std::ostringstream o; + Error::setOutput(&o); + DualQuaternion::fromMatrix(m*2); + CORRADE_COMPARE(o.str(), "Math::DualQuaternion::fromMatrix(): the matrix doesn't represent rigid transformation\n"); + + DualQuaternion p = DualQuaternion::fromMatrix(m); + CORRADE_COMPARE(p, q); } void DualQuaternionTest::transformPoint() { diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 6577ea5ab..9f9bcc865 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -282,12 +282,29 @@ void QuaternionTest::angle() { } void QuaternionTest::matrix() { - Quaternion q = Quaternion::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())); - Matrix3 m = Matrix4::rotation(Deg(37.0f), Vector3(1.0f/Constants::sqrt3())).rotationScaling(); + Vector3 axis = Vector3(1.0f, -3.0f, 5.0f).normalized(); + + Quaternion q = Quaternion::rotation(Deg(37.0f), axis); + Matrix3 m = Matrix4::rotation(Deg(37.0f), axis).rotationScaling(); /* Verify that negated quaternion gives the same rotation */ CORRADE_COMPARE(q.toMatrix(), m); CORRADE_COMPARE((-q).toMatrix(), m); + + std::ostringstream o; + Error::setOutput(&o); + Quaternion::fromMatrix(m*2); + CORRADE_COMPARE(o.str(), "Math::Quaternion::fromMatrix(): the matrix is not orthogonal\n"); + + /* Trace > 0 */ + CORRADE_VERIFY(m.trace() > 0.0f); + CORRADE_COMPARE(Quaternion::fromMatrix(m), q); + + /* Trace < 0 */ + Matrix3 m2 = Matrix4::rotation(Deg(130.0f), axis).rotationScaling(); + Quaternion q2 = Quaternion::rotation(Deg(130.0f), axis); + CORRADE_VERIFY(m2.trace() < 0.0f); + CORRADE_COMPARE(Quaternion::fromMatrix(m2), q2); } void QuaternionTest::lerp() { From 8548a2e08ba25aea230859991da6f927394d15b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 00:42:54 +0100 Subject: [PATCH 548/567] SceneGraph: renamed {Euclidean -> Rigid}MatrixTransformation{2,3}D. It's shorter, following changes in Math (Matrix*::invertedRigid(), Matrix*::isRigidTransformation()). --- src/SceneGraph/CMakeLists.txt | 8 +-- src/SceneGraph/MatrixTransformation2D.h | 2 +- src/SceneGraph/MatrixTransformation3D.h | 2 +- src/SceneGraph/Object.h | 4 +- ...2D.cpp => RigidMatrixTransformation2D.cpp} | 4 +- ...tion2D.h => RigidMatrixTransformation2D.h} | 35 ++++++----- ...3D.cpp => RigidMatrixTransformation3D.cpp} | 4 +- ...tion3D.h => RigidMatrixTransformation3D.h} | 37 ++++++------ src/SceneGraph/SceneGraph.h | 7 ++- src/SceneGraph/Test/CMakeLists.txt | 4 +- ...pp => RigidMatrixTransformation2DTest.cpp} | 60 +++++++++---------- ...pp => RigidMatrixTransformation3DTest.cpp} | 60 +++++++++---------- 12 files changed, 113 insertions(+), 114 deletions(-) rename src/SceneGraph/{EuclideanMatrixTransformation2D.cpp => RigidMatrixTransformation2D.cpp} (91%) rename src/SceneGraph/{EuclideanMatrixTransformation2D.h => RigidMatrixTransformation2D.h} (76%) rename src/SceneGraph/{EuclideanMatrixTransformation3D.cpp => RigidMatrixTransformation3D.cpp} (91%) rename src/SceneGraph/{EuclideanMatrixTransformation3D.h => RigidMatrixTransformation3D.h} (78%) rename src/SceneGraph/Test/{EuclideanMatrixTransformation2DTest.cpp => RigidMatrixTransformation2DTest.cpp} (67%) rename src/SceneGraph/Test/{EuclideanMatrixTransformation3DTest.cpp => RigidMatrixTransformation3DTest.cpp} (71%) diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index e1b68c04e..6ad4f53e4 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -26,8 +26,8 @@ set(MagnumSceneGraph_SRCS Animable.cpp Camera.cpp - EuclideanMatrixTransformation2D.cpp - EuclideanMatrixTransformation3D.cpp + RigidMatrixTransformation2D.cpp + RigidMatrixTransformation3D.cpp Object.cpp) # Files compiled with different flags for main library and unit test library @@ -54,8 +54,8 @@ set(MagnumSceneGraph_HEADERS Camera3D.h Camera3D.hpp Drawable.h - EuclideanMatrixTransformation2D.h - EuclideanMatrixTransformation3D.h + RigidMatrixTransformation2D.h + RigidMatrixTransformation3D.h FeatureGroup.h MatrixTransformation2D.h MatrixTransformation3D.h diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index a3300a504..04e6f1e1c 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -38,7 +38,7 @@ namespace Magnum { namespace SceneGraph { @brief Two-dimensional transformation implemented using matrices Uses Math::Matrix3 as underlying type. -@see @ref scenegraph, EuclideanMatrixTransformation2D, MatrixTransformation3D +@see @ref scenegraph, RigidMatrixTransformation2D, MatrixTransformation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index d6a40cbe6..86989a3f5 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -38,7 +38,7 @@ namespace Magnum { namespace SceneGraph { @brief Three-dimensional transformation implemented using matrices Uses Math::Matrix4 as underlying type. -@see @ref scenegraph, EuclideanMatrixTransformation3D, MatrixTransformation2D +@see @ref scenegraph, RigidMatrixTransformation3D, MatrixTransformation2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 07c798249..5216fab3c 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -83,8 +83,8 @@ See @ref compilation-speedup-hpp for more information. - @ref MatrixTransformation2D "Object>" - @ref MatrixTransformation3D "Object>" - - @ref EuclideanMatrixTransformation2D "Object>" - - @ref EuclideanMatrixTransformation3D "Object>" + - @ref RigidMatrixTransformation2D "Object>" + - @ref RigidMatrixTransformation3D "Object>" @see Scene, AbstractFeature, AbstractTransformation, DebugTools::ObjectRenderer */ diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.cpp b/src/SceneGraph/RigidMatrixTransformation2D.cpp similarity index 91% rename from src/SceneGraph/EuclideanMatrixTransformation2D.cpp rename to src/SceneGraph/RigidMatrixTransformation2D.cpp index cbf5bccfe..a6e7506e9 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.cpp +++ b/src/SceneGraph/RigidMatrixTransformation2D.cpp @@ -22,14 +22,14 @@ DEALINGS IN THE SOFTWARE. */ -#include "EuclideanMatrixTransformation2D.h" +#include "RigidMatrixTransformation2D.h" #include "Object.hpp" namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT -template class MAGNUM_SCENEGRAPH_EXPORT Object>; +template class MAGNUM_SCENEGRAPH_EXPORT Object>; #endif }} diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h similarity index 76% rename from src/SceneGraph/EuclideanMatrixTransformation2D.h rename to src/SceneGraph/RigidMatrixTransformation2D.h index b5c920e27..cb6e72f7a 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -1,5 +1,5 @@ -#ifndef Magnum_SceneGraph_EuclideanMatrixTransformation2D_h -#define Magnum_SceneGraph_EuclideanMatrixTransformation2D_h +#ifndef Magnum_SceneGraph_RigidMatrixTransformation2D_h +#define Magnum_SceneGraph_RigidMatrixTransformation2D_h /* This file is part of Magnum. @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::EuclideanMatrixTransformation2D + * @brief Class Magnum::SceneGraph::RigidMatrixTransformation2D */ #include "Math/Matrix3.h" @@ -36,20 +36,19 @@ namespace Magnum { namespace SceneGraph { /** -@brief Two-dimensional euclidean transformation implemented using matrices +@brief Two-dimensional rigid transformation implemented using matrices Unlike MatrixTransformation2D this class allows only rotation, reflection and translation (no scaling or setting arbitrary transformations). This allows to -use Matrix3::invertedEuclidean() for faster computation of inverse -transformations. -@see @ref scenegraph, EuclideanMatrixTransformation3D +use Matrix3::invertedRigid() for faster computation of inverse transformations. +@see @ref scenegraph, RigidMatrixTransformation3D */ #ifndef DOXYGEN_GENERATING_OUTPUT template #else template #endif -class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { +class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { public: /** @brief Transformation matrix type */ typedef typename DimensionTraits<2, T>::MatrixType DataType; @@ -80,7 +79,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * @brief Reset transformation to default * @return Pointer to self (for method chaining) */ - inline EuclideanMatrixTransformation2D* resetTransformation() { + inline RigidMatrixTransformation2D* resetTransformation() { setTransformation({}); return this; } @@ -92,7 +91,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * Normalizes the rotation part using Math::Algorithms::gramSchmidt() * to prevent rounding errors when rotating the object subsequently. */ - EuclideanMatrixTransformation2D* normalizeRotation() { + RigidMatrixTransformation2D* normalizeRotation() { setTransformation(Math::Matrix3::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); @@ -100,7 +99,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { } /** @copydoc AbstractTranslationRotation2D::translate() */ - inline EuclideanMatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::translation(vector), type); return this; } @@ -113,7 +112,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * * @see normalizeRotation(), Matrix3::rotation() */ - inline EuclideanMatrixTransformation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::rotation(angle), type); return this; } @@ -127,7 +126,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * * @see Matrix3::reflection() */ - inline EuclideanMatrixTransformation2D* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { + inline RigidMatrixTransformation2D* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { transform(Math::Matrix3::reflection(normal), type); return this; } @@ -138,23 +137,23 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { * if you want to move it above all. * @return Pointer to self (for method chaining) */ - inline EuclideanMatrixTransformation2D* move(Object>* under) { - static_cast*>(this)->Corrade::Containers::template LinkedList>>::move(this, under); + inline RigidMatrixTransformation2D* move(Object>* under) { + static_cast*>(this)->Corrade::Containers::template LinkedList>>::move(this, under); return this; } protected: /* Allow construction only from Object */ - inline explicit EuclideanMatrixTransformation2D() = default; + inline explicit RigidMatrixTransformation2D() = default; private: inline void setTransformation(const Math::Matrix3& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ - if(!static_cast>*>(this)->isScene()) { + if(!static_cast>*>(this)->isScene()) { _transformation = transformation; - static_cast>*>(this)->setDirty(); + static_cast>*>(this)->setDirty(); } } diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.cpp b/src/SceneGraph/RigidMatrixTransformation3D.cpp similarity index 91% rename from src/SceneGraph/EuclideanMatrixTransformation3D.cpp rename to src/SceneGraph/RigidMatrixTransformation3D.cpp index d42cab0ad..008f5fb5d 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.cpp +++ b/src/SceneGraph/RigidMatrixTransformation3D.cpp @@ -22,14 +22,14 @@ DEALINGS IN THE SOFTWARE. */ -#include "EuclideanMatrixTransformation3D.h" +#include "RigidMatrixTransformation3D.h" #include "Object.hpp" namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT -template class MAGNUM_SCENEGRAPH_EXPORT Object>; +template class MAGNUM_SCENEGRAPH_EXPORT Object>; #endif }} diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h similarity index 78% rename from src/SceneGraph/EuclideanMatrixTransformation3D.h rename to src/SceneGraph/RigidMatrixTransformation3D.h index 90c32f435..90248860a 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -1,5 +1,5 @@ -#ifndef Magnum_SceneGraph_EuclideanMatrixTransformation3D_h -#define Magnum_SceneGraph_EuclideanMatrixTransformation3D_h +#ifndef Magnum_SceneGraph_RigidMatrixTransformation3D_h +#define Magnum_SceneGraph_RigidMatrixTransformation3D_h /* This file is part of Magnum. @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::EuclideanMatrixTransformation3D + * @brief Class Magnum::SceneGraph::RigidMatrixTransformation3D */ #include "Math/Matrix4.h" @@ -36,20 +36,19 @@ namespace Magnum { namespace SceneGraph { /** -@brief Three-dimensional euclidean transformation implemented using matrices +@brief Three-dimensional rigid transformation implemented using matrices Unlike MatrixTransformation3D this class allows only rotation, reflection and translation (no scaling or setting arbitrary transformations). This allows to -use Matrix4::invertedEuclidean() for faster computation of inverse -transformations. -@see @ref scenegraph, EuclideanMatrixTransformation2D +use Matrix4::invertedRigid() for faster computation of inverse transformations. +@see @ref scenegraph, RigidMatrixTransformation2D */ #ifndef DOXYGEN_GENERATING_OUTPUT template #else template #endif -class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { +class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { public: /** @brief Transformation matrix type */ typedef typename DimensionTraits<3, T>::MatrixType DataType; @@ -80,7 +79,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * @brief Reset transformation to default * @return Pointer to self (for method chaining) */ - inline EuclideanMatrixTransformation3D* resetTransformation() { + inline RigidMatrixTransformation3D* resetTransformation() { setTransformation({}); return this; } @@ -92,7 +91,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * Normalizes the rotation part using Math::Algorithms::gramSchmidt() * to prevent rounding errors when rotating the object subsequently. */ - EuclideanMatrixTransformation3D* normalizeRotation() { + RigidMatrixTransformation3D* normalizeRotation() { setTransformation(Math::Matrix4::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); @@ -108,7 +107,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), * Matrix4::translation() */ - inline EuclideanMatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::translation(vector), type); return this; } @@ -124,7 +123,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation(), * Matrix4::rotation() */ - inline EuclideanMatrixTransformation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotation(angle, normalizedAxis), type); return this; } @@ -137,7 +136,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * * @see normalizeRotation(), Matrix4::rotationX() */ - inline EuclideanMatrixTransformation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationX(angle), type); return this; } @@ -150,7 +149,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * * @see normalizeRotation(), Matrix4::rotationY() */ - inline EuclideanMatrixTransformation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationY(angle), type); return this; } @@ -163,7 +162,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * * @see normalizeRotation(), Matrix4::rotationZ() */ - inline EuclideanMatrixTransformation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) override { + inline RigidMatrixTransformation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) override { transform(Math::Matrix4::rotationZ(angle), type); return this; } @@ -177,23 +176,23 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { * * @see Matrix4::reflection() */ - inline EuclideanMatrixTransformation3D* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { + inline RigidMatrixTransformation3D* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::reflection(normal), type); return this; } protected: /* Allow construction only from Object */ - inline explicit EuclideanMatrixTransformation3D() = default; + inline explicit RigidMatrixTransformation3D() = default; private: inline void setTransformation(const Math::Matrix4& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ - if(!static_cast>*>(this)->isScene()) { + if(!static_cast>*>(this)->isScene()) { _transformation = transformation; - static_cast>*>(this)->setDirty(); + static_cast>*>(this)->setDirty(); } } diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index 196a5572e..61563633f 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -98,9 +98,6 @@ template using Drawable2D = Drawable<2, T>; template using Drawable3D = Drawable<3, T>; #endif -template class EuclideanMatrixTransformation2D; -template class EuclideanMatrixTransformation3D; - template class FeatureGroup; #ifndef CORRADE_GCC46_COMPATIBILITY template using FeatureGroup2D = FeatureGroup<2, Feature, T>; @@ -119,6 +116,10 @@ template class MatrixTransformation2D; template class MatrixTransformation3D; template class Object; + +template class RigidMatrixTransformation2D; +template class RigidMatrixTransformation3D; + template class Scene; #endif diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index c587cd07a..8396b2a54 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -24,9 +24,9 @@ corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) -corrade_add_test(SceneGraphEuclideanMatrixTr___2DTest EuclideanMatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) -corrade_add_test(SceneGraphEuclideanMatrixTr___3DTest EuclideanMatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphMatrixTransformation2DTest MatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphMatrixTransformation3DTest MatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) +corrade_add_test(SceneGraphRigidMatrixTransfor___2DTest RigidMatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphRigidMatrixTransfor___3DTest RigidMatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp similarity index 67% rename from src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp rename to src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp index 6f5cb9fba..c254413da 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp @@ -24,17 +24,17 @@ #include -#include "SceneGraph/EuclideanMatrixTransformation2D.h" +#include "SceneGraph/RigidMatrixTransformation2D.h" #include "SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { -typedef Object> Object2D; -typedef Scene> Scene2D; +typedef Object> Object2D; +typedef Scene> Scene2D; -class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { +class RigidMatrixTransformation2DTest: public Corrade::TestSuite::Tester { public: - explicit EuclideanMatrixTransformation2DTest(); + explicit RigidMatrixTransformation2DTest(); void fromMatrix(); void toMatrix(); @@ -48,41 +48,41 @@ class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { void normalizeRotation(); }; -EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() { - addTests({&EuclideanMatrixTransformation2DTest::fromMatrix, - &EuclideanMatrixTransformation2DTest::toMatrix, - &EuclideanMatrixTransformation2DTest::compose, - &EuclideanMatrixTransformation2DTest::inverted, - - &EuclideanMatrixTransformation2DTest::setTransformation, - &EuclideanMatrixTransformation2DTest::translate, - &EuclideanMatrixTransformation2DTest::rotate, - &EuclideanMatrixTransformation2DTest::reflect, - &EuclideanMatrixTransformation2DTest::normalizeRotation}); +RigidMatrixTransformation2DTest::RigidMatrixTransformation2DTest() { + addTests({&RigidMatrixTransformation2DTest::fromMatrix, + &RigidMatrixTransformation2DTest::toMatrix, + &RigidMatrixTransformation2DTest::compose, + &RigidMatrixTransformation2DTest::inverted, + + &RigidMatrixTransformation2DTest::setTransformation, + &RigidMatrixTransformation2DTest::translate, + &RigidMatrixTransformation2DTest::rotate, + &RigidMatrixTransformation2DTest::reflect, + &RigidMatrixTransformation2DTest::normalizeRotation}); } -void EuclideanMatrixTransformation2DTest::fromMatrix() { +void RigidMatrixTransformation2DTest::fromMatrix() { Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::fromMatrix(m), m); + CORRADE_COMPARE(RigidMatrixTransformation2D<>::fromMatrix(m), m); } -void EuclideanMatrixTransformation2DTest::toMatrix() { +void RigidMatrixTransformation2DTest::toMatrix() { Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::toMatrix(m), m); + CORRADE_COMPARE(RigidMatrixTransformation2D<>::toMatrix(m), m); } -void EuclideanMatrixTransformation2DTest::compose() { +void RigidMatrixTransformation2DTest::compose() { Matrix3 parent = Matrix3::rotation(Deg(17.0f)); Matrix3 child = Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::compose(parent, child), parent*child); + CORRADE_COMPARE(RigidMatrixTransformation2D<>::compose(parent, child), parent*child); } -void EuclideanMatrixTransformation2DTest::inverted() { +void RigidMatrixTransformation2DTest::inverted() { Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3()); + CORRADE_COMPARE(RigidMatrixTransformation2D<>::inverted(m)*m, Matrix3()); } -void EuclideanMatrixTransformation2DTest::setTransformation() { +void RigidMatrixTransformation2DTest::setTransformation() { /* Dirty after setting transformation */ Object2D o; o.setClean(); @@ -97,7 +97,7 @@ void EuclideanMatrixTransformation2DTest::setTransformation() { CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); } -void EuclideanMatrixTransformation2DTest::translate() { +void RigidMatrixTransformation2DTest::translate() { { Object2D o; o.rotate(Deg(17.0f)); @@ -111,7 +111,7 @@ void EuclideanMatrixTransformation2DTest::translate() { } } -void EuclideanMatrixTransformation2DTest::rotate() { +void RigidMatrixTransformation2DTest::rotate() { { Object2D o; o.translate({1.0f, -0.3f}); @@ -125,7 +125,7 @@ void EuclideanMatrixTransformation2DTest::rotate() { } } -void EuclideanMatrixTransformation2DTest::reflect() { +void RigidMatrixTransformation2DTest::reflect() { { Object2D o; o.rotate(Deg(17.0f)); @@ -139,7 +139,7 @@ void EuclideanMatrixTransformation2DTest::reflect() { } } -void EuclideanMatrixTransformation2DTest::normalizeRotation() { +void RigidMatrixTransformation2DTest::normalizeRotation() { Object2D o; o.rotate(Deg(17.0f)); o.normalizeRotation(); @@ -148,4 +148,4 @@ void EuclideanMatrixTransformation2DTest::normalizeRotation() { }}} -CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation2DTest) +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::RigidMatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp similarity index 71% rename from src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp rename to src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp index 840b7c590..424ee5a76 100644 --- a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp @@ -24,17 +24,17 @@ #include -#include "SceneGraph/EuclideanMatrixTransformation3D.h" +#include "SceneGraph/RigidMatrixTransformation3D.h" #include "SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { -typedef Object> Object3D; -typedef Scene> Scene3D; +typedef Object> Object3D; +typedef Scene> Scene3D; -class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { +class RigidMatrixTransformation3DTest: public Corrade::TestSuite::Tester { public: - explicit EuclideanMatrixTransformation3DTest(); + explicit RigidMatrixTransformation3DTest(); void fromMatrix(); void toMatrix(); @@ -48,41 +48,41 @@ class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { void normalizeRotation(); }; -EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() { - addTests({&EuclideanMatrixTransformation3DTest::fromMatrix, - &EuclideanMatrixTransformation3DTest::toMatrix, - &EuclideanMatrixTransformation3DTest::compose, - &EuclideanMatrixTransformation3DTest::inverted, - - &EuclideanMatrixTransformation3DTest::setTransformation, - &EuclideanMatrixTransformation3DTest::translate, - &EuclideanMatrixTransformation3DTest::rotate, - &EuclideanMatrixTransformation3DTest::reflect, - &EuclideanMatrixTransformation3DTest::normalizeRotation}); +RigidMatrixTransformation3DTest::RigidMatrixTransformation3DTest() { + addTests({&RigidMatrixTransformation3DTest::fromMatrix, + &RigidMatrixTransformation3DTest::toMatrix, + &RigidMatrixTransformation3DTest::compose, + &RigidMatrixTransformation3DTest::inverted, + + &RigidMatrixTransformation3DTest::setTransformation, + &RigidMatrixTransformation3DTest::translate, + &RigidMatrixTransformation3DTest::rotate, + &RigidMatrixTransformation3DTest::reflect, + &RigidMatrixTransformation3DTest::normalizeRotation}); } -void EuclideanMatrixTransformation3DTest::fromMatrix() { +void RigidMatrixTransformation3DTest::fromMatrix() { Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::fromMatrix(m), m); + CORRADE_COMPARE(RigidMatrixTransformation3D<>::fromMatrix(m), m); } -void EuclideanMatrixTransformation3DTest::toMatrix() { +void RigidMatrixTransformation3DTest::toMatrix() { Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::toMatrix(m), m); + CORRADE_COMPARE(RigidMatrixTransformation3D<>::toMatrix(m), m); } -void EuclideanMatrixTransformation3DTest::compose() { +void RigidMatrixTransformation3DTest::compose() { Matrix4 parent = Matrix4::rotationX(Deg(17.0f)); Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::compose(parent, child), parent*child); + CORRADE_COMPARE(RigidMatrixTransformation3D<>::compose(parent, child), parent*child); } -void EuclideanMatrixTransformation3DTest::inverted() { +void RigidMatrixTransformation3DTest::inverted() { Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4()); + CORRADE_COMPARE(RigidMatrixTransformation3D<>::inverted(m)*m, Matrix4()); } -void EuclideanMatrixTransformation3DTest::setTransformation() { +void RigidMatrixTransformation3DTest::setTransformation() { /* Dirty after setting transformation */ Object3D o; o.setClean(); @@ -97,7 +97,7 @@ void EuclideanMatrixTransformation3DTest::setTransformation() { CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); } -void EuclideanMatrixTransformation3DTest::translate() { +void RigidMatrixTransformation3DTest::translate() { { Object3D o; o.rotateX(Deg(17.0f)); @@ -111,7 +111,7 @@ void EuclideanMatrixTransformation3DTest::translate() { } } -void EuclideanMatrixTransformation3DTest::rotate() { +void RigidMatrixTransformation3DTest::rotate() { { Object3D o; o.translate({1.0f, -0.3f, 2.3f}); @@ -141,7 +141,7 @@ void EuclideanMatrixTransformation3DTest::rotate() { } } -void EuclideanMatrixTransformation3DTest::reflect() { +void RigidMatrixTransformation3DTest::reflect() { { Object3D o; o.rotateX(Deg(17.0f)); @@ -155,7 +155,7 @@ void EuclideanMatrixTransformation3DTest::reflect() { } } -void EuclideanMatrixTransformation3DTest::normalizeRotation() { +void RigidMatrixTransformation3DTest::normalizeRotation() { Object3D o; o.rotateX(Deg(17.0f)); o.normalizeRotation(); @@ -164,4 +164,4 @@ void EuclideanMatrixTransformation3DTest::normalizeRotation() { }}} -CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation3DTest) +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::RigidMatrixTransformation3DTest) From 332e4cdb713f3d31b6393c27005ea9e195a2eec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 10:50:29 +0100 Subject: [PATCH 549/567] SceneGraph: added AbstractTransformation::resetTransformation(). It was doable in subclasses, but not via any interface, making some things impossible. --- src/SceneGraph/AbstractTransformation.h | 6 ++++++ src/SceneGraph/MatrixTransformation2D.h | 5 +++++ src/SceneGraph/MatrixTransformation3D.h | 5 +++++ src/SceneGraph/RigidMatrixTransformation2D.h | 14 +++++--------- src/SceneGraph/RigidMatrixTransformation3D.h | 14 +++++--------- src/SceneGraph/Test/MatrixTransformation2DTest.cpp | 10 ++++++++++ src/SceneGraph/Test/MatrixTransformation3DTest.cpp | 10 ++++++++++ .../Test/RigidMatrixTransformation2DTest.cpp | 10 ++++++++++ .../Test/RigidMatrixTransformation3DTest.cpp | 10 ++++++++++ 9 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 1e27b1682..1717d576f 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -137,6 +137,12 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractTransformation { /*@}*/ #endif + + /** + * @brief Reset object transformation + * @return Pointer to self (for method chaining) + */ + virtual AbstractTransformation* resetTransformation() = 0; }; /** @brief Transformation type */ diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index 04e6f1e1c..e7ad90e40 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -100,6 +100,11 @@ class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { return this; } + inline MatrixTransformation2D* resetTransformation() override { + setTransformation({}); + return this; + } + /** * @copydoc AbstractTranslationRotationScaling2D::translate() * Same as calling transform() with Matrix3::translation(). diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 86989a3f5..3cc8dd00f 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -88,6 +88,11 @@ class MatrixTransformation3D: public AbstractTranslationRotationScaling3D { return this; } + inline MatrixTransformation3D* resetTransformation() override { + setTransformation({}); + return this; + } + /** * @brief Multiply transformation * @param transformation Transformation diff --git a/src/SceneGraph/RigidMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h index cb6e72f7a..c8ba75829 100644 --- a/src/SceneGraph/RigidMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -75,15 +75,6 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { } #endif - /** - * @brief Reset transformation to default - * @return Pointer to self (for method chaining) - */ - inline RigidMatrixTransformation2D* resetTransformation() { - setTransformation({}); - return this; - } - /** * @brief Normalize rotation part * @return Pointer to self (for method chaining) @@ -98,6 +89,11 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { return this; } + inline RigidMatrixTransformation2D* resetTransformation() override { + setTransformation({}); + return this; + } + /** @copydoc AbstractTranslationRotation2D::translate() */ inline RigidMatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { transform(Math::Matrix3::translation(vector), type); diff --git a/src/SceneGraph/RigidMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h index 90248860a..f76cb1b23 100644 --- a/src/SceneGraph/RigidMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -75,15 +75,6 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { } #endif - /** - * @brief Reset transformation to default - * @return Pointer to self (for method chaining) - */ - inline RigidMatrixTransformation3D* resetTransformation() { - setTransformation({}); - return this; - } - /** * @brief Normalize rotation part * @return Pointer to self (for method chaining) @@ -98,6 +89,11 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { return this; } + inline RigidMatrixTransformation3D* resetTransformation() override { + setTransformation({}); + return this; + } + /** * @brief Translate object * @param vector Translation vector diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp index 976fb46b2..91576e87f 100644 --- a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -42,6 +42,7 @@ class MatrixTransformation2DTest: public Corrade::TestSuite::Tester { void inverted(); void setTransformation(); + void resetTransformation(); void transform(); void translate(); void rotate(); @@ -56,6 +57,7 @@ MatrixTransformation2DTest::MatrixTransformation2DTest() { &MatrixTransformation2DTest::inverted, &MatrixTransformation2DTest::setTransformation, + &MatrixTransformation2DTest::resetTransformation, &MatrixTransformation2DTest::transform, &MatrixTransformation2DTest::translate, &MatrixTransformation2DTest::rotate, @@ -102,6 +104,14 @@ void MatrixTransformation2DTest::setTransformation() { CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); } +void MatrixTransformation2DTest::resetTransformation() { + Object2D o; + o.rotate(Deg(17.0f)); + CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); + o.resetTransformation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); +} + void MatrixTransformation2DTest::transform() { { Object2D o; diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index ce624065f..651d8101d 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -42,6 +42,7 @@ class MatrixTransformation3DTest: public Corrade::TestSuite::Tester { void inverted(); void setTransformation(); + void resetTransformation(); void transform(); void translate(); void rotate(); @@ -56,6 +57,7 @@ MatrixTransformation3DTest::MatrixTransformation3DTest() { &MatrixTransformation3DTest::inverted, &MatrixTransformation3DTest::setTransformation, + &MatrixTransformation3DTest::resetTransformation, &MatrixTransformation3DTest::transform, &MatrixTransformation3DTest::translate, &MatrixTransformation3DTest::rotate, @@ -102,6 +104,14 @@ void MatrixTransformation3DTest::setTransformation() { CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); } +void MatrixTransformation3DTest::resetTransformation() { + Object3D o; + o.rotateX(Deg(17.0f)); + CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); + o.resetTransformation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); +} + void MatrixTransformation3DTest::transform() { { Object3D o; diff --git a/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp index c254413da..229ee5b04 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp @@ -42,6 +42,7 @@ class RigidMatrixTransformation2DTest: public Corrade::TestSuite::Tester { void inverted(); void setTransformation(); + void resetTransformation(); void translate(); void rotate(); void reflect(); @@ -55,6 +56,7 @@ RigidMatrixTransformation2DTest::RigidMatrixTransformation2DTest() { &RigidMatrixTransformation2DTest::inverted, &RigidMatrixTransformation2DTest::setTransformation, + &RigidMatrixTransformation2DTest::resetTransformation, &RigidMatrixTransformation2DTest::translate, &RigidMatrixTransformation2DTest::rotate, &RigidMatrixTransformation2DTest::reflect, @@ -97,6 +99,14 @@ void RigidMatrixTransformation2DTest::setTransformation() { CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); } +void RigidMatrixTransformation2DTest::resetTransformation() { + Object2D o; + o.rotate(Deg(17.0f)); + CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); + o.resetTransformation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); +} + void RigidMatrixTransformation2DTest::translate() { { Object2D o; diff --git a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp index 424ee5a76..e392db2ed 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp @@ -42,6 +42,7 @@ class RigidMatrixTransformation3DTest: public Corrade::TestSuite::Tester { void inverted(); void setTransformation(); + void resetTransformation(); void translate(); void rotate(); void reflect(); @@ -55,6 +56,7 @@ RigidMatrixTransformation3DTest::RigidMatrixTransformation3DTest() { &RigidMatrixTransformation3DTest::inverted, &RigidMatrixTransformation3DTest::setTransformation, + &RigidMatrixTransformation3DTest::resetTransformation, &RigidMatrixTransformation3DTest::translate, &RigidMatrixTransformation3DTest::rotate, &RigidMatrixTransformation3DTest::reflect, @@ -97,6 +99,14 @@ void RigidMatrixTransformation3DTest::setTransformation() { CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); } +void RigidMatrixTransformation3DTest::resetTransformation() { + Object3D o; + o.rotateX(Deg(17.0f)); + CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); + o.resetTransformation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); +} + void RigidMatrixTransformation3DTest::translate() { { Object3D o; From e4f14c4163ed399b4135e7519c20d97a9462a4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 11:09:39 +0100 Subject: [PATCH 550/567] SceneGraph: assert proper matrix type in RigidMatrixTransformation*D. --- src/SceneGraph/RigidMatrixTransformation2D.h | 4 +++- src/SceneGraph/RigidMatrixTransformation3D.h | 4 +++- src/SceneGraph/Test/CMakeLists.txt | 4 ++++ src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp | 6 ++++++ src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp | 6 ++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/SceneGraph/RigidMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h index c8ba75829..20a79dd02 100644 --- a/src/SceneGraph/RigidMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -54,7 +54,9 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { typedef typename DimensionTraits<2, T>::MatrixType DataType; #ifndef DOXYGEN_GENERATING_OUTPUT - inline constexpr static Math::Matrix3 fromMatrix(const Math::Matrix3& matrix) { + inline static Math::Matrix3 fromMatrix(const Math::Matrix3& matrix) { + CORRADE_ASSERT(matrix.isRigidTransformation(), + "SceneGraph::RigidMatrixTransformation2D::fromMatrix(): the matrix doesn't represent rigid transformation", {}); return matrix; } diff --git a/src/SceneGraph/RigidMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h index f76cb1b23..e89ceb498 100644 --- a/src/SceneGraph/RigidMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -54,7 +54,9 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { typedef typename DimensionTraits<3, T>::MatrixType DataType; #ifndef DOXYGEN_GENERATING_OUTPUT - inline constexpr static Math::Matrix4 fromMatrix(const Math::Matrix4& matrix) { + inline static Math::Matrix4 fromMatrix(const Math::Matrix4& matrix) { + CORRADE_ASSERT(matrix.isRigidTransformation(), + "SceneGraph::RigidMatrixTransformation3D::fromMatrix(): the matrix doesn't represent rigid transformation", {}); return matrix; } diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index 8396b2a54..8839941a1 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -30,3 +30,7 @@ corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphT corrade_add_test(SceneGraphRigidMatrixTransfor___2DTest RigidMatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphRigidMatrixTransfor___3DTest RigidMatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) + +set_target_properties(SceneGraphRigidMatrixTransfor___2DTest + SceneGraphRigidMatrixTransfor___3DTest + PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT") diff --git a/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp index 229ee5b04..2457b3ac9 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp @@ -22,6 +22,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include "SceneGraph/RigidMatrixTransformation2D.h" @@ -64,6 +65,11 @@ RigidMatrixTransformation2DTest::RigidMatrixTransformation2DTest() { } void RigidMatrixTransformation2DTest::fromMatrix() { + std::ostringstream o; + Error::setOutput(&o); + RigidMatrixTransformation2D<>::fromMatrix(Matrix3::scaling(Vector2(4.0f))); + CORRADE_COMPARE(o.str(), "SceneGraph::RigidMatrixTransformation2D::fromMatrix(): the matrix doesn't represent rigid transformation\n"); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); CORRADE_COMPARE(RigidMatrixTransformation2D<>::fromMatrix(m), m); } diff --git a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp index e392db2ed..a154a487f 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp @@ -22,6 +22,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include "SceneGraph/RigidMatrixTransformation3D.h" @@ -64,6 +65,11 @@ RigidMatrixTransformation3DTest::RigidMatrixTransformation3DTest() { } void RigidMatrixTransformation3DTest::fromMatrix() { + std::ostringstream o; + Error::setOutput(&o); + RigidMatrixTransformation3D<>::fromMatrix(Matrix4::scaling(Vector3(4.0f))); + CORRADE_COMPARE(o.str(), "SceneGraph::RigidMatrixTransformation3D::fromMatrix(): the matrix doesn't represent rigid transformation\n"); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(RigidMatrixTransformation3D<>::fromMatrix(m), m); } From 0d5f234f644633ccef44654a21a608dc0ba38f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 12:16:57 +0100 Subject: [PATCH 551/567] SceneGraph: public setTransformation() and transform() for RigidMT*D. Now it is nearly similar to MatrixTransformation*D except for scaling. Public functions setTransformation() and transform() assert that the matrix represents rigid transformation. --- src/SceneGraph/RigidMatrixTransformation2D.h | 56 +++++++++++++--- src/SceneGraph/RigidMatrixTransformation3D.h | 66 ++++++++++++++----- .../Test/RigidMatrixTransformation2DTest.cpp | 54 +++++++++++---- .../Test/RigidMatrixTransformation3DTest.cpp | 55 ++++++++++++---- 4 files changed, 181 insertions(+), 50 deletions(-) diff --git a/src/SceneGraph/RigidMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h index 20a79dd02..cdc76d65a 100644 --- a/src/SceneGraph/RigidMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -85,20 +85,53 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { * to prevent rounding errors when rotating the object subsequently. */ RigidMatrixTransformation2D* normalizeRotation() { - setTransformation(Math::Matrix3::from( + setTransformationInternal(Math::Matrix3::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); return this; } + /** + * @brief Set transformation + * @return Pointer to self (for method chaining) + * + * Expects that the matrix represents rigid transformation. + * @see Matrix3::isRigidTransformation() + */ + RigidMatrixTransformation2D* setTransformation(const Math::Matrix3& transformation) { + CORRADE_ASSERT(transformation.isRigidTransformation(), + "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation", this); + setTransformationInternal(transformation); + return this; + } + inline RigidMatrixTransformation2D* resetTransformation() override { - setTransformation({}); + setTransformationInternal({}); + return this; + } + + /** + * @brief Transform object + * @param transformation Transformation + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Expects that the matrix represents rigid transformation. + * @see Matrix3::isRigidTransformation() + */ + inline RigidMatrixTransformation2D* transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { + CORRADE_ASSERT(transformation.isRigidTransformation(), + "SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation", this); + transformInternal(transformation, type); return this; } - /** @copydoc AbstractTranslationRotation2D::translate() */ + /** + * @copydoc AbstractTranslationRotationScaling2D::translate() + * Same as calling transform() with Matrix3::translation(). + */ inline RigidMatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix3::translation(vector), type); + transformInternal(Math::Matrix3::translation(vector), type); return this; } @@ -108,10 +141,11 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see normalizeRotation(), Matrix3::rotation() + * Same as calling transform() with Matrix3::rotation(). + * @see normalizeRotation() */ inline RigidMatrixTransformation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix3::rotation(angle), type); + transformInternal(Math::Matrix3::rotation(angle), type); return this; } @@ -122,10 +156,10 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see Matrix3::reflection() + * Same as calling transform() with Matrix3::reflection(). */ inline RigidMatrixTransformation2D* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { - transform(Math::Matrix3::reflection(normal), type); + transformInternal(Math::Matrix3::reflection(normal), type); return this; } @@ -145,7 +179,8 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { inline explicit RigidMatrixTransformation2D() = default; private: - inline void setTransformation(const Math::Matrix3& transformation) { + /* No assertions fired, for internal use */ + inline void setTransformationInternal(const Math::Matrix3& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -155,7 +190,8 @@ class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { } } - inline void transform(const Math::Matrix3& transformation, TransformationType type) { + /* No assertions fired, for internal use */ + inline void transformInternal(const Math::Matrix3& transformation, TransformationType type) { setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); } diff --git a/src/SceneGraph/RigidMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h index e89ceb498..e087b7420 100644 --- a/src/SceneGraph/RigidMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -91,22 +91,47 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { return this; } + /** + * @brief Set transformation + * @return Pointer to self (for method chaining) + * + * Expects that the matrix represents rigid transformation. + * @see Matrix4::isRigidTransformation() + */ + RigidMatrixTransformation3D* setTransformation(const Math::Matrix4& transformation) { + CORRADE_ASSERT(transformation.isRigidTransformation(), + "SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation", this); + setTransformationInternal(transformation); + return this; + } + inline RigidMatrixTransformation3D* resetTransformation() override { setTransformation({}); return this; } /** - * @brief Translate object - * @param vector Translation vector + * @brief Multiply transformation + * @param transformation Transformation * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), - * Matrix4::translation() + * Expects that the matrix represents rigid transformation. + * @see Matrix4::isRigidTransformation() + */ + inline RigidMatrixTransformation3D* transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { + CORRADE_ASSERT(transformation.isRigidTransformation(), + "SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation", this); + transformInternal(transformation, type); + return this; + } + + /** + * @copydoc AbstractTranslationRotationScaling3D::translate() + * Same as calling transform() with Matrix4::translation(). */ inline RigidMatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix4::translation(vector), type); + transformInternal(Math::Matrix4::translation(vector), type); return this; } @@ -117,12 +142,12 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * + * Same as calling transform() with Matrix4::rotation(). * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation(), - * Matrix4::rotation() + * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation() */ inline RigidMatrixTransformation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix4::rotation(angle, normalizedAxis), type); + transformInternal(Math::Matrix4::rotation(angle, normalizedAxis), type); return this; } @@ -132,10 +157,11 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see normalizeRotation(), Matrix4::rotationX() + * Same as calling transform() with Matrix4::rotationX(). + * @see normalizeRotation() */ inline RigidMatrixTransformation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix4::rotationX(angle), type); + transformInternal(Math::Matrix4::rotationX(angle), type); return this; } @@ -145,10 +171,11 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see normalizeRotation(), Matrix4::rotationY() + * Same as calling transform() with Matrix4::rotationY(). + * @see normalizeRotation() */ inline RigidMatrixTransformation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix4::rotationY(angle), type); + transformInternal(Math::Matrix4::rotationY(angle), type); return this; } @@ -158,10 +185,11 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see normalizeRotation(), Matrix4::rotationZ() + * Same as calling transform() with Matrix4::rotationZ(). + * @see normalizeRotation() */ inline RigidMatrixTransformation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) override { - transform(Math::Matrix4::rotationZ(angle), type); + transformInternal(Math::Matrix4::rotationZ(angle), type); return this; } @@ -172,10 +200,10 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { * @param type Transformation type * @return Pointer to self (for method chaining) * - * @see Matrix4::reflection() + * Same as calling transform() with Matrix4::reflection(). */ inline RigidMatrixTransformation3D* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { - transform(Math::Matrix4::reflection(normal), type); + transformInternal(Math::Matrix4::reflection(normal), type); return this; } @@ -184,7 +212,8 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { inline explicit RigidMatrixTransformation3D() = default; private: - inline void setTransformation(const Math::Matrix4& transformation) { + /* No assertions fired, for internal use */ + inline void setTransformationInternal(const Math::Matrix4& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -194,7 +223,8 @@ class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { } } - inline void transform(const Math::Matrix4& transformation, TransformationType type) { + /* No assertions fired, for internal use */ + inline void transformInternal(const Math::Matrix4& transformation, TransformationType type) { setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); } diff --git a/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp index 2457b3ac9..dccefa1b3 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp @@ -44,6 +44,7 @@ class RigidMatrixTransformation2DTest: public Corrade::TestSuite::Tester { void setTransformation(); void resetTransformation(); + void transform(); void translate(); void rotate(); void reflect(); @@ -58,6 +59,7 @@ RigidMatrixTransformation2DTest::RigidMatrixTransformation2DTest() { &RigidMatrixTransformation2DTest::setTransformation, &RigidMatrixTransformation2DTest::resetTransformation, + &RigidMatrixTransformation2DTest::transform, &RigidMatrixTransformation2DTest::translate, &RigidMatrixTransformation2DTest::rotate, &RigidMatrixTransformation2DTest::reflect, @@ -91,37 +93,67 @@ void RigidMatrixTransformation2DTest::inverted() { } void RigidMatrixTransformation2DTest::setTransformation() { - /* Dirty after setting transformation */ Object2D o; + + /* Can't transform with non-rigid transformation */ + std::ostringstream out; + Error::setOutput(&out); + o.setTransformation(Matrix3::scaling(Vector2(3.0f))); + CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation\n"); + + /* Dirty after setting transformation */ o.setClean(); - o.rotate(Deg(17.0f)); + CORRADE_VERIFY(!o.isDirty()); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(o.isDirty()); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); /* Scene cannot be transformed */ Scene2D s; s.setClean(); - s.rotate(Deg(17.0f)); + s.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); } void RigidMatrixTransformation2DTest::resetTransformation() { Object2D o; - o.rotate(Deg(17.0f)); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); o.resetTransformation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); } +void RigidMatrixTransformation2DTest::transform() { + { + /* Can't transform with non-rigid transformation */ + Object2D o; + std::ostringstream out; + Error::setOutput(&out); + o.transform(Matrix3::scaling(Vector2(3.0f))); + CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation\n"); + } { + Object2D o; + o.setTransformation(Matrix3::rotation(Deg(17.0f))); + o.transform(Matrix3::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + } { + Object2D o; + o.setTransformation(Matrix3::rotation(Deg(17.0f))); + o.transform(Matrix3::translation({1.0f, -0.3f}), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } +} + void RigidMatrixTransformation2DTest::translate() { { Object2D o; - o.rotate(Deg(17.0f)); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.translate({1.0f, -0.3f}); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.rotate(Deg(17.0f)); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.translate({1.0f, -0.3f}, TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } @@ -130,12 +162,12 @@ void RigidMatrixTransformation2DTest::translate() { void RigidMatrixTransformation2DTest::rotate() { { Object2D o; - o.translate({1.0f, -0.3f}); + o.setTransformation(Matrix3::translation({1.0f, -0.3f})); o.rotate(Deg(17.0f)); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); } { Object2D o; - o.translate({1.0f, -0.3f}); + o.setTransformation(Matrix3::translation({1.0f, -0.3f})); o.rotate(Deg(17.0f), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); } @@ -144,12 +176,12 @@ void RigidMatrixTransformation2DTest::rotate() { void RigidMatrixTransformation2DTest::reflect() { { Object2D o; - o.rotate(Deg(17.0f)); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.reflect(Vector2(-1.0f/Constants::sqrt2())); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f))); } { Object2D o; - o.rotate(Deg(17.0f)); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); } @@ -157,7 +189,7 @@ void RigidMatrixTransformation2DTest::reflect() { void RigidMatrixTransformation2DTest::normalizeRotation() { Object2D o; - o.rotate(Deg(17.0f)); + o.setTransformation(Matrix3::rotation(Deg(17.0f))); o.normalizeRotation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); } diff --git a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp index a154a487f..2d14c3bab 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp @@ -44,6 +44,7 @@ class RigidMatrixTransformation3DTest: public Corrade::TestSuite::Tester { void setTransformation(); void resetTransformation(); + void transform(); void translate(); void rotate(); void reflect(); @@ -58,6 +59,7 @@ RigidMatrixTransformation3DTest::RigidMatrixTransformation3DTest() { &RigidMatrixTransformation3DTest::setTransformation, &RigidMatrixTransformation3DTest::resetTransformation, + &RigidMatrixTransformation3DTest::transform, &RigidMatrixTransformation3DTest::translate, &RigidMatrixTransformation3DTest::rotate, &RigidMatrixTransformation3DTest::reflect, @@ -91,37 +93,68 @@ void RigidMatrixTransformation3DTest::inverted() { } void RigidMatrixTransformation3DTest::setTransformation() { - /* Dirty after setting transformation */ Object3D o; + + /* Can't transform with non-rigid transformation */ + std::ostringstream out; + Error::setOutput(&out); + o.setTransformation(Matrix4::scaling(Vector3(3.0f))); + CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation\n"); + + /* Dirty after setting transformation */ o.setClean(); - o.rotateX(Deg(17.0f)); + CORRADE_VERIFY(!o.isDirty()); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); CORRADE_VERIFY(o.isDirty()); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); /* Scene cannot be transformed */ Scene3D s; s.setClean(); - s.rotateX(Deg(17.0f)); + CORRADE_VERIFY(!s.isDirty()); + s.setTransformation(Matrix4::rotationX(Deg(17.0f))); CORRADE_VERIFY(!s.isDirty()); CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); } void RigidMatrixTransformation3DTest::resetTransformation() { Object3D o; - o.rotateX(Deg(17.0f)); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); o.resetTransformation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); } +void RigidMatrixTransformation3DTest::transform() { + { + /* Can't transform with non-rigid transformation */ + Object3D o; + std::ostringstream out; + Error::setOutput(&out); + o.transform(Matrix4::scaling(Vector3(3.0f))); + CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation\n"); + } { + Object3D o; + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); + o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + } { + Object3D o; + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); + o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f}), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + } +} + void RigidMatrixTransformation3DTest::translate() { { Object3D o; - o.rotateX(Deg(17.0f)); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.translate({1.0f, -0.3f, 2.3f}); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.rotateX(Deg(17.0f)); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); } @@ -130,7 +163,7 @@ void RigidMatrixTransformation3DTest::translate() { void RigidMatrixTransformation3DTest::rotate() { { Object3D o; - o.translate({1.0f, -0.3f, 2.3f}); + o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f)) ->rotateY(Deg(25.0f)) ->rotateZ(Deg(-23.0f)) @@ -143,7 +176,7 @@ void RigidMatrixTransformation3DTest::rotate() { Matrix4::translation({1.0f, -0.3f, 2.3f})); } { Object3D o; - o.translate({1.0f, -0.3f, 2.3f}); + o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f), TransformationType::Local) ->rotateY(Deg(25.0f), TransformationType::Local) ->rotateZ(Deg(-23.0f), TransformationType::Local) @@ -160,12 +193,12 @@ void RigidMatrixTransformation3DTest::rotate() { void RigidMatrixTransformation3DTest::reflect() { { Object3D o; - o.rotateX(Deg(17.0f)); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.reflect(Vector3(-1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f))); } { Object3D o; - o.rotateX(Deg(17.0f)); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); } @@ -173,7 +206,7 @@ void RigidMatrixTransformation3DTest::reflect() { void RigidMatrixTransformation3DTest::normalizeRotation() { Object3D o; - o.rotateX(Deg(17.0f)); + o.setTransformation(Matrix4::rotationX(Deg(17.0f))); o.normalizeRotation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); } From 3db2aa13c4b274889ac93a7beb17695c5351b38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 15:13:24 +0100 Subject: [PATCH 552/567] Math: added convenience function Vector::isNormalized(). --- src/Math/Matrix3.h | 4 ++-- src/Math/Matrix4.h | 8 ++++---- src/Math/Test/VectorTest.cpp | 9 +++++++++ src/Math/Vector.h | 27 ++++++++++++++++++++++----- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Math/Matrix3.h b/src/Math/Matrix3.h index a60e0133e..344f55d86 100644 --- a/src/Math/Matrix3.h +++ b/src/Math/Matrix3.h @@ -93,10 +93,10 @@ template class Matrix3: public Matrix<3, T> { * @param normal Normal of the line through which to reflect * * Expects that the normal is normalized. - * @see Matrix4::reflection() + * @see Matrix4::reflection(), Vector::isNormalized() */ static Matrix3 reflection(const Vector2& normal) { - CORRADE_ASSERT(TypeTraits::equals(normal.dot(), T(1)), + CORRADE_ASSERT(normal.isNormalized(), "Math::Matrix3::reflection(): normal must be normalized", {}); return from(Matrix<2, T>() - T(2)*normal*RectangularMatrix<1, 2, T>(normal).transposed(), {}); } diff --git a/src/Math/Matrix4.h b/src/Math/Matrix4.h index 9837bdae7..9202d3437 100644 --- a/src/Math/Matrix4.h +++ b/src/Math/Matrix4.h @@ -88,10 +88,10 @@ template class Matrix4: public Matrix<4, T> { * faster alternatives like rotationX(), rotationY() and rotationZ(). * @see rotation() const, Quaternion::rotation(), DualQuaternion::rotation(), * Matrix3::rotation(Rad), Vector3::xAxis(), Vector3::yAxis(), - * Vector3::zAxis() + * Vector3::zAxis(), Vector::isNormalized() */ static Matrix4 rotation(Rad angle, const Vector3& normalizedAxis) { - CORRADE_ASSERT(TypeTraits::equals(normalizedAxis.dot(), T(1)), + CORRADE_ASSERT(normalizedAxis.isNormalized(), "Math::Matrix4::rotation(): axis must be normalized", {}); T sine = std::sin(T(angle)); @@ -181,10 +181,10 @@ template class Matrix4: public Matrix<4, T> { * @param normal Normal of the plane through which to reflect * * Expects that the normal is normalized. - * @see Matrix3::reflection() + * @see Matrix3::reflection(), Vector::isNormalized() */ static Matrix4 reflection(const Vector3& normal) { - CORRADE_ASSERT(TypeTraits::equals(normal.dot(), T(1)), + CORRADE_ASSERT(normal.isNormalized(), "Math::Matrix4::reflection(): normal must be normalized", {}); return from(Matrix<3, T>() - T(2)*normal*RectangularMatrix<1, 3, T>(normal).transposed(), {}); } diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 7c301cd7e..9b492efcd 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -62,6 +62,8 @@ class VectorTest: public Corrade::TestSuite::Tester { void constructConversion(); void constructCopy(); + void isNormalized(); + void convert(); void data(); @@ -107,6 +109,8 @@ VectorTest::VectorTest() { &VectorTest::constructConversion, &VectorTest::constructCopy, + &VectorTest::isNormalized, + &VectorTest::convert, &VectorTest::data, @@ -188,6 +192,11 @@ void VectorTest::constructCopy() { CORRADE_COMPARE(b, Vector4(1.0f, 3.5f, 4.0f, -2.7f)); } +void VectorTest::isNormalized() { + CORRADE_VERIFY(!Vector3(1.0f, 2.0f, -1.0f).isNormalized()); + CORRADE_VERIFY(Vector3(0.0f, 1.0f, 0.0f).isNormalized()); +} + void VectorTest::convert() { Vec3 a{1.5f, 2.0f, -3.5f}; Vector3 b(1.5f, 2.0f, -3.5f); diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 767c79ce0..1d4c197a9 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -99,10 +99,10 @@ template class Vector { * Expects that both vectors are normalized. @f[ * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) * @f] - * @see Quaternion::angle(), Complex::angle() + * @see isNormalized(), Quaternion::angle(), Complex::angle() */ inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { - CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(normalizedA.isNormalized() && normalizedB.isNormalized(), "Math::Vector::angle(): vectors must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(std::acos(dot(normalizedA, normalizedB))); } @@ -245,6 +245,18 @@ template class Vector { return out; } + /** + * @brief Whether the vector is normalized + * + * The vector is normalized if it has unit length: @f[ + * |\boldsymbol a|^2 = |\boldsymbol a| = 1 + * @f] + * @see dot(), normalized() + */ + inline bool isNormalized() const { + return TypeTraits::equals(dot(), T(1)); + } + /** * @brief Negated vector * @@ -422,7 +434,7 @@ template class Vector { * other values, because it doesn't compute the square root. @f[ * \boldsymbol a \cdot \boldsymbol a = \sum_{i=0}^{n-1} \boldsymbol a_i^2 * @f] - * @see dot(const Vector&, const Vector&) + * @see dot(const Vector&, const Vector&), isNormalized() */ inline T dot() const { return dot(*this, *this); @@ -435,13 +447,18 @@ template class Vector { * values. @f[ * |\boldsymbol a| = \sqrt{\boldsymbol a \cdot \boldsymbol a} * @f] + * @see isNormalized() * @todo something like std::hypot() for possibly better precision? */ inline T length() const { return std::sqrt(dot()); } - /** @brief Normalized vector (of unit length) */ + /** + * @brief Normalized vector (of unit length) + * + * @see isNormalized() + */ inline Vector normalized() const { return *this/length(); } @@ -468,7 +485,7 @@ template class Vector { * @f] */ inline Vector projectedOntoNormalized(const Vector& line) const { - CORRADE_ASSERT(TypeTraits::equals(line.dot(), T(1)), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); + CORRADE_ASSERT(line.isNormalized(), "Math::Vector::projectedOntoNormalized(): line must be normalized", (Vector(std::numeric_limits::quiet_NaN()))); return line*dot(*this, line); } From 1790f37295a221dc4bf49347236314b0a7bc41a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 15:20:14 +0100 Subject: [PATCH 553/567] Math: added convenience functions {Complex,DualComplex}::isNormalized(). --- src/Math/Complex.h | 29 +++++++++++++++++++++++------ src/Math/DualComplex.h | 15 ++++++++++++++- src/Math/Test/ComplexTest.cpp | 9 +++++++++ src/Math/Test/DualComplexTest.cpp | 9 +++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 65c455b2e..9b1d36ea3 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -75,10 +75,10 @@ template class Complex { * Expects that both complex numbers are normalized. @f[ * \theta = acos \left( \frac{Re(c_0 \cdot c_1))}{|c_0| |c_1|} \right) = acos (a_0 a_1 + b_0 b_1) * @f] - * @see Quaternion::angle(), Vector::angle() + * @see isNormalized(), Quaternion::angle(), Vector::angle() */ inline static Rad angle(const Complex& normalizedA, const Complex& normalizedB) { - CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(normalizedA.isNormalized() && normalizedB.isNormalized(), "Math::Complex::angle(): complex numbers must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(std::acos(normalizedA._real*normalizedB._real + normalizedA._imaginary*normalizedB._imaginary)); } @@ -147,6 +147,18 @@ template class Complex { return !operator==(other); } + /** + * @brief Whether the complex number is normalized + * + * Complex number is normalized if it has unit length: @f[ + * |c|^2 = |c| = 1 + * @f] + * @see dot(), normalized() + */ + inline bool isNormalized() const { + return TypeTraits::equals(dot(), T(1)); + } + /** @brief Real part */ inline constexpr T real() const { return _real; } @@ -311,7 +323,7 @@ template class Complex { * with other values, because it doesn't compute the square root. @f[ * c \cdot c = a^2 + b^2 * @f] - * @see dot(const Complex&, const Complex&) + * @see dot(const Complex&, const Complex&), isNormalized() */ inline T dot() const { return dot(*this, *this); @@ -324,12 +336,17 @@ template class Complex { * values. @f[ * |c| = \sqrt{c \cdot c} * @f] + * @see isNormalized() */ inline T length() const { return std::hypot(_real, _imaginary); } - /** @brief Normalized complex number (of unit length) */ + /** + * @brief Normalized complex number (of unit length) + * + * @see isNormalized() + */ inline Complex normalized() const { return (*this)/length(); } @@ -364,10 +381,10 @@ template class Complex { * normalized. @f[ * c^{-1} = \frac{c^*}{c \cdot c} = c^* * @f] - * @see inverted() + * @see isNormalized(), inverted() */ inline Complex invertedNormalized() const { - CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(isNormalized(), "Math::Complex::invertedNormalized(): complex number must be normalized", Complex(std::numeric_limits::quiet_NaN(), {})); return conjugated(); diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index f1cce6981..6854c4f6a 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -126,6 +126,18 @@ template class DualComplex: public Dual> { inline constexpr explicit DualComplex(const Vector2& vector): Dual>({}, Complex(vector)) {} #endif + /** + * @brief Whether the dual complex number is normalized + * + * Dual complex number is normalized if its real part has unit length: @f[ + * |c_0|^2 = |c_0| = 1 + * @f] + * @see Complex::dot(), normalized() + */ + inline bool isNormalized() const { + return TypeTraits::equals(this->real().dot(), T(1)); + } + /** * @brief Rotation angle of dual complex number * @@ -240,6 +252,7 @@ template class DualComplex: public Dual> { * @f[ * c' = \frac{c_0}{|c_0|} * @f] + * @see isNormalized() * @todo can this be done similarly to dual quaternions? */ inline DualComplex normalized() const { @@ -265,7 +278,7 @@ template class DualComplex: public Dual> { * Expects that the complex number is normalized. @f[ * \hat c^{-1} = c_0^{-1} - \epsilon c_\epsilon = c_0^* - \epsilon c_\epsilon * @f] - * @see inverted() + * @see isNormalized(), inverted() * @todo can this be done similarly to dual quaternions? */ inline DualComplex invertedNormalized() const { diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 75ad05df8..931a66ead 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -37,7 +37,9 @@ class ComplexTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void compare(); + void isNormalized(); void constExpressions(); @@ -67,7 +69,9 @@ ComplexTest::ComplexTest() { addTests({&ComplexTest::construct, &ComplexTest::constructDefault, &ComplexTest::constructFromVector, + &ComplexTest::compare, + &ComplexTest::isNormalized, &ComplexTest::constExpressions, @@ -126,6 +130,11 @@ void ComplexTest::compare() { CORRADE_VERIFY(Complex(1.0f+TypeTraits::epsilon()*2, 3.7f) != Complex(1.0f, 3.7f)); } +void ComplexTest::isNormalized() { + CORRADE_VERIFY(!Complex(2.5f, -3.7f).isNormalized()); + CORRADE_VERIFY(Complex::rotation(Deg(23.0f)).isNormalized()); +} + void ComplexTest::constExpressions() { /* Default constructor */ constexpr Complex a; diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index b67f69259..9d8db2094 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -38,6 +38,8 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void constructDefault(); void constructFromVector(); + void isNormalized(); + void constExpressions(); void multiply(); @@ -74,6 +76,8 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::constructDefault, &DualComplexTest::constructFromVector, + &DualComplexTest::isNormalized, + &DualComplexTest::constExpressions, &DualComplexTest::multiply, @@ -112,6 +116,11 @@ void DualComplexTest::constructFromVector() { CORRADE_COMPARE(DualComplex(Vector2(1.5f, -3.0f)), DualComplex({1.0f, 0.0f}, {1.5f, -3.0f})); } +void DualComplexTest::isNormalized() { + CORRADE_VERIFY(!DualComplex({2.0f, 1.0f}, {}).isNormalized()); + CORRADE_VERIFY((DualComplex::rotation(Deg(23.0f))*DualComplex::translation({6.0f, 3.0f})).isNormalized()); +} + void DualComplexTest::constExpressions() { /* Default constructor */ constexpr DualComplex a; From b00554fd7f04fb9fe2a198f0b43c66b8ad083a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 15:21:52 +0100 Subject: [PATCH 554/567] Math: added convenience {Quaternion,DualQuaternion}::isNormalized(). --- src/Math/DualQuaternion.h | 31 ++++++++++++++---- src/Math/Quaternion.h | 49 +++++++++++++++++++--------- src/Math/Test/DualQuaternionTest.cpp | 9 +++++ src/Math/Test/QuaternionTest.cpp | 9 +++++ 4 files changed, 75 insertions(+), 23 deletions(-) diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 9d3e79902..29aefc127 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -56,7 +56,7 @@ template class DualQuaternion: public Dual> { * @f] * @see rotationAngle(), rotationAxis(), Quaternion::rotation(), * Matrix4::rotation(), DualComplex::rotation(), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis() + * Vector3::yAxis(), Vector3::zAxis(), Vector::isNormalized() */ inline static DualQuaternion rotation(Rad angle, const Vector3& normalizedAxis) { return {Quaternion::rotation(angle, normalizedAxis), {{}, T(0)}}; @@ -132,6 +132,18 @@ template class DualQuaternion: public Dual> { inline constexpr explicit DualQuaternion(const Vector3& vector): Dual>({}, {vector, T(0)}) {} #endif + /** + * @brief Whether the dual quaternion is normalized + * + * Dual quaternion is normalized if it has unit length: @f[ + * |\hat q|^2 = |\hat q| = 1 + \epsilon 0 + * @f] + * @see lengthSquared(), normalized() + */ + inline bool isNormalized() const { + return lengthSquared() == Dual(1); + } + /** * @brief Rotation angle of unit dual quaternion * @@ -240,7 +252,11 @@ template class DualQuaternion: public Dual> { return Math::sqrt(lengthSquared()); } - /** @brief Normalized dual quaternion (of unit length) */ + /** + * @brief Normalized dual quaternion (of unit length) + * + * @see isNormalized() + */ inline DualQuaternion normalized() const { return (*this)/length(); } @@ -264,10 +280,10 @@ template class DualQuaternion: public Dual> { * normalized. @f[ * \hat q^{-1} = \frac{\hat q^*}{|\hat q|^2} = \hat q^* * @f] - * @see inverted() + * @see isNormalized(), inverted() */ inline DualQuaternion invertedNormalized() const { - CORRADE_ASSERT(lengthSquared() == Dual(1), + CORRADE_ASSERT(isNormalized(), "Math::DualQuaternion::invertedNormalized(): dual quaternion must be normalized", {}); return quaternionConjugated(); } @@ -293,11 +309,12 @@ template class DualQuaternion: public Dual> { * quaternion is normalized. @f[ * v' = \hat q v \overline{\hat q^{-1}} = \hat q v \overline{\hat q^*} = \hat q ([\boldsymbol 0, 1] + \epsilon [\boldsymbol v, 0]) \overline{\hat q^*} * @f] - * @see DualQuaternion(const Vector3&), dual(), Matrix4::transformPoint(), - * Quaternion::transformVectorNormalized(), DualComplex::transformPointNormalized() + * @see isNormalized(), DualQuaternion(const Vector3&), dual(), + * Matrix4::transformPoint(), Quaternion::transformVectorNormalized(), + * DualComplex::transformPointNormalized() */ inline Vector3 transformPointNormalized(const Vector3& vector) const { - CORRADE_ASSERT(lengthSquared() == Dual(1), + CORRADE_ASSERT(isNormalized(), "Math::DualQuaternion::transformPointNormalized(): dual quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*DualQuaternion(vector)*conjugated()).dual().vector(); diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index aa5614810..217c852cf 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -107,10 +107,10 @@ template class Quaternion { * Expects that both quaternions are normalized. @f[ * \theta = acos \left( \frac{p \cdot q}{|p| |q|} \right) = acos(p \cdot q) * @f] - * @see Complex::angle(), Vector::angle() + * @see isNormalized(), Complex::angle(), Vector::angle() */ inline static Rad angle(const Quaternion& normalizedA, const Quaternion& normalizedB) { - CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(normalizedA.isNormalized() && normalizedB.isNormalized(), "Math::Quaternion::angle(): quaternions must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(angleInternal(normalizedA, normalizedB)); } @@ -124,10 +124,10 @@ template class Quaternion { * Expects that both quaternions are normalized. @f[ * q_{LERP} = \frac{(1 - t) q_A + t q_B}{|(1 - t) q_A + t q_B|} * @f] - * @see slerp(), Math::lerp() + * @see isNormalized(), slerp(), Math::lerp() */ inline static Quaternion lerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(normalizedA.isNormalized() && normalizedB.isNormalized(), "Math::Quaternion::lerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return ((T(1) - t)*normalizedA + t*normalizedB).normalized(); @@ -144,10 +144,10 @@ template class Quaternion { * ~~~~~~~~~~ * \theta = acos \left( \frac{q_A \cdot q_B}{|q_A| \cdot |q_B|} \right) = acos(q_A \cdot q_B) * @f] - * @see lerp() + * @see isNormalized(), lerp() */ inline static Quaternion slerp(const Quaternion& normalizedA, const Quaternion& normalizedB, T t) { - CORRADE_ASSERT(TypeTraits::equals(normalizedA.dot(), T(1)) && TypeTraits::equals(normalizedB.dot(), T(1)), + CORRADE_ASSERT(normalizedA.isNormalized() && normalizedB.isNormalized(), "Math::Quaternion::slerp(): quaternions must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); T a = angleInternal(normalizedA, normalizedB); @@ -164,10 +164,10 @@ template class Quaternion { * @f] * @see rotationAngle(), rotationAxis(), DualQuaternion::rotation(), * Matrix4::rotation(), Complex::rotation(), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis() + * Vector3::yAxis(), Vector3::zAxis(), Vector::isNormalized() */ inline static Quaternion rotation(Rad angle, const Vector3& normalizedAxis) { - CORRADE_ASSERT(TypeTraits::equals(normalizedAxis.dot(), T(1)), + CORRADE_ASSERT(normalizedAxis.isNormalized(), "Math::Quaternion::rotation(): axis must be normalized", {}); return {normalizedAxis*std::sin(T(angle)/2), std::cos(T(angle)/2)}; @@ -223,6 +223,18 @@ template class Quaternion { return !operator==(other); } + /** + * @brief Whether the quaternion is normalized + * + * Quaternion is normalized if it has unit length: @f[ + * |q|^2 = |q| = 1 + * @f] + * @see dot(), normalized() + */ + inline bool isNormalized() const { + return TypeTraits::equals(dot(), T(1)); + } + /** @brief %Vector part */ inline constexpr Vector3 vector() const { return _vector; } @@ -238,7 +250,7 @@ template class Quaternion { * @see rotationAxis(), rotation(), DualQuaternion::rotationAngle() */ inline Rad rotationAngle() const { - CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(isNormalized(), "Math::Quaternion::rotationAngle(): quaternion must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(T(2)*std::acos(_scalar)); @@ -255,7 +267,7 @@ template class Quaternion { * @see rotationAngle(), rotation() */ inline Vector3 rotationAxis() const { - CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(isNormalized(), "Math::Quaternion::rotationAxis(): quaternion must be normalized", {}); return _vector/std::sqrt(1-pow2(_scalar)); @@ -400,7 +412,7 @@ template class Quaternion { * with other values, because it doesn't compute the square root. @f[ * q \cdot q = \boldsymbol q_V \cdot \boldsymbol q_V + q_S^2 * @f] - * @see dot(const Quaternion&, const Quaternion&) + * @see isNormalized(), dot(const Quaternion&, const Quaternion&) */ inline T dot() const { return dot(*this, *this); @@ -413,12 +425,17 @@ template class Quaternion { * values. @f[ * |q| = \sqrt{q \cdot q} * @f] + * @see isNormalized() */ inline T length() const { return std::sqrt(dot()); } - /** @brief Normalized quaternion (of unit length) */ + /** + * @brief Normalized quaternion (of unit length) + * + * @see isNormalized() + */ inline Quaternion normalized() const { return (*this)/length(); } @@ -453,10 +470,10 @@ template class Quaternion { * normalized. @f[ * q^{-1} = \frac{q^*}{|q|^2} = q^* * @f] - * @see inverted() + * @see isNormalized(), inverted() */ inline Quaternion invertedNormalized() const { - CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(isNormalized(), "Math::Quaternion::invertedNormalized(): quaternion must be normalized", Quaternion({}, std::numeric_limits::quiet_NaN())); return conjugated(); @@ -483,11 +500,11 @@ template class Quaternion { * is normalized. @f[ * v' = qvq^{-1} = qvq^* = q [\boldsymbol v, 0] q^* * @f] - * @see Quaternion(const Vector3&), vector(), Matrix4::transformVector(), + * @see isNormalized(), Quaternion(const Vector3&), vector(), Matrix4::transformVector(), * DualQuaternion::transformPointNormalized(), Complex::transformVector() */ inline Vector3 transformVectorNormalized(const Vector3& vector) const { - CORRADE_ASSERT(TypeTraits::equals(dot(), T(1)), + CORRADE_ASSERT(isNormalized(), "Math::Quaternion::transformVectorNormalized(): quaternion must be normalized", Vector3(std::numeric_limits::quiet_NaN())); return ((*this)*Quaternion(vector)*conjugated()).vector(); diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index cb5011d94..d8594fcfb 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -37,6 +37,8 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void constructDefault(); void constructFromVector(); + void isNormalized(); + void constExpressions(); void lengthSquared(); @@ -72,6 +74,8 @@ DualQuaternionTest::DualQuaternionTest() { &DualQuaternionTest::constructDefault, &DualQuaternionTest::constructFromVector, + &DualQuaternionTest::isNormalized, + &DualQuaternionTest::constExpressions, &DualQuaternionTest::lengthSquared, @@ -109,6 +113,11 @@ void DualQuaternionTest::constructFromVector() { CORRADE_COMPARE(DualQuaternion(Vector3(1.0f, 2.0f, 3.0f)), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); } +void DualQuaternionTest::isNormalized() { + CORRADE_VERIFY(!DualQuaternion({{1.0f, 2.0f, 3.0f}, 4.0f}, {}).isNormalized()); + CORRADE_VERIFY((DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({3.0f, 1.0f, -0.5f})).isNormalized()); +} + void DualQuaternionTest::constExpressions() { /* Default constructor */ constexpr DualQuaternion a; diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 9f9bcc865..18b635da5 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -37,7 +37,9 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void compare(); + void isNormalized(); void constExpressions(); @@ -78,7 +80,9 @@ QuaternionTest::QuaternionTest() { addTests({&QuaternionTest::construct, &QuaternionTest::constructDefault, &QuaternionTest::constructFromVector, + &QuaternionTest::compare, + &QuaternionTest::isNormalized, &QuaternionTest::constExpressions, @@ -129,6 +133,11 @@ void QuaternionTest::compare() { CORRADE_VERIFY(Quaternion({4.0f, 2.0f, 3.0f}, -1.0f+TypeTraits::epsilon()*2) != Quaternion({4.0f, 2.0f, 3.0f}, -1.0f)); } +void QuaternionTest::isNormalized() { + CORRADE_VERIFY(!Quaternion({1.0f, 2.0f, 3.0f}, 4.0f).isNormalized()); + CORRADE_VERIFY(Quaternion::rotation(Deg(23.0f), Vector3::xAxis()).isNormalized()); +} + void QuaternionTest::constExpressions() { /* Default constructor */ constexpr Quaternion a; From da2bbac104f11c8fd13730ef7fefacdb1464ab83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 15:21:10 +0100 Subject: [PATCH 555/567] Math: simplified Matrix::isOrthogonal(). No need to call std::abs() when comparing with zero, as dot() should always be positive. --- src/Math/Matrix.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 432ded0d8..1db788d34 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -114,13 +114,12 @@ template class Matrix: public RectangularMatrix::equals((*this)[i].dot(), T(1))) - return false; + if(!(*this)[i].isNormalized()) return false; /* Orthogonality */ for(std::size_t i = 0; i != size-1; ++i) for(std::size_t j = i+1; j != size; ++j) - if(!TypeTraits::equals(Vector::dot((*this)[i], (*this)[j]), T(0))) + if(Vector::dot((*this)[i], (*this)[j]) > TypeTraits::epsilon()) return false; return true; From e9b322894326089404be55519f5ff94eaaf979cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 15 Mar 2013 15:22:34 +0100 Subject: [PATCH 556/567] SceneGraph: minor code cleanup. --- src/SceneGraph/MatrixTransformation2D.h | 4 ++-- src/SceneGraph/MatrixTransformation3D.h | 4 ++-- src/SceneGraph/RigidMatrixTransformation2D.h | 4 ++-- src/SceneGraph/RigidMatrixTransformation3D.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index e7ad90e40..80b1bd294 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -47,8 +47,8 @@ template #endif class MatrixTransformation2D: public AbstractTranslationRotationScaling2D { public: - /** @brief Transformation matrix type */ - typedef typename DimensionTraits<2, T>::MatrixType DataType; + /** @brief Underlying transformation type */ + typedef Math::Matrix3 DataType; #ifndef DOXYGEN_GENERATING_OUTPUT inline constexpr static Math::Matrix3 fromMatrix(const Math::Matrix3& matrix) { diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 3cc8dd00f..08a36bd77 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -47,8 +47,8 @@ template #endif class MatrixTransformation3D: public AbstractTranslationRotationScaling3D { public: - /** @brief Transformation matrix type */ - typedef typename DimensionTraits<3, T>::MatrixType DataType; + /** @brief Underlying transformation type */ + typedef Math::Matrix4 DataType; #ifndef DOXYGEN_GENERATING_OUTPUT inline constexpr static Math::Matrix4 fromMatrix(const Math::Matrix4& matrix) { diff --git a/src/SceneGraph/RigidMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h index cdc76d65a..4d49c2a5b 100644 --- a/src/SceneGraph/RigidMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -50,8 +50,8 @@ template #endif class RigidMatrixTransformation2D: public AbstractTranslationRotation2D { public: - /** @brief Transformation matrix type */ - typedef typename DimensionTraits<2, T>::MatrixType DataType; + /** @brief Underlying transformation type */ + typedef Math::Matrix3 DataType; #ifndef DOXYGEN_GENERATING_OUTPUT inline static Math::Matrix3 fromMatrix(const Math::Matrix3& matrix) { diff --git a/src/SceneGraph/RigidMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h index e087b7420..9757b2271 100644 --- a/src/SceneGraph/RigidMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -50,8 +50,8 @@ template #endif class RigidMatrixTransformation3D: public AbstractTranslationRotation3D { public: - /** @brief Transformation matrix type */ - typedef typename DimensionTraits<3, T>::MatrixType DataType; + /** @brief Underlying transformation type */ + typedef Math::Matrix4 DataType; #ifndef DOXYGEN_GENERATING_OUTPUT inline static Math::Matrix4 fromMatrix(const Math::Matrix4& matrix) { From 85abf5767eca308fe81fbee39a789ed0de6a10d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 18:05:06 +0100 Subject: [PATCH 557/567] SceneGraph: new class DualComplexTransformation. Uses dual complex numbers for 2D transformation. --- src/SceneGraph/CMakeLists.txt | 2 + src/SceneGraph/DualComplexTransformation.cpp | 35 ++++ src/SceneGraph/DualComplexTransformation.h | 185 ++++++++++++++++++ src/SceneGraph/Object.h | 1 + src/SceneGraph/SceneGraph.h | 2 + src/SceneGraph/Test/CMakeLists.txt | 4 +- .../Test/DualComplexTransformationTest.cpp | 180 +++++++++++++++++ 7 files changed, 408 insertions(+), 1 deletion(-) create mode 100644 src/SceneGraph/DualComplexTransformation.cpp create mode 100644 src/SceneGraph/DualComplexTransformation.h create mode 100644 src/SceneGraph/Test/DualComplexTransformationTest.cpp diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 6ad4f53e4..7f69e96bd 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -26,6 +26,7 @@ set(MagnumSceneGraph_SRCS Animable.cpp Camera.cpp + DualComplexTransformation.cpp RigidMatrixTransformation2D.cpp RigidMatrixTransformation3D.cpp Object.cpp) @@ -54,6 +55,7 @@ set(MagnumSceneGraph_HEADERS Camera3D.h Camera3D.hpp Drawable.h + DualComplexTransformation.h RigidMatrixTransformation2D.h RigidMatrixTransformation3D.h FeatureGroup.h diff --git a/src/SceneGraph/DualComplexTransformation.cpp b/src/SceneGraph/DualComplexTransformation.cpp new file mode 100644 index 000000000..56a1f0af5 --- /dev/null +++ b/src/SceneGraph/DualComplexTransformation.cpp @@ -0,0 +1,35 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "DualComplexTransformation.h" + +#include "Object.hpp" + +namespace Magnum { namespace SceneGraph { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template class MAGNUM_SCENEGRAPH_EXPORT Object>; +#endif + +}} diff --git a/src/SceneGraph/DualComplexTransformation.h b/src/SceneGraph/DualComplexTransformation.h new file mode 100644 index 000000000..8f96126cb --- /dev/null +++ b/src/SceneGraph/DualComplexTransformation.h @@ -0,0 +1,185 @@ +#ifndef Magnum_SceneGraph_DualComplexTransformation_h +#define Magnum_SceneGraph_DualComplexTransformation_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::DualComplexTransformation + */ + +#include "Math/DualComplex.h" +#include "AbstractTranslationRotation2D.h" +#include "Object.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Two-dimensional transformation implemented using dual complex numbers + +This class allows only rigid transformation (i.e. only rotation and +translation). +@see @ref scenegraph, Math::DualComplex, DualQuaternionTransformation +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class DualComplexTransformation: public AbstractTranslationRotation2D { + public: + /** @brief Transformation type */ + typedef Math::DualComplex DataType; + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline static Math::DualComplex fromMatrix(const Math::Matrix3& matrix) { + return Math::DualComplex::fromMatrix(matrix); + } + + inline constexpr static Math::Matrix3 toMatrix(const Math::DualComplex& transformation) { + return transformation.toMatrix(); + } + + inline static Math::DualComplex compose(const Math::DualComplex& parent, const Math::DualComplex& child) { + return parent*child; + } + + inline static Math::DualComplex inverted(const Math::DualComplex& transformation) { + return transformation.invertedNormalized(); + } + + inline Math::DualComplex transformation() const { + return _transformation; + } + #endif + + /** + * @brief Normalize rotation part + * @return Pointer to self (for method chaining) + * + * Normalizes the rotation part to prevent rounding errors when rotating + * the object subsequently. + * @see DualComplex::normalized() + */ + DualComplexTransformation* normalizeRotation() { + setTransformationInternal(_transformation.normalized()); + return this; + } + + /** + * @brief Set transformation + * @return Pointer to self (for method chaining) + * + * Expects that the dual complex number is normalized. + * @see DualComplex::isNormalized() + */ + DualComplexTransformation* setTransformation(const Math::DualComplex& transformation) { + CORRADE_ASSERT(transformation.isNormalized(), + "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized", this); + setTransformationInternal(transformation); + return this; + } + + inline DualComplexTransformation* resetTransformation() override { + setTransformationInternal({}); + return this; + } + + /** + * @brief Transform object + * @param transformation Transformation + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Expects that the dual complex number is normalized. + * @see DualComplex::isNormalized() + */ + inline DualComplexTransformation* transform(const Math::DualComplex& transformation, TransformationType type = TransformationType::Global) { + CORRADE_ASSERT(transformation.isNormalized(), + "SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized", this); + transformInternal(transformation, type); + return this; + } + + /** + * @copydoc AbstractTranslationRotationScaling2D::translate() + * Same as calling transform() with DualComplex::translation(). + */ + inline DualComplexTransformation* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { + transformInternal(Math::DualComplex::translation(vector), type); + return this; + } + + /** + * @brief Rotate object + * @param angle Angle (counterclockwise) + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Same as calling transform() with DualComplex::rotation(). + * @see normalizeRotation() + */ + inline DualComplexTransformation* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) override { + transformInternal(Math::DualComplex::rotation(angle), type); + return this; + } + + /** + * @brief Move object in stacking order + * @param under Sibling object under which to move or `nullptr`, + * if you want to move it above all. + * @return Pointer to self (for method chaining) + */ + inline DualComplexTransformation* move(Object>* under) { + static_cast*>(this)->Corrade::Containers::template LinkedList>>::move(this, under); + return this; + } + + protected: + /* Allow construction only from Object */ + inline explicit DualComplexTransformation() = default; + + private: + /* No assertions fired, for internal use */ + inline void setTransformationInternal(const Math::DualComplex& transformation) { + /* Setting transformation is forbidden for the scene */ + /** @todo Assert for this? */ + /** @todo Do this in some common code so we don't need to include Object? */ + if(!static_cast>*>(this)->isScene()) { + _transformation = transformation; + static_cast>*>(this)->setDirty(); + } + } + + /* No assertions fired, for internal use */ + inline void transformInternal(const Math::DualComplex& transformation, TransformationType type) { + setTransformation(type == TransformationType::Global ? + transformation*_transformation : _transformation*transformation); + } + + Math::DualComplex _transformation; +}; + +}} + +#endif diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 5216fab3c..a712837b2 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -81,6 +81,7 @@ For other specializations (e.g. using Double type or special transformation class) you have to use Object.hpp implementation file to avoid linker errors. See @ref compilation-speedup-hpp for more information. + - @ref DualComplexTransformation "Object>" - @ref MatrixTransformation2D "Object>" - @ref MatrixTransformation3D "Object>" - @ref RigidMatrixTransformation2D "Object>" diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index 61563633f..c316c2aa5 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -98,6 +98,8 @@ template using Drawable2D = Drawable<2, T>; template using Drawable3D = Drawable<3, T>; #endif +template class DualComplexTransformation; + template class FeatureGroup; #ifndef CORRADE_GCC46_COMPATIBILITY template using FeatureGroup2D = FeatureGroup<2, Feature, T>; diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index 8839941a1..b6e8ba3e4 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -24,6 +24,7 @@ corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphDualComplexTransforma___Test DualComplexTransformationTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphMatrixTransformation2DTest MatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphMatrixTransformation3DTest MatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) @@ -31,6 +32,7 @@ corrade_add_test(SceneGraphRigidMatrixTransfor___2DTest RigidMatrixTransformatio corrade_add_test(SceneGraphRigidMatrixTransfor___3DTest RigidMatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) -set_target_properties(SceneGraphRigidMatrixTransfor___2DTest +set_target_properties(SceneGraphDualComplexTransforma___Test + SceneGraphRigidMatrixTransfor___2DTest SceneGraphRigidMatrixTransfor___3DTest PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT") diff --git a/src/SceneGraph/Test/DualComplexTransformationTest.cpp b/src/SceneGraph/Test/DualComplexTransformationTest.cpp new file mode 100644 index 000000000..d9c71d1c9 --- /dev/null +++ b/src/SceneGraph/Test/DualComplexTransformationTest.cpp @@ -0,0 +1,180 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include + +#include "SceneGraph/DualComplexTransformation.h" +#include "SceneGraph/Scene.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +typedef Object> Object2D; +typedef Scene> Scene2D; + +class DualComplexTransformationTest: public Corrade::TestSuite::Tester { + public: + explicit DualComplexTransformationTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); + + void setTransformation(); + void resetTransformation(); + void transform(); + void translate(); + void rotate(); + void normalizeRotation(); +}; + +DualComplexTransformationTest::DualComplexTransformationTest() { + addTests({&DualComplexTransformationTest::fromMatrix, + &DualComplexTransformationTest::toMatrix, + &DualComplexTransformationTest::compose, + &DualComplexTransformationTest::inverted, + + &DualComplexTransformationTest::setTransformation, + &DualComplexTransformationTest::resetTransformation, + &DualComplexTransformationTest::transform, + &DualComplexTransformationTest::translate, + &DualComplexTransformationTest::rotate, + &DualComplexTransformationTest::normalizeRotation}); +} + +void DualComplexTransformationTest::fromMatrix() { + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); + CORRADE_COMPARE(DualComplexTransformation<>::fromMatrix(m), c); +} + +void DualComplexTransformationTest::toMatrix() { + DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); + Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(DualComplexTransformation<>::toMatrix(c), m); +} + +void DualComplexTransformationTest::compose() { + DualComplex parent = DualComplex::rotation(Deg(17.0f)); + DualComplex child = DualComplex::translation({1.0f, -0.3f}); + CORRADE_COMPARE(DualComplexTransformation<>::compose(parent, child), parent*child); +} + +void DualComplexTransformationTest::inverted() { + DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); + CORRADE_COMPARE(DualComplexTransformation<>::inverted(c)*c, DualComplex()); +} + +void DualComplexTransformationTest::setTransformation() { + Object2D o; + + /* Can't transform with non-rigid transformation */ + std::ostringstream out; + Error::setOutput(&out); + o.setTransformation(DualComplex({1.0f, 2.0f}, {})); + CORRADE_COMPARE(out.str(), "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized\n"); + + /* Dirty after setting transformation */ + o.setClean(); + CORRADE_VERIFY(!o.isDirty()); + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + CORRADE_VERIFY(o.isDirty()); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); + + /* Scene cannot be transformed */ + Scene2D s; + s.setClean(); + s.setTransformation(DualComplex::rotation(Deg(17.0f))); + CORRADE_VERIFY(!s.isDirty()); + CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); +} + +void DualComplexTransformationTest::resetTransformation() { + Object2D o; + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); + o.resetTransformation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); +} + +void DualComplexTransformationTest::transform() { + { + /* Can't transform with non-rigid transformation */ + Object2D o; + std::ostringstream out; + Error::setOutput(&out); + o.transform(DualComplex({1.0f, 2.0f}, {})); + CORRADE_COMPARE(out.str(), "SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized\n"); + } { + Object2D o; + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + o.transform(DualComplex::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + } { + Object2D o; + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + o.transform(DualComplex::translation({1.0f, -0.3f}), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } +} + +void DualComplexTransformationTest::translate() { + { + Object2D o; + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + o.translate({1.0f, -0.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + } { + Object2D o; + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + o.translate({1.0f, -0.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } +} + +void DualComplexTransformationTest::rotate() { + { + Object2D o; + o.setTransformation(DualComplex::translation({1.0f, -0.3f})); + o.rotate(Deg(17.0f)); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + } { + Object2D o; + o.setTransformation(DualComplex::translation({1.0f, -0.3f})); + o.rotate(Deg(17.0f), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + } +} + +void DualComplexTransformationTest::normalizeRotation() { + Object2D o; + o.setTransformation(DualComplex::rotation(Deg(17.0f))); + o.normalizeRotation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::DualComplexTransformationTest) From b349eaf753514bccd670834cd95cb16fd6b04d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 18:06:59 +0100 Subject: [PATCH 558/567] SceneGraph: new class DualQuaternionTransformation. Uses dual quaternions for 3D transformation. --- src/SceneGraph/CMakeLists.txt | 2 + .../DualQuaternionTransformation.cpp | 35 ++++ src/SceneGraph/DualQuaternionTransformation.h | 178 ++++++++++++++++ src/SceneGraph/Object.h | 1 + src/SceneGraph/SceneGraph.h | 1 + src/SceneGraph/Test/CMakeLists.txt | 2 + .../Test/DualQuaternionTransformationTest.cpp | 197 ++++++++++++++++++ 7 files changed, 416 insertions(+) create mode 100644 src/SceneGraph/DualQuaternionTransformation.cpp create mode 100644 src/SceneGraph/DualQuaternionTransformation.h create mode 100644 src/SceneGraph/Test/DualQuaternionTransformationTest.cpp diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 7f69e96bd..41bec81e3 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -27,6 +27,7 @@ set(MagnumSceneGraph_SRCS Animable.cpp Camera.cpp DualComplexTransformation.cpp + DualQuaternionTransformation.cpp RigidMatrixTransformation2D.cpp RigidMatrixTransformation3D.cpp Object.cpp) @@ -56,6 +57,7 @@ set(MagnumSceneGraph_HEADERS Camera3D.hpp Drawable.h DualComplexTransformation.h + DualQuaternionTransformation.h RigidMatrixTransformation2D.h RigidMatrixTransformation3D.h FeatureGroup.h diff --git a/src/SceneGraph/DualQuaternionTransformation.cpp b/src/SceneGraph/DualQuaternionTransformation.cpp new file mode 100644 index 000000000..bedf48480 --- /dev/null +++ b/src/SceneGraph/DualQuaternionTransformation.cpp @@ -0,0 +1,35 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "DualQuaternionTransformation.h" + +#include "Object.hpp" + +namespace Magnum { namespace SceneGraph { + +#ifndef DOXYGEN_GENERATING_OUTPUT +template class MAGNUM_SCENEGRAPH_EXPORT Object>; +#endif + +}} diff --git a/src/SceneGraph/DualQuaternionTransformation.h b/src/SceneGraph/DualQuaternionTransformation.h new file mode 100644 index 000000000..4245749c6 --- /dev/null +++ b/src/SceneGraph/DualQuaternionTransformation.h @@ -0,0 +1,178 @@ +#ifndef Magnum_SceneGraph_DualQuaternionTransformation_h +#define Magnum_SceneGraph_DualQuaternionTransformation_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::DualQuaternionTransformation + */ + +#include "Math/DualQuaternion.h" +#include "AbstractTranslationRotation3D.h" +#include "Object.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Three-dimensional transformation implemented using dual quaternions + +This class allows only rigid transformation (i.e. only rotation and +translation). +@see @ref scenegraph, Math::DualQuaternion, DualComplexTransformation +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class DualQuaternionTransformation: public AbstractTranslationRotation3D { + public: + /** @brief Underlying transformation type */ + typedef Math::DualQuaternion DataType; + + #ifndef DOXYGEN_GENERATING_OUTPUT + inline static Math::DualQuaternion fromMatrix(const Math::Matrix4& matrix) { + CORRADE_ASSERT(matrix.isRigidTransformation(), + "SceneGraph::DualQuaternionTransformation::fromMatrix(): the matrix doesn't represent rigid transformation", {}); + return Math::DualQuaternion::fromMatrix(matrix); + } + + inline constexpr static Math::Matrix4 toMatrix(const Math::DualQuaternion& transformation) { + return transformation.toMatrix(); + } + + inline static Math::DualQuaternion compose(const Math::DualQuaternion& parent, const Math::DualQuaternion& child) { + return parent*child; + } + + inline static Math::DualQuaternion inverted(const Math::DualQuaternion& transformation) { + return transformation.invertedNormalized(); + } + + inline Math::DualQuaternion transformation() const { + return _transformation; + } + #endif + + /** + * @brief Normalize rotation part + * @return Pointer to self (for method chaining) + * + * Normalizes the rotation part to prevent rounding errors when rotating + * the object subsequently. + * @see DualQuaternion::normalized() + */ + DualQuaternionTransformation* normalizeRotation() { + setTransformation(_transformation.normalized()); + return this; + } + + /** + * @brief Set transformation + * @return Pointer to self (for method chaining) + * + * Expects that the dual quaternion is normalized. + * @see DualQuaternion::isNormalized() + */ + DualQuaternionTransformation* setTransformation(const Math::DualQuaternion& transformation) { + CORRADE_ASSERT(transformation.isNormalized(), + "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized", this); + setTransformationInternal(transformation); + return this; + } + + inline DualQuaternionTransformation* resetTransformation() override { + setTransformation({}); + return this; + } + + /** + * @brief Multiply transformation + * @param transformation Transformation + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Expects that the dual quaternion is normalized. + * @see DualQuaternion::isNormalized() + */ + inline DualQuaternionTransformation* transform(const Math::DualQuaternion& transformation, TransformationType type = TransformationType::Global) { + CORRADE_ASSERT(transformation.isNormalized(), + "SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized", this); + transformInternal(transformation, type); + return this; + } + + /** + * @copydoc AbstractTranslationRotationScaling3D::translate() + * Same as calling transform() with DualQuaternion::translation(). + */ + inline DualQuaternionTransformation* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { + transformInternal(Math::DualQuaternion::translation(vector), type); + return this; + } + + /** + * @brief Rotate object + * @param angle Angle (counterclockwise) + * @param normalizedAxis Normalized rotation axis + * @param type Transformation type + * @return Pointer to self (for method chaining) + * + * Same as calling transform() with DualQuaternion::rotation(). + * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), + * normalizeRotation() + */ + inline DualQuaternionTransformation* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { + transformInternal(Math::DualQuaternion::rotation(angle, normalizedAxis), type); + return this; + } + + protected: + /* Allow construction only from Object */ + inline explicit DualQuaternionTransformation() = default; + + private: + /* No assertions fired, for internal use */ + inline void setTransformationInternal(const Math::DualQuaternion& transformation) { + /* Setting transformation is forbidden for the scene */ + /** @todo Assert for this? */ + /** @todo Do this in some common code so we don't need to include Object? */ + if(!static_cast>*>(this)->isScene()) { + _transformation = transformation; + static_cast>*>(this)->setDirty(); + } + } + + /* No assertions fired, for internal use */ + inline void transformInternal(const Math::DualQuaternion& transformation, TransformationType type) { + setTransformation(type == TransformationType::Global ? + transformation*_transformation : _transformation*transformation); + } + + Math::DualQuaternion _transformation; +}; + +}} + +#endif diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index a712837b2..07bfc61b1 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -82,6 +82,7 @@ class) you have to use Object.hpp implementation file to avoid linker errors. See @ref compilation-speedup-hpp for more information. - @ref DualComplexTransformation "Object>" + - @ref DualQuaternionTransformation "Object>" - @ref MatrixTransformation2D "Object>" - @ref MatrixTransformation3D "Object>" - @ref RigidMatrixTransformation2D "Object>" diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index c316c2aa5..8e3ccb63e 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -99,6 +99,7 @@ template using Drawable3D = Drawable<3, T>; #endif template class DualComplexTransformation; +template class DualQuaternionTransformation; template class FeatureGroup; #ifndef CORRADE_GCC46_COMPATIBILITY diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index b6e8ba3e4..83101f39e 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -25,6 +25,7 @@ corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphDualComplexTransforma___Test DualComplexTransformationTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphDualQuaternionTransfo___Test DualQuaternionTransformationTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphMatrixTransformation2DTest MatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphMatrixTransformation3DTest MatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) @@ -33,6 +34,7 @@ corrade_add_test(SceneGraphRigidMatrixTransfor___3DTest RigidMatrixTransformatio corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) set_target_properties(SceneGraphDualComplexTransforma___Test + SceneGraphDualQuaternionTransfo___Test SceneGraphRigidMatrixTransfor___2DTest SceneGraphRigidMatrixTransfor___3DTest PROPERTIES COMPILE_FLAGS "-DCORRADE_GRACEFUL_ASSERT") diff --git a/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp b/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp new file mode 100644 index 000000000..6de60f080 --- /dev/null +++ b/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp @@ -0,0 +1,197 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include + +#include "SceneGraph/DualQuaternionTransformation.h" +#include "SceneGraph/Scene.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +typedef Object> Object3D; +typedef Scene> Scene3D; + +class DualQuaternionTransformationTest: public Corrade::TestSuite::Tester { + public: + explicit DualQuaternionTransformationTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); + + void setTransformation(); + void resetTransformation(); + void transform(); + void translate(); + void rotate(); + void normalizeRotation(); +}; + +DualQuaternionTransformationTest::DualQuaternionTransformationTest() { + addTests({&DualQuaternionTransformationTest::fromMatrix, + &DualQuaternionTransformationTest::toMatrix, + &DualQuaternionTransformationTest::compose, + &DualQuaternionTransformationTest::inverted, + + &DualQuaternionTransformationTest::setTransformation, + &DualQuaternionTransformationTest::resetTransformation, + &DualQuaternionTransformationTest::transform, + &DualQuaternionTransformationTest::translate, + &DualQuaternionTransformationTest::rotate, + &DualQuaternionTransformationTest::normalizeRotation}); +} + +void DualQuaternionTransformationTest::fromMatrix() { + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(DualQuaternionTransformation<>::fromMatrix(m), q); +} + +void DualQuaternionTransformationTest::toMatrix() { + DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); + Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(DualQuaternionTransformation<>::toMatrix(q), m); +} + +void DualQuaternionTransformationTest::compose() { + DualQuaternion parent = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis()); + DualQuaternion child = DualQuaternion::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(DualQuaternionTransformation<>::compose(parent, child), parent*child); +} + +void DualQuaternionTransformationTest::inverted() { + DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(DualQuaternionTransformation<>::inverted(q)*q, DualQuaternion()); +} + +void DualQuaternionTransformationTest::setTransformation() { + Object3D o; + + /* Can't transform with non-rigid transformation */ + std::ostringstream out; + Error::setOutput(&out); + o.setTransformation(DualQuaternion({{1.0f, 2.0f, 3.0f}, 4.0f}, {})); + CORRADE_COMPARE(out.str(), "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized\n"); + + /* Dirty after setting transformation */ + o.setClean(); + CORRADE_VERIFY(!o.isDirty()); + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + CORRADE_VERIFY(o.isDirty()); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); + + /* Scene cannot be transformed */ + Scene3D s; + s.setClean(); + CORRADE_VERIFY(!s.isDirty()); + s.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + CORRADE_VERIFY(!s.isDirty()); + CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); +} + +void DualQuaternionTransformationTest::resetTransformation() { + Object3D o; + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); + o.resetTransformation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); +} + +void DualQuaternionTransformationTest::transform() { + { + /* Can't transform with non-rigid transformation */ + Object3D o; + std::ostringstream out; + Error::setOutput(&out); + o.transform(DualQuaternion({{1.0f, 2.0f, 3.0f}, 4.0f}, {})); + CORRADE_COMPARE(out.str(), "SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized\n"); + } { + Object3D o; + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + } { + Object3D o; + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f}), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + } +} + +void DualQuaternionTransformationTest::translate() { + { + Object3D o; + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + o.translate({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + } { + Object3D o; + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + } +} + +void DualQuaternionTransformationTest::rotate() { + { + Object3D o; + o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); + o.rotateX(Deg(17.0f)) + ->rotateY(Deg(25.0f)) + ->rotateZ(Deg(-23.0f)) + ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), + Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* + Matrix4::rotationZ(Deg(-23.0f))* + Matrix4::rotationY(Deg(25.0f))* + Matrix4::rotationX(Deg(17.0f))* + Matrix4::translation({1.0f, -0.3f, 2.3f})); + } { + Object3D o; + o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); + o.rotateX(Deg(17.0f), TransformationType::Local) + ->rotateY(Deg(25.0f), TransformationType::Local) + ->rotateZ(Deg(-23.0f), TransformationType::Local) + ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + CORRADE_COMPARE(o.transformationMatrix(), + Matrix4::translation({1.0f, -0.3f, 2.3f})* + Matrix4::rotationX(Deg(17.0f))* + Matrix4::rotationY(Deg(25.0f))* + Matrix4::rotationZ(Deg(-23.0f))* + Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + } +} + +void DualQuaternionTransformationTest::normalizeRotation() { + Object3D o; + o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + o.normalizeRotation(); + CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::DualQuaternionTransformationTest) From 73a4e9b18ac74281f9ccd0e348e1d419c494eda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 18:37:57 +0100 Subject: [PATCH 559/567] Math: doc++ --- src/Math/Quaternion.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 217c852cf..2d373eae1 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -247,7 +247,8 @@ template class Quaternion { * Expects that the quaternion is normalized. @f[ * \theta = 2 \cdot acos q_S * @f] - * @see rotationAxis(), rotation(), DualQuaternion::rotationAngle() + * @see isNormalized(), rotationAxis(), rotation(), + * DualQuaternion::rotationAngle() */ inline Rad rotationAngle() const { CORRADE_ASSERT(isNormalized(), @@ -264,7 +265,7 @@ template class Quaternion { * default-constructed quaternion. @f[ * \boldsymbol a = \frac{\boldsymbol q_V}{\sqrt{1 - q_S^2}} * @f] - * @see rotationAngle(), rotation() + * @see isNormalized(), rotationAngle(), rotation() */ inline Vector3 rotationAxis() const { CORRADE_ASSERT(isNormalized(), From 3e0e91d7db9ca1a76b08fadea85a0e545af7fcd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 19:21:59 +0100 Subject: [PATCH 560/567] Math: renamed {rotationAngle, rotationAxis}() -> {rotation, angle, axis}(). DualQuaternion and DualComplex has now only rotation() which returns full rotation part, rotationAngle() and rotationAxis() on Quaternion and Complex were renamed to angle() and axis(). --- doc/transformations.dox | 14 ++++++------- src/Math/Complex.h | 6 +++--- src/Math/DualComplex.h | 13 +++++------- src/Math/DualQuaternion.h | 31 +++++++--------------------- src/Math/Quaternion.h | 15 +++++++------- src/Math/Test/ComplexTest.cpp | 6 +++--- src/Math/Test/DualComplexTest.cpp | 11 +++++++--- src/Math/Test/DualQuaternionTest.cpp | 17 +++++++++------ src/Math/Test/QuaternionTest.cpp | 14 ++++++------- 9 files changed, 58 insertions(+), 69 deletions(-) diff --git a/doc/transformations.dox b/doc/transformations.dox index a069e2fe8..138adb951 100644 --- a/doc/transformations.dox +++ b/doc/transformations.dox @@ -243,18 +243,18 @@ Matrix3 c = Matrix3::from(rotation, {1.0f, 3.0f}); @endcode %Complex numbers and quaternions are far better in this regard and they allow -you to extract rotation angle using Complex::rotationAngle(), Quaternion::rotationAngle(), -DualComplex::rotationAngle() or DualQuaternion::rotationAngle(), and rotation -axis in 3D using Quaternion::rotationAxis() or DualQuaternion::rotationAxis(). -It is also possible to extract translation from their dual versions using -DualComplex::translation() const and DualQuaternion::translation() const. +you to extract rotation angle using Complex::angle() or Quaternion::angle() or +rotation axis in 3D using Quaternion::axis(). Their dual versions allow to +extract both rotation and translation part using DualComplex::rotation() const, +DualQuaternion::rotation() const, DualComplex::translation() const and +DualQuaternion::translation() const. @code DualComplex a; -Rad rotation = a.rotationAngle(); +Rad rotationAngle = a.rotation().angle(); Vector2 translation = a.translation(); Quaternion b; -Vector3 rotationAxis = b.rotationAxis(); +Vector3 rotationAxis = b.axis(); @endcode You can convert Complex and Quaternion to rotation matrix using Complex::toMatrix() diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 9b1d36ea3..766d577cb 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -90,7 +90,7 @@ template class Complex { * @f[ * c = cos \theta + i sin \theta * @f] - * @see rotationAngle(), Matrix3::rotation(), Quaternion::rotation() + * @see angle(), Matrix3::rotation(), Quaternion::rotation() */ inline static Complex rotation(Rad angle) { return {std::cos(T(angle)), std::sin(T(angle))}; @@ -182,9 +182,9 @@ template class Complex { * @f[ * \theta = atan2(b, a) * @f] - * @see rotation(), DualComplex::rotationAngle() + * @see rotation() */ - inline Rad rotationAngle() const { + inline Rad angle() const { return Rad(std::atan2(_imaginary, _real)); } diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 6854c4f6a..1655ac529 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -55,7 +55,7 @@ template class DualComplex: public Dual> { * @f[ * \hat c = (cos \theta + i sin \theta) + \epsilon (0 + i0) * @f] - * @see rotationAngle(), Complex::rotation(), Matrix3::rotation(), + * @see angle(), Complex::rotation(), Matrix3::rotation(), * DualQuaternion::rotation() */ inline static DualComplex rotation(Rad angle) { @@ -139,15 +139,12 @@ template class DualComplex: public Dual> { } /** - * @brief Rotation angle of dual complex number + * @brief Rotation part of dual complex number * - * @f[ - * \theta = atan2(b_0, a_0) - * @f] - * @see rotation(), Complex::rotationAngle() + * @see Complex::angle() */ - inline Rad rotationAngle() const { - return this->real().rotationAngle(); + inline constexpr Complex rotation() const { + return this->real(); } /** diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 29aefc127..6d6e86cf3 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -54,9 +54,9 @@ template class DualQuaternion: public Dual> { * Expects that the rotation axis is normalized. @f[ * \hat q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] + \epsilon [\boldsymbol 0, 0] * @f] - * @see rotationAngle(), rotationAxis(), Quaternion::rotation(), - * Matrix4::rotation(), DualComplex::rotation(), Vector3::xAxis(), - * Vector3::yAxis(), Vector3::zAxis(), Vector::isNormalized() + * @see rotation() const, Quaternion::rotation(), Matrix4::rotation(), + * DualComplex::rotation(), Vector3::xAxis(), Vector3::yAxis(), + * Vector3::zAxis(), Vector::isNormalized() */ inline static DualQuaternion rotation(Rad angle, const Vector3& normalizedAxis) { return {Quaternion::rotation(angle, normalizedAxis), {{}, T(0)}}; @@ -145,29 +145,12 @@ template class DualQuaternion: public Dual> { } /** - * @brief Rotation angle of unit dual quaternion + * @brief Rotation part of unit dual quaternion * - * Expects that the real part of the quaternion is normalized. @f[ - * \theta = 2 \cdot acos q_{S 0} - * @f] - * @see rotationAxis(), rotation(), Quaternion::rotationAngle() - */ - inline Math::Rad rotationAngle() const { - return this->real().rotationAngle(); - } - - /** - * @brief Rotation axis of unit dual quaternion - * - * Expects that the quaternion is normalized. Returns either unit-length - * vector for valid rotation quaternion or NaN vector for - * default-constructed quaternion. @f[ - * \boldsymbol a = \frac{\boldsymbol q_{V 0}}{\sqrt{1 - q_{S 0}^2}} - * @f] - * @see rotationAngle(), rotation(), Quaternion::rotationAxis() + * @see Quaternion::angle(), Quaternion::axis() */ - inline Vector3 rotationAxis() const { - return this->real().rotationAxis(); + inline constexpr Quaternion rotation() const { + return this->real(); } /** diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 2d373eae1..0e3f77503 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -162,7 +162,7 @@ template class Quaternion { * Expects that the rotation axis is normalized. @f[ * q = [\boldsymbol a \cdot sin \frac \theta 2, cos \frac \theta 2] * @f] - * @see rotationAngle(), rotationAxis(), DualQuaternion::rotation(), + * @see angle(), axis(), DualQuaternion::rotation(), * Matrix4::rotation(), Complex::rotation(), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis(), Vector::isNormalized() */ @@ -247,12 +247,11 @@ template class Quaternion { * Expects that the quaternion is normalized. @f[ * \theta = 2 \cdot acos q_S * @f] - * @see isNormalized(), rotationAxis(), rotation(), - * DualQuaternion::rotationAngle() + * @see isNormalized(), axis(), rotation() */ - inline Rad rotationAngle() const { + inline Rad angle() const { CORRADE_ASSERT(isNormalized(), - "Math::Quaternion::rotationAngle(): quaternion must be normalized", + "Math::Quaternion::angle(): quaternion must be normalized", Rad(std::numeric_limits::quiet_NaN())); return Rad(T(2)*std::acos(_scalar)); } @@ -265,11 +264,11 @@ template class Quaternion { * default-constructed quaternion. @f[ * \boldsymbol a = \frac{\boldsymbol q_V}{\sqrt{1 - q_S^2}} * @f] - * @see isNormalized(), rotationAngle(), rotation() + * @see isNormalized(), angle(), rotation() */ - inline Vector3 rotationAxis() const { + inline Vector3 axis() const { CORRADE_ASSERT(isNormalized(), - "Math::Quaternion::rotationAxis(): quaternion must be normalized", + "Math::Quaternion::axis(): quaternion must be normalized", {}); return _vector/std::sqrt(1-pow2(_scalar)); } diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index 931a66ead..ae5b2a6e4 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -273,15 +273,15 @@ void ComplexTest::rotation() { Complex a = Complex::rotation(Deg(120.0f)); CORRADE_COMPARE(a.length(), 1.0f); CORRADE_COMPARE(a, Complex(-0.5f, 0.8660254f)); - CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); + CORRADE_COMPARE_AS(a.angle(), Deg(120.0f), Rad); /* Verify negative angle */ Complex b = Complex::rotation(Deg(-240.0f)); CORRADE_COMPARE(b, Complex(-0.5f, 0.8660254f)); - CORRADE_COMPARE_AS(b.rotationAngle(), Deg(120.0f), Rad); + CORRADE_COMPARE_AS(b.angle(), Deg(120.0f), Rad); /* Default-constructed complex number has zero angle */ - CORRADE_COMPARE_AS(Complex().rotationAngle(), Deg(0.0f), Rad); + CORRADE_COMPARE_AS(Complex().angle(), Deg(0.0f), Rad); } void ComplexTest::matrix() { diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 9d8db2094..6ea187159 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -207,7 +207,12 @@ void DualComplexTest::rotation() { DualComplex a = DualComplex::rotation(Deg(120.0f)); CORRADE_COMPARE(a.length(), 1.0f); CORRADE_COMPARE(a, DualComplex({-0.5f, 0.8660254f}, {0.0f, 0.0f})); - CORRADE_COMPARE_AS(a.rotationAngle(), Deg(120.0f), Rad); + CORRADE_COMPARE_AS(a.rotation().angle(), Deg(120.0f), Rad); + + /* Constexpr access to rotation */ + constexpr DualComplex b({-1.0f, 2.0f}, {}); + constexpr Complex c = b.rotation(); + CORRADE_COMPARE(c, Complex(-1.0f, 2.0f)); } void DualComplexTest::translation() { @@ -223,8 +228,8 @@ void DualComplexTest::combinedTransformParts() { DualComplex a = DualComplex::translation(translation)*DualComplex::rotation(Deg(23.0f)); DualComplex b = DualComplex::rotation(Deg(23.0f))*DualComplex::translation(translation); - CORRADE_COMPARE_AS(a.rotationAngle(), Deg(23.0f), Rad); - CORRADE_COMPARE_AS(b.rotationAngle(), Deg(23.0f), Rad); + CORRADE_COMPARE_AS(a.rotation().angle(), Deg(23.0f), Rad); + CORRADE_COMPARE_AS(b.rotation().angle(), Deg(23.0f), Rad); CORRADE_COMPARE(a.translation(), translation); CORRADE_COMPARE(b.translation(), Complex::rotation(Deg(23.0f)).transformVector(translation)); } diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index d8594fcfb..db6809b26 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -210,8 +210,13 @@ void DualQuaternionTest::rotation() { DualQuaternion q = DualQuaternion::rotation(Deg(120.0f), axis); CORRADE_COMPARE(q.length(), 1.0f); CORRADE_COMPARE(q, DualQuaternion({Vector3(0.5f, 0.5f, 0.5f), 0.5f}, {{}, 0.0f})); - CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); - CORRADE_COMPARE(q.rotationAxis(), axis); + CORRADE_COMPARE_AS(q.rotation().angle(), Deg(120.0f), Deg); + CORRADE_COMPARE(q.rotation().axis(), axis); + + /* Constexpr access to rotation */ + constexpr DualQuaternion b({{-1.0f, 2.0f, 3.0f}, 4.0f}, {}); + constexpr Quaternion c = b.rotation(); + CORRADE_COMPARE(c, Quaternion({-1.0f, 2.0f, 3.0f}, 4.0f)); } void DualQuaternionTest::translation() { @@ -227,10 +232,10 @@ void DualQuaternionTest::combinedTransformParts() { DualQuaternion a = DualQuaternion::translation(translation)*DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis()); DualQuaternion b = DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation(translation); - CORRADE_COMPARE(a.rotationAxis(), Vector3::xAxis()); - CORRADE_COMPARE(b.rotationAxis(), Vector3::xAxis()); - CORRADE_COMPARE_AS(a.rotationAngle(), Deg(23.0f), Rad); - CORRADE_COMPARE_AS(b.rotationAngle(), Deg(23.0f), Rad); + CORRADE_COMPARE(a.rotation().axis(), Vector3::xAxis()); + CORRADE_COMPARE(b.rotation().axis(), Vector3::xAxis()); + CORRADE_COMPARE_AS(a.rotation().angle(), Deg(23.0f), Rad); + CORRADE_COMPARE_AS(b.rotation().angle(), Deg(23.0f), Rad); CORRADE_COMPARE(a.translation(), translation); CORRADE_COMPARE(b.translation(), Quaternion::rotation(Deg(23.0f), Vector3::xAxis()).transformVector(translation)); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 18b635da5..4ffefcdd2 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -255,19 +255,19 @@ void QuaternionTest::rotation() { Quaternion q = Quaternion::rotation(Deg(120.0f), axis); CORRADE_COMPARE(q.length(), 1.0f); CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f)); - CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); - CORRADE_COMPARE(q.rotationAxis(), axis); - CORRADE_COMPARE(q.rotationAxis().length(), 1.0f); + CORRADE_COMPARE_AS(q.angle(), Deg(120.0f), Deg); + CORRADE_COMPARE(q.axis(), axis); + CORRADE_COMPARE(q.axis().length(), 1.0f); /* Verify negative angle */ Quaternion q2 = Quaternion::rotation(Deg(-120.0f), axis); CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f)); - CORRADE_COMPARE_AS(q2.rotationAngle(), Deg(120.0f), Deg); - CORRADE_COMPARE(q2.rotationAxis(), -axis); + CORRADE_COMPARE_AS(q2.angle(), Deg(120.0f), Deg); + CORRADE_COMPARE(q2.axis(), -axis); /* Default-constructed quaternion has zero angle and NaN axis */ - CORRADE_COMPARE_AS(Quaternion().rotationAngle(), Deg(0.0f), Deg); - CORRADE_VERIFY(Quaternion().rotationAxis() != Quaternion().rotationAxis()); + CORRADE_COMPARE_AS(Quaternion().angle(), Deg(0.0f), Deg); + CORRADE_VERIFY(Quaternion().axis() != Quaternion().axis()); } void QuaternionTest::angle() { From b28b90a9df32f67ec573c9397567f9d2e0e8c480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 21:12:51 +0100 Subject: [PATCH 561/567] Math: merged constExpressions() test cases into other test cases. Simplifies the code and reduces duplicates. --- src/Math/Test/ComplexTest.cpp | 61 +++++++++++----------------- src/Math/Test/DualComplexTest.cpp | 48 +++++++++------------- src/Math/Test/DualQuaternionTest.cpp | 49 ++++++++++------------ src/Math/Test/DualTest.cpp | 53 ++++++++++-------------- src/Math/Test/QuaternionTest.cpp | 54 +++++++++--------------- 5 files changed, 105 insertions(+), 160 deletions(-) diff --git a/src/Math/Test/ComplexTest.cpp b/src/Math/Test/ComplexTest.cpp index ae5b2a6e4..ecf939ada 100644 --- a/src/Math/Test/ComplexTest.cpp +++ b/src/Math/Test/ComplexTest.cpp @@ -37,12 +37,11 @@ class ComplexTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void constructCopy(); void compare(); void isNormalized(); - void constExpressions(); - void addSubtract(); void negated(); void multiplyDivideScalar(); @@ -69,12 +68,11 @@ ComplexTest::ComplexTest() { addTests({&ComplexTest::construct, &ComplexTest::constructDefault, &ComplexTest::constructFromVector, + &ComplexTest::constructCopy, &ComplexTest::compare, &ComplexTest::isNormalized, - &ComplexTest::constExpressions, - &ComplexTest::addSubtract, &ComplexTest::negated, &ComplexTest::multiplyDivideScalar, @@ -105,22 +103,35 @@ typedef Math::Matrix3 Matrix3; typedef Math::Matrix<2, Float> Matrix2; void ComplexTest::construct() { - Complex c(0.5f, -3.7f); - CORRADE_COMPARE(c.real(), 0.5f); - CORRADE_COMPARE(c.imaginary(), -3.7f); + constexpr Complex a(0.5f, -3.7f); + CORRADE_COMPARE(a, Complex(0.5f, -3.7f)); + + constexpr Float b = a.real(); + constexpr Float c = a.imaginary(); + CORRADE_COMPARE(b, 0.5f); + CORRADE_COMPARE(c, -3.7f); } void ComplexTest::constructDefault() { - CORRADE_COMPARE(Complex(), Complex(1.0f, 0.0f)); - CORRADE_COMPARE(Complex().length(), 1.0f); + constexpr Complex a; + CORRADE_COMPARE(a, Complex(1.0f, 0.0f)); + CORRADE_COMPARE(a.length(), 1.0f); } void ComplexTest::constructFromVector() { - Vector2 vec(1.5f, -3.0f); + constexpr Vector2 vec(1.5f, -3.0f); - Complex a(vec); + constexpr Complex a(vec); CORRADE_COMPARE(a, Complex(1.5f, -3.0f)); - CORRADE_COMPARE(Vector2(a), vec); + + constexpr Vector2 b(a); + CORRADE_COMPARE(b, vec); +} + +void ComplexTest::constructCopy() { + constexpr Complex a(2.5f, -5.0f); + constexpr Complex b(a); + CORRADE_COMPARE(b, Complex(2.5f, -5.0f)); } void ComplexTest::compare() { @@ -135,32 +146,6 @@ void ComplexTest::isNormalized() { CORRADE_VERIFY(Complex::rotation(Deg(23.0f)).isNormalized()); } -void ComplexTest::constExpressions() { - /* Default constructor */ - constexpr Complex a; - CORRADE_COMPARE(a, Complex(1.0f, 0.0f)); - - /* Value constructor */ - constexpr Complex b(2.5f, -5.0f); - CORRADE_COMPARE(b, Complex(2.5f, -5.0f)); - - /* Vector constructor */ - constexpr Complex c(Vector2(-1.0f, 2.2f)); - CORRADE_COMPARE(c, Complex(-1.0f, 2.2f)); - - /* Copy constructor */ - constexpr Complex d(b); - CORRADE_COMPARE(d, Complex(2.5f, -5.0f)); - - /* Data access */ - constexpr Float e = b.real(); - constexpr Float f = b.imaginary(); - constexpr Vector2 g(b); - CORRADE_COMPARE(e, 2.5f); - CORRADE_COMPARE(f, -5.0f); - CORRADE_COMPARE(g, Vector2(2.5f, -5.0f)); -} - void ComplexTest::addSubtract() { Complex a( 1.7f, -3.7f); Complex b(-3.6f, 0.2f); diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 6ea187159..9e8f0ca20 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -37,11 +37,10 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void constructCopy(); void isNormalized(); - void constExpressions(); - void multiply(); void lengthSquared(); @@ -75,11 +74,10 @@ DualComplexTest::DualComplexTest() { addTests({&DualComplexTest::construct, &DualComplexTest::constructDefault, &DualComplexTest::constructFromVector, + &DualComplexTest::constructCopy, &DualComplexTest::isNormalized, - &DualComplexTest::constExpressions, - &DualComplexTest::multiply, &DualComplexTest::lengthSquared, @@ -102,18 +100,30 @@ DualComplexTest::DualComplexTest() { } void DualComplexTest::construct() { - DualComplex a({-1.0f, 2.5f}, {3.0f, -7.5f}); - CORRADE_COMPARE(a.real(), Complex(-1.0f, 2.5f)); - CORRADE_COMPARE(a.dual(), Complex(3.0f, -7.5f)); + constexpr DualComplex a({-1.0f, 2.5f}, {3.0f, -7.5f}); + CORRADE_COMPARE(a, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); + + constexpr Complex b = a.real(); + constexpr Complex c = a.dual(); + CORRADE_COMPARE(b, Complex(-1.0f, 2.5f)); + CORRADE_COMPARE(c, Complex(3.0f, -7.5f)); } void DualComplexTest::constructDefault() { - CORRADE_COMPARE(DualComplex(), DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); - CORRADE_COMPARE(DualComplex().length(), 1.0f); + constexpr DualComplex a; + CORRADE_COMPARE(a, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); + CORRADE_COMPARE(a.length(), 1.0f); } void DualComplexTest::constructFromVector() { - CORRADE_COMPARE(DualComplex(Vector2(1.5f, -3.0f)), DualComplex({1.0f, 0.0f}, {1.5f, -3.0f})); + constexpr DualComplex a(Vector2(1.5f, -3.0f)); + CORRADE_COMPARE(a, DualComplex({1.0f, 0.0f}, {1.5f, -3.0f})); +} + +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})); } void DualComplexTest::isNormalized() { @@ -121,24 +131,6 @@ void DualComplexTest::isNormalized() { CORRADE_VERIFY((DualComplex::rotation(Deg(23.0f))*DualComplex::translation({6.0f, 3.0f})).isNormalized()); } -void DualComplexTest::constExpressions() { - /* Default constructor */ - constexpr DualComplex a; - CORRADE_COMPARE(a, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f})); - - /* Value constructor */ - constexpr DualComplex b({-1.0f, 2.5f}, {3.0f, -7.5f}); - CORRADE_COMPARE(b, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); - - /* Vector constructor */ - constexpr DualComplex c(Vector2(-3.0f, 7.5f)); - CORRADE_COMPARE(c, DualComplex({}, {-3.0f, 7.5f})); - - /* Copy constructor */ - constexpr DualComplex d(b); - CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {3.0f, -7.5f})); -} - void DualComplexTest::multiply() { DualComplex a({-1.5f, 2.0f}, { 3.0f, -6.5f}); DualComplex b({ 2.0f, -7.5f}, {-0.5f, 1.0f});; diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index db6809b26..f25594961 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -36,11 +36,10 @@ class DualQuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void constructCopy(); void isNormalized(); - void constExpressions(); - void lengthSquared(); void length(); void normalized(); @@ -73,11 +72,10 @@ DualQuaternionTest::DualQuaternionTest() { addTests({&DualQuaternionTest::construct, &DualQuaternionTest::constructDefault, &DualQuaternionTest::constructFromVector, + &DualQuaternionTest::constructCopy, &DualQuaternionTest::isNormalized, - &DualQuaternionTest::constExpressions, - &DualQuaternionTest::lengthSquared, &DualQuaternionTest::length, &DualQuaternionTest::normalized, @@ -99,18 +97,31 @@ DualQuaternionTest::DualQuaternionTest() { } void DualQuaternionTest::construct() { - DualQuaternion q({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.1f, 3.3f}, 2.0f}); - CORRADE_COMPARE(q.real(), Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); - CORRADE_COMPARE(q.dual(), Quaternion({0.5f, -3.1f, 3.3f}, 2.0f)); + constexpr DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.1f, 3.3f}, 2.0f}); + CORRADE_COMPARE(a, DualQuaternion({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.1f, 3.3f}, 2.0f})); + + constexpr Quaternion b = a.real(); + CORRADE_COMPARE(b, Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + + constexpr Quaternion c = a.dual(); + CORRADE_COMPARE(c, Quaternion({0.5f, -3.1f, 3.3f}, 2.0f)); } void DualQuaternionTest::constructDefault() { - CORRADE_COMPARE(DualQuaternion(), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); - CORRADE_COMPARE(DualQuaternion().length(), 1.0f); + constexpr DualQuaternion a; + CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); + CORRADE_COMPARE(a.length(), 1.0f); } void DualQuaternionTest::constructFromVector() { - CORRADE_COMPARE(DualQuaternion(Vector3(1.0f, 2.0f, 3.0f)), DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); + constexpr DualQuaternion a(Vector3(1.0f, 2.0f, 3.0f)); + CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.0f, 2.0f, 3.0f}, 0.0f})); +} + +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})); } void DualQuaternionTest::isNormalized() { @@ -118,24 +129,6 @@ void DualQuaternionTest::isNormalized() { CORRADE_VERIFY((DualQuaternion::rotation(Deg(23.0f), Vector3::xAxis())*DualQuaternion::translation({3.0f, 1.0f, -0.5f})).isNormalized()); } -void DualQuaternionTest::constExpressions() { - /* Default constructor */ - constexpr DualQuaternion a; - CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); - - /* Value constructor */ - constexpr DualQuaternion b({{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})); - - /* Vector constructor */ - constexpr DualQuaternion c(Vector3(1.5f, -5.0f, 3.0f)); - CORRADE_COMPARE(c, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{1.5f, -5.0f, 3.0f}, 0.0f})); - - /* Copy constructor */ - constexpr DualQuaternion d(b); - CORRADE_COMPARE(d, DualQuaternion({{1.0f, 2.0f, -3.0f}, -3.5f}, {{4.5f, -7.0f, 2.0f}, 1.0f})); -} - void DualQuaternionTest::lengthSquared() { DualQuaternion a({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.5f, -3.0f, 3.0f}, 2.0f}); CORRADE_COMPARE(a.lengthSquared(), Dual(30.0f, -9.0f)); diff --git a/src/Math/Test/DualTest.cpp b/src/Math/Test/DualTest.cpp index dd6338f0c..1bf0c2da7 100644 --- a/src/Math/Test/DualTest.cpp +++ b/src/Math/Test/DualTest.cpp @@ -35,9 +35,9 @@ class DualTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); - void compare(); + void constructCopy(); - void constExpressions(); + void compare(); void addSubtract(); void negated(); @@ -54,9 +54,9 @@ typedef Math::Dual Dual; DualTest::DualTest() { addTests({&DualTest::construct, &DualTest::constructDefault, - &DualTest::compare, + &DualTest::constructCopy, - &DualTest::constExpressions, + &DualTest::compare, &DualTest::addSubtract, &DualTest::negated, @@ -69,17 +69,26 @@ DualTest::DualTest() { } void DualTest::construct() { - Dual a(2.0f, -7.5f); - CORRADE_COMPARE(a.real(), 2.0f); - CORRADE_COMPARE(a.dual(), -7.5f); - - Dual b(3.0f); - CORRADE_COMPARE(b.real(), 3.0f); - CORRADE_COMPARE(b.dual(), 0.0f); + constexpr Dual a(2.0f, -7.5f); + constexpr Float b = a.real(); + constexpr Float c = a.dual(); + CORRADE_COMPARE(b, 2.0f); + CORRADE_COMPARE(c, -7.5f); + + constexpr Dual d(3.0f); + CORRADE_COMPARE(d.real(), 3.0f); + CORRADE_COMPARE(d.dual(), 0.0f); } void DualTest::constructDefault() { - CORRADE_COMPARE(Dual(), Dual(0.0f, 0.0f)); + constexpr Dual a; + CORRADE_COMPARE(a, Dual(0.0f, 0.0f)); +} + +void DualTest::constructCopy() { + constexpr Dual a(2.0f, 3.0f); + constexpr Dual b(a); + CORRADE_COMPARE(b, Dual(2.0f, 3.0f)); } void DualTest::compare() { @@ -93,26 +102,6 @@ void DualTest::compare() { CORRADE_VERIFY(Dual(1.0f, 3.0f) != 1.0f); } -void DualTest::constExpressions() { - /* Default constructor */ - constexpr Dual a; - CORRADE_COMPARE(a, Dual(0.0f, 0.0f)); - - /* Value constructor */ - constexpr Dual b(2.0f, 3.0f); - CORRADE_COMPARE(b, Dual(2.0f, 3.0f)); - - /* Copy constructor */ - constexpr Dual c(b); - CORRADE_COMPARE(c, Dual(2.0f, 3.0f)); - - /* Data access */ - constexpr Float e = b.real(); - constexpr Float f = b.dual(); - CORRADE_COMPARE(e, 2.0f); - CORRADE_COMPARE(f, 3.0f); -} - void DualTest::addSubtract() { Dual a(2.0f, -7.5f); Dual b(-3.3f, 0.2f); diff --git a/src/Math/Test/QuaternionTest.cpp b/src/Math/Test/QuaternionTest.cpp index 4ffefcdd2..7cd6fc1d1 100644 --- a/src/Math/Test/QuaternionTest.cpp +++ b/src/Math/Test/QuaternionTest.cpp @@ -37,12 +37,11 @@ class QuaternionTest: public Corrade::TestSuite::Tester { void construct(); void constructDefault(); void constructFromVector(); + void constructCopy(); void compare(); void isNormalized(); - void constExpressions(); - void addSubtract(); void negated(); void multiplyDivideScalar(); @@ -80,12 +79,11 @@ QuaternionTest::QuaternionTest() { addTests({&QuaternionTest::construct, &QuaternionTest::constructDefault, &QuaternionTest::constructFromVector, + &QuaternionTest::constructCopy, &QuaternionTest::compare, &QuaternionTest::isNormalized, - &QuaternionTest::constExpressions, - &QuaternionTest::addSubtract, &QuaternionTest::negated, &QuaternionTest::multiplyDivideScalar, @@ -112,18 +110,30 @@ QuaternionTest::QuaternionTest() { } void QuaternionTest::construct() { - Quaternion q({1.0f, 2.0f, 3.0f}, -4.0f); - CORRADE_COMPARE(q.vector(), Vector3(1.0f, 2.0f, 3.0f)); - CORRADE_COMPARE(q.scalar(), -4.0f); + constexpr Quaternion a({1.0f, 2.0f, 3.0f}, -4.0f); + CORRADE_COMPARE(a, Quaternion({1.0f, 2.0f, 3.0f}, -4.0f)); + + constexpr Vector3 b = a.vector(); + constexpr Float c = a.scalar(); + CORRADE_COMPARE(b, Vector3(1.0f, 2.0f, 3.0f)); + CORRADE_COMPARE(c, -4.0f); } void QuaternionTest::constructDefault() { - CORRADE_COMPARE(Quaternion(), Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); - CORRADE_COMPARE(Quaternion().length(), 1.0f); + constexpr Quaternion a; + CORRADE_COMPARE(a, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); + CORRADE_COMPARE(a.length(), 1.0f); } void QuaternionTest::constructFromVector() { - CORRADE_COMPARE(Quaternion(Vector3(1.0f, 2.0f, 3.0f)), Quaternion({1.0f, 2.0f, 3.0f}, 0.0f)); + constexpr Quaternion a(Vector3(1.0f, 2.0f, 3.0f)); + CORRADE_COMPARE(a, Quaternion({1.0f, 2.0f, 3.0f}, 0.0f)); +} + +void QuaternionTest::constructCopy() { + constexpr Quaternion a({1.0f, -3.0f, 7.0f}, 2.5f); + constexpr Quaternion b(a); + CORRADE_COMPARE(b, Quaternion({1.0f, -3.0f, 7.0f}, 2.5f)); } void QuaternionTest::compare() { @@ -138,30 +148,6 @@ void QuaternionTest::isNormalized() { CORRADE_VERIFY(Quaternion::rotation(Deg(23.0f), Vector3::xAxis()).isNormalized()); } -void QuaternionTest::constExpressions() { - /* Default constructor */ - constexpr Quaternion a; - CORRADE_COMPARE(a, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f)); - - /* Value constructor */ - constexpr Quaternion b({1.0f, -3.0f, 7.0f}, 2.5f); - CORRADE_COMPARE(b, Quaternion({1.0f, -3.0f, 7.0f}, 2.5f)); - - /* Construct from vector */ - constexpr Quaternion c(Vector3(2.0f, -3.0f, 1.5f)); - CORRADE_COMPARE(c, Quaternion({2.0f, -3.0f, 1.5f}, 0.0f)); - - /* Copy constructor */ - constexpr Quaternion d(b); - CORRADE_COMPARE(d, Quaternion({1.0f, -3.0f, 7.0f}, 2.5f)); - - /* Data access */ - constexpr Vector3 e = b.vector(); - constexpr Float f = b.scalar(); - CORRADE_COMPARE(e, Vector3(1.0f, -3.0f, 7.0f)); - CORRADE_COMPARE(f, 2.5f); -} - void QuaternionTest::addSubtract() { Quaternion a({ 1.0f, 3.0f, -2.0f}, -4.0f); Quaternion b({-0.5f, 1.4f, 3.0f}, 12.0f); From 7cb79b145e069bdc1aedf1a104bcad609078f6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 21:13:27 +0100 Subject: [PATCH 562/567] Math: test Constants constexpr. --- src/Math/Test/ConstantsTest.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index 98211496b..eef26316f 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -41,11 +41,15 @@ ConstantsTest::ConstantsTest() { } void ConstantsTest::constants() { - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0f); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0f); - - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt2()), 2.0); - CORRADE_COMPARE(Math::pow<2>(Constants::sqrt3()), 3.0); + 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); + + 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); } }}} From 4744b631bbbdfcaddde41e472e518b067c317ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 21:13:46 +0100 Subject: [PATCH 563/567] Math: test pow() constexpr. --- src/Math/Test/FunctionsTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Math/Test/FunctionsTest.cpp b/src/Math/Test/FunctionsTest.cpp index 55191dd1b..2d178c166 100644 --- a/src/Math/Test/FunctionsTest.cpp +++ b/src/Math/Test/FunctionsTest.cpp @@ -259,6 +259,10 @@ void FunctionsTest::pow() { CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); CORRADE_COMPARE(Math::pow<2>(2.0f), 4.0f); + + /* Constant expression */ + constexpr Int a = Math::pow<3>(5); + CORRADE_COMPARE(a, 125); } void FunctionsTest::log() { From f4f44d9d9068b05d24d60d2e54300c704f59c2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 16 Mar 2013 21:25:48 +0100 Subject: [PATCH 564/567] Math: allow creating DualComplex/DualQuaternion from real part only. Useful when creating transformation from rotation only. --- src/Math/DualComplex.h | 2 +- src/Math/DualQuaternion.h | 2 +- src/Math/Test/DualComplexTest.cpp | 3 +++ src/Math/Test/DualQuaternionTest.cpp | 3 +++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index 1655ac529..d008b78e0 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -110,7 +110,7 @@ template class DualComplex: public Dual> { * \hat c = c_0 + \epsilon c_\epsilon * @f] */ - inline constexpr /*implicit*/ DualComplex(const Complex& real, const Complex& dual): Dual>(real, dual) {} + inline constexpr /*implicit*/ DualComplex(const Complex& real, const Complex& dual = Complex(T(0), T(0))): Dual>(real, dual) {} /** * @brief Construct dual complex number from vector diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index 6d6e86cf3..c3e8002cc 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -115,7 +115,7 @@ template class DualQuaternion: public Dual> { * \hat q = q_0 + \epsilon q_\epsilon * @f] */ - inline constexpr /*implicit*/ DualQuaternion(const Quaternion& real, const Quaternion& dual): Dual>(real, dual) {} + inline constexpr /*implicit*/ DualQuaternion(const Quaternion& real, const Quaternion& dual = Quaternion({}, T(0))): Dual>(real, dual) {} /** * @brief Construct dual quaternion from vector diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 9e8f0ca20..d0ddce9f5 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -107,6 +107,9 @@ void DualComplexTest::construct() { constexpr Complex c = a.dual(); CORRADE_COMPARE(b, Complex(-1.0f, 2.5f)); CORRADE_COMPARE(c, Complex(3.0f, -7.5f)); + + constexpr DualComplex d(Complex(-1.0f, 2.5f)); + CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {0.0f, 0.0f})); } void DualComplexTest::constructDefault() { diff --git a/src/Math/Test/DualQuaternionTest.cpp b/src/Math/Test/DualQuaternionTest.cpp index f25594961..d0dc65039 100644 --- a/src/Math/Test/DualQuaternionTest.cpp +++ b/src/Math/Test/DualQuaternionTest.cpp @@ -105,6 +105,9 @@ void DualQuaternionTest::construct() { constexpr Quaternion c = a.dual(); CORRADE_COMPARE(c, Quaternion({0.5f, -3.1f, 3.3f}, 2.0f)); + + constexpr DualQuaternion d({{1.0f, 2.0f, 3.0f}, -4.0f}); + CORRADE_COMPARE(d, DualQuaternion({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f})); } void DualQuaternionTest::constructDefault() { From ce6f99990430a16a6fae6ea85f572a72e03f38eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Mar 2013 11:42:01 +0100 Subject: [PATCH 565/567] Math: better isNormalized() implementation. Comparing squared length to 1 is not sufficient to compare within range [1 - epsilon, 1 + epsilon], as e.g. Quaternion with dot() = 1 + 1e-7 when converted to matrix has column vectors with dot() = 1 + 1e-6, which is just above 1 + epsilon. Thus it's needed to compare sqrt(dot()) in range [1 - epsilon, 1 + epsilon] or dot() in range [1 - 2*epsilon + epsilon^2, 1 + 2*epsilon + epsilon^2]. Because epsilon^2 is way off machine precision, it's omitted, thus dot() in all isNormalized() implementations is now compared this way: abs(dot() - 1) < 2*epsilon; --- src/Math/Complex.h | 2 +- src/Math/DualComplex.h | 2 +- src/Math/DualQuaternion.h | 6 +++++- src/Math/Quaternion.h | 2 +- src/Math/TypeTraits.h | 13 +++++++++++++ src/Math/Vector.h | 2 +- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 766d577cb..2a2cb2349 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -156,7 +156,7 @@ template class Complex { * @see dot(), normalized() */ inline bool isNormalized() const { - return TypeTraits::equals(dot(), T(1)); + return Implementation::isNormalizedSquared(dot()); } /** @brief Real part */ diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index d008b78e0..648f9f6bc 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -135,7 +135,7 @@ template class DualComplex: public Dual> { * @see Complex::dot(), normalized() */ inline bool isNormalized() const { - return TypeTraits::equals(this->real().dot(), T(1)); + return Implementation::isNormalizedSquared(lengthSquared()); } /** diff --git a/src/Math/DualQuaternion.h b/src/Math/DualQuaternion.h index c3e8002cc..8d4837aac 100644 --- a/src/Math/DualQuaternion.h +++ b/src/Math/DualQuaternion.h @@ -141,7 +141,11 @@ template class DualQuaternion: public Dual> { * @see lengthSquared(), normalized() */ inline bool isNormalized() const { - return lengthSquared() == Dual(1); + /* Comparing dual part classically, as comparing sqrt() of it would + lead to overly strict precision */ + Dual a = lengthSquared(); + return Implementation::isNormalizedSquared(a.real()) && + TypeTraits::equals(a.dual(), T(0)); } /** diff --git a/src/Math/Quaternion.h b/src/Math/Quaternion.h index 0e3f77503..0cc1ac8ad 100644 --- a/src/Math/Quaternion.h +++ b/src/Math/Quaternion.h @@ -232,7 +232,7 @@ template class Quaternion { * @see dot(), normalized() */ inline bool isNormalized() const { - return TypeTraits::equals(dot(), T(1)); + return Implementation::isNormalizedSquared(dot()); } /** @brief %Vector part */ diff --git a/src/Math/TypeTraits.h b/src/Math/TypeTraits.h index 8897f33c3..addcb4206 100644 --- a/src/Math/TypeTraits.h +++ b/src/Math/TypeTraits.h @@ -174,6 +174,19 @@ template<> struct TypeTraits: Implementation::TypeTraitsFloatingPoi inline constexpr static long double epsilon() { return LONG_DOUBLE_EQUALITY_PRECISION; } }; + +/* Comparing squared length to 1 is not sufficient to compare within range + [1 - epsilon, 1 + epsilon], as e.g. Quaternion with dot() = 1 + 1e-7 when + converted to matrix has column vectors with dot() = 1 + 1e-6, which is just + above 1 + epsilon. Thus it's needed to compare sqrt(dot()) in range + [1 - epsilon, 1 + epsilon] or dot() in range [1 - 2*epsilon + epsilon^2, + 1 + 2*epsilon + epsilon^2]. Because epsilon^2 is way off machine precision, + it's omitted. */ +namespace Implementation { + template inline bool isNormalizedSquared(T lengthSquared) { + return std::abs(lengthSquared - T(1)) < T(2)*TypeTraits::epsilon(); + } +} #endif }} diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 1d4c197a9..5ef5b508a 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -254,7 +254,7 @@ template class Vector { * @see dot(), normalized() */ inline bool isNormalized() const { - return TypeTraits::equals(dot(), T(1)); + return Implementation::isNormalizedSquared(dot()); } /** From fe3a73aab29bf6d1c9743300bbf6940a1fc2f753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Mar 2013 13:28:44 +0100 Subject: [PATCH 566/567] SceneGraph: add DualQuaternionTransformation::rotate[XYZ]() overloads. They only pass the arguments to original implementation but return proper type to avoid weird issues with different method chaining order. --- src/SceneGraph/DualQuaternionTransformation.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/SceneGraph/DualQuaternionTransformation.h b/src/SceneGraph/DualQuaternionTransformation.h index 4245749c6..811450d19 100644 --- a/src/SceneGraph/DualQuaternionTransformation.h +++ b/src/SceneGraph/DualQuaternionTransformation.h @@ -148,6 +148,22 @@ class DualQuaternionTransformation: public AbstractTranslationRotation3D { return this; } + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline DualQuaternionTransformation* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) override { + AbstractTranslationRotation3D::rotateX(angle, type); + return this; + } + inline DualQuaternionTransformation* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) override { + AbstractTranslationRotation3D::rotateY(angle, type); + return this; + } + inline DualQuaternionTransformation* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) override { + AbstractTranslationRotation3D::rotateZ(angle, type); + return this; + } + #endif + protected: /* Allow construction only from Object */ inline explicit DualQuaternionTransformation() = default; From 8b7c21cef96c8f70a102474d3950eeda6dd70848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Mar 2013 15:29:26 +0100 Subject: [PATCH 567/567] Better README with catchy design goals and stuff. --- README.md | 87 ++++++++++++++++++++++++++++-------------- doc/mainpage.dox | 98 ++++++++++++++++++++++++++---------------------- 2 files changed, 111 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 1164a9484..fdb1f940f 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,60 @@ -Magnum is 3D graphics engine written in C++11 and OpenGL 3 Core Profile. -Features: - - * Easy-to-use templated mathematical library for matrix/vector calculations - and geometry. - * Classes wrapping OpenGL objects and simplifying their usage - shaders, - buffers, meshes and textures. Access to framebuffer and occlusion queries. - * Mesh tools for cleaning, optimizing and generating meshes, utility classes - for color conversion, timeline and profiling. - * Hierarchical scene graph which supports transformation caching for better - performance, physics library for collision detection and rigid body - dynamics. - * Plugin-based data exchange framework for importing image, mesh, material - and scene data in various formats. - * Collection of pre-made graphic primitives and shaders for testing purposes. - * Classes for creating OpenGL-enabled applications with various toolkits, - methods for querying supported OpenGL version and available extensions. - * Comprehensive use of C++11 features for safety, performance and ease of - development. All code which doesn't directly interact with OpenGL is - covered with unit tests. - * Actively maintained Doxygen documentation. Occasionally updated snapshot is - also available online at http://mosra.cz/blog/magnum-doc/ . +Magnum is 2D/3D graphics engine written in C++11 and OpenGL 3 Core Profile. + +DESIGN GOALS +============ + +* **2D is not an ugly stepchild** + Many engines out there are either purely 2D or 3D and if you want to do + your next project in 2D only, you have to either relearn another engine + from scratch or emulate it in 3D, leaving many things overly complicated. + Magnum treats 2D equivalently to 3D so you can reuse what you already + learned for 3D and even combine 2D and 3D in one project. + +* **Forward compatibility** + If newer technology makes things faster, simpler or more intuitive, it is + the way to go. If you then really need to, you can selectively backport + some features and it will be easier than maintaining full backward + compatibility by default. Magnum by default relies on decent C++11 support + and modern OpenGL features, but compatibility functions for older hardware + and compatibility branch for older compilers are available if you need + them. + +* **Intuitive, but not restrictive API** + Scripting languages are often preferred to C/C++ because they tend to do + more with less -- less complicated APIs, nicer syntax and less boilerplate + code. Magnum is designed with scripting language intuitivity in mind, but + also with speed and static checks that native code and strong typing + offers. Usually the most common way is the most simple, but if you need + full control, you can have it. + +* **Extensible and replaceable components** + If you want to use different mathematical library for specific purposes, + that new windowing toolkit, your own file formats or another physics + library, you can. Conversion of data between different libraries can be + done on top of pre-made skeleton classes, support for file formats is done + using plugins and platform support is done by writing simple wrapper class. + +FEATURES +======== + +* Actively maintained Doxygen documentation with tutorials and examples. + Snapshot is available at http://mosra.cz/blog/magnum-doc/. +* Vector and matrix library with implementation of complex numbers, + quaternions and their dual counterparts for representing transformations. +* Classes wrapping OpenGL and simplifying its usage with direct state access + and automatic fallback for unavailable features. +* Extensible scene graph which can be modified for each specific usage. +* Plugin-based data exchange framework, tools for manipulating meshes, + textures and images. +* Integration with various windowing toolkits and also ability to create + windowless contexts. +* Pre-made shaders, primitives and other tools for easy prototyping and + debugging. INSTALLATION ============ -You can either use packaging scripts, which are stored in package/ +You can either use packaging scripts, which are stored in `package/` subdirectory, or compile and install everything manually. Note that Doxygen documentation (see above or build your own using instructions below) contains more comprehensive guide for building, packaging and crosscompiling. @@ -38,7 +68,7 @@ Minimal dependencies * **CMake** >= 2.8.8 (needed for `OBJECT` library target) * **GLEW** - OpenGL extension wrangler (only if targeting desktop OpenGL) * **Corrade** - Plugin management and utility library. You can get it at - http://github.com/mosra/corrade or at http://mosra.cz/blog/corrade.php. + https://github.com/mosra/corrade. Compilation, installation ------------------------- @@ -85,12 +115,11 @@ PLUGINS AND EXAMPLES ==================== Various importer plugins for image and 3D model formats are maintained in -separate repository, which can be found at -http://github.com/mosra/magnum-plugins . +separate repository, which can be found at https://github.com/mosra/magnum-plugins. -There are also examples of engine usage, varying from simple *Hello -World*-like example to more advanced applications, such as viewer for complex -3D models. Example repository is at http://github.com/mosra/magnum-examples . +There are also examples of engine usage, varying from simple *Hello World*-like +example to more advanced applications, such as viewer for complex 3D models. +Example repository is at https://github.com/mosra/magnum-examples. CONTACT ======= diff --git a/doc/mainpage.dox b/doc/mainpage.dox index d9233a841..cc5e6df15 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -25,59 +25,67 @@ namespace Magnum { /** @mainpage -%Magnum is 3D graphics engine written in C++11 and OpenGL 3 Core Profile. -Features: - -- Easy-to-use templated @ref Math "mathematical library" for - @ref matrix-vector "matrix/vector calculations" and - @ref Math::Geometry "geometry". -- Classes wrapping OpenGL objects and simplifying their usage - - @ref AbstractShaderProgram "shaders", @ref Buffer "buffers", - @ref Mesh "meshes" and @ref AbstractTexture "textures". Access to - @ref Framebuffer "framebuffer" and @ref AbstractQuery "occlusion queries". -- @ref MeshTools "Mesh tools" for cleaning, optimizing and generating meshes, - utility classes for @ref Color.h "color conversion", @ref Timeline "timeline" - and @ref DebugTools::Profiler "profiling". -- Hierarchical @ref SceneGraph "scene graph" which supports transformation - caching for better performance, @ref Physics "physics library" for collision - detection and rigid body dynamics. -- Plugin-based @ref Trade "data exchange framework" for importing image, mesh, - material and scene data in various formats. -- Collection of pre-made @ref Primitives "graphic primitives" and - @ref Shaders "shaders" for testing purposes. -- Classes for creating OpenGL-enabled applications with @ref Platform - "various toolkits", methods for querying - @ref Context "supported OpenGL version and available extensions". -- Comprehensive use of C++11 features for safety, performance and ease of - development. All code which doesn't directly interact with OpenGL is - covered with unit tests. - -The engine is meant to be run on OpenGL 3 capable hardware, but most of the -functionality is working on OpenGL 2.1 hardware too. The engine can be built -also for OpenGL ES with limited functionality. See also @ref required-extensions. - -@section download-build Downloading and building Magnum +%Magnum is 2D/3D graphics engine written in C++11 and OpenGL 3 Core Profile. + +@section mainpage-design-goals Design goals + +- **2D is not an ugly stepchild** + Many engines out there are either purely 2D or 3D and if you want to do + your next project in 2D only, you have to either relearn another engine + from scratch or emulate it in 3D, leaving many things overly complicated. + %Magnum treats 2D equivalently to 3D so you can reuse what you already + learned for 3D and even combine 2D and 3D in one project. + +- **Forward compatibility** + If newer technology makes things faster, simpler or more intuitive, it is + the way to go. If you then really need to, you can selectively backport + some features and it will be easier than maintaining full backward + compatibility by default. %Magnum by default relies on decent C++11 support + and modern OpenGL features, but compatibility functions for older hardware + and compatibility branch for older compilers are available if you need + them. + +- **Intuitive, but not restrictive API** + Scripting languages are often preferred to C/C++ because they tend to do + more with less -- less complicated APIs, nicer syntax and less boilerplate + code. %Magnum is designed with scripting language intuitivity in mind, but + also with speed and static checks that native code and strong typing + offers. Usually the most common way is the most simple, but if you need + full control, you can have it. + +- **Extensible and replaceable components** + If you want to use different mathematical library for specific purposes, + that new windowing toolkit, your own file formats or another physics + library, you can. Conversion of data between different libraries can be + done on top of pre-made skeleton classes, support for file formats is done + using plugins and platform support is done by writing simple wrapper class. + +@section mainpage-features Features + +- Vector and matrix library with implementation of complex numbers, + quaternions and their dual counterparts for representing transformations. +- Classes wrapping OpenGL and simplifying its usage with direct state access + and automatic fallback for unavailable features. +- Extensible scene graph which can be modified for each specific usage. +- Plugin-based data exchange framework, tools for manipulating meshes, + textures and images. +- Integration with various windowing toolkits and also ability to create + windowless contexts. Ported to OpenGL ES and various platforms. +- Pre-made shaders, primitives and other tools for easy prototyping and + debugging. + +@section mainpage-download-build Downloading and building Magnum Guide @ref building "how to download and build Magnum" on different platforms. -@section getting-started Getting started - -To get up and running, you must first subclass one of the provided window -context classes and implement required functions. %Magnum provides -implementations for the most common toolkits (such as GLUT, Xlib, or SDL2) in -Platform namespace. - -Then you can either draw your meshes directly or use SceneGraph which will -help you with object hierarchy, transformations and resource management. - -@subsection getting-started-examples Tutorials and examples +@section mainpage-getting-started Getting started The best way to get started is to render your first triangle in @ref example-index "step-by-step tutorial". Then you can dig deeper and try other examples, read about @ref features "fundamental principles" in the documentation or start experimenting on your own! -@subsection getting-started-hacking Hacking Magnum +@section mainpage-hacking Hacking Magnum If you want to hack on this engine, if you spotted a bug, need an feature or have an awesome idea, you can get a copy of the sources from GitHub and start @@ -93,7 +101,7 @@ Feel free to get more information or contact the author at: - E-mail - mosra@centrum.cz - Jabber - mosra@jabbim.cz -@section license License +@section mainpage-license License %Magnum is licensed under MIT/Expat license: