From 2f4092bde040fad3f875d0574bfbff35cd59e1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 20:40:44 +0100 Subject: [PATCH 01/20] Prefix *_EXPORT macros with MAGNUM_ to avoid collisions. --- src/MeshTools/CompressIndices.h | 2 +- src/MeshTools/FlipNormals.h | 4 ++-- src/MeshTools/GenerateFlatNormals.h | 2 +- src/MeshTools/Tipsify.h | 2 +- src/MeshTools/magnumMeshToolsVisibility.h | 6 +++--- src/Physics/AbstractShape.h | 6 +++--- src/Physics/AxisAlignedBox.h | 2 +- src/Physics/Box.h | 2 +- src/Physics/Capsule.h | 2 +- src/Physics/DebugDrawResourceManager.cpp | 4 ++-- src/Physics/DebugDrawResourceManager.h | 4 ++-- src/Physics/Line.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/Physics/magnumPhysicsVisibility.h | 6 +++--- src/SceneGraph/AbstractCamera.h | 2 +- src/SceneGraph/Camera.cpp | 8 ++++---- src/SceneGraph/Camera2D.h | 2 +- src/SceneGraph/Camera3D.h | 2 +- src/SceneGraph/MatrixTransformation2D.cpp | 2 +- src/SceneGraph/MatrixTransformation3D.cpp | 2 +- src/SceneGraph/magnumSceneGraphVisibility.h | 6 +++--- src/Shaders/FlatShader.h | 2 +- src/Shaders/PhongShader.h | 2 +- src/Shaders/VertexColorShader.h | 2 +- src/Shaders/magnumShadersVisibility.h | 6 +++--- 30 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/MeshTools/CompressIndices.h b/src/MeshTools/CompressIndices.h index e9bf40c9e..34ccb7991 100644 --- a/src/MeshTools/CompressIndices.h +++ b/src/MeshTools/CompressIndices.h @@ -31,7 +31,7 @@ namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -class MESHTOOLS_EXPORT CompressIndices { +class MAGNUM_MESHTOOLS_EXPORT CompressIndices { public: CompressIndices(const std::vector& indices): indices(indices) {} diff --git a/src/MeshTools/FlipNormals.h b/src/MeshTools/FlipNormals.h index c113e908d..98d71eb08 100644 --- a/src/MeshTools/FlipNormals.h +++ b/src/MeshTools/FlipNormals.h @@ -34,7 +34,7 @@ namespace Magnum { namespace MeshTools { The same as flipNormals(std::vector&, std::vector&), but flips only face winding. */ -void MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); +void MAGNUM_MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); /** @brief Flip mesh normals @@ -42,7 +42,7 @@ void MESHTOOLS_EXPORT flipFaceWinding(std::vector& indices); The same as flipNormals(std::vector&, std::vector&), but flips only normals, not face winding. */ -void MESHTOOLS_EXPORT flipNormals(std::vector& normals); +void MAGNUM_MESHTOOLS_EXPORT flipNormals(std::vector& normals); /** @brief Flip mesh normals and face winding diff --git a/src/MeshTools/GenerateFlatNormals.h b/src/MeshTools/GenerateFlatNormals.h index 2e23dfa5e..35a6e8047 100644 --- a/src/MeshTools/GenerateFlatNormals.h +++ b/src/MeshTools/GenerateFlatNormals.h @@ -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> 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/Tipsify.h b/src/MeshTools/Tipsify.h index ca93c1297..69d65082e 100644 --- a/src/MeshTools/Tipsify.h +++ b/src/MeshTools/Tipsify.h @@ -29,7 +29,7 @@ namespace Magnum { namespace MeshTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { -class MESHTOOLS_EXPORT Tipsify { +class MAGNUM_MESHTOOLS_EXPORT Tipsify { public: inline Tipsify(std::vector& indices, std::uint32_t vertexCount): indices(indices), vertexCount(vertexCount) {} diff --git a/src/MeshTools/magnumMeshToolsVisibility.h b/src/MeshTools/magnumMeshToolsVisibility.h index 61b0a0d39..ebef4ae43 100644 --- a/src/MeshTools/magnumMeshToolsVisibility.h +++ b/src/MeshTools/magnumMeshToolsVisibility.h @@ -17,12 +17,12 @@ #ifdef _WIN32 #if defined(MagnumMeshTools_EXPORTS) || defined(MagnumMeshToolsObjects_EXPORTS) - #define MESHTOOLS_EXPORT __declspec(dllexport) + #define MAGNUM_MESHTOOLS_EXPORT __declspec(dllexport) #else - #define MESHTOOLS_EXPORT __declspec(dllimport) + #define MAGNUM_MESHTOOLS_EXPORT __declspec(dllimport) #endif #else - #define MESHTOOLS_EXPORT __attribute__ ((visibility ("default"))) + #define MAGNUM_MESHTOOLS_EXPORT __attribute__ ((visibility ("default"))) #endif #endif diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index c4e6dff67..44fa0af6a 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -65,7 +65,7 @@ namespace Implementation { See @ref collision-detection for brief introduction. @see AbstractShape2D, AbstractShape3D */ -template class PHYSICS_EXPORT AbstractShape { +template class MAGNUM_PHYSICS_EXPORT AbstractShape { public: /** @brief Dimension count */ static const std::uint8_t Dimensions = dimensions; @@ -126,8 +126,8 @@ typedef AbstractShape<3> AbstractShape3D; /** @debugoperator{Magnum::Physics::AbstractShape} */ #ifndef DOXYGEN_GENERATING_OUTPUT -Debug PHYSICS_EXPORT operator<<(Debug debug, AbstractShape2D::Type value); -Debug PHYSICS_EXPORT operator<<(Debug debug, AbstractShape3D::Type value); +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 diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 2c00e8f35..6d76e7da5 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { @see AxisAlignedBox2D, AxisAlignedBox3D */ -template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { +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) {} diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 87f259a12..f09e093b2 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Physics { @todo Use quat + position + size instead? @see Box2D, Box3D */ -template class PHYSICS_EXPORT Box: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 3c5aad2d6..015050ffe 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -34,7 +34,7 @@ Unlike other elements the capsule doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Capsule2D, Capsule3D */ -template class PHYSICS_EXPORT Capsule: public AbstractShape { +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) {} diff --git a/src/Physics/DebugDrawResourceManager.cpp b/src/Physics/DebugDrawResourceManager.cpp index 8e958bc57..ba2560e02 100644 --- a/src/Physics/DebugDrawResourceManager.cpp +++ b/src/Physics/DebugDrawResourceManager.cpp @@ -43,8 +43,8 @@ template SceneGraph::Drawable* DebugDrawRes return renderer; } -template SceneGraph::Drawable<2> PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<2>* shape, ResourceKey options); -template SceneGraph::Drawable<3> PHYSICS_EXPORT * DebugDrawResourceManager::createDebugRenderer(ObjectShape<3>* shape, ResourceKey options); +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()) { diff --git a/src/Physics/DebugDrawResourceManager.h b/src/Physics/DebugDrawResourceManager.h index d7a2fff44..ffabe9350 100644 --- a/src/Physics/DebugDrawResourceManager.h +++ b/src/Physics/DebugDrawResourceManager.h @@ -43,7 +43,7 @@ namespace Physics { namespace Implementation { }} #endif -extern template ResourceManager PHYSICS_EXPORT *& ResourceManager::internalInstance(); +extern template ResourceManager MAGNUM_PHYSICS_EXPORT *& ResourceManager::internalInstance(); namespace Physics { @@ -81,7 +81,7 @@ ObjectShape2D* shape; group.add(DebugDrawResourceManager::createDebugRenderer(shape, "red")); @endcode */ -class PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager { +class MAGNUM_PHYSICS_EXPORT DebugDrawResourceManager: public ResourceManager { public: #ifdef DOXYGEN_GENERATING_OUTPUT /** @brief %Options */ diff --git a/src/Physics/Line.h b/src/Physics/Line.h index df509d87d..26d3232dd 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 PHYSICS_EXPORT Line: public AbstractShape { +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) {} diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 8a2d23d6a..61791fa21 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Physics { Adds shape for collision detection to object. @see ObjectShape2D, ObjectShape3D */ -template class PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { +template class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { public: /** * @brief Constructor diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index e05233434..4e2c1a188 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Physics { @see ObjectShapeGroup2D, ObjectShapeGroup3D */ -template class PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { +template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { friend class ObjectShape; public: diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 253e41484..d3ff91617 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { /** @brief Infinite plane, defined by position and normal (3D only) */ -class PHYSICS_EXPORT Plane: public AbstractShape<3> { +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) {} diff --git a/src/Physics/Point.h b/src/Physics/Point.h index a228173f9..70bf6df40 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { @see Point2D, Point3D */ -template class PHYSICS_EXPORT Point: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 04992413d..5a00f0488 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -57,7 +57,7 @@ Result of logical operations on shapes. See @ref collision-detection for brief introduction. @see ShapeGroup2D, ShapeGroup3D */ -template class 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; diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index f77cf8415..1f96f698a 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -34,7 +34,7 @@ Unlike other elements the sphere doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Sphere2D, Sphere3D */ -template class PHYSICS_EXPORT Sphere: public AbstractShape { +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) {} diff --git a/src/Physics/magnumPhysicsVisibility.h b/src/Physics/magnumPhysicsVisibility.h index f7af6cd73..a2e487560 100644 --- a/src/Physics/magnumPhysicsVisibility.h +++ b/src/Physics/magnumPhysicsVisibility.h @@ -17,12 +17,12 @@ #ifdef _WIN32 #ifdef MagnumPhysics_EXPORTS - #define PHYSICS_EXPORT __declspec(dllexport) + #define MAGNUM_PHYSICS_EXPORT __declspec(dllexport) #else - #define PHYSICS_EXPORT __declspec(dllimport) + #define MAGNUM_PHYSICS_EXPORT __declspec(dllimport) #endif #else - #define PHYSICS_EXPORT __attribute__ ((visibility ("default"))) + #define MAGNUM_PHYSICS_EXPORT __attribute__ ((visibility ("default"))) #endif #endif diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index 0b538d672..dae625e54 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -69,7 +69,7 @@ template #else template #endif -class SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature { +class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature { public: /** * @brief Constructor diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index dbb8e1081..1bdc04553 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 SCENEGRAPH_EXPORT AbstractCamera<2, GLfloat>; -template class SCENEGRAPH_EXPORT AbstractCamera<3, GLfloat>; -template class SCENEGRAPH_EXPORT Camera2D; -template class SCENEGRAPH_EXPORT Camera3D; +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; #endif }} diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index c38e9d052..072fc6f92 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -43,7 +43,7 @@ template #else template #endif -class SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { +class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { public: /** * @brief Constructor diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 4c6056fc5..fae8579ff 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -48,7 +48,7 @@ template #else template #endif -class SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { +class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { public: /** * @brief Constructor diff --git a/src/SceneGraph/MatrixTransformation2D.cpp b/src/SceneGraph/MatrixTransformation2D.cpp index 340371b97..7850ca48c 100644 --- a/src/SceneGraph/MatrixTransformation2D.cpp +++ b/src/SceneGraph/MatrixTransformation2D.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT -template class SCENEGRAPH_EXPORT Object>; +template class MAGNUM_SCENEGRAPH_EXPORT Object>; #endif }} diff --git a/src/SceneGraph/MatrixTransformation3D.cpp b/src/SceneGraph/MatrixTransformation3D.cpp index 8c2d78a48..bbcc227e8 100644 --- a/src/SceneGraph/MatrixTransformation3D.cpp +++ b/src/SceneGraph/MatrixTransformation3D.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace SceneGraph { #ifndef DOXYGEN_GENERATING_OUTPUT -template class SCENEGRAPH_EXPORT Object>; +template class MAGNUM_SCENEGRAPH_EXPORT Object>; #endif }} diff --git a/src/SceneGraph/magnumSceneGraphVisibility.h b/src/SceneGraph/magnumSceneGraphVisibility.h index 2e1c2e758..cd1be31fa 100644 --- a/src/SceneGraph/magnumSceneGraphVisibility.h +++ b/src/SceneGraph/magnumSceneGraphVisibility.h @@ -17,13 +17,13 @@ #ifdef _WIN32 #if defined(MagnumSceneGraph_EXPORTS) || defined(MagnumSceneGraphObjects_EXPORTS) - #define SCENEGRAPH_EXPORT __declspec(dllexport) + #define MAGNUM_SCENEGRAPH_EXPORT __declspec(dllexport) #else - #define SCENEGRAPH_EXPORT __declspec(dllimport) + #define MAGNUM_SCENEGRAPH_EXPORT __declspec(dllimport) #endif #define SCENEGRAPH_LOCAL #else - #define SCENEGRAPH_EXPORT __attribute__ ((visibility ("default"))) + #define MAGNUM_SCENEGRAPH_EXPORT __attribute__ ((visibility ("default"))) #define SCENEGRAPH_LOCAL __attribute__ ((visibility ("hidden"))) #endif diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index 68ff70231..3467666ad 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 SHADERS_EXPORT FlatShader: public AbstractShaderProgram { +template class MAGNUM_SHADERS_EXPORT FlatShader: public AbstractShaderProgram { public: /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::PointType> Position; diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 9ec97be53..14d4dd970 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Shaders { If supported, uses GLSL 3.20 and @extension{ARB,explicit_attrib_location}, otherwise falls back to GLSL 1.20. */ -class SHADERS_EXPORT PhongShader: public AbstractShaderProgram { +class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { public: typedef Attribute<0, Point3D> Position; /**< @brief Vertex position */ typedef Attribute<1, Vector3> Normal; /**< @brief Normal direction */ diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index fbed9f38a..35cd3377f 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 SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { +template class MAGNUM_SHADERS_EXPORT VertexColorShader: public AbstractShaderProgram { public: /** @brief Vertex position */ typedef Attribute<0, typename DimensionTraits::PointType> Position; diff --git a/src/Shaders/magnumShadersVisibility.h b/src/Shaders/magnumShadersVisibility.h index 75d681731..047ee9eca 100644 --- a/src/Shaders/magnumShadersVisibility.h +++ b/src/Shaders/magnumShadersVisibility.h @@ -17,12 +17,12 @@ #ifdef _WIN32 #ifdef MagnumShaders_EXPORTS - #define SHADERS_EXPORT __declspec(dllexport) + #define MAGNUM_SHADERS_EXPORT __declspec(dllexport) #else - #define SHADERS_EXPORT __declspec(dllimport) + #define MAGNUM_SHADERS_EXPORT __declspec(dllimport) #endif #else - #define SHADERS_EXPORT __attribute__ ((visibility ("default"))) + #define MAGNUM_SHADERS_EXPORT __attribute__ ((visibility ("default"))) #endif #endif From 3ac906db9e3f02eafd41c778cf0b48fa9e6e4f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 21:01:22 +0100 Subject: [PATCH 02/20] Fixed AbstractShaderProgram documentation. Forgot to do it in 259a9f6666ac73d83ebf41d082aca524df695061. --- src/AbstractShaderProgram.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 7729a25cb..19653753c 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -53,9 +53,9 @@ functions and properties: - %Attribute definitions with location and type for configuring meshes, for example: @code -static const Attribute<0, Point3D> Position; -static const Attribute<1, Vector3> Normal; -static const Attribute<2, Vector2> TextureCoordinates; +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()) @@ -127,9 +127,9 @@ the program: @code // Shaders attached... -bindAttributeLocation(Position.Location, "position"); -bindAttributeLocation(Normal.Location, "normal"); -bindAttributeLocation(TextureCoords.Location, "textureCoordinates"); +bindAttributeLocation(Position::Location, "position"); +bindAttributeLocation(Normal::Location, "normal"); +bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates"); bindFragmentDataLocationIndexed(0, 0, "color"); bindFragmentDataLocationIndexed(1, 1, "ambient"); From 0181bad7493d9a4cd223ff68bcd588942953f59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 22 Nov 2012 21:06:39 +0100 Subject: [PATCH 03/20] Workaround to fix KDevelop autocompletion. --- src/Magnum.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magnum.h b/src/Magnum.h index 6a2d174df..fd941af29 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -119,8 +119,8 @@ typedef BufferedImage<3> BufferedImage3D; class BufferedTexture; #endif -template class Color3; -template class Color4; +template class Color3; +template class Color4; enum class Version: GLint; class Context; From b7e3871cde8dac93ed917992adfdf55899656d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 23 Nov 2012 12:31:22 +0100 Subject: [PATCH 04/20] Split Resource and ResourceManager to two files. They still include each other, but at least it is now possible to scroll through the files. --- src/CMakeLists.txt | 1 + src/Resource.h | 264 ++++++++++++++++++++++++++++++++++++++++++ src/ResourceManager.h | 235 +------------------------------------ 3 files changed, 268 insertions(+), 232 deletions(-) create mode 100644 src/Resource.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ac3038d5..c9460aeca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,6 +68,7 @@ set(Magnum_HEADERS Profiler.h Query.h Renderbuffer.h + Resource.h ResourceManager.h Shader.h SizeTraits.h diff --git a/src/Resource.h b/src/Resource.h new file mode 100644 index 000000000..0909d5eb5 --- /dev/null +++ b/src/Resource.h @@ -0,0 +1,264 @@ +#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. +*/ + +/** @file /Resource.h + * @brief Class Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState, Magnum::ResourceDataState, Magnum::ResourcePolicy + */ + +namespace Magnum { + +/** @relates ResourceManager + * @brief %Resource state + * + * @see Resource::state(), ResourceManager::state() + */ +enum class ResourceState: std::uint8_t { + /** The resource is not yet loaded. */ + NotLoaded, + + /** The resource is not yet loaded and fallback resource is used instead. */ + Fallback, + + /** The resource is loaded, but can be changed by the manager at any time. */ + Mutable, + + /** The resource is loaded and won't be changed by the manager anymore. */ + Final +}; + +/** @relates ResourceManager + * @brief %Resource data state + * + * @see ResourceManager::set() + */ +enum class ResourceDataState: std::uint8_t { + /** + * The resource can be changed by the manager in the future. This is + * slower, as Resource needs to ask the manager for new version every time + * the data are accessed, but allows changing the data for e.g. debugging + * purposes. + */ + Mutable = int(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 = int(ResourceState::Final) +}; + +/** @relates ResourceManager +@brief %Resource policy + +@see ResourceManager::set(), ResourceManager::free() + */ +enum class ResourcePolicy: std::uint8_t { + /** The resource will stay resident for whole lifetime of resource manager. */ + Resident, + + /** + * The resource will be unloaded when manually calling + * ResourceManager::free() if nothing references it. + */ + Manual, + + /** The resource will be unloaded when last reference to it is gone. */ + ReferenceCounted +}; + +/** +@brief Key for accessing resource + +@see ResourceManager::referenceCount(), ResourceManager::state(), + ResourceManager::get(), ResourceManager::set(), Resource::key() +*/ +class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { + public: + /** + * @brief Default constructor + * + * Creates zero key. Note that it is not the same as calling other + * constructors with empty string. + */ + inline constexpr ResourceKey() {} + + /** @brief Constructor */ + inline ResourceKey(const std::string& key): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} + + /** + * @brief Constructor + * @todo constexpr + */ + template inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} +}; + +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Implementation { + template class ResourceManagerData; +} +#endif + +/** +@brief %Resource reference + +See ResourceManager for more information. +*/ +template class Resource { + friend class Implementation::ResourceManagerData; + + public: + /** + * @brief Default constructor + * + * Creates empty resource. Resources are acquired from the manager by + * calling ResourceManager::get(). + */ + inline 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) { + if(manager) manager->incrementReferenceCount(_key); + } + + /** @brief Move constructor */ + inline Resource(Resource&& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + other.manager = nullptr; + } + + /** @brief Destructor */ + inline ~Resource() { + if(manager) manager->decrementReferenceCount(_key); + } + + /** @brief Assignment operator */ + Resource& operator=(const Resource& other) { + if(manager) manager->decrementReferenceCount(_key); + + manager = other.manager; + _key = other._key; + lastCheck = other.lastCheck; + _state = other._state; + data = other.data; + + if(manager) manager->incrementReferenceCount(_key); + return *this; + } + + /** @brief Assignment move operator */ + Resource& operator=(Resource&& other) { + if(manager) manager->decrementReferenceCount(_key); + + manager = other.manager; + _key = other._key; + lastCheck = other.lastCheck; + _state = other._state; + data = other.data; + + other.manager = nullptr; + return *this; + } + + /** @brief Resource key */ + inline ResourceKey key() const { return _key; } + + /** + * @brief %Resource state + * + * @see operator bool() + */ + inline ResourceState state() { + acquire(); + return _state; + } + + /** + * @brief Whether the resource is available + * @return False when resource is not loaded and no fallback is + * available, true otherwise. + * + * @see state() + */ + inline operator bool() { + acquire(); + return data; + } + + /** + * @brief %Resource data + * + * The resource must be loaded before accessing it. Use boolean + * conversion operator or state() for testing whether it is loaded. + */ + inline operator U*() { + acquire(); + CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr); + return static_cast(data); + } + + /** @overload */ + inline U* operator->() { + acquire(); + CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr); + return static_cast(data); + } + + /** @overload */ + inline U& operator*() { + acquire(); + CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), *static_cast(data)); + return *static_cast(data); + } + + private: + inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), _key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { + manager->incrementReferenceCount(key); + } + + void acquire() { + /* The data are already final, nothing to do */ + if(_state == ResourceState::Final) return; + + /* Nothing changed since last check */ + if(manager->lastChange() < lastCheck) return; + + /* Acquire new data and save last check time */ + const typename Implementation::ResourceManagerData::Data& d = manager->data(_key); + lastCheck = manager->lastChange(); + + /* Try to get the data */ + if((data = d.data)) + _state = static_cast(d.state); + else if((data = manager->fallback())) + _state = ResourceState::Fallback; + else + _state = ResourceState::NotLoaded; + } + + Implementation::ResourceManagerData* manager; + ResourceKey _key; + std::size_t lastCheck; + ResourceState _state; + T* data; +}; + +} + +/* Make the definition complete */ +#include "ResourceManager.h" + +#endif diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 22a7097e4..696eb3640 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -16,101 +16,15 @@ */ /** @file - * @brief Class Magnum::ResourceManager, Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState, Magnum::ResourceDataState, Magnum::ResourcePolicy + * @brief Class Magnum::ResourceManager */ #include #include -namespace Magnum { - -/** @relates ResourceManager - * @brief %Resource state - * - * @see Resource::state(), ResourceManager::state() - */ -enum class ResourceState: std::uint8_t { - /** The resource is not yet loaded. */ - NotLoaded, - - /** The resource is not yet loaded and fallback resource is used instead. */ - Fallback, - - /** The resource is loaded, but can be changed by the manager at any time. */ - Mutable, - - /** The resource is loaded and won't be changed by the manager anymore. */ - Final -}; - -/** @relates ResourceManager - * @brief %Resource data state - * - * @see ResourceManager::set() - */ -enum class ResourceDataState: std::uint8_t { - /** - * The resource can be changed by the manager in the future. This is - * slower, as Resource needs to ask the manager for new version every time - * the data are accessed, but allows changing the data for e.g. debugging - * purposes. - */ - Mutable = int(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 = int(ResourceState::Final) -}; - -/** @relates ResourceManager -@brief %Resource policy - -@see ResourceManager::set(), ResourceManager::free() - */ -enum class ResourcePolicy: std::uint8_t { - /** The resource will stay resident for whole lifetime of resource manager. */ - Resident, - - /** - * The resource will be unloaded when manually calling - * ResourceManager::free() if nothing references it. - */ - Manual, - - /** The resource will be unloaded when last reference to it is gone. */ - ReferenceCounted -}; - -/** -@brief Key for accessing resource - -@see ResourceManager::referenceCount(), ResourceManager::state(), - ResourceManager::get(), ResourceManager::set(), Resource::key() -*/ -class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { - public: - /** - * @brief Default constructor - * - * Creates zero key. Note that it is not the same as calling other - * constructors with empty string. - */ - inline constexpr ResourceKey() {} - - /** @brief Constructor */ - inline ResourceKey(const std::string& key): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} +#include "Resource.h" - /** - * @brief Constructor - * @todo constexpr - */ - template inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} -}; - -template class Resource; +namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { @@ -249,149 +163,6 @@ namespace Implementation { } #endif -/** -@brief %Resource reference - -See ResourceManager for more information. -*/ -template class Resource { - friend class Implementation::ResourceManagerData; - - public: - /** - * @brief Default constructor - * - * Creates empty resource. Resources are acquired from the manager by - * calling ResourceManager::get(). - */ - inline 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) { - if(manager) manager->incrementReferenceCount(_key); - } - - /** @brief Move constructor */ - inline Resource(Resource&& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { - other.manager = nullptr; - } - - /** @brief Destructor */ - inline ~Resource() { - if(manager) manager->decrementReferenceCount(_key); - } - - /** @brief Assignment operator */ - Resource& operator=(const Resource& other) { - if(manager) manager->decrementReferenceCount(_key); - - manager = other.manager; - _key = other._key; - lastCheck = other.lastCheck; - _state = other._state; - data = other.data; - - if(manager) manager->incrementReferenceCount(_key); - return *this; - } - - /** @brief Assignment move operator */ - Resource& operator=(Resource&& other) { - if(manager) manager->decrementReferenceCount(_key); - - manager = other.manager; - _key = other._key; - lastCheck = other.lastCheck; - _state = other._state; - data = other.data; - - other.manager = nullptr; - return *this; - } - - /** @brief Resource key */ - inline ResourceKey key() const { return _key; } - - /** - * @brief %Resource state - * - * @see operator bool() - */ - inline ResourceState state() { - acquire(); - return _state; - } - - /** - * @brief Whether the resource is available - * @return False when resource is not loaded and no fallback is - * available, true otherwise. - * - * @see state() - */ - inline operator bool() { - acquire(); - return data; - } - - /** - * @brief %Resource data - * - * The resource must be loaded before accessing it. Use boolean - * conversion operator or state() for testing whether it is loaded. - */ - inline operator U*() { - acquire(); - CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr); - return static_cast(data); - } - - /** @overload */ - inline U* operator->() { - acquire(); - CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), nullptr); - return static_cast(data); - } - - /** @overload */ - inline U& operator*() { - acquire(); - CORRADE_ASSERT(data, "Resource: accessing not loaded data with key" << key(), *static_cast(data)); - return *static_cast(data); - } - - private: - inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), _key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { - manager->incrementReferenceCount(key); - } - - void acquire() { - /* The data are already final, nothing to do */ - if(_state == ResourceState::Final) return; - - /* Nothing changed since last check */ - if(manager->lastChange() < lastCheck) return; - - /* Acquire new data and save last check time */ - const typename Implementation::ResourceManagerData::Data& d = manager->data(_key); - lastCheck = manager->lastChange(); - - /* Try to get the data */ - if((data = d.data)) - _state = static_cast(d.state); - else if((data = manager->fallback())) - _state = ResourceState::Fallback; - else - _state = ResourceState::NotLoaded; - } - - Implementation::ResourceManagerData* manager; - ResourceKey _key; - std::size_t lastCheck; - ResourceState _state; - T* data; -}; - /** @brief %Resource manager From a387e23f433a28a484bf73b282187c5f4b41c32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 11:11:02 +0100 Subject: [PATCH 05/20] Updated forward declarations. --- src/Magnum.h | 3 ++- src/Resource.h | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Magnum.h b/src/Magnum.h index fd941af29..363d6d97c 100644 --- a/src/Magnum.h +++ b/src/Magnum.h @@ -155,7 +155,8 @@ class Renderbuffer; enum class ResourceState: std::uint8_t; enum class ResourceDataState: std::uint8_t; enum class ResourcePolicy: std::uint8_t; -template class Resource; +template class Resource; +class ResourceKey; template class ResourceManager; class Shader; diff --git a/src/Resource.h b/src/Resource.h index 0909d5eb5..35ddebda2 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -19,6 +19,8 @@ * @brief Class Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState, Magnum::ResourceDataState, Magnum::ResourcePolicy */ +#include "Magnum.h" + namespace Magnum { /** @relates ResourceManager @@ -118,7 +120,12 @@ namespace Implementation { See ResourceManager for more information. */ -template class Resource { +#ifndef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class Resource { friend class Implementation::ResourceManagerData; public: From 4545eb8987f2d61ebf11f5e48fd3f5e277559e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 11:33:57 +0100 Subject: [PATCH 06/20] Doc++ --- src/AbstractTexture.h | 10 ++++++---- src/Mesh.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index ae43129c7..038e4ad5d 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -29,10 +29,12 @@ 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 mipmap -filtering in setMinificationFilter(), be sure to also either explicitly set -all mip levels or call generateMipmap(). + 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 diff --git a/src/Mesh.h b/src/Mesh.h index 21930fad8..8eee5324d 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -33,8 +33,8 @@ namespace Magnum { @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 them with vertex data. You can also use MeshTools::interleave() to +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(). From 9c007114ac1df418a43282adb368598fe19dec4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 11:34:29 +0100 Subject: [PATCH 07/20] ResourceManager: make internal functions private. Even if this is internal implementation class, the functions should be accessible only from Resource itself. --- src/ResourceManager.h | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 696eb3640..4621e212c 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -35,35 +35,14 @@ namespace Implementation { }; template class ResourceManagerData { + template friend class Resource; + ResourceManagerData(const ResourceManagerData&) = delete; ResourceManagerData(ResourceManagerData&&) = delete; ResourceManagerData& operator=(const ResourceManagerData&) = delete; ResourceManagerData& operator=(ResourceManagerData&&) = delete; public: - struct Data { - Data(const Data&) = delete; - Data& operator=(const Data&) = delete; - Data& operator=(Data&&) = delete; - - inline Data(): data(nullptr), state(ResourceDataState::Mutable), policy(ResourcePolicy::Manual), referenceCount(0) {} - - inline Data(Data&& other): data(other.data), state(other.state), policy(other.policy), referenceCount(other.referenceCount) { - other.data = nullptr; - other.referenceCount = 0; - } - - inline ~Data() { - CORRADE_ASSERT(referenceCount == 0, "ResourceManager: cannot destruct it while data are still referenced", ); - delete data; - } - - T* data; - ResourceDataState state; - ResourcePolicy policy; - std::size_t referenceCount; - }; - inline virtual ~ResourceManagerData() { delete _fallback; } @@ -136,6 +115,33 @@ namespace Implementation { inline T* fallback() const { return _fallback; } + protected: + inline ResourceManagerData(): _fallback(nullptr), _lastChange(0) {} + + private: + struct Data { + Data(const Data&) = delete; + Data& operator=(const Data&) = delete; + Data& operator=(Data&&) = delete; + + inline Data(): data(nullptr), state(ResourceDataState::Mutable), policy(ResourcePolicy::Manual), referenceCount(0) {} + + inline Data(Data&& other): data(other.data), state(other.state), policy(other.policy), referenceCount(other.referenceCount) { + other.data = nullptr; + other.referenceCount = 0; + } + + inline ~Data() { + CORRADE_ASSERT(referenceCount == 0, "ResourceManager: cannot destruct it while data are still referenced", ); + delete data; + } + + T* data; + ResourceDataState state; + ResourcePolicy policy; + std::size_t referenceCount; + }; + inline const Data& data(ResourceKey key) { return _data[key]; } @@ -152,10 +158,6 @@ namespace Implementation { _data.erase(it); } - protected: - inline ResourceManagerData(): _fallback(nullptr), _lastChange(0) {} - - private: std::unordered_map _data; T* _fallback; std::size_t _lastChange; From 9623229ec09f4d7d55734a676a03d19387d200bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 12:36:20 +0100 Subject: [PATCH 08/20] Reorganized ResourceManager.h / Resource.h files. Moved #include where it belongs, moved ResourceManager-only enums to ResourceManager.h, moved debug operator for ResourceKey to Resource.h. --- src/Resource.h | 52 ++++++++----------------------------------- src/ResourceManager.h | 48 ++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/Resource.h b/src/Resource.h index 35ddebda2..9b90cf41e 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -16,14 +16,16 @@ */ /** @file /Resource.h - * @brief Class Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState, Magnum::ResourceDataState, Magnum::ResourcePolicy + * @brief Class Magnum::ResourceKey, Magnum::Resource, enum Magnum::ResourceState */ +#include + #include "Magnum.h" namespace Magnum { -/** @relates ResourceManager +/** @relates Resource * @brief %Resource state * * @see Resource::state(), ResourceManager::state() @@ -42,47 +44,6 @@ enum class ResourceState: std::uint8_t { Final }; -/** @relates ResourceManager - * @brief %Resource data state - * - * @see ResourceManager::set() - */ -enum class ResourceDataState: std::uint8_t { - /** - * The resource can be changed by the manager in the future. This is - * slower, as Resource needs to ask the manager for new version every time - * the data are accessed, but allows changing the data for e.g. debugging - * purposes. - */ - Mutable = int(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 = int(ResourceState::Final) -}; - -/** @relates ResourceManager -@brief %Resource policy - -@see ResourceManager::set(), ResourceManager::free() - */ -enum class ResourcePolicy: std::uint8_t { - /** The resource will stay resident for whole lifetime of resource manager. */ - Resident, - - /** - * The resource will be unloaded when manually calling - * ResourceManager::free() if nothing references it. - */ - Manual, - - /** The resource will be unloaded when last reference to it is gone. */ - ReferenceCounted -}; - /** @brief Key for accessing resource @@ -109,6 +70,11 @@ class ResourceKey: public Corrade::Utility::MurmurHash2::Digest { template inline constexpr ResourceKey(const char(&key)[size]): Corrade::Utility::MurmurHash2::Digest(Corrade::Utility::MurmurHash2()(key)) {} }; +/** @debugoperator{Magnum::ResourceKey} */ +inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { + return debug << static_cast&>(value); +} + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template class ResourceManagerData; diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 4621e212c..7b54c586c 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -16,16 +16,56 @@ */ /** @file - * @brief Class Magnum::ResourceManager + * @brief Class Magnum::ResourceManager, enum Magnum::ResourceDataState, Magnum::ResourcePolicy */ #include -#include #include "Resource.h" namespace Magnum { +/** @relates ResourceManager + * @brief %Resource data state + * + * @see ResourceManager::set() + */ +enum class ResourceDataState: std::uint8_t { + /** + * The resource can be changed by the manager in the future. This is + * slower, as Resource needs to ask the manager for new version every time + * the data are accessed, but allows changing the data for e.g. debugging + * purposes. + */ + Mutable = int(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 = int(ResourceState::Final) +}; + +/** @relates ResourceManager +@brief %Resource policy + +@see ResourceManager::set(), ResourceManager::free() + */ +enum class ResourcePolicy: std::uint8_t { + /** The resource will stay resident for whole lifetime of resource manager. */ + Resident, + + /** + * The resource will be unloaded when manually calling + * ResourceManager::free() if nothing references it. + */ + Manual, + + /** The resource will be unloaded when last reference to it is gone. */ + ReferenceCounted +}; + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { struct ResourceKeyHash { @@ -356,11 +396,7 @@ template ResourceManager*& ResourceManager:: } #endif -/** @debugoperator{Magnum::ResourceKey} */ -template inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const ResourceKey& value) { - return debug << static_cast&>(value); } -} #endif From 4bdb248e767a9bef3b2762e545469267005a5795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 15:06:15 +0100 Subject: [PATCH 09/20] ResourceManager: public accessor for fallback resource. --- src/ResourceManager.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 7b54c586c..6d0b0a860 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -139,6 +139,9 @@ namespace Implementation { ++_lastChange; } + inline T* fallback() { return _fallback; } + inline const T* fallback() const { return _fallback; } + inline void setFallback(T* data) { delete _fallback; _fallback = data; @@ -153,8 +156,6 @@ namespace Implementation { } } - inline T* fallback() const { return _fallback; } - protected: inline ResourceManagerData(): _fallback(nullptr), _lastChange(0) {} @@ -364,6 +365,16 @@ template class ResourceManager: protected Implementation::Resour this->Implementation::ResourceManagerData::set(key, data, state, policy); } + /** @brief Fallback for not found resources */ + template inline T* fallback() { + return this->Implementation::ResourceManagerData::fallback(); + } + + /** @overload */ + template inline const T* fallback() const { + return this->Implementation::ResourceManagerData::fallback(); + } + /** @brief Set fallback for not found resources */ template inline void setFallback(T* data) { return this->Implementation::ResourceManagerData::setFallback(data); From 510755ea6ebc1fb34b680eec394d71453f4f4e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 16:08:11 +0100 Subject: [PATCH 10/20] ResourceManager: privately inherit Implementation::ResourceManagerData. Protected inheritance has no sense, as there shouldn't be any subclasses touching internals in Implementation namespace. --- src/ResourceManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 6d0b0a860..4a5e1cf49 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -272,7 +272,7 @@ cube->draw(); /* Due to too much work involved with explicit template instantiation (all Resource combinations, all ResourceManagerData...), this class doesn't have template implementation file. */ -template class ResourceManager: protected Implementation::ResourceManagerData... { +template class ResourceManager: private Implementation::ResourceManagerData... { public: /** @brief Global instance */ inline static ResourceManager* instance() { From ca9828de641001d6c37468bd3be0058982bf78ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 15:10:13 +0100 Subject: [PATCH 11/20] ResourceManager: various cleanup. Using proper cast in ResourceDataState enum. --- src/ResourceManager.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 4a5e1cf49..b11142eda 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -28,7 +28,7 @@ namespace Magnum { /** @relates ResourceManager * @brief %Resource data state * - * @see ResourceManager::set() + * @see ResourceManager::set(), ResourceState */ enum class ResourceDataState: std::uint8_t { /** @@ -37,14 +37,14 @@ enum class ResourceDataState: std::uint8_t { * the data are accessed, but allows changing the data for e.g. debugging * purposes. */ - Mutable = int(ResourceState::Mutable), + Mutable = std::uint8_t(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 = int(ResourceState::Final) + Final = std::uint8_t(ResourceState::Final) }; /** @relates ResourceManager @@ -113,7 +113,8 @@ namespace Implementation { auto it = _data.find(key); /* Cannot change resource with already final state */ - CORRADE_ASSERT(it == _data.end() || it->second.state != ResourceDataState::Final, "ResourceManager: cannot change already final resource", ); + CORRADE_ASSERT(it == _data.end() || it->second.state != ResourceDataState::Final, + "ResourceManager: cannot change already final resource", ); /* If nothing is referencing reference-counted resource, we're done */ if(policy == ResourcePolicy::ReferenceCounted && (it == _data.end() || it->second.referenceCount == 0)) { @@ -358,7 +359,7 @@ template class ResourceManager: private Implementation::Resource * } * @endcode * @attention If resource state is already `ResourceState::Final`, - * subsequent updates are not possible. + * subsequent updates are not possible. * @see referenceCount(), state() */ template inline void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { From 1ac90416805bf839f9c8d8a34b526061a151271b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 15:34:07 +0100 Subject: [PATCH 12/20] ResourceManager: stateless test. It now doesn't reuse manager instance among test cases, making it more failproof. --- src/Test/ResourceManagerTest.cpp | 85 ++++++++++++++++++++------------ src/Test/ResourceManagerTest.h | 21 +------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index bf99d364f..57e7490aa 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -26,94 +26,115 @@ CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerTest) namespace Magnum { namespace Test { +class Data { + public: + static std::size_t count; + + inline Data() { ++count; } + inline ~Data() { --count; } +}; + +typedef Magnum::ResourceManager ResourceManager; + size_t Data::count = 0; ResourceManagerTest::ResourceManagerTest() { - rm = new ResourceManager; - addTests(&ResourceManagerTest::state, + &ResourceManagerTest::residentPolicy, &ResourceManagerTest::referenceCountedPolicy, - &ResourceManagerTest::manualPolicy, - &ResourceManagerTest::destroy); + &ResourceManagerTest::manualPolicy); } void ResourceManagerTest::state() { + ResourceManager rm; + ResourceKey questionKey("the-question"); - rm->set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); - Resource theQuestion = rm->get(questionKey); + rm.set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); + Resource theQuestion = rm.get(questionKey); CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable); CORRADE_COMPARE(*theQuestion, 10); /* Check that hash function is working properly */ ResourceKey answerKey("the-answer"); - rm->set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); - Resource theAnswer = rm->get(answerKey); + rm.set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); + Resource theAnswer = rm.get(answerKey); CORRADE_VERIFY(theAnswer.state() == ResourceState::Final); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(rm->count(), 2); + CORRADE_COMPARE(rm.count(), 2); /* Cannot change already final resource */ stringstream out; Error::setOutput(&out); - rm->set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm.set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(out.str(), "ResourceManager: cannot change already final resource\n"); /* Check non-final resource changes */ - rm->set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); + rm.set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_VERIFY(theQuestion.state() == ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } +void ResourceManagerTest::residentPolicy() { + ResourceManager* rm = new ResourceManager; + + rm->set("blah", new Data(), ResourceDataState::Mutable, ResourcePolicy::Resident); + CORRADE_COMPARE(Data::count, 1); + + rm->free(); + CORRADE_COMPARE(Data::count, 1); + + delete rm; + CORRADE_COMPARE(Data::count, 0); +} + void ResourceManagerTest::referenceCountedPolicy() { + ResourceManager rm; + ResourceKey dataRefCountKey("dataRefCount"); /* Reference counted resources must be requested first */ { - rm->set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); - CORRADE_COMPARE(rm->count(), 0); - Resource data = rm->get(dataRefCountKey); + rm.set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); + CORRADE_COMPARE(rm.count(), 0); + Resource data = rm.get(dataRefCountKey); CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); CORRADE_COMPARE(Data::count, 0); } { - Resource data = rm->get(dataRefCountKey); - CORRADE_COMPARE(rm->count(), 1); + Resource data = rm.get(dataRefCountKey); + CORRADE_COMPARE(rm.count(), 1); CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); - rm->set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); + rm.set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); CORRADE_VERIFY(data.state() == ResourceState::Final); CORRADE_COMPARE(Data::count, 1); } - CORRADE_COMPARE(rm->count(), 0); + CORRADE_COMPARE(rm.count(), 0); CORRADE_COMPARE(Data::count, 0); } void ResourceManagerTest::manualPolicy() { + ResourceManager rm; + ResourceKey dataKey("data"); /* Manual free */ { - rm->set(dataKey, new Data(), ResourceDataState::Mutable, ResourcePolicy::Manual); - Resource data = rm->get(dataKey); - rm->free(); + rm.set(dataKey, new Data(), ResourceDataState::Mutable, ResourcePolicy::Manual); + Resource data = rm.get(dataKey); + rm.free(); } - CORRADE_COMPARE(rm->count(), 1); + CORRADE_COMPARE(rm.count(), 1); CORRADE_COMPARE(Data::count, 1); - rm->free(); - CORRADE_COMPARE(rm->count(), 0); + rm.free(); + CORRADE_COMPARE(rm.count(), 0); CORRADE_COMPARE(Data::count, 0); - rm->set(dataKey, new Data(), ResourceDataState::Mutable, ResourcePolicy::Manual); - CORRADE_COMPARE(rm->count(), 1); + rm.set(dataKey, new Data(), ResourceDataState::Mutable, ResourcePolicy::Manual); + CORRADE_COMPARE(rm.count(), 1); CORRADE_COMPARE(Data::count, 1); } -void ResourceManagerTest::destroy() { - delete rm; - rm = nullptr; - CORRADE_COMPARE(Data::count, 0); -} - }} diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index ef7c1826a..b6f387498 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -17,33 +17,16 @@ #include -namespace Magnum { - -template class ResourceManager; - -namespace Test { - -class Data { - public: - static std::size_t count; - - inline Data() { ++count; } - inline ~Data() { --count; } -}; - -typedef Magnum::ResourceManager ResourceManager; +namespace Magnum { namespace Test { class ResourceManagerTest: public Corrade::TestSuite::Tester { public: ResourceManagerTest(); void state(); + void residentPolicy(); void referenceCountedPolicy(); void manualPolicy(); - void destroy(); - - private: - ResourceManager* rm; }; }} From 72145e1339732427f61be6ea93e0b6a9db2ea05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 16:22:51 +0100 Subject: [PATCH 13/20] Debug output operator for ResourceState enum. --- src/CMakeLists.txt | 1 + src/Resource.cpp | 39 ++++++++++++++++++++++++++++++++ src/Resource.h | 5 ++++ src/Test/CMakeLists.txt | 2 +- src/Test/ResourceManagerTest.cpp | 12 +++++----- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 src/Resource.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c9460aeca..26601309b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ set(Magnum_SRCS Profiler.cpp Query.cpp Renderbuffer.cpp + Resource.cpp Shader.cpp SizeTraits.cpp Timeline.cpp diff --git a/src/Resource.cpp b/src/Resource.cpp new file mode 100644 index 000000000..6093091d4 --- /dev/null +++ b/src/Resource.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 "Resource.h" + +namespace Magnum { + +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug MAGNUM_EXPORT operator<<(Debug debug, ResourceState value) { + switch(value) { + #define _c(value) case ResourceState::value: return debug << "ResourceState::" #value; + _c(NotLoaded) + _c(NotLoadedFallback) + _c(Loading) + _c(LoadingFallback) + _c(NotFound) + _c(NotFoundFallback) + _c(Mutable) + _c(Final) + #undef _c + } + + return debug << "ResourceState::(invalid)"; +} +#endif + +} diff --git a/src/Resource.h b/src/Resource.h index 9b90cf41e..484036726 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -23,6 +23,8 @@ #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** @relates Resource @@ -44,6 +46,9 @@ enum class ResourceState: std::uint8_t { Final }; +/** @debugoperator{Magnum::Resource} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, ResourceState value); + /** @brief Key for accessing resource diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 2a2c2ebc8..e7950f7f4 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,5 +1,5 @@ corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp) +corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test2(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 57e7490aa..9c50d214b 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -51,14 +51,14 @@ void ResourceManagerTest::state() { ResourceKey questionKey("the-question"); rm.set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); Resource theQuestion = rm.get(questionKey); - CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable); + CORRADE_COMPARE(theQuestion.state(), ResourceState::Mutable); CORRADE_COMPARE(*theQuestion, 10); /* Check that hash function is working properly */ ResourceKey answerKey("the-answer"); rm.set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); Resource theAnswer = rm.get(answerKey); - CORRADE_VERIFY(theAnswer.state() == ResourceState::Final); + CORRADE_COMPARE(theAnswer.state(), ResourceState::Final); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(rm.count(), 2); @@ -72,7 +72,7 @@ void ResourceManagerTest::state() { /* Check non-final resource changes */ rm.set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); - CORRADE_VERIFY(theQuestion.state() == ResourceState::Final); + CORRADE_COMPARE(theQuestion.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } @@ -99,14 +99,14 @@ void ResourceManagerTest::referenceCountedPolicy() { rm.set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); CORRADE_COMPARE(rm.count(), 0); Resource data = rm.get(dataRefCountKey); - CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); + CORRADE_COMPARE(data.state(), ResourceState::NotLoaded); CORRADE_COMPARE(Data::count, 0); } { Resource data = rm.get(dataRefCountKey); CORRADE_COMPARE(rm.count(), 1); - CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); + CORRADE_COMPARE(data.state(), ResourceState::NotLoaded); rm.set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); - CORRADE_VERIFY(data.state() == ResourceState::Final); + CORRADE_COMPARE(data.state(), ResourceState::Final); CORRADE_COMPARE(Data::count, 1); } From d688cf2efc8e303550d4a578080db84df4011b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Nov 2012 15:12:13 +0100 Subject: [PATCH 14/20] ResourceManager: new Loading and NotFound data states. Updated, cleaned up and extended unit tests. --- src/Resource.h | 48 +++++++++++++----- src/ResourceManager.h | 41 +++++++++++++-- src/Test/ResourceManagerTest.cpp | 86 ++++++++++++++++++++++++++++---- src/Test/ResourceManagerTest.h | 3 ++ 4 files changed, 152 insertions(+), 26 deletions(-) diff --git a/src/Resource.h b/src/Resource.h index 484036726..33085cb7c 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -33,11 +33,23 @@ namespace Magnum { * @see Resource::state(), ResourceManager::state() */ enum class ResourceState: std::uint8_t { - /** The resource is not yet loaded. */ + /** The resource is not yet loaded (and no fallback is available). */ NotLoaded, /** The resource is not yet loaded and fallback resource is used instead. */ - Fallback, + NotLoadedFallback, + + /** The resource is currently loading (and no fallback is available). */ + Loading, + + /** The resource is currently loading and fallback resource is used instead. */ + LoadingFallback, + + /** The resource was not found (and no fallback is available). */ + NotFound, + + /** The resource was not found and fallback resource is used instead. */ + NotFoundFallback, /** The resource is loaded, but can be changed by the manager at any time. */ Mutable, @@ -157,7 +169,7 @@ class Resource { /** * @brief %Resource state * - * @see operator bool() + * @see operator bool(), ResourceManager::state() */ inline ResourceState state() { acquire(); @@ -166,10 +178,11 @@ class Resource { /** * @brief Whether the resource is available - * @return False when resource is not loaded and no fallback is - * available, true otherwise. * - * @see state() + * Returns `false` when resource is not loaded and no fallback is + * available (i.e. state() is either @ref ResourceState "ResourceState::NotLoaded", + * @ref ResourceState "ResourceState::Loading" or + * @ref ResourceState "ResourceState::NotFound"), true otherwise. */ inline operator bool() { acquire(); @@ -219,12 +232,23 @@ class Resource { lastCheck = manager->lastChange(); /* Try to get the data */ - if((data = d.data)) - _state = static_cast(d.state); - else if((data = manager->fallback())) - _state = ResourceState::Fallback; - else - _state = ResourceState::NotLoaded; + data = d.data; + _state = static_cast(d.state); + + /* Data are not available */ + if(!data) { + /* Fallback found, add *Fallback to state */ + if((data = manager->fallback())) { + if(_state == ResourceState::Loading) + _state = ResourceState::LoadingFallback; + else if(_state == ResourceState::NotFound) + _state = ResourceState::NotFoundFallback; + else _state = ResourceState::NotLoadedFallback; + + /* Fallback not found and loading didn't start yet */ + } else if(_state != ResourceState::Loading && _state != ResourceState::NotFound) + _state = ResourceState::NotLoaded; + } } Implementation::ResourceManagerData* manager; diff --git a/src/ResourceManager.h b/src/ResourceManager.h index b11142eda..22fe1c0b0 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -31,6 +31,18 @@ namespace Magnum { * @see ResourceManager::set(), ResourceState */ enum class ResourceDataState: std::uint8_t { + /** + * The resource is currently loading. Parameter @p data in ResourceManager::set() + * should be set to `null`. + */ + Loading = int(ResourceState::Loading), + + /** + * The resource was not found. Parameter @p data in ResourceManager::set() + * should be set to `null`. + */ + NotFound = int(ResourceState::NotFound), + /** * The resource can be changed by the manager in the future. This is * slower, as Resource needs to ask the manager for new version every time @@ -99,10 +111,25 @@ namespace Implementation { ResourceState state(ResourceKey key) const { auto it = _data.find(key); - if(it == _data.end() || !it->second.data) - return _fallback ? ResourceState::Fallback : ResourceState::NotLoaded; - else - return static_cast(it->second.state); + + /* Resource not loaded */ + if(it == _data.end() || !it->second.data) { + /* Fallback found, add *Fallback to state */ + if(_fallback) { + if(it != _data.end() && it->second.state == ResourceDataState::Loading) + return ResourceState::LoadingFallback; + else if(it != _data.end() && it->second.state == ResourceDataState::NotFound) + return ResourceState::NotFoundFallback; + else return ResourceState::NotLoadedFallback; + } + + /* Fallback not found, loading didn't start yet */ + if(it == _data.end() || (it->second.state != ResourceDataState::Loading && it->second.state != ResourceDataState::NotFound)) + return ResourceState::NotLoaded; + } + + /* Loading / NotFound without fallback, Mutable / Final */ + return static_cast(it->second.state); } template inline Resource get(ResourceKey key) { @@ -112,9 +139,13 @@ namespace Implementation { void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { auto it = _data.find(key); + /* NotFound / Loading state shouldn't have any data */ + CORRADE_ASSERT((data == nullptr) == (state == ResourceDataState::NotFound || state == ResourceDataState::Loading), + "ResourceManager::set(): data should be null if and only if state is NotFound or Loading", ); + /* Cannot change resource with already final state */ CORRADE_ASSERT(it == _data.end() || it->second.state != ResourceDataState::Final, - "ResourceManager: cannot change already final resource", ); + "ResourceManager::set(): cannot change already final resource", ); /* 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 9c50d214b..863a5d2c1 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -40,6 +40,9 @@ size_t Data::count = 0; ResourceManagerTest::ResourceManagerTest() { addTests(&ResourceManagerTest::state, + &ResourceManagerTest::stateFallback, + &ResourceManagerTest::stateDisallowed, + &ResourceManagerTest::basic, &ResourceManagerTest::residentPolicy, &ResourceManagerTest::referenceCountedPolicy, &ResourceManagerTest::manualPolicy); @@ -48,19 +51,84 @@ ResourceManagerTest::ResourceManagerTest() { void ResourceManagerTest::state() { ResourceManager rm; - ResourceKey questionKey("the-question"); - rm.set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); - Resource theQuestion = rm.get(questionKey); - CORRADE_COMPARE(theQuestion.state(), ResourceState::Mutable); - CORRADE_COMPARE(*theQuestion, 10); + Resource data = rm.get("data"); + CORRADE_VERIFY(!data); + CORRADE_COMPARE(data.state(), ResourceState::NotLoaded); + CORRADE_COMPARE(rm.state("data"), ResourceState::NotLoaded); + + rm.set("data", nullptr, ResourceDataState::Loading, ResourcePolicy::Resident); + CORRADE_VERIFY(!data); + CORRADE_COMPARE(data.state(), ResourceState::Loading); + CORRADE_COMPARE(rm.state("data"), ResourceState::Loading); + + rm.set("data", nullptr, ResourceDataState::NotFound, ResourcePolicy::Resident); + CORRADE_VERIFY(!data); + CORRADE_COMPARE(data.state(), ResourceState::NotFound); + CORRADE_COMPARE(rm.state("data"), ResourceState::NotFound); + + /* Nothing happened at all */ + CORRADE_COMPARE(Data::count, 0); +} + +void ResourceManagerTest::stateFallback() { + { + ResourceManager rm; + rm.setFallback(new Data); + + Resource data = rm.get("data"); + CORRADE_VERIFY(data); + CORRADE_COMPARE(data.state(), ResourceState::NotLoadedFallback); + CORRADE_COMPARE(rm.state("data"), ResourceState::NotLoadedFallback); + + rm.set("data", nullptr, ResourceDataState::Loading, ResourcePolicy::Resident); + CORRADE_VERIFY(data); + CORRADE_COMPARE(data.state(), ResourceState::LoadingFallback); + CORRADE_COMPARE(rm.state("data"), ResourceState::LoadingFallback); + + rm.set("data", nullptr, ResourceDataState::NotFound, ResourcePolicy::Resident); + CORRADE_VERIFY(data); + CORRADE_COMPARE(data.state(), ResourceState::NotFoundFallback); + CORRADE_COMPARE(rm.state("data"), ResourceState::NotFoundFallback); + + /* Only fallback is here */ + CORRADE_COMPARE(Data::count, 1); + } + + /* Fallback gets destroyed */ + CORRADE_COMPARE(Data::count, 0); +} + +void ResourceManagerTest::stateDisallowed() { + ResourceManager rm; + + stringstream out; + Error::setOutput(&out); + + Data d; + 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(""); + 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"); +} - /* Check that hash function is working properly */ +void ResourceManagerTest::basic() { + ResourceManager rm; + + /* 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); + + /* 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); /* Cannot change already final resource */ @@ -68,9 +136,9 @@ void ResourceManagerTest::state() { Error::setOutput(&out); rm.set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(out.str(), "ResourceManager: cannot change already final resource\n"); + CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource\n"); - /* Check non-final resource changes */ + /* But non-final can be changed */ rm.set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_COMPARE(theQuestion.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index b6f387498..73b4a49ea 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -24,6 +24,9 @@ class ResourceManagerTest: public Corrade::TestSuite::Tester Date: Sat, 24 Nov 2012 17:42:59 +0100 Subject: [PATCH 15/20] Class AbstractResourceLoader. Base for (a)synchronous resource loading automatically trigerred from ResourceManager. --- src/AbstractResourceLoader.h | 137 +++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/ResourceManager.h | 49 ++++++++++- src/Test/ResourceManagerTest.cpp | 34 +++++++- src/Test/ResourceManagerTest.h | 1 + 5 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 src/AbstractResourceLoader.h diff --git a/src/AbstractResourceLoader.h b/src/AbstractResourceLoader.h new file mode 100644 index 000000000..038054604 --- /dev/null +++ b/src/AbstractResourceLoader.h @@ -0,0 +1,137 @@ +#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. +*/ + +/** @file + * @brief Class Magnum::AbstractResourceLoader + */ + +#include "Magnum.h" + +#include + +#include "ResourceManager.h" + +namespace Magnum { + +/** +@brief Base for resource loaders + +Provides asynchronous resource loading for ResourceManager. +*/ +template class AbstractResourceLoader { + friend class Implementation::ResourceManagerData; + + public: + inline AbstractResourceLoader(): manager(nullptr), _requestedCount(0), _loadedCount(0), _notFoundCount(0) {} + + inline virtual ~AbstractResourceLoader() { + if(manager) manager->_loader = nullptr; + } + + /** + * @brief Count of requested resources + * + * Count of resources requested by calling load(). + */ + inline std::size_t requestedCount() const { return _requestedCount; } + + /** + * @brief Count of not found resources + * + * Count of resources requested by calling load(), but not found by + * the loader. + */ + inline std::size_t notFountCount() const { return _notFoundCount; } + + /** + * @brief Count of loaded resources + * + * Count of resources requested by calling load(), but not found by + * the loader. + */ + inline std::size_t loadedCount() const { return _loadedCount; } + + /** + * @brief %Resource name corresponding to given key + * + * If no such resource exists or the resource name is not available, + * returns empty string. Default implementation returns empty string. + */ + virtual std::string name(ResourceKey key) const; + + /** + * @brief Request resource to be loaded + * + * 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. + * + * The resource might be loaded asynchronously and added to + * ResourceManager when loading is done. + * @see ResourceManager::state(), requestedCount(), notFountCount(), + * loadedCount() + */ + virtual void load(ResourceKey key) = 0; + + protected: + /** + * @brief Set loaded resource to resource manager + * + * Also increments count of loaded resources. Parameter @p state + * must be either @ref ResourceManager::ResourceDataState "ResourceDataState::Mutable" + * or @ref ResourceManager::ResourceDataState "ResourceDataState::Final". See + * ResourceManager::set() for more information. + * @see loadedCount() + */ + inline void set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { + CORRADE_ASSERT(state == ResourceDataState::Mutable || state == ResourceDataState::Final, + "AbstractResourceLoader::set(): state must be either Mutable or Final", ); + ++_loadedCount; + manager->set(key, data, state, policy); + } + + /** + * @brief Mark resource as not found + * + * Also increments count of not found resources. See + * ResourceManager::setNotFound() for more information. + * @see notFountCount() + */ + inline void setNotFound(ResourceKey key) { + ++_notFoundCount; + /** @todo What policy for notfound resources? */ + manager->set(key, nullptr, ResourceDataState::NotFound, ResourcePolicy::Resident); + } + + private: + Implementation::ResourceManagerData* manager; + std::size_t _requestedCount; + std::size_t _loadedCount; + std::size_t _notFoundCount; +}; + +template inline std::string AbstractResourceLoader::name(ResourceKey) const { return {}; } + +template inline void AbstractResourceLoader::load(ResourceKey key) { + ++_requestedCount; + /** @todo What policy for loading resources? */ + manager->set(key, nullptr, ResourceDataState::Loading, ResourcePolicy::Resident); +} + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26601309b..bbb9506dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ endif() set(Magnum_HEADERS AbstractImage.h + AbstractResourceLoader.h AbstractShaderProgram.h AbstractTexture.h Buffer.h diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 22fe1c0b0..9546e3dc5 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -78,6 +78,8 @@ enum class ResourcePolicy: std::uint8_t { ReferenceCounted }; +template class AbstractResourceLoader; + #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { struct ResourceKeyHash { @@ -88,6 +90,7 @@ namespace Implementation { template class ResourceManagerData { template friend class Resource; + friend class AbstractResourceLoader; ResourceManagerData(const ResourceManagerData&) = delete; ResourceManagerData(ResourceManagerData&&) = delete; @@ -97,6 +100,11 @@ namespace Implementation { public: inline virtual ~ResourceManagerData() { delete _fallback; + + if(_loader) { + _loader->manager = nullptr; + delete _loader; + } } inline std::size_t lastChange() const { return _lastChange; } @@ -133,6 +141,10 @@ namespace Implementation { } template inline Resource get(ResourceKey key) { + /* Ask loader for the data, if they aren't there yet */ + if(_loader && _data.find(key) == _data.end()) + _loader->load(key); + return Resource(this, key); } @@ -188,8 +200,20 @@ namespace Implementation { } } + inline AbstractResourceLoader* loader() { return _loader; } + inline const AbstractResourceLoader* loader() const { return _loader; } + + inline void setLoader(AbstractResourceLoader* loader) { + /* Delete previous loader */ + delete _loader; + + /* Add new loader */ + _loader = loader; + if(_loader) _loader->manager = this; + } + protected: - inline ResourceManagerData(): _fallback(nullptr), _lastChange(0) {} + inline ResourceManagerData(): _fallback(nullptr), _loader(nullptr), _lastChange(0) {} private: struct Data { @@ -233,6 +257,7 @@ namespace Implementation { std::unordered_map _data; T* _fallback; + AbstractResourceLoader* _loader; std::size_t _lastChange; }; } @@ -422,6 +447,26 @@ template class ResourceManager: private Implementation::Resource freeInternal(std::common_type()...); } + /** @brief Loader for given type of resources */ + template inline AbstractResourceLoader* loader() { + return this->Implementation::ResourceManagerData::loader(); + } + + /** @overload */ + template inline const AbstractResourceLoader* loader() const { + return this->Implementation::ResourceManagerData::loader(); + } + + /** + * @brief Set loader for given type of resources + * + * The loader will affect only loading of resources requested after + * that. + */ + template inline void setLoader(AbstractResourceLoader* loader) { + return this->Implementation::ResourceManagerData::setLoader(loader); + } + private: template inline void freeInternal(std::common_type, std::common_type... t) { free(); @@ -441,5 +486,7 @@ template ResourceManager*& ResourceManager:: } +/* Make the definition complete */ +#include "AbstractResourceLoader.h" #endif diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 863a5d2c1..9b87ea360 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -17,6 +17,7 @@ #include +#include "AbstractResourceLoader.h" #include "ResourceManager.h" using namespace std; @@ -36,6 +37,18 @@ class Data { typedef Magnum::ResourceManager ResourceManager; +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); + setNotFound("world"); + } +}; + size_t Data::count = 0; ResourceManagerTest::ResourceManagerTest() { @@ -45,7 +58,8 @@ ResourceManagerTest::ResourceManagerTest() { &ResourceManagerTest::basic, &ResourceManagerTest::residentPolicy, &ResourceManagerTest::referenceCountedPolicy, - &ResourceManagerTest::manualPolicy); + &ResourceManagerTest::manualPolicy, + &ResourceManagerTest::loader); } void ResourceManagerTest::state() { @@ -205,4 +219,22 @@ void ResourceManagerTest::manualPolicy() { CORRADE_COMPARE(Data::count, 1); } +void ResourceManagerTest::loader() { + ResourceManager rm; + IntResourceLoader loader; + rm.setLoader(&loader); + + Resource data = rm.get("data"); + 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); + + loader.load(); + CORRADE_COMPARE(hello.state(), ResourceState::Final); + CORRADE_COMPARE(*hello, 773); + CORRADE_COMPARE(world.state(), ResourceState::NotFound); +} + }} diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index 73b4a49ea..fa95ec724 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -30,6 +30,7 @@ class ResourceManagerTest: public Corrade::TestSuite::Tester Date: Sun, 25 Nov 2012 01:20:09 +0100 Subject: [PATCH 16/20] Adapted to Corrade changes. --- src/Context.cpp | 1 + src/Platform/AbstractXApplication.cpp | 2 ++ src/Platform/Sdl2Application.cpp | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/Context.cpp b/src/Context.cpp index 27821ce6f..b620e5812 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "AbstractShaderProgram.h" #include "AbstractTexture.h" diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 50948e61b..9379d7492 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -15,6 +15,8 @@ #include "AbstractXApplication.h" +#include + #include "Context.h" #include "ExtensionWrangler.h" diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 165cbcfe8..cf6a31b34 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -15,6 +15,8 @@ #include "Sdl2Application.h" +#include + #include "Context.h" #include "ExtensionWrangler.h" From f184c6f005a263c8077b3abb5d50ad33a17ed133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 25 Nov 2012 01:21:19 +0100 Subject: [PATCH 17/20] Using real class for testing configuration value parsing. --- src/Math/RectangularMatrix.h | 6 +++--- src/Math/Test/Matrix3Test.cpp | 10 +++++++--- src/Math/Test/Matrix4Test.cpp | 10 +++++++--- src/Math/Test/MatrixTest.cpp | 10 +++++++--- src/Math/Test/Point2DTest.cpp | 10 +++++++--- src/Math/Test/Point3DTest.cpp | 10 +++++++--- src/Math/Test/RectangularMatrixTest.cpp | 10 +++++++--- src/Math/Test/Vector2Test.cpp | 10 +++++++--- src/Math/Test/Vector3Test.cpp | 10 +++++++--- src/Math/Test/Vector4Test.cpp | 10 +++++++--- src/Math/Test/VectorTest.cpp | 10 +++++++--- src/Test/ColorTest.cpp | 16 ++++++++++++---- 12 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 2dd862b2b..bc4822323 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include "MathTypeTraits.h" @@ -508,7 +508,7 @@ namespace Corrade { namespace Utility { /** @configurationvalue{Magnum::Math::RectangularMatrix} */ template struct ConfigurationValue> { /** @brief Writes elements separated with spaces */ - static std::string toString(const Magnum::Math::RectangularMatrix& value, int flags = 0) { + static std::string toString(const Magnum::Math::RectangularMatrix& value, ConfigurationValueFlags flags) { std::string output; for(std::size_t row = 0; row != rows; ++row) { @@ -522,7 +522,7 @@ template struct ConfigurationValue< } /** @brief Reads elements separated with whitespace */ - static Magnum::Math::RectangularMatrix fromString(const std::string& stringValue, int flags = 0) { + static Magnum::Math::RectangularMatrix fromString(const std::string& stringValue, ConfigurationValueFlags flags) { Magnum::Math::RectangularMatrix result; std::istringstream in(stringValue); diff --git a/src/Math/Test/Matrix3Test.cpp b/src/Math/Test/Matrix3Test.cpp index 6df43a7ca..e25c020b0 100644 --- a/src/Math/Test/Matrix3Test.cpp +++ b/src/Math/Test/Matrix3Test.cpp @@ -15,7 +15,7 @@ #include "Matrix3Test.h" -#include +#include #include "Constants.h" #include "Matrix3.h" @@ -148,14 +148,18 @@ void Matrix3Test::debug() { } void Matrix3Test::configuration() { + Configuration c; + Matrix3 m( 5.0f, 8.0f, 4.0f, 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"); - CORRADE_COMPARE(ConfigurationValue::toString(m), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), m); + + c.setValue("matrix", m); + 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 89792fa4c..a1e8c4cbc 100644 --- a/src/Math/Test/Matrix4Test.cpp +++ b/src/Math/Test/Matrix4Test.cpp @@ -15,7 +15,7 @@ #include "Matrix4Test.h" -#include +#include #include "Constants.h" #include "Matrix4.h" @@ -195,6 +195,8 @@ 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, @@ -202,8 +204,10 @@ void Matrix4Test::configuration() { 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"); - CORRADE_COMPARE(ConfigurationValue::toString(m), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), m); + + c.setValue("matrix", m); + 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 6a015b328..cc902f199 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -15,7 +15,7 @@ #include "MatrixTest.h" -#include +#include #include "Matrix.h" @@ -186,6 +186,8 @@ 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, @@ -193,8 +195,10 @@ void MatrixTest::configuration() { 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"); - CORRADE_COMPARE(ConfigurationValue::toString(m), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), m); + + c.setValue("matrix", m); + 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 64d5540bc..63a93c345 100644 --- a/src/Math/Test/Point2DTest.cpp +++ b/src/Math/Test/Point2DTest.cpp @@ -15,7 +15,7 @@ #include "Point2DTest.h" -#include +#include #include "Point2D.h" @@ -47,10 +47,14 @@ void Point2DTest::debug() { } void Point2DTest::configuration() { + Configuration c; + Point2D vec(3.0f, 3.125f, 9.55f); string value("3 3.125 9.55"); - CORRADE_COMPARE(ConfigurationValue::toString(vec), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); + + c.setValue("point", vec); + 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 092f5a0f0..e4f24920f 100644 --- a/src/Math/Test/Point3DTest.cpp +++ b/src/Math/Test/Point3DTest.cpp @@ -15,7 +15,7 @@ #include "Point3DTest.h" -#include +#include #include "Point3D.h" @@ -47,10 +47,14 @@ void Point3DTest::debug() { } void Point3DTest::configuration() { + Configuration c; + Point3D vec(3.0f, 3.125f, 9.0f, 9.55f); string value("3 3.125 9 9.55"); - CORRADE_COMPARE(ConfigurationValue::toString(vec), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); + + c.setValue("point", vec); + 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 e43c6e5e2..344e2fcd1 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -15,7 +15,7 @@ #include "RectangularMatrixTest.h" -#include +#include #include "RectangularMatrix.h" @@ -242,8 +242,12 @@ void RectangularMatrixTest::configuration() { 7.0f, -1.0f, 8.0f, 9.55f ); string value("3 4 7 5 4 -1 8 7 8 4 3.125 9.55"); - CORRADE_COMPARE(ConfigurationValue::toString(m), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), m); + + Configuration c; + c.setValue("matrix", m); + + 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 a60a253d7..297e0e67a 100644 --- a/src/Math/Test/Vector2Test.cpp +++ b/src/Math/Test/Vector2Test.cpp @@ -15,7 +15,7 @@ #include "Vector2Test.h" -#include +#include #include "Vector2.h" @@ -57,10 +57,14 @@ void Vector2Test::debug() { } void Vector2Test::configuration() { + Configuration c; + Vector2 vec(3.125f, 9.0f); string value("3.125 9"); - CORRADE_COMPARE(ConfigurationValue::toString(vec), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); + + c.setValue("vector", vec); + 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 6ffdc267d..7ef022ff7 100644 --- a/src/Math/Test/Vector3Test.cpp +++ b/src/Math/Test/Vector3Test.cpp @@ -15,7 +15,7 @@ #include "Vector3Test.h" -#include +#include #include "Vector3.h" @@ -75,10 +75,14 @@ void Vector3Test::debug() { } void Vector3Test::configuration() { + Configuration c; + Vector3 vec(3.0f, 3.125f, 9.55f); string value("3 3.125 9.55"); - CORRADE_COMPARE(ConfigurationValue::toString(vec), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); + + c.setValue("vector", vec); + 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 c12838a20..33d52deb0 100644 --- a/src/Math/Test/Vector4Test.cpp +++ b/src/Math/Test/Vector4Test.cpp @@ -15,7 +15,7 @@ #include "Vector4Test.h" -#include +#include #include "Vector4.h" @@ -59,10 +59,14 @@ void Vector4Test::debug() { } void Vector4Test::configuration() { + Configuration c; + Vector4 vec(3.0f, 3.125f, 9.0f, 9.55f); string value("3 3.125 9 9.55"); - CORRADE_COMPARE(ConfigurationValue::toString(vec), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); + + c.setValue("vector", vec); + 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 5bd824c16..e89907bf4 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -15,7 +15,7 @@ #include "VectorTest.h" -#include +#include #include "Constants.h" #include "Vector.h" @@ -116,10 +116,14 @@ void VectorTest::debug() { } void VectorTest::configuration() { + Configuration c; + Vector4 vec(3.0f, 3.125f, 9.0f, 9.55f); string value("3 3.125 9 9.55"); - CORRADE_COMPARE(ConfigurationValue::toString(vec), value); - CORRADE_COMPARE(ConfigurationValue::fromString(value), vec); + + c.setValue("vector", vec); + CORRADE_COMPARE(c.value("vector"), value); + CORRADE_COMPARE(c.value("vector"), vec); } }}} diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 7625131af..176270f2b 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -15,6 +15,8 @@ #include "ColorTest.h" +#include + #include "Color.h" using namespace std; @@ -135,15 +137,21 @@ void ColorTest::debug() { } void ColorTest::configuration() { + Configuration c; + Color3f color3(0.5f, 0.75f, 1.0f); string value3("0.5 0.75 1"); - CORRADE_COMPARE(ConfigurationValue::toString(color3), value3); - CORRADE_COMPARE(ConfigurationValue::fromString(value3), color3); + + c.setValue("color3", color3); + 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"); - CORRADE_COMPARE(ConfigurationValue::toString(color4), value4); - CORRADE_COMPARE(ConfigurationValue::fromString(value4), color4); + + c.setValue("color4", color4); + CORRADE_COMPARE(c.value("color4"), value4); + CORRADE_COMPARE(c.value("color4"), color4); } }} From ca0bbe79fbc0c65a9cc238c4850a7c5f1f6a84c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 25 Nov 2012 01:35:29 +0100 Subject: [PATCH 18/20] Debug output and configuration parser for Type enum. --- src/Test/CMakeLists.txt | 1 + src/Test/TypeTraitsTest.cpp | 47 ++++++++++++++++++++++++++++ src/Test/TypeTraitsTest.h | 32 +++++++++++++++++++ src/TypeTraits.cpp | 61 +++++++++++++++++++++++++++++++++++++ src/TypeTraits.h | 26 ++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 src/Test/TypeTraitsTest.cpp create mode 100644 src/Test/TypeTraitsTest.h diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index e7950f7f4..d46a463fb 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,5 +1,6 @@ corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test2(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test2(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 new file mode 100644 index 000000000..521e16019 --- /dev/null +++ b/src/Test/TypeTraitsTest.cpp @@ -0,0 +1,47 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without 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 "TypeTraitsTest.h" + +#include + +#include "TypeTraits.h" + +CORRADE_TEST_MAIN(Magnum::Test::TypeTraitsTest) + +using namespace Corrade::Utility; + +namespace Magnum { namespace Test { + +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); +} + +}} diff --git a/src/Test/TypeTraitsTest.h b/src/Test/TypeTraitsTest.h new file mode 100644 index 000000000..2f634f50c --- /dev/null +++ b/src/Test/TypeTraitsTest.h @@ -0,0 +1,32 @@ +#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/TypeTraits.cpp b/src/TypeTraits.cpp index 4dad71afe..2d598de4a 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -16,6 +16,7 @@ #include "TypeTraits.h" #include +#include using namespace std; @@ -67,4 +68,64 @@ bool TypeInfo::isIntegral(Type type) { } } +#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 49e75e871..c6f878e61 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -19,6 +19,8 @@ * @brief Enum Magnum::Type, class Magnum::TypeOf, Magnum::TypeInfo, Magnum::TypeTraits */ +#include + #include "Math/MathTypeTraits.h" #include "AbstractImage.h" @@ -114,6 +116,9 @@ enum class Type: GLenum { #endif }; +/** @debugoperator{Magnum::TypeInfo} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, Type value); + /** @brief Class for converting Type enum values to types @@ -340,4 +345,25 @@ template struct TypeTraits>: TypeTraits struct MAGNUM_EXPORT ConfigurationValue { + /** + * @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 35d8905790876582601cb7ff759b0a55754404c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 25 Nov 2012 01:36:14 +0100 Subject: [PATCH 19/20] Debug output and configuration parser for Mesh::Primitive. --- src/Mesh.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ src/Mesh.h | 24 +++++++++++++++++++ src/Test/CMakeLists.txt | 1 + src/Test/MeshTest.cpp | 47 +++++++++++++++++++++++++++++++++++++ src/Test/MeshTest.h | 32 ++++++++++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 src/Test/MeshTest.cpp create mode 100644 src/Test/MeshTest.h diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 93ff6917e..49956a899 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -265,4 +265,55 @@ void Mesh::unbindImplementationDefault() { void Mesh::unbindImplementationVAO() {} +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug operator<<(Debug debug, Mesh::Primitive value) { + switch(value) { + #define _c(value) case Mesh::Primitive::value: return debug << "Mesh::Primitive::" #value; + _c(Points) + _c(Lines) + _c(LineStrip) + _c(LineLoop) + _c(Triangles) + _c(TriangleStrip) + _c(TriangleFan) + #undef _c + } + + return debug << "Mesh::Primitive::(invalid)"; +} +#endif + +} + +namespace Corrade { namespace Utility { + +std::string ConfigurationValue::toString(Magnum::Mesh::Primitive value, ConfigurationValueFlags) { + switch(value) { + #define _c(value) case Magnum::Mesh::Primitive::value: return #value; + _c(Points) + _c(Lines) + _c(LineStrip) + _c(LineLoop) + _c(Triangles) + _c(TriangleStrip) + _c(TriangleFan) + #undef _c + } + + return ""; } + +Magnum::Mesh::Primitive ConfigurationValue::fromString(const std::string& stringValue, ConfigurationValueFlags) { + #define _c(value) if(stringValue == #value) return Magnum::Mesh::Primitive::value; + _c(Lines) + _c(LineStrip) + _c(LineLoop) + _c(Triangles) + _c(TriangleStrip) + _c(TriangleFan) + #undef _c + + return Magnum::Mesh::Primitive::Points; +} + +}} diff --git a/src/Mesh.h b/src/Mesh.h index 8eee5324d..369d47a66 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -742,6 +742,30 @@ class MAGNUM_EXPORT Mesh { #endif }; +/** @debugoperator{Magnum::Mesh} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value); + } +namespace Corrade { namespace Utility { + +/** @configurationvalue{Magnum::Mesh} */ +template<> struct MAGNUM_EXPORT ConfigurationValue { + /** + * @brief Writes enum value as string + * + * If the value is invalid, returns empty string. + */ + static std::string toString(Magnum::Mesh::Primitive value, ConfigurationValueFlags); + + /** + * @brief Reads enum value as string + * + * If the value is invalid, returns @ref Magnum::Mesh::Primitive "Mesh::Primitive::Points". + */ + static Magnum::Mesh::Primitive fromString(const std::string& stringValue, ConfigurationValueFlags); +}; + +}} + #endif diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index d46a463fb..2e6f58e3e 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,4 +1,5 @@ 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) diff --git a/src/Test/MeshTest.cpp b/src/Test/MeshTest.cpp new file mode 100644 index 000000000..0e1a9d949 --- /dev/null +++ b/src/Test/MeshTest.cpp @@ -0,0 +1,47 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without 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 "MeshTest.h" + +#include + +#include "Mesh.h" + +CORRADE_TEST_MAIN(Magnum::Test::MeshTest) + +using namespace Corrade::Utility; + +namespace Magnum { namespace Test { + +MeshTest::MeshTest() { + addTests(&MeshTest::debug, + &MeshTest::configuration); +} + +void MeshTest::debug() { + std::ostringstream o; + Debug(&o) << Mesh::Primitive::TriangleFan; + CORRADE_COMPARE(o.str(), "Mesh::Primitive::TriangleFan\n"); +} + +void MeshTest::configuration() { + Configuration c; + + c.setValue("primitive", Mesh::Primitive::LineStrip); + CORRADE_COMPARE(c.value("primitive"), "LineStrip"); + CORRADE_COMPARE(c.value("primitive"), Mesh::Primitive::LineStrip); +} + +}} diff --git a/src/Test/MeshTest.h b/src/Test/MeshTest.h new file mode 100644 index 000000000..051488fbf --- /dev/null +++ b/src/Test/MeshTest.h @@ -0,0 +1,32 @@ +#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 From 231c002838be5889c399f079d4abf1ef3043f0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 25 Nov 2012 12:22:03 +0100 Subject: [PATCH 20/20] Explicitly use *Matrix in names when appropriate. * In shader uniforms (projectionMatrix makes more sense than projection alone) * For underlying types for SceneGraph transformation. It is already used in Drawable::clean() as transformationMatrix, so why not use it also in AbstractFeature::clean(). Moreover, clean() could be in future also done using something else, this helps to distinguish the type just from parameter name. * In Physics shapes - applyTransformationMatrix() (as it could be in future also done using something else). --- src/Physics/AbstractShape.h | 8 ++++---- src/Physics/AxisAlignedBox.cpp | 6 +++--- src/Physics/AxisAlignedBox.h | 2 +- src/Physics/Box.cpp | 4 ++-- src/Physics/Box.h | 2 +- src/Physics/Capsule.cpp | 8 ++++---- src/Physics/Capsule.h | 2 +- src/Physics/Implementation/AxisAlignedBoxRenderer.cpp | 2 +- src/Physics/Implementation/BoxRenderer.cpp | 2 +- src/Physics/Line.cpp | 6 +++--- src/Physics/Line.h | 2 +- src/Physics/ObjectShape.cpp | 4 ++-- src/Physics/ObjectShape.h | 2 +- src/Physics/Plane.cpp | 6 +++--- src/Physics/Plane.h | 4 ++-- src/Physics/Point.cpp | 4 ++-- src/Physics/Point.h | 2 +- src/Physics/ShapeGroup.cpp | 6 +++--- src/Physics/ShapeGroup.h | 2 +- src/Physics/Sphere.cpp | 6 +++--- src/Physics/Sphere.h | 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/PlaneTest.cpp | 4 ++-- src/Physics/Test/PointTest.cpp | 2 +- src/Physics/Test/ShapeGroupTest.cpp | 4 ++-- src/Physics/Test/ShapeTestBase.h | 2 +- src/Physics/Test/SphereTest.cpp | 6 +++--- src/SceneGraph/AbstractCamera.h | 4 ++-- src/SceneGraph/AbstractFeature.h | 8 ++++---- src/Shaders/FlatShader.cpp | 2 +- src/Shaders/FlatShader.h | 6 +++--- src/Shaders/FlatShader2D.vert | 4 ++-- src/Shaders/PhongShader.h | 6 +++--- src/Shaders/VertexColorShader.cpp | 2 +- src/Shaders/VertexColorShader.h | 8 ++++---- src/Shaders/VertexColorShader2D.vert | 4 ++-- 39 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 44fa0af6a..cebb5f61e 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -100,12 +100,12 @@ template class MAGNUM_PHYSICS_EXPORT AbstractShape { virtual Type type() const = 0; /** - * @brief Apply transformation + * @brief Apply transformation matrix * - * Applies transformation to user-defined shape properties and caches - * them for later usage in collision detection. + * Applies transformation matrix to user-defined shape properties and + * caches them for later usage in collision detection. */ - virtual void applyTransformation(const typename DimensionTraits::MatrixType& transformation) = 0; + virtual void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) = 0; /** * @brief Detect collision with other shape diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 8b15efa27..9c2f004cf 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -20,9 +20,9 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); - _transformedSize = transformation.rotationScaling()*_size; +template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { + _transformedPosition = (matrix*typename DimensionTraits::PointType(_position)).vector(); + _transformedSize = matrix.rotationScaling()*_size; } template class AxisAlignedBox<2>; diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index 6d76e7da5..b94a1c70e 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -40,7 +40,7 @@ template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: pu return AbstractShape::Type::AxisAlignedBox; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; /** @brief Position */ inline typename DimensionTraits::VectorType position() const { diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index e1ed39501..d71c6d570 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -20,8 +20,8 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedTransformation = (transformation*_transformation); +template void Box::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { + _transformedTransformation = matrix*_transformation; } template class Box<2>; diff --git a/src/Physics/Box.h b/src/Physics/Box.h index f09e093b2..828f9e2af 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -42,7 +42,7 @@ template class MAGNUM_PHYSICS_EXPORT Box: public Abstra return AbstractShape::Type::Box; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; /** @brief Transformation */ inline typename DimensionTraits::MatrixType transformation() const { diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 422bd12bb..8fc516ba6 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -27,10 +27,10 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); - _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); - float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); +template void Capsule::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { + _transformedA = (matrix*typename DimensionTraits::PointType(_a)).vector(); + _transformedB = (matrix*typename DimensionTraits::PointType(_b)).vector(); + float scaling = (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 015050ffe..f279985de 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -43,7 +43,7 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab return AbstractShape::Type::Capsule; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; bool collides(const AbstractShape* other) const override; diff --git a/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp b/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp index d53732742..97102bf35 100644 --- a/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/Physics/Implementation/AxisAlignedBoxRenderer.cpp @@ -26,7 +26,7 @@ template void AxisAlignedBoxRenderer::draw( typename DimensionTraits::MatrixType transformation = DimensionTraits::MatrixType::translation(axisAlignedBox.transformedPosition())* DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedSize()); - this->shader->setTransformationProjection(camera->projectionMatrix()*camera->cameraMatrix()*transformation) + this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*transformation) ->setColor(options->color) ->use(); this->mesh->draw(); diff --git a/src/Physics/Implementation/BoxRenderer.cpp b/src/Physics/Implementation/BoxRenderer.cpp index ea4531324..840c6b306 100644 --- a/src/Physics/Implementation/BoxRenderer.cpp +++ b/src/Physics/Implementation/BoxRenderer.cpp @@ -23,7 +23,7 @@ namespace Magnum { namespace Physics { namespace Implementation { template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType&, typename SceneGraph::AbstractCamera* camera) { - this->shader->setTransformationProjection(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) + this->shader->setTransformationProjectionMatrix(camera->projectionMatrix()*camera->cameraMatrix()*box.transformedTransformation()) ->setColor(options->color) ->use(); this->mesh->draw(); diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 65533e3ef..49fbe566e 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,9 +20,9 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); - _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); +template void Line::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { + _transformedA = (matrix*typename DimensionTraits::PointType(_a)).vector(); + _transformedB = (matrix*typename DimensionTraits::PointType(_b)).vector(); } /* Explicitly instantiate the templates */ diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 26d3232dd..9246133a4 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -41,7 +41,7 @@ template class MAGNUM_PHYSICS_EXPORT Line: public Abstr return AbstractShape::Type::Line; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; /** @brief First point */ inline typename DimensionTraits::VectorType a() const { diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index 446433d5a..766a475a9 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -36,8 +36,8 @@ template void ObjectShape::markDirty() { group()->setDirty(); } -template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { - if(_shape) _shape->applyTransformation(absoluteTransformation); +template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { + if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); } template class ObjectShape<2>; diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 61791fa21..b1d04e1fd 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -78,7 +78,7 @@ template class MAGNUM_PHYSICS_EXPORT ObjectShape: publi void markDirty() override; /** Applies transformation to associated shape. */ - void clean(const typename DimensionTraits::MatrixType& absoluteTransformation) override; + void clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) override; private: AbstractShape* _shape; diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index e1ddf5ac5..4798b991c 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -27,9 +27,9 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -void Plane::applyTransformation(const Matrix4& transformation) { - _transformedPosition = (transformation*Magnum::Point3D(_position)).xyz(); - _transformedNormal = transformation.rotation()*_normal; +void Plane::applyTransformationMatrix(const Matrix4& matrix) { + _transformedPosition = (matrix*Magnum::Point3D(_position)).xyz(); + _transformedNormal = matrix.rotation()*_normal; } bool Plane::collides(const AbstractShape<3>* other) const { diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index d3ff91617..4a622ec58 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -36,10 +36,10 @@ class MAGNUM_PHYSICS_EXPORT Plane: public AbstractShape<3> { inline Type type() const override { return Type::Plane; } #ifndef DOXYGEN_GENERATING_OUTPUT - void applyTransformation(const Matrix4& transformation) override; + void applyTransformationMatrix(const Matrix4& matrix) override; bool collides(const AbstractShape<3>* other) const override; #else - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; bool collides(const AbstractShape* other) const override; #endif diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 06850fd68..53f697109 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,8 +20,8 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); +template void Point::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { + _transformedPosition = (matrix*typename DimensionTraits::PointType(_position)).vector(); } template class Point<2>; diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 70bf6df40..5c8e48574 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -40,7 +40,7 @@ template class MAGNUM_PHYSICS_EXPORT Point: public Abst return AbstractShape::Type::Point; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; /** @brief Position */ inline typename DimensionTraits::VectorType position() const { diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index 3352a2664..d77a0ce18 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -43,9 +43,9 @@ template ShapeGroup& ShapeGroup return *this; } -template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - if(a) a->applyTransformation(transformation); - if(b) b->applyTransformation(transformation); +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 { diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 5a00f0488..88fd7bd1b 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -105,7 +105,7 @@ template class MAGNUM_PHYSICS_EXPORT ShapeGroup: public return AbstractShape::Type::ShapeGroup; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; bool collides(const AbstractShape* other) const override; diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index 94b971b3e..9bd6f754e 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -39,9 +39,9 @@ namespace { } } -template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { - _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); - float scaling = (transformation.rotationScaling()*unitVector()).length(); +template void Sphere::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { + _transformedPosition = (matrix*typename DimensionTraits::PointType(_position)).vector(); + float scaling = (matrix.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 1f96f698a..083fea64e 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -43,7 +43,7 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs return AbstractShape::Type::Sphere; } - void applyTransformation(const typename DimensionTraits::MatrixType& transformation) override; + void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) override; bool collides(const AbstractShape* other) const override; diff --git a/src/Physics/Test/AxisAlignedBoxTest.cpp b/src/Physics/Test/AxisAlignedBoxTest.cpp index da5cd0894..a3b8595d8 100644 --- a/src/Physics/Test/AxisAlignedBoxTest.cpp +++ b/src/Physics/Test/AxisAlignedBoxTest.cpp @@ -30,11 +30,11 @@ AxisAlignedBoxTest::AxisAlignedBoxTest() { void AxisAlignedBoxTest::applyTransformation() { Physics::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); - box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); + 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.applyTransformation(Matrix4::translation(Vector3(1.0f))*Matrix4::rotation(deg(90.0f), Vector3::xAxis())); + 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)); } diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp index 32c04ff48..824ce34d9 100644 --- a/src/Physics/Test/BoxTest.cpp +++ b/src/Physics/Test/BoxTest.cpp @@ -29,7 +29,7 @@ BoxTest::BoxTest() { void BoxTest::applyTransformation() { Physics::Box3D box(Matrix4::translation({1.0f, 2.0f, -3.0f})); - box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); + box.applyTransformationMatrix(Matrix4::scaling({2.0f, -1.0f, 1.5f})); CORRADE_COMPARE(box.transformedTransformation(), Matrix4::scaling({2.0f, -1.0f, 1.5f})*Matrix4::translation({1.0f, 2.0f, -3.0f})); } diff --git a/src/Physics/Test/CapsuleTest.cpp b/src/Physics/Test/CapsuleTest.cpp index 698778a90..04c85235b 100644 --- a/src/Physics/Test/CapsuleTest.cpp +++ b/src/Physics/Test/CapsuleTest.cpp @@ -32,13 +32,13 @@ CapsuleTest::CapsuleTest() { void CapsuleTest::applyTransformation() { Physics::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); - capsule.applyTransformation(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); /* Apply average scaling to radius */ - capsule.applyTransformation(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); + capsule.applyTransformationMatrix(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); CORRADE_COMPARE(capsule.transformedRadius(), Constants::sqrt3()*7.0f); } diff --git a/src/Physics/Test/LineTest.cpp b/src/Physics/Test/LineTest.cpp index 2a673d33c..2de48f44a 100644 --- a/src/Physics/Test/LineTest.cpp +++ b/src/Physics/Test/LineTest.cpp @@ -29,7 +29,7 @@ LineTest::LineTest() { void LineTest::applyTransformation() { Physics::Line3D line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}); - line.applyTransformation(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 294032de7..2ec0ab9d0 100644 --- a/src/Physics/Test/PlaneTest.cpp +++ b/src/Physics/Test/PlaneTest.cpp @@ -33,12 +33,12 @@ PlaneTest::PlaneTest() { void PlaneTest::applyTransformation() { Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0}); - plane.applyTransformation(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())); /* The normal should stay normalized */ - plane.applyTransformation(Matrix4::scaling({1.5f, 2.0f, 3.0f})); + plane.applyTransformationMatrix(Matrix4::scaling({1.5f, 2.0f, 3.0f})); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.5f, 4.0f, 9.0f)); CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), -Constants::sqrt2(), 0)); } diff --git a/src/Physics/Test/PointTest.cpp b/src/Physics/Test/PointTest.cpp index f6e47e785..25c36bf53 100644 --- a/src/Physics/Test/PointTest.cpp +++ b/src/Physics/Test/PointTest.cpp @@ -28,7 +28,7 @@ PointTest::PointTest() { void PointTest::applyTransformation() { Physics::Point3D point({1.0f, 2.0f, 3.0f}); - point.applyTransformation(Matrix4::translation({5.0f, 6.0f, 7.0f})); + point.applyTransformationMatrix(Matrix4::translation({5.0f, 6.0f, 7.0f})); CORRADE_COMPARE(point.transformedPosition(), Vector3(6.0f, 8.0f, 10.0f)); } diff --git a/src/Physics/Test/ShapeGroupTest.cpp b/src/Physics/Test/ShapeGroupTest.cpp index 4270fd4be..249dc8dd7 100644 --- a/src/Physics/Test/ShapeGroupTest.cpp +++ b/src/Physics/Test/ShapeGroupTest.cpp @@ -41,7 +41,7 @@ void ShapeGroupTest::copy() { } /* Just to test that it doesn't crash */ - group.applyTransformation(Matrix4::translation(Vector3::xAxis(1.0f))); + group.applyTransformationMatrix(Matrix4::translation(Vector3::xAxis(1.0f))); CORRADE_VERIFY(true); } @@ -52,7 +52,7 @@ void ShapeGroupTest::reference() { ShapeGroup3D group = !(ref(point) || ref(segment)); - group.applyTransformation(Matrix4::translation(Vector3(1.0f))); + group.applyTransformationMatrix(Matrix4::translation(Vector3(1.0f))); CORRADE_VERIFY((point.transformedPosition() == Vector3(2.0f, 3.0f, 4.0f))); CORRADE_VERIFY((segment.transformedA() == Vector3(3.0f, 2.0f, 31.0f))); diff --git a/src/Physics/Test/ShapeTestBase.h b/src/Physics/Test/ShapeTestBase.h index d5503bc65..099fb20c0 100644 --- a/src/Physics/Test/ShapeTestBase.h +++ b/src/Physics/Test/ShapeTestBase.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Physics { namespace Test { class ShapeTestBase { protected: template void randomTransformation(T& shape) { - shape.applyTransformation(Matrix4::translation({7.0f, 8.0f, -9.0f})); + shape.applyTransformationMatrix(Matrix4::translation({7.0f, 8.0f, -9.0f})); } }; diff --git a/src/Physics/Test/SphereTest.cpp b/src/Physics/Test/SphereTest.cpp index f845b942e..3b8414e79 100644 --- a/src/Physics/Test/SphereTest.cpp +++ b/src/Physics/Test/SphereTest.cpp @@ -35,17 +35,17 @@ SphereTest::SphereTest() { void SphereTest::applyTransformation() { Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); - sphere.applyTransformation(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); /* Symmetric scaling */ - sphere.applyTransformation(Matrix4::scaling(Vector3(2.0f))); + sphere.applyTransformationMatrix(Matrix4::scaling(Vector3(2.0f))); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(2.0f, 4.0f, 6.0f)); CORRADE_COMPARE(sphere.transformedRadius(), 14.0f); /* Apply average scaling to radius */ - sphere.applyTransformation(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); + sphere.applyTransformationMatrix(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f})); CORRADE_COMPARE(sphere.transformedRadius(), Constants::sqrt3()*7.0f); } diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index dae625e54..e5a3793f6 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -141,8 +141,8 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature::MatrixType& invertedAbsoluteTransformation) override { - _cameraMatrix = invertedAbsoluteTransformation; + inline void cleanInverted(const typename DimensionTraits::MatrixType& invertedAbsoluteTransformationMatrix) override { + _cameraMatrix = invertedAbsoluteTransformationMatrix; } #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/SceneGraph/AbstractFeature.h b/src/SceneGraph/AbstractFeature.h index f48b88034..9e29b77a6 100644 --- a/src/SceneGraph/AbstractFeature.h +++ b/src/SceneGraph/AbstractFeature.h @@ -72,8 +72,8 @@ class CachingFeature: public SceneGraph::AbstractFeature3D<> { } protected: - void clean(const Matrix4& absoluteTransformation) override { - absolutePosition = absoluteTransformation.translation(); + void clean(const Matrix4& absoluteTransformationMatrix) override { + absolutePosition = absoluteTransformationMatrix.translation(); } private: @@ -258,7 +258,7 @@ template class AbstractFeature * Default implementation does nothing. * @see @ref scenegraph-caching, cleanInverted() */ - virtual void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); + virtual void clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix); /** * @brief Clean data based on inverted absolute transformation @@ -272,7 +272,7 @@ template class AbstractFeature * Default implementation does nothing. * @see @ref scenegraph-caching, clean() */ - virtual void cleanInverted(const typename DimensionTraits::MatrixType& invertedAbsoluteTransformation); + virtual void cleanInverted(const typename DimensionTraits::MatrixType& invertedAbsoluteTransformationMatrix); /*@}*/ diff --git a/src/Shaders/FlatShader.cpp b/src/Shaders/FlatShader.cpp index 78ad7a450..d232e342b 100644 --- a/src/Shaders/FlatShader.cpp +++ b/src/Shaders/FlatShader.cpp @@ -65,7 +65,7 @@ template FlatShader::FlatShader() { link(); - transformationProjectionUniform = uniformLocation("transformationProjection"); + transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); colorUniform = uniformLocation("color"); } diff --git a/src/Shaders/FlatShader.h b/src/Shaders/FlatShader.h index 3467666ad..e8787cdd4 100644 --- a/src/Shaders/FlatShader.h +++ b/src/Shaders/FlatShader.h @@ -46,8 +46,8 @@ template class MAGNUM_SHADERS_EXPORT FlatShader: public * @brief Set transformation and projection matrix * @return Pointer to self (for method chaining) */ - FlatShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { - setUniform(transformationProjectionUniform, matrix); + FlatShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + setUniform(transformationProjectionMatrixUniform, matrix); return this; } @@ -61,7 +61,7 @@ template class MAGNUM_SHADERS_EXPORT FlatShader: public } private: - GLint transformationProjectionUniform, + GLint transformationProjectionMatrixUniform, colorUniform; }; diff --git a/src/Shaders/FlatShader2D.vert b/src/Shaders/FlatShader2D.vert index dc702bf98..78d041e8d 100644 --- a/src/Shaders/FlatShader2D.vert +++ b/src/Shaders/FlatShader2D.vert @@ -2,7 +2,7 @@ #define in attribute #endif -uniform highp mat3 transformationProjection; +uniform highp mat3 transformationProjectionMatrix; #ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in highp vec3 position; @@ -11,5 +11,5 @@ in highp vec3 position; #endif void main() { - gl_Position.xywz = vec4(transformationProjection*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); } diff --git a/src/Shaders/PhongShader.h b/src/Shaders/PhongShader.h index 14d4dd970..6be38d84c 100644 --- a/src/Shaders/PhongShader.h +++ b/src/Shaders/PhongShader.h @@ -84,10 +84,10 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { } /** - * @brief Set transformation matrix and normal matrix + * @brief Set transformation and normal matrix * @return Pointer to self (for method chaining) */ - inline PhongShader* setTransformation(const Matrix4& matrix) { + inline PhongShader* setTransformationMatrix(const Matrix4& matrix) { setUniform(transformationMatrixUniform, matrix); setUniform(normalMatrixUniform, matrix.rotation()); return this; @@ -97,7 +97,7 @@ class MAGNUM_SHADERS_EXPORT PhongShader: public AbstractShaderProgram { * @brief Set projection matrix * @return Pointer to self (for method chaining) */ - inline PhongShader* setProjection(const Matrix4& matrix) { + inline PhongShader* setProjectionMatrix(const Matrix4& matrix) { setUniform(projectionMatrixUniform, matrix); return this; } diff --git a/src/Shaders/VertexColorShader.cpp b/src/Shaders/VertexColorShader.cpp index bb6305b4d..5313da38c 100644 --- a/src/Shaders/VertexColorShader.cpp +++ b/src/Shaders/VertexColorShader.cpp @@ -66,7 +66,7 @@ template VertexColorShader::VertexColorShad link(); - transformationProjectionUniform = uniformLocation("transformationProjection"); + transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); } template class VertexColorShader<2>; diff --git a/src/Shaders/VertexColorShader.h b/src/Shaders/VertexColorShader.h index 35cd3377f..896fefdc6 100644 --- a/src/Shaders/VertexColorShader.h +++ b/src/Shaders/VertexColorShader.h @@ -46,16 +46,16 @@ template class MAGNUM_SHADERS_EXPORT VertexColorShader: VertexColorShader(); /** - * @brief Set transformation and projection + * @brief Set transformation and projection matrix * @return Pointer to self (for method chaining) */ - inline VertexColorShader* setTransformationProjection(const typename DimensionTraits::MatrixType& matrix) { - setUniform(transformationProjectionUniform, matrix); + inline VertexColorShader* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + setUniform(transformationProjectionMatrixUniform, matrix); return this; } private: - GLint transformationProjectionUniform; + GLint transformationProjectionMatrixUniform; }; /** @brief 2D vertex color shader */ diff --git a/src/Shaders/VertexColorShader2D.vert b/src/Shaders/VertexColorShader2D.vert index 12be1d046..88c8fc9a5 100644 --- a/src/Shaders/VertexColorShader2D.vert +++ b/src/Shaders/VertexColorShader2D.vert @@ -3,7 +3,7 @@ #define out varying #endif -uniform highp mat3 transformationProjection; +uniform highp mat3 transformationProjectionMatrix; #ifdef EXPLICIT_ATTRIB_LOCATION layout(location = 0) in highp vec3 position; @@ -16,6 +16,6 @@ in lowp vec3 color; out lowp vec3 interpolatedColor; void main() { - gl_Position.xywz = vec4(transformationProjection*position, 0.0); + gl_Position.xywz = vec4(transformationProjectionMatrix*position, 0.0); interpolatedColor = color; }