Browse Source

Trade: improved *Data constructors and destructors.

* They are now deinlined into source files, as most of the classes have
   either heavy members (std::vector) or virtual methods.
 * All of them are explicit now (that should be already done, don't know
   why not).
 * Passing huge classes by value and using move constructors to avoid
   unnecessary copying.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
b1fcdf81af
  1. 7
      src/CMakeLists.txt
  2. 33
      src/Trade/AbstractMaterialData.cpp
  3. 8
      src/Trade/AbstractMaterialData.h
  4. 2
      src/Trade/ImageData.h
  5. 2
      src/Trade/MeshData2D.h
  6. 2
      src/Trade/MeshData3D.h
  7. 31
      src/Trade/MeshObjectData2D.cpp
  8. 4
      src/Trade/MeshObjectData2D.h
  9. 31
      src/Trade/MeshObjectData3D.cpp
  10. 4
      src/Trade/MeshObjectData3D.h
  11. 6
      src/Trade/ObjectData2D.cpp
  12. 8
      src/Trade/ObjectData2D.h
  13. 4
      src/Trade/ObjectData3D.cpp
  14. 6
      src/Trade/ObjectData3D.h
  15. 31
      src/Trade/PhongMaterialData.cpp
  16. 4
      src/Trade/PhongMaterialData.h
  17. 31
      src/Trade/SceneData.cpp
  18. 3
      src/Trade/SceneData.h

7
src/CMakeLists.txt

@ -68,10 +68,15 @@ set(Magnum_SRCS
Implementation/State.cpp
Trade/AbstractImporter.cpp
Trade/AbstractMaterialData.cpp
Trade/MeshData2D.cpp
Trade/MeshData3D.cpp
Trade/MeshObjectData2D.cpp
Trade/MeshObjectData3D.cpp
Trade/ObjectData2D.cpp
Trade/ObjectData3D.cpp)
Trade/ObjectData3D.cpp
Trade/PhongMaterialData.cpp
Trade/SceneData.cpp)
# Desktop-only code
if(NOT TARGET_GLES)

33
src/Trade/AbstractMaterialData.cpp

@ -0,0 +1,33 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "AbstractMaterialData.h"
namespace Magnum { namespace Trade {
AbstractMaterialData::AbstractMaterialData(AbstractMaterialData::Type type): _type(type) {}
AbstractMaterialData::~AbstractMaterialData() {}
}}

8
src/Trade/AbstractMaterialData.h

@ -28,7 +28,7 @@
* @brief Class Magnum::Trade::AbstractMaterialData
*/
#include <string>
#include "magnumVisibility.h"
namespace Magnum { namespace Trade {
@ -37,7 +37,7 @@ namespace Magnum { namespace Trade {
Subclasses provide access to parameters for given material type.
*/
class AbstractMaterialData {
class MAGNUM_EXPORT AbstractMaterialData {
AbstractMaterialData(const AbstractMaterialData&) = delete;
AbstractMaterialData(AbstractMaterialData&&) = delete;
AbstractMaterialData& operator=(const AbstractMaterialData&) = delete;
@ -53,7 +53,7 @@ class AbstractMaterialData {
* @brief Constructor
* @param type Material type
*/
inline AbstractMaterialData(Type type): _type(type) {}
explicit AbstractMaterialData(Type type);
/** @brief Destructor */
virtual ~AbstractMaterialData() = 0;
@ -65,8 +65,6 @@ class AbstractMaterialData {
Type _type;
};
inline AbstractMaterialData::~AbstractMaterialData() {}
}}
#endif

2
src/Trade/ImageData.h

@ -55,7 +55,7 @@ template<UnsignedInt dimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
inline ImageData(const typename DimensionTraits<Dimensions, Int>::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
inline explicit ImageData(const typename DimensionTraits<Dimensions, Int>::VectorType& size, Format format, Type type, GLvoid* data): AbstractImage(format, type), _size(size), _data(reinterpret_cast<char*>(data)) {}
/** @brief Destructor */
inline ~ImageData() { delete[] _data; }

2
src/Trade/MeshData2D.h

@ -56,7 +56,7 @@ class MAGNUM_EXPORT MeshData2D {
* @param textureCoords2D Array with two-dimensional texture
* coordinate arrays or empty array
*/
MeshData2D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector2>*> positions, std::vector<std::vector<Vector2>*> textureCoords2D);
explicit MeshData2D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector2>*> positions, std::vector<std::vector<Vector2>*> textureCoords2D);
/** @brief Move constructor */
MeshData2D(MeshData2D&&);

2
src/Trade/MeshData3D.h

@ -57,7 +57,7 @@ class MAGNUM_EXPORT MeshData3D {
* @param textureCoords2D Array with two-dimensional texture
* coordinate arrays or empty array
*/
MeshData3D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector3>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D);
explicit MeshData3D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector3>*> positions, std::vector<std::vector<Vector3>*> normals, std::vector<std::vector<Vector2>*> textureCoords2D);
/** @brief Move constructor */
MeshData3D(MeshData3D&&);

31
src/Trade/MeshObjectData2D.cpp

@ -0,0 +1,31 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "MeshObjectData2D.h"
namespace Magnum { namespace Trade {
MeshObjectData2D::MeshObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation, UnsignedInt instance, UnsignedInt material): ObjectData2D(std::move(children), transformation, InstanceType::Mesh, instance), _material(material) {}
}}

4
src/Trade/MeshObjectData2D.h

@ -38,7 +38,7 @@ namespace Magnum { namespace Trade {
Provides access to material information for given mesh instance.
@see MeshObjectData3D
*/
class MeshObjectData2D: public ObjectData2D {
class MAGNUM_EXPORT MeshObjectData2D: public ObjectData2D {
MeshObjectData2D(const MeshObjectData2D&) = delete;
MeshObjectData2D(MeshObjectData2D&&) = delete;
MeshObjectData2D& operator=(const MeshObjectData2D&) = delete;
@ -54,7 +54,7 @@ class MeshObjectData2D: public ObjectData2D {
*
* Creates object with mesh instance type.
*/
inline MeshObjectData2D(const std::vector<UnsignedInt>& children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material): ObjectData2D(children, transformation, InstanceType::Mesh, instance), _material(material) {}
explicit MeshObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation, UnsignedInt instance, UnsignedInt material);
/** @brief Material ID */
inline UnsignedInt material() const { return _material; }

31
src/Trade/MeshObjectData3D.cpp

@ -0,0 +1,31 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "MeshObjectData3D.h"
namespace Magnum { namespace Trade {
MeshObjectData3D::MeshObjectData3D(std::vector< UnsignedInt > children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material): ObjectData3D(children, transformation, InstanceType::Mesh, instance), _material(material) {}
}}

4
src/Trade/MeshObjectData3D.h

@ -38,7 +38,7 @@ namespace Magnum { namespace Trade {
Provides access to material information for given mesh instance.
@see MeshObjectData2D
*/
class MeshObjectData3D: public ObjectData3D {
class MAGNUM_EXPORT MeshObjectData3D: public ObjectData3D {
MeshObjectData3D(const MeshObjectData3D&) = delete;
MeshObjectData3D(MeshObjectData3D&&) = delete;
MeshObjectData3D& operator=(const MeshObjectData3D&) = delete;
@ -54,7 +54,7 @@ class MeshObjectData3D: public ObjectData3D {
*
* Creates object with mesh instance type.
*/
inline MeshObjectData3D(const std::vector<UnsignedInt>& children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material): ObjectData3D(children, transformation, InstanceType::Mesh, instance), _material(material) {}
explicit MeshObjectData3D(std::vector<UnsignedInt> children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material);
/** @brief Material ID */
inline UnsignedInt material() const { return _material; }

6
src/Trade/ObjectData2D.cpp

@ -26,6 +26,12 @@
namespace Magnum { namespace Trade {
ObjectData2D::ObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation, ObjectData2D::InstanceType instanceType, UnsignedInt instanceId): _children(std::move(children)), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {}
ObjectData2D::ObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {}
ObjectData2D::~ObjectData2D() = default;
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug operator<<(Debug debug, ObjectData2D::InstanceType value) {
switch(value) {

8
src/Trade/ObjectData2D.h

@ -42,7 +42,7 @@ Provides access to object transformation and hierarchy. See also
MeshObjectData2D, which is specialized for objects with mesh instance type.
@see ObjectData3D
*/
class ObjectData2D {
class MAGNUM_EXPORT ObjectData2D {
ObjectData2D(const ObjectData2D&) = delete;
ObjectData2D(ObjectData2D&&) = delete;
ObjectData2D& operator=(const ObjectData2D&) = delete;
@ -63,17 +63,17 @@ class ObjectData2D {
* @param instanceType Instance type
* @param instanceId Instance ID
*/
inline ObjectData2D(const std::vector<UnsignedInt>& children, const Matrix3& transformation, InstanceType instanceType, UnsignedInt instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {}
explicit ObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation, InstanceType instanceType, UnsignedInt instanceId);
/**
* @brief Constructor for empty instance
* @param children Child objects
* @param transformation Transformation (relative to parent)
*/
inline ObjectData2D(const std::vector<UnsignedInt>& children, const Matrix3& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {}
explicit ObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation);
/** @brief Destructor */
inline virtual ~ObjectData2D() {}
virtual ~ObjectData2D();
/** @brief Child objects */
inline std::vector<UnsignedInt>& children() { return _children; }

4
src/Trade/ObjectData3D.cpp

@ -26,6 +26,10 @@
namespace Magnum { namespace Trade {
ObjectData3D::ObjectData3D(std::vector<UnsignedInt> children, const Matrix4& transformation, ObjectData3D::InstanceType instanceType, UnsignedInt instanceId): _children(std::move(children)), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {}
ObjectData3D::ObjectData3D(std::vector<UnsignedInt> children, const Matrix4& transformation): _children(std::move(children)), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {}
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug operator<<(Debug debug, ObjectData3D::InstanceType value) {
switch(value) {

6
src/Trade/ObjectData3D.h

@ -42,7 +42,7 @@ Provides access to object transformation and hierarchy. See also
MeshObjectData3D, which is specialized for objects with mesh instance type.
@see ObjectData2D
*/
class ObjectData3D {
class MAGNUM_EXPORT ObjectData3D {
ObjectData3D(const ObjectData3D&) = delete;
ObjectData3D(ObjectData3D&&) = delete;
ObjectData3D& operator=(const ObjectData3D&) = delete;
@ -64,14 +64,14 @@ class ObjectData3D {
* @param instanceType Instance type
* @param instanceId Instance ID
*/
inline ObjectData3D(const std::vector<UnsignedInt>& children, const Matrix4& transformation, InstanceType instanceType, UnsignedInt instanceId): _children(children), _transformation(transformation), _instanceType(instanceType), _instanceId(instanceId) {}
explicit ObjectData3D(std::vector<UnsignedInt> children, const Matrix4& transformation, InstanceType instanceType, UnsignedInt instanceId);
/**
* @brief Constructor for empty instance
* @param children Child objects
* @param transformation Transformation (relative to parent)
*/
inline ObjectData3D(const std::vector<UnsignedInt>& children, const Matrix4& transformation): _children(children), _transformation(transformation), _instanceType(InstanceType::Empty), _instanceId(-1) {}
explicit ObjectData3D(std::vector<UnsignedInt> children, const Matrix4& transformation);
/** @brief Destructor */
inline virtual ~ObjectData3D() {}

31
src/Trade/PhongMaterialData.cpp

@ -0,0 +1,31 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "PhongMaterialData.h"
namespace Magnum { namespace Trade {
PhongMaterialData::PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, Float shininess): AbstractMaterialData(Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {}
}}

4
src/Trade/PhongMaterialData.h

@ -37,7 +37,7 @@ namespace Magnum { namespace Trade {
/**
@brief Phong material data
*/
class PhongMaterialData: public AbstractMaterialData {
class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData {
public:
/**
* @brief Constructor
@ -46,7 +46,7 @@ class PhongMaterialData: public AbstractMaterialData {
* @param specularColor Specular color
* @param shininess Shininess
*/
PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, Float shininess): AbstractMaterialData(Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {}
explicit PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, Float shininess);
/** @brief Ambient color */
inline Vector3 ambientColor() const { return _ambientColor; }

31
src/Trade/SceneData.cpp

@ -0,0 +1,31 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "SceneData.h"
namespace Magnum { namespace Trade {
SceneData::SceneData(std::vector<UnsignedInt> children2D, std::vector<UnsignedInt> children3D): _children2D(std::move(children2D)), _children3D(std::move(children3D)) {}
}}

3
src/Trade/SceneData.h

@ -32,6 +32,7 @@
#include <vector>
#include "Types.h"
#include "magnumVisibility.h"
namespace Magnum { namespace Trade {
@ -50,7 +51,7 @@ class MAGNUM_EXPORT SceneData {
* @param children2D Two-dimensional child objects
* @param children3D Three-dimensional child objects
*/
inline SceneData(const std::vector<UnsignedInt>& children2D, const std::vector<UnsignedInt>& children3D): _children2D(children2D), _children3D(children3D) {}
explicit SceneData(std::vector<UnsignedInt> children2D, std::vector<UnsignedInt> children3D);
/** @brief Two-dimensional child objects */
inline const std::vector<UnsignedInt>& children2D() const { return _children2D; }

Loading…
Cancel
Save