diff --git a/doc/namespaces.dox b/doc/namespaces.dox index a302028f3..18edc4d94 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -100,17 +100,24 @@ more information. This library is also available as a single-header, dependency-less [MagnumMath.hpp](https://github.com/mosra/magnum-singles/tree/master/MagnumMath.hpp) library in the Magnum Singles repository for easier integration into your - projects. See @ref singles for more information. Everything except contents - of the @ref Magnum/Math/ColorBatch.h, @ref Magnum/Math/FunctionsBatch.h, - @ref Magnum/Math/PackingBatch.h and @ref Magnum/Math/Algorithms/Svd.h - headers and the @ref Magnum::Math::StrictWeakOrdering helper is included. - The library has a separate non-inline implementation part, enable it + projects, with the batch APIs available in + [MagnumMathBatch.hpp](https://github.com/mosra/magnum-singles/tree/master/MagnumMathBatch.hpp) instead. See @ref singles for more information. + Everything except contents of the @ref Magnum/Math/Algorithms/Svd.h header + and the @ref Magnum::Math::StrictWeakOrdering helper is included. The + libraries have a separate non-inline implementation part, enable it * *just once* like this: @par @code{.cpp} #define MAGNUM_MATH_IMPLEMENTATION #include @endcode +@par + Or, for the batch APIs, like this: +@par + @code{.cpp} + #define MAGNUM_MATH_BATCH_IMPLEMENTATION + #include + @endcode @par If you need the deinlined symbols to be exported from a shared library, @cpp #define MAGNUM_EXPORT @ce as appropriate. The STL compatibility bits @@ -431,6 +438,27 @@ is built with both `MAGNUM_WITH_GL` and `MAGNUM_TARGET_GL` enabled (which is done by default). See @ref building, @ref cmake and @ref meshtools for more information. + +@m_class{m-block m-success} + +@par Single-header version + A subset of this library is also available as a single-header, + dependency-less [MagnumMeshTools.hpp](https://github.com/mosra/magnum-singles/tree/master/MagnumMeshTools.hpp) + library in the Magnum Singles repository for easier integration into your + projects. See @ref singles for more information. At the moment, the + @ref Magnum/MeshTools/BoundingVolume.h and + @ref Magnum/MeshTools/GenerateIndices.h headers are included, except for + APIs relying on the @ref Trade library. The library has a separate + non-inline implementation part, enable it *just once* like this: +@par + @code{.cpp} + #define MAGNUM_MESHTOOLS_IMPLEMENTATION + #include + @endcode +@par + If you need the deinlined symbols to be exported from a shared library, + @cpp #define MAGNUM_MESHTOOLS_EXPORT @ce as appropriate. + */ /** @dir Magnum/Primitives diff --git a/doc/singles.dox b/doc/singles.dox index c84f43261..34f562a0e 100644 --- a/doc/singles.dox +++ b/doc/singles.dox @@ -48,6 +48,8 @@ sources using the builtin @ref acme "single-header generator tool". Class or library | Single-header version --------------------------- | ---------------------------- @ref Math, \n @ref EigenIntegration, \n @ref GlmIntegration | [MagnumMath.hpp](https://github.com/mosra/magnum-singles/tree/master/MagnumMath.hpp), depends on `CorradePair.h` +@ref Math batch APIs | [MagnumMathBatch.hpp](https://github.com/mosra/magnum-singles/tree/master/MagnumMathBatch.hpp), depends on `MagnumMath.hpp` and `CorradeStridedArrayView.h` +@ref MeshTools | [MagnumMeshTools.hpp](https://github.com/mosra/magnum-singles/tree/master/MagnumMeshTools.hpp), depends on `MagnumMathBatch.hpp` and `CorradeArray.h` There are also @ref corrade-singles "single-header libraries for Corrade APIs". diff --git a/src/Magnum/Math/PackingBatch.cpp b/src/Magnum/Math/PackingBatch.cpp index 148519d7b..0681bb5bb 100644 --- a/src/Magnum/Math/PackingBatch.cpp +++ b/src/Magnum/Math/PackingBatch.cpp @@ -27,7 +27,9 @@ #include "PackingBatch.h" #include +#ifndef MAGNUM_SINGLES_NO_UTILITY_ALGORITHMS_DEPENDENCY #include +#endif #include #include "Magnum/Math/Packing.h" @@ -404,6 +406,7 @@ void castInto(const Containers::StridedArrayView2D& src, const Con namespace { +#ifndef MAGNUM_SINGLES_NO_UTILITY_ALGORITHMS_DEPENDENCY template inline void copyImplementation(const Containers::StridedArrayView2D& src, const Containers::StridedArrayView2D& dst) { /* Utility::copy() has its own assertions, but those are debug-only for perf reasons and don't require the second dimension to be contiguous. @@ -418,6 +421,13 @@ template inline void copyImplementation(const Containers::StridedArrayV Utility::copy(src, dst); } +#else +/* Not as great because it doesn't have a fast memcpy codepath but more + acceptable than excluding the APIs altogether */ +template inline void copyImplementation(const Containers::StridedArrayView2D& src, const Containers::StridedArrayView2D& dst) { + castIntoImplementation(src, dst); +} +#endif } diff --git a/src/Magnum/MeshTools/GenerateIndices.cpp b/src/Magnum/MeshTools/GenerateIndices.cpp index 14712cfcf..ecf84579e 100644 --- a/src/Magnum/MeshTools/GenerateIndices.cpp +++ b/src/Magnum/MeshTools/GenerateIndices.cpp @@ -28,15 +28,20 @@ #include #include +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY #include +#endif #include "Magnum/Math/Vector3.h" +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY #include "Magnum/MeshTools/Copy.h" #include "Magnum/MeshTools/Implementation/remapAttributeData.h" #include "Magnum/Trade/MeshData.h" +#endif namespace Magnum { namespace MeshTools { +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY UnsignedInt primitiveCount(const MeshPrimitive primitive, const UnsignedInt elementCount) { #ifndef CORRADE_NO_ASSERT UnsignedInt minElementCount; @@ -84,6 +89,7 @@ UnsignedInt primitiveCount(const MeshPrimitive primitive, const UnsignedInt elem return elementCount < 2 ? 0 : elementCount - 2; CORRADE_ASSERT_UNREACHABLE("MeshTools::primitiveCount(): invalid primitive" << primitive, {}); } +#endif void generateTrivialIndicesInto(const Containers::StridedArrayView1D& output, /*mutable*/ UnsignedInt offset) { for(std::size_t i = 0; i != output.size(); ++i) @@ -589,6 +595,7 @@ void generateQuadIndicesInto(const Containers::StridedArrayView1D return generateQuadIndicesIntoImplementation(positions, quads, output, offset); } +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY Trade::MeshData generateIndices(Trade::MeshData&& mesh) { CORRADE_ASSERT(!mesh.isIndexed() || !isMeshIndexTypeImplementationSpecific(mesh.indexType()), "MeshTools::generateIndices(): mesh has an implementation-specific index type" << Debug::hex << meshIndexTypeUnwrap(mesh.indexType()), @@ -687,5 +694,6 @@ Trade::MeshData generateIndices(const Trade::MeshData& mesh) { anything based on the DataFlags */ return generateIndices(reference(mesh)); } +#endif }} diff --git a/src/Magnum/MeshTools/GenerateIndices.h b/src/Magnum/MeshTools/GenerateIndices.h index 1a8260e85..01c59a596 100644 --- a/src/Magnum/MeshTools/GenerateIndices.h +++ b/src/Magnum/MeshTools/GenerateIndices.h @@ -33,10 +33,13 @@ #include "Magnum/Magnum.h" #include "Magnum/MeshTools/visibility.h" +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY #include "Magnum/Trade/Trade.h" +#endif namespace Magnum { namespace MeshTools { +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY /** @brief Actual primitive count for given primitive type and element count @m_since{2020,06} @@ -49,6 +52,7 @@ is either zero or at least @cpp 2 @ce for a line-based primitive and at least @ref MeshPrimitive::Lines and by @cpp 3 @ce for @ref MeshPrimitive::Triangles. */ MAGNUM_MESHTOOLS_EXPORT UnsignedInt primitiveCount(MeshPrimitive primitive, UnsignedInt elementCount); +#endif /** @brief Create a trivial index buffer @@ -509,6 +513,7 @@ MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedAr */ MAGNUM_MESHTOOLS_EXPORT void generateQuadIndicesInto(const Containers::StridedArrayView1D& positions, const Containers::StridedArrayView1D& quads, const Containers::StridedArrayView1D& output, UnsignedInt offset = 0); +#ifndef MAGNUM_SINGLES_NO_TRADE_DEPENDENCY /** @brief Convert a mesh to a plain indexed one @m_since{2020,06} @@ -550,6 +555,7 @@ it's owned, doesn't need expanding and is already with @see @ref Trade::MeshData::vertexDataFlags() */ MAGNUM_MESHTOOLS_EXPORT Trade::MeshData generateIndices(Trade::MeshData&& mesh); +#endif }} diff --git a/src/singles/MagnumMath.hpp b/src/singles/MagnumMath.hpp index b7ca889d6..fd228f8c2 100644 --- a/src/singles/MagnumMath.hpp +++ b/src/singles/MagnumMath.hpp @@ -399,7 +399,6 @@ typedef Math::Frustum Frustumd; #include "Magnum/Math/Bezier.h" #include "Magnum/Math/BitVector.h" #include "Magnum/Math/Color.h" -// TODO: ColorBatch (separate library because of StridedArrayView) #include "Magnum/Math/Complex.h" #include "Magnum/Math/Constants.h" #include "Magnum/Math/CubicHermite.h" @@ -409,14 +408,12 @@ typedef Math::Frustum Frustumd; #include "Magnum/Math/DualQuaternion.h" #include "Magnum/Math/Frustum.h" #include "Magnum/Math/Functions.h" -// TODO: FunctionsBatch (separate library because of StridedArrayView) #include "Magnum/Math/Half.h" #include "Magnum/Math/Intersection.h" #include "Magnum/Math/Matrix.h" #include "Magnum/Math/Matrix3.h" #include "Magnum/Math/Matrix4.h" #include "Magnum/Math/Packing.h" -// TODO: PackingBatch (separate library because of StridedArrayView) #include "Magnum/Math/Quaternion.h" #include "Magnum/Math/Range.h" #include "Magnum/Math/RectangularMatrix.h" diff --git a/src/singles/MagnumMathBatch.hpp b/src/singles/MagnumMathBatch.hpp new file mode 100644 index 000000000..dbfeb78fd --- /dev/null +++ b/src/singles/MagnumMathBatch.hpp @@ -0,0 +1,69 @@ +/* + Magnum::Math + — a graphics-focused vector math library, batch APIs + + https://doc.magnum.graphics/magnum/namespaceMagnum_1_1Math.html + + Depends on ContainersStridedArrayView.h and MagnumMath.hpp. + + This is a single-header library generated from the Magnum project. With the + goal being easy integration, it's deliberately free of all comments to keep + the file size small. More info, changelogs and full docs here: + + - Project homepage — https://magnum.graphics/magnum/ + - Documentation — https://doc.magnum.graphics/ + - GitHub project page — https://github.com/mosra/magnum + - GitHub Singles repository — https://github.com/mosra/magnum-singles + + The library has a separate non-inline implementation part, enable it *just + once* like this: + + #define MAGNUM_MATH_BATCH_IMPLEMENTATION + #include + + If you need the deinlined symbols to be exported from a shared library, + `#define MAGNUM_EXPORT` as appropriate. + + Generated from Corrade {{revision:corrade/src}} and + Magnum {{revision:magnum/src}}, {{stats:loc}} / {{stats:preprocessed}} LoC +*/ + +#include "base.h" +// {{includes}} + +/* All asserts we use are present in dependencies already */ +#include "singles/assert.h" + +/* Some castInto() overloads are convenience wrappers over Utility::copy(). Use + a (slower) fallback instead. */ +#pragma ACME enable MAGNUM_SINGLES_NO_UTILITY_ALGORITHMS_DEPENDENCY + +/* We don't need anything from configure.h here that isn't pulled in by + MagnumMath already */ +#pragma ACME enable Corrade_configure_h +#pragma ACME enable Magnum_configure_h + +/* CorradeStridedArrayView and MagnumMath is a dependency */ +#pragma ACME noexpand CorradeStridedArrayView.h +#pragma ACME enable Corrade_Containers_Containers_h +#pragma ACME enable Corrade_Containers_Pair_h +#pragma ACME enable Corrade_Containers_StridedArrayView_h +#pragma ACME enable Corrade_Utility_Move_h +#pragma ACME enable Corrade_Utility_VisibilityMacros_h +#include "CorradeStridedArrayView.h" +#pragma ACME noexpand MagnumMath.hpp +#pragma ACME enable Magnum_visibility_h +#pragma ACME enable Magnum_Magnum_h +#pragma ACME enable Magnum_Types_h +#pragma ACME enable Magnum_Math_Functions_h +#pragma ACME enable Magnum_Math_Packing_h +/* This guard is there only for tests I think, not needed for anything else */ +#pragma ACME disable Magnum_Math_halfTables_hpp +#include "MagnumMath.hpp" + +// TODO ColorBatch once it's more useful +#include "Magnum/Math/FunctionsBatch.h" +#include "Magnum/Math/PackingBatch.h" +#ifdef MAGNUM_MATH_BATCH_IMPLEMENTATION +#include "Magnum/Math/PackingBatch.cpp" +#endif diff --git a/src/singles/MagnumMeshTools.hpp b/src/singles/MagnumMeshTools.hpp new file mode 100644 index 000000000..2048b4d92 --- /dev/null +++ b/src/singles/MagnumMeshTools.hpp @@ -0,0 +1,154 @@ +/* + Magnum::MeshTools + — algorithms for dealing with mesh data + + https://doc.magnum.graphics/magnum/namespaceMagnum_1_1MeshTools.html + + Depends on CorradeArray.h and MagnumMathBatch.hpp. + + This is a single-header library generated from the Magnum project. With the + goal being easy integration, it's deliberately free of all comments to keep + the file size small. More info, changelogs and full docs here: + + - Project homepage — https://magnum.graphics/magnum/ + - Documentation — https://doc.magnum.graphics/ + - GitHub project page — https://github.com/mosra/magnum + - GitHub Singles repository — https://github.com/mosra/magnum-singles + + The library has a separate non-inline implementation part, enable it *just + once* like this: + + #define MAGNUM_MESHTOOLS_IMPLEMENTATION + #include + + If you need the deinlined symbols to be exported from a shared library, + `#define MAGNUM_MESHTOOLS_EXPORT` as appropriate. + + Generated from Corrade {{revision:corrade/src}} and + Magnum {{revision:magnum/src}}, {{stats:loc}} / {{stats:preprocessed}} LoC +*/ + +#include "base.h" +// {{includes}} +#include /* std::size_t, std::ptrdiff_t */ + +/* Exclude everything that relies on Trade, or also the MeshPrimitive etc enums + from Magnum core namespace */ +#pragma ACME enable MAGNUM_SINGLES_NO_TRADE_DEPENDENCY + +/* Our own subset of visibility macros */ +#pragma ACME enable Magnum_MeshTools_visibility_h +#pragma ACME enable Corrade_Utility_VisibilityMacros_h +#ifndef MAGNUM_MESHTOOLS_EXPORT +#define MAGNUM_MESHTOOLS_EXPORT +#endif + +/* We don't need anything from configure.h for the declarations, only the + implementation does */ +#pragma ACME enable Corrade_configure_h +#pragma ACME enable Magnum_configure_h + +/* This is just a tiny subset of the full forward declaration header in + MagnumMath. We don't need that whole header, especially given the user may + not need to use any of the Math types. */ +#include "Magnum/Types.h" +#ifndef MagnumMeshTools_hpp +#define MagnumMeshTools_hpp +namespace Corrade { namespace Containers { + +template class Pair; +template class StridedArrayView; +template using StridedArrayView1D = StridedArrayView<1, T>; +template using StridedArrayView2D = StridedArrayView<2, T>; + +}} +namespace Magnum { + +using namespace Corrade; + +namespace Math { + template class Vector3; + template class Range3D; +} + +typedef Math::Vector3 Vector3; +typedef Math::Range3D Range3D; + +} +#endif +/* This is a verbatim copy from CorradeArray.h. In case it gets included, only + one of the two occurences gets picked, and thus it has to be present in + full, including StaticArray and other types we don't strictly need, in order + to make sure the default template argument is listed exactly once. */ +#ifndef CorradeArray_h +#define CorradeArray_h +namespace Corrade { namespace Containers { + +/* In case Corrade/Containers/Containers.h is included too, these two would + conflict */ +#ifndef Corrade_Containers_Containers_h +template class Array; +#endif +/* Needs to be defined here because it's referenced before its definition */ +template class StaticArray; +/* These need to be defined here because the other occurence is guarded with + #ifndef CORRADE_MSVC2015_COMPATIBILITY */ +template using Array2 = StaticArray<2, T>; +template using Array3 = StaticArray<3, T>; +template using Array4 = StaticArray<4, T>; + +}} +#endif +#pragma ACME enable Magnum_Magnum_h +#include "Magnum/MeshTools/BoundingVolume.h" +#include "Magnum/MeshTools/GenerateIndices.h" +// TODO CompressIndices once it's renamed to Pack +// TODO FlipNormals? +// TODO GenerateNormals? +// TODO RemoveDuplicates? +#ifdef MAGNUM_MESHTOOLS_IMPLEMENTATION +// {{includes}} +#if !defined(CORRADE_ASSERT_UNREACHABLE) && !defined(NDEBUG) +#include +#endif + +/* CorradeArray and MagnumMathBatch is an implementation dependency. + CorradeStridedArrayView is pulled in by MagnumMathBatch already. */ +#pragma ACME noexpand CorradeArray.h +#pragma ACME noexpand MagnumMathBatch.hpp +#include "CorradeArray.h" +#include "MagnumMathBatch.hpp" + +/* We need CORRADE_TARGET_BIG_ENDIAN from configure.h */ +#ifdef __BYTE_ORDER__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define CORRADE_TARGET_BIG_ENDIAN +#elif __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ +#error what kind of endianness is this? +#endif +#elif defined(__hppa__) || \ + defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ + (defined(__MIPS__) && defined(__MIPSEB__)) || \ + defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ + defined(__sparc__) +#define CORRADE_TARGET_BIG_ENDIAN +#endif + +/* All asserts we use are present in dependencies already, except for + CORRADE_ASSERT_UNREACHABLE */ +#include "singles/assert.h" +#pragma ACME forget CORRADE_ASSERT_UNREACHABLE +#pragma ACME enable Corrade_Utility_Move_h +#include + +#pragma ACME enable Corrade_Containers_Array_h +#pragma ACME enable Corrade_Containers_Pair_h +#pragma ACME enable Corrade_Containers_StridedArrayView_h +#pragma ACME enable Magnum_Math_Vector3_h +#pragma ACME enable Magnum_Math_Range_h +#pragma ACME enable Magnum_Math_FunctionsBatch_h +/* This guard is there only for tests I think, not needed for anything else */ +#pragma ACME disable Magnum_Math_halfTables_hpp +#include "Magnum/MeshTools/BoundingVolume.cpp" +#include "Magnum/MeshTools/GenerateIndices.cpp" +#endif diff --git a/src/singles/generate.sh b/src/singles/generate.sh index 7d565eaa7..818782445 100755 --- a/src/singles/generate.sh +++ b/src/singles/generate.sh @@ -1,3 +1,5 @@ set -e ../../../corrade/src/acme/acme.py MagnumMath.hpp --output ../../../magnum-singles +../../../corrade/src/acme/acme.py MagnumMathBatch.hpp --output ../../../magnum-singles +../../../corrade/src/acme/acme.py MagnumMeshTools.hpp --output ../../../magnum-singles