Browse Source

Merge branch 'master' into compatibility

Conflicts:
	src/DebugTools/ShapeRenderer.cpp
	src/Trade/AbstractImageConverter.cpp
	src/Trade/MeshData2D.cpp
	src/Trade/MeshData3D.cpp
Vladimír Vondruš 13 years ago
parent
commit
ade77eaf2e
  1. 4
      src/DebugTools/ForceRenderer.cpp
  2. 16
      src/DebugTools/Implementation/AbstractShapeRenderer.cpp
  3. 2
      src/DebugTools/Implementation/AbstractShapeRenderer.h
  4. 6
      src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp
  5. 2
      src/DebugTools/Implementation/AxisAlignedBoxRenderer.h
  6. 2
      src/DebugTools/Implementation/BoxRenderer.cpp
  7. 2
      src/DebugTools/Implementation/BoxRenderer.h
  8. 2
      src/DebugTools/Implementation/ForceRendererTransformation.h
  9. 2
      src/DebugTools/Implementation/LineSegmentRenderer.cpp
  10. 2
      src/DebugTools/Implementation/LineSegmentRenderer.h
  11. 4
      src/DebugTools/Implementation/LineSegmentRendererTransformation.h
  12. 6
      src/DebugTools/Implementation/PointRenderer.cpp
  13. 2
      src/DebugTools/Implementation/PointRenderer.h
  14. 6
      src/DebugTools/Implementation/SphereRenderer.cpp
  15. 2
      src/DebugTools/Implementation/SphereRenderer.h
  16. 4
      src/DebugTools/ObjectRenderer.cpp
  17. 4
      src/DebugTools/ShapeRenderer.cpp
  18. 4
      src/DimensionTraits.h
  19. 21
      src/Platform/AbstractXApplication.cpp
  20. 28
      src/Platform/AbstractXApplication.h
  21. 26
      src/Platform/GlutApplication.cpp
  22. 56
      src/Platform/GlutApplication.h
  23. 8
      src/Platform/GlxApplication.h
  24. 30
      src/Platform/NaClApplication.cpp
  25. 42
      src/Platform/NaClApplication.h
  26. 36
      src/Platform/Sdl2Application.cpp
  27. 40
      src/Platform/Sdl2Application.h
  28. 15
      src/Platform/WindowlessGlxApplication.cpp
  29. 14
      src/Platform/WindowlessGlxApplication.h
  30. 22
      src/Platform/WindowlessNaClApplication.cpp
  31. 30
      src/Platform/WindowlessNaClApplication.h
  32. 8
      src/Platform/XEglApplication.h
  33. 7
      src/Primitives/Capsule.cpp
  34. 22
      src/Primitives/Circle.cpp
  35. 4
      src/Primitives/Crosshair.cpp
  36. 10
      src/Primitives/Cube.cpp
  37. 5
      src/Primitives/Cylinder.cpp
  38. 6
      src/Primitives/Icosphere.cpp
  39. 76
      src/Primitives/Implementation/Spheroid.cpp
  40. 15
      src/Primitives/Implementation/Spheroid.h
  41. 4
      src/Primitives/Line.cpp
  42. 6
      src/Primitives/Plane.cpp
  43. 4
      src/Primitives/Square.cpp
  44. 12
      src/Primitives/Test/CapsuleTest.cpp
  45. 4
      src/Primitives/Test/CircleTest.cpp
  46. 14
      src/Primitives/Test/CylinderTest.cpp
  47. 12
      src/Primitives/Test/UVSphereTest.cpp
  48. 9
      src/Primitives/UVSphere.cpp
  49. 4
      src/SceneGraph/AbstractTransformation.h
  50. 3
      src/SceneGraph/AbstractTranslationRotation2D.h
  51. 3
      src/SceneGraph/AbstractTranslationRotation3D.h
  52. 3
      src/SceneGraph/AbstractTranslationRotationScaling2D.h
  53. 3
      src/SceneGraph/AbstractTranslationRotationScaling3D.h
  54. 1
      src/SceneGraph/Object.hpp
  55. 2
      src/Shaders/AbstractVector.h
  56. 2
      src/Shaders/DistanceFieldVector.h
  57. 4
      src/Shaders/Flat.h
  58. 2
      src/Shaders/Vector.h
  59. 4
      src/Shaders/VertexColor.h
  60. 2
      src/Shapes/AxisAlignedBox.cpp
  61. 14
      src/Shapes/AxisAlignedBox.h
  62. 2
      src/Shapes/Box.cpp
  63. 12
      src/Shapes/Box.h
  64. 4
      src/Shapes/Capsule.cpp
  65. 14
      src/Shapes/Capsule.h
  66. 2
      src/Shapes/Composition.cpp
  67. 2
      src/Shapes/Composition.h
  68. 2
      src/Shapes/Line.cpp
  69. 14
      src/Shapes/Line.h
  70. 4
      src/Shapes/LineSegment.h
  71. 2
      src/Shapes/Point.cpp
  72. 10
      src/Shapes/Point.h
  73. 2
      src/Shapes/Shape.cpp
  74. 14
      src/Shapes/Shape.h
  75. 4
      src/Shapes/Sphere.cpp
  76. 10
      src/Shapes/Sphere.h
  77. 4
      src/Shapes/shapeImplementation.h
  78. 12
      src/Trade/AbstractImageConverter.cpp
  79. 14
      src/Trade/AbstractImageConverter.h
  80. 46
      src/Trade/MeshData2D.cpp
  81. 66
      src/Trade/MeshData2D.h
  82. 58
      src/Trade/MeshData3D.cpp
  83. 76
      src/Trade/MeshData3D.h
  84. 12
      src/Trade/Test/AbstractImageConverterTest.cpp

4
src/DebugTools/ForceRenderer.cpp

@ -94,8 +94,8 @@ template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneG
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
}
template<UnsignedInt dimensions> void ForceRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation<dimensions>(transformationMatrix.transformPoint(forcePosition), *force)*DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->scale())))
template<UnsignedInt dimensions> void ForceRenderer<dimensions>::draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation<dimensions>(transformationMatrix.transformPoint(forcePosition), *force)*DimensionTraits<dimensions, Float>::MatrixType::scaling(typename DimensionTraits<dimensions, Float>::VectorType(options->scale())))
->setColor(options->color())
->use();
mesh->draw();

16
src/DebugTools/Implementation/AbstractShapeRenderer.cpp

@ -46,21 +46,21 @@ template<UnsignedInt dimensions> void create(typename MeshData<dimensions>::Type
template<> void create<2>(Trade::MeshData2D& data, Resource<Mesh>& meshResource, Resource<Buffer>& vertexBufferResource, Resource<Buffer>& indexBufferResource) {
/* Vertex buffer */
Buffer* buffer = new Buffer(Buffer::Target::Array);
buffer->setData(*data.positions(0), Buffer::Usage::StaticDraw);
buffer->setData(data.positions(0), Buffer::Usage::StaticDraw);
ResourceManager::instance()->set(vertexBufferResource.key(), buffer, ResourceDataState::Final, ResourcePolicy::Manual);
/* Mesh configuration */
Mesh* mesh = new Mesh;
mesh->setPrimitive(data.primitive())
->setVertexCount(data.positions(0)->size())
->setVertexCount(data.positions(0).size())
->addVertexBuffer(buffer, 0, Shaders::Flat2D::Position());
ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
/* Index buffer, if needed, if not, resource key doesn't have to be set */
if(data.indices()) {
if(data.isIndexed()) {
CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey());
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray);
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices());
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, data.indices());
ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);
}
}
@ -68,21 +68,21 @@ template<> void create<2>(Trade::MeshData2D& data, Resource<Mesh>& meshResource,
template<> void create<3>(Trade::MeshData3D& data, Resource<Mesh>& meshResource, Resource<Buffer>& vertexBufferResource, Resource<Buffer>& indexBufferResource) {
/* Vertex buffer */
Buffer* vertexBuffer = new Buffer(Buffer::Target::Array);
vertexBuffer->setData(*data.positions(0), Buffer::Usage::StaticDraw);
vertexBuffer->setData(data.positions(0), Buffer::Usage::StaticDraw);
ResourceManager::instance()->set(vertexBufferResource.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);
/* Mesh configuration */
Mesh* mesh = new Mesh;
mesh->setPrimitive(data.primitive())
->setVertexCount(data.positions(0)->size())
->setVertexCount(data.positions(0).size())
->addVertexBuffer(vertexBuffer, 0, Shaders::Flat3D::Position());
ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
/* Index buffer, if needed, if not, resource key doesn't have to be set */
if(data.indices()) {
if(data.isIndexed()) {
CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey());
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray);
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices());
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, data.indices());
ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);
}
}

2
src/DebugTools/Implementation/AbstractShapeRenderer.h

@ -49,7 +49,7 @@ template<UnsignedInt dimensions> class AbstractShapeRenderer {
AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer);
virtual ~AbstractShapeRenderer();
virtual void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) = 0;
virtual void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) = 0;
protected:
/* Call only if the mesh resource isn't already present */

6
src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp

@ -33,10 +33,10 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> AxisAlignedBoxRenderer<dimensions>::AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* axisAlignedBox): axisAlignedBox(static_cast<const Shapes::Implementation::Shape<Shapes::AxisAlignedBox<dimensions>>*>(axisAlignedBox)->shape) {}
template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*
DimensionTraits<dimensions>::MatrixType::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)*
DimensionTraits<dimensions>::MatrixType::scaling(axisAlignedBox.max()-axisAlignedBox.min()))
DimensionTraits<dimensions, Float>::MatrixType::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)*
DimensionTraits<dimensions, Float>::MatrixType::scaling(axisAlignedBox.max()-axisAlignedBox.min()))
->setColor(options->color())
->use();
this->wireframeMesh->draw();

2
src/DebugTools/Implementation/AxisAlignedBoxRenderer.h

@ -36,7 +36,7 @@ template<UnsignedInt dimensions> class AxisAlignedBoxRenderer: public AbstractBo
public:
AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* axisAlignedBox);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) override;
private:
const Shapes::AxisAlignedBox<dimensions>& axisAlignedBox;

2
src/DebugTools/Implementation/BoxRenderer.cpp

@ -33,7 +33,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> BoxRenderer<dimensions>::BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* box): box(static_cast<const Shapes::Implementation::Shape<Shapes::Box<dimensions>>*>(box)->shape) {}
template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation())
->setColor(options->color())
->use();

2
src/DebugTools/Implementation/BoxRenderer.h

@ -36,7 +36,7 @@ template<UnsignedInt dimensions> class BoxRenderer: public AbstractBoxRenderer<d
public:
BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* box);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) override;
private:
const Shapes::Box<dimensions>& box;

2
src/DebugTools/Implementation/ForceRendererTransformation.h

@ -31,7 +31,7 @@
namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> typename DimensionTraits<dimensions>::MatrixType forceRendererTransformation(const typename DimensionTraits<dimensions>::VectorType& forcePosition, const typename DimensionTraits<dimensions>::VectorType& force);
template<UnsignedInt dimensions> typename DimensionTraits<dimensions, Float>::MatrixType forceRendererTransformation(const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType& force);
template<> inline Matrix3 forceRendererTransformation<2>(const Vector2& forcePosition, const Vector2& force) {
return Matrix3::from({force, Vector2(-force.y(), force.x())}, forcePosition);

2
src/DebugTools/Implementation/LineSegmentRenderer.cpp

@ -54,7 +54,7 @@ template<UnsignedInt dimensions> LineSegmentRenderer<dimensions>::LineSegmentRen
if(!this->wireframeMesh) this->createResources(meshData<dimensions>());
}
template<UnsignedInt dimensions> void LineSegmentRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
template<UnsignedInt dimensions> void LineSegmentRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*
Implementation::lineSegmentRendererTransformation<dimensions>(line.a(), line.b()))
->setColor(options->color())

2
src/DebugTools/Implementation/LineSegmentRenderer.h

@ -36,7 +36,7 @@ template<UnsignedInt dimensions> class LineSegmentRenderer: public AbstractShape
public:
LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>* line);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) override;
private:
const Shapes::LineSegment<dimensions>& line;

4
src/DebugTools/Implementation/LineSegmentRendererTransformation.h

@ -28,8 +28,8 @@
namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> typename DimensionTraits<dimensions>::MatrixType lineSegmentRendererTransformation(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b) {
auto transformation = DimensionTraits<dimensions>::MatrixType::translation(a);
template<UnsignedInt dimensions> typename DimensionTraits<dimensions, Float>::MatrixType lineSegmentRendererTransformation(const typename DimensionTraits<dimensions, Float>::VectorType& a, const typename DimensionTraits<dimensions, Float>::VectorType& b) {
auto transformation = DimensionTraits<dimensions, Float>::MatrixType::translation(a);
transformation.right() = b - a;
return transformation;
}

6
src/DebugTools/Implementation/PointRenderer.cpp

@ -52,11 +52,11 @@ template<UnsignedInt dimensions> PointRenderer<dimensions>::PointRenderer(const
if(!this->wireframeMesh) this->createResources(meshData<dimensions>());
}
template<UnsignedInt dimensions> void PointRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
template<UnsignedInt dimensions> void PointRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) {
/* Half scale, because the point is 2x2(x2) */
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*
DimensionTraits<dimensions>::MatrixType::translation(point.position())*
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->pointSize()/2)))
DimensionTraits<dimensions, Float>::MatrixType::translation(point.position())*
DimensionTraits<dimensions, Float>::MatrixType::scaling(typename DimensionTraits<dimensions, Float>::VectorType(options->pointSize()/2)))
->setColor(options->color())
->use();
this->wireframeMesh->draw();

2
src/DebugTools/Implementation/PointRenderer.h

@ -36,7 +36,7 @@ template<UnsignedInt dimensions> class PointRenderer: public AbstractShapeRender
public:
PointRenderer(const Shapes::Implementation::AbstractShape<dimensions>* point);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) override;
private:
const Shapes::Point<dimensions>& point;

6
src/DebugTools/Implementation/SphereRenderer.cpp

@ -39,10 +39,10 @@ AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("s
template<UnsignedInt dimensions> SphereRenderer<dimensions>::SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>* sphere): sphere(static_cast<const Shapes::Implementation::Shape<Shapes::Sphere<dimensions>>*>(sphere)->shape) {}
template<UnsignedInt dimensions> void SphereRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
template<UnsignedInt dimensions> void SphereRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*
DimensionTraits<dimensions>::MatrixType::translation(sphere.position())*
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(sphere.radius())))
DimensionTraits<dimensions, Float>::MatrixType::translation(sphere.position())*
DimensionTraits<dimensions, Float>::MatrixType::scaling(typename DimensionTraits<dimensions, Float>::VectorType(sphere.radius())))
->setColor(options->color())
->use();
this->wireframeMesh->draw();

2
src/DebugTools/Implementation/SphereRenderer.h

@ -43,7 +43,7 @@ template<UnsignedInt dimensions> class SphereRenderer: public AbstractSphereRend
public:
SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>* sphere);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions, Float>::MatrixType& projectionMatrix) override;
private:
const Shapes::Sphere<dimensions>& sphere;

4
src/DebugTools/ObjectRenderer.cpp

@ -173,8 +173,8 @@ template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(Scen
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
}
template<UnsignedInt dimensions> void ObjectRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->size())))
template<UnsignedInt dimensions> void ObjectRenderer<dimensions>::draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits<dimensions, Float>::MatrixType::scaling(typename DimensionTraits<dimensions, Float>::VectorType(options->size())))
->use();
mesh->draw();

4
src/DebugTools/ShapeRenderer.cpp

@ -103,8 +103,8 @@ template<UnsignedInt dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() {
delete *it;
}
template<UnsignedInt dimensions> void ShapeRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType&, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
typename DimensionTraits<dimensions>::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix();
template<UnsignedInt dimensions> void ShapeRenderer<dimensions>::draw(const typename DimensionTraits<dimensions, Float>::MatrixType&, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
typename DimensionTraits<dimensions, Float>::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix();
for(auto it = renderers.begin(); it != renderers.end(); ++it)
(*it)->draw(options, projectionMatrix);
}

4
src/DimensionTraits.h

@ -33,8 +33,8 @@
namespace Magnum {
/** @brief Matrix, point and vector specializations for given dimension count */
template<UnsignedInt dimensions, class T = Float> struct DimensionTraits {
/** @brief Matrix and vector specializations for given dimension count */
template<UnsignedInt dimensions, class T> struct DimensionTraits {
DimensionTraits() = delete;
#ifdef DOXYGEN_GENERATING_OUTPUT

21
src/Platform/AbstractXApplication.cpp

@ -36,18 +36,22 @@
namespace Magnum { namespace Platform {
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext(new Configuration);
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext(configuration);
}
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
if(configuration) createContext(configuration);
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext({});
}
void AbstractXApplication::createContext(AbstractXApplication::Configuration* configuration) {
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {}
void AbstractXApplication::createContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "AbstractXApplication::createContext(): context already created", );
viewportSize = configuration->size();
viewportSize = configuration.size();
/* Get default X display */
display = XOpenDisplay(nullptr);
@ -73,8 +77,8 @@ void AbstractXApplication::createContext(AbstractXApplication::Configuration* co
attr.colormap = XCreateColormap(display, root, visInfo->visual, AllocNone);
attr.event_mask = 0;
unsigned long mask = CWBackPixel|CWBorderPixel|CWColormap|CWEventMask;
window = XCreateWindow(display, root, 20, 20, configuration->size().x(), configuration->size().y(), 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr);
XSetStandardProperties(display, window, configuration->title().c_str(), nullptr, None, nullptr, 0, nullptr);
window = XCreateWindow(display, root, 20, 20, configuration.size().x(), configuration.size().y(), 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr);
XSetStandardProperties(display, window, configuration.title().data(), nullptr, None, nullptr, 0, nullptr);
XFree(visInfo);
/* Be notified about closing the window */
@ -94,7 +98,6 @@ void AbstractXApplication::createContext(AbstractXApplication::Configuration* co
ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures());
c = new Context;
delete configuration;
}
AbstractXApplication::~AbstractXApplication() {

28
src/Platform/AbstractXApplication.h

@ -73,10 +73,17 @@ class AbstractXApplication {
* @param contextHandler OpenGL context handler
* @param arguments Application arguments
*
* Creates application with default configuration. See Configuration
* for more information.
* Creates application with default or user-specified configuration.
* See Configuration for more information. The program exits if the
* context cannot be created, see below for an alternative.
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, const Configuration& configuration);
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments);
#endif
/**
* @brief Constructor
@ -84,11 +91,10 @@ class AbstractXApplication {
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext().
* Unlike above, the context is not created and must be created later
* with createContext() or tryCreateContext().
*/
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, Configuration* configuration);
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, std::nullptr_t);
/**
* @brief Execute main loop
@ -110,7 +116,7 @@ class AbstractXApplication {
~AbstractXApplication();
/** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration);
void createContext(const Configuration& configuration);
/** @{ @name Drawing functions */
@ -202,9 +208,9 @@ class AbstractXApplication::Configuration {
*
* Default is `"Magnum X Application"`.
*/
Configuration* setTitle(std::string title) {
Configuration& setTitle(std::string title) {
_title = std::move(title);
return this;
return *this;
}
/** @brief Window size */
@ -216,9 +222,9 @@ class AbstractXApplication::Configuration {
*
* Default is `{800, 600}`.
*/
Configuration* setSize(const Vector2i& size) {
Configuration& setSize(const Vector2i& size) {
_size = size;
return this;
return *this;
}
private:

26
src/Platform/GlutApplication.cpp

@ -31,14 +31,20 @@ namespace Magnum { namespace Platform {
GlutApplication* GlutApplication::instance = nullptr;
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
GlutApplication::GlutApplication(const Arguments& arguments, const Configuration& configuration): c(nullptr) {
initialize(arguments.argc, arguments.argv);
createContext(configuration);
}
GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) {
initialize(arguments.argc, arguments.argv);
createContext(new Configuration);
createContext({});
}
GlutApplication::GlutApplication(const Arguments& arguments, Configuration* configuration): c(nullptr) {
GlutApplication::GlutApplication(const Arguments& arguments, std::nullptr_t): c(nullptr) {
initialize(arguments.argc, arguments.argv);
if(configuration) createContext(configuration);
}
void GlutApplication::initialize(int& argc, char** argv) {
@ -50,26 +56,24 @@ void GlutApplication::initialize(int& argc, char** argv) {
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
}
void GlutApplication::createContext(Configuration* configuration) {
void GlutApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::GlutApplication::createContext(): cannot create context";
delete configuration;
std::exit(1);
} else delete configuration;
}
}
bool GlutApplication::tryCreateContext(Configuration* configuration) {
bool GlutApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "Platform::GlutApplication::tryCreateContext(): context already created", false);
unsigned int flags = GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL;
/* Multisampling */
if(configuration->sampleCount()) flags |= GLUT_MULTISAMPLE;
if(configuration.sampleCount()) flags |= GLUT_MULTISAMPLE;
glutInitDisplayMode(flags);
glutInitWindowSize(configuration->size().x(), configuration->size().y());
if(!glutCreateWindow(configuration->title().c_str()))
glutInitWindowSize(configuration.size().x(), configuration.size().y());
if(!glutCreateWindow(configuration.title().data()))
return false;
glutReshapeFunc(staticViewportEvent);
glutSpecialFunc(staticKeyEvent);

56
src/Platform/GlutApplication.h

@ -82,24 +82,28 @@ class GlutApplication {
/**
* @brief Default constructor
* @param arguments Application arguments
* @param configuration %Configuration
*
* Creates application with default configuration. See Configuration
* for more information. The program exits if the context cannot be
* created, see tryCreateContext() for an alternative.
* Creates application with default or user-specified configuration.
* See Configuration for more information. The program exits if the
* context cannot be created, see below for an alternative.
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit GlutApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit GlutApplication(const Arguments& arguments, const Configuration& configuration);
explicit GlutApplication(const Arguments& arguments);
#endif
/**
* @brief Constructor
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext(). The program exits if the context cannot be
* created, see tryCreateContext() for an alternative.
* Unlike above, the context is not created and must be created later
* with createContext() or tryCreateContext().
*/
explicit GlutApplication(const Arguments& arguments, Configuration* configuration);
explicit GlutApplication(const Arguments& arguments, std::nullptr_t);
/**
* @brief Execute main loop
@ -118,21 +122,19 @@ class GlutApplication {
/**
* @brief Create context with given configuration
*
* The @p configuration is deleted afterwards. Must be called if and
* only if the context wasn't created by the constructor itself. The
* program exits if the context cannot be created, see tryCreateContext()
* for an alternative.
* Must be called if and only if the context wasn't created by the
* constructor itself. The program exits if the context cannot be
* created, see tryCreateContext() for an alternative.
*/
void createContext(Configuration* configuration);
void createContext(const Configuration& configuration);
/**
* @brief Try to create context with given configuration
*
* Unlike createContext() the @p configuration is *not* deleted
* afterwards. Returns `false` if the context cannot be created, `true`
* otherwise.
* Unlike createContext() returns `false` if the context cannot be
* created, `true` otherwise.
*/
bool tryCreateContext(Configuration* configuration);
bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */
@ -288,13 +290,13 @@ class GlutApplication::Configuration {
/**
* @brief Set window title
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `"Magnum GLUT Application"`.
*/
Configuration* setTitle(std::string title) {
Configuration& setTitle(std::string title) {
_title = std::move(title);
return this;
return *this;
}
/** @brief Window size */
@ -302,13 +304,13 @@ class GlutApplication::Configuration {
/**
* @brief Set window size
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `{800, 600}`.
*/
Configuration* setSize(const Vector2i& size) {
Configuration& setSize(const Vector2i& size) {
_size = size;
return this;
return *this;
}
/** @brief Sample count */
@ -316,15 +318,15 @@ class GlutApplication::Configuration {
/**
* @brief Set sample count
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `0`, thus no multisampling. The actual sample count is
* ignored, GLUT either enables it or disables. See also
* @ref Renderer::Feature "Renderer::Feature::Multisampling".
*/
Configuration* setSampleCount(Int count) {
Configuration& setSampleCount(Int count) {
_sampleCount = count;
return this;
return *this;
}
private:

8
src/Platform/GlxApplication.h

@ -56,11 +56,11 @@ to simplify porting.
*/
class GlxApplication: public AbstractXApplication {
public:
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
explicit GlxApplication(const Arguments& arguments): AbstractXApplication(new GlxContextHandler, arguments) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
explicit GlxApplication(const Arguments& arguments, const Configuration& configuration = Configuration()): AbstractXApplication(new GlxContextHandler, arguments, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
explicit GlxApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new GlxContextHandler, arguments, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit GlxApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new GlxContextHandler, arguments, nullptr) {}
protected:
/* Nobody will need to have (and delete) GlxApplication*, thus this is

30
src/Platform/NaClApplication.cpp

@ -49,38 +49,42 @@ NaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance):
Error::setOutput(&errorOutput);
}
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
NaClApplication::NaClApplication(const Arguments& arguments, const Configuration& configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), graphics(nullptr), fullscreen(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(configuration);
}
NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(new Configuration);
createContext({});
}
NaClApplication::NaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), graphics(nullptr), fullscreen(nullptr), c(nullptr) {
NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
if(configuration) createContext(configuration);
}
void NaClApplication::createContext(Configuration* configuration) {
void NaClApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::NaClApplication::createContext(): cannot create context";
delete configuration;
std::exit(1);
} else delete configuration;
}
}
bool NaClApplication::tryCreateContext(Configuration* configuration) {
bool NaClApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "Platform::NaClApplication::tryCreateContext(): context already created", false);
viewportSize = configuration->size();
viewportSize = configuration.size();
const std::int32_t attributes[] = {
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
PP_GRAPHICS3DATTRIB_SAMPLES, configuration->sampleCount(),
PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, configuration->sampleCount() > 1? 1 : 0,
PP_GRAPHICS3DATTRIB_WIDTH, configuration->size().x(),
PP_GRAPHICS3DATTRIB_HEIGHT, configuration->size().y(),
PP_GRAPHICS3DATTRIB_SAMPLES, configuration.sampleCount(),
PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, configuration.sampleCount() > 1 ? 1 : 0,
PP_GRAPHICS3DATTRIB_WIDTH, configuration.size().x(),
PP_GRAPHICS3DATTRIB_HEIGHT, configuration.size().y(),
PP_GRAPHICS3DATTRIB_NONE
};

42
src/Platform/NaClApplication.h

@ -137,25 +137,17 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
class MouseEvent;
class MouseMoveEvent;
/**
* @brief Default constructor
* @param arguments Application arguments
*
* Creates application with default configuration. See Configuration
* for more information.
*/
/** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit NaClApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit NaClApplication(const Arguments& arguments, const Configuration& configuration);
explicit NaClApplication(const Arguments& arguments);
#endif
/**
* @brief Constructor
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext().
*/
explicit NaClApplication(const Arguments& arguments, Configuration* configuration);
/** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit NaClApplication(const Arguments& arguments, std::nullptr_t);
/** @brief Whether the application runs fullscreen */
bool isFullscreen();
@ -176,10 +168,10 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
~NaClApplication();
/** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration);
void createContext(const Configuration& configuration);
/** @copydoc GlutApplication::tryCreateContext() */
bool tryCreateContext(Configuration* configuration);
bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */
@ -323,13 +315,13 @@ class NaClApplication::Configuration {
/**
* @brief Set window size
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `{640, 480}`.
*/
Configuration* setSize(const Vector2i& size) {
Configuration& setSize(const Vector2i& size) {
_size = size;
return this;
return *this;
}
/** @brief Sample count */
@ -337,14 +329,14 @@ class NaClApplication::Configuration {
/**
* @brief Set sample count
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `0`, thus no multisampling. See also
* @ref Renderer::Feature "Renderer::Feature::Multisampling".
*/
Configuration* setSampleCount(Int count) {
Configuration& setSampleCount(Int count) {
_sampleCount = count;
return this;
return *this;
}
private:

36
src/Platform/Sdl2Application.cpp

@ -47,14 +47,20 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) {
}
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
Sdl2Application::Sdl2Application(const Arguments&, const Configuration& configuration): context(nullptr), flags(Flag::Redraw) {
initialize();
createContext(configuration);
}
Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) {
initialize();
createContext(new Configuration);
createContext({});
}
Sdl2Application::Sdl2Application(const Arguments&, Configuration* configuration): context(nullptr), flags(Flag::Redraw) {
Sdl2Application::Sdl2Application(const Arguments&, std::nullptr_t): context(nullptr), flags(Flag::Redraw) {
initialize();
if(configuration) createContext(configuration);
}
void Sdl2Application::initialize() {
@ -64,16 +70,14 @@ void Sdl2Application::initialize() {
}
}
void Sdl2Application::createContext(Configuration* configuration) {
void Sdl2Application::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::Sdl2Application::createContext(): cannot create context:" << SDL_GetError();
delete configuration;
std::exit(1);
} else delete configuration;
}
}
bool Sdl2Application::tryCreateContext(Configuration* configuration) {
bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!context, "Platform::Sdl2Application::tryCreateContext(): context already created", false);
/* Enable double buffering and 24bt depth buffer */
@ -81,16 +85,16 @@ bool Sdl2Application::tryCreateContext(Configuration* configuration) {
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
/* Multisampling */
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configuration->sampleCount() > 1 ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configuration->sampleCount());
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configuration.sampleCount() > 1 ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configuration.sampleCount());
/* Flags: if not hidden, set as shown */
Uint32 flags(configuration->flags());
if(!(configuration->flags() & Configuration::Flag::Hidden)) flags |= SDL_WINDOW_SHOWN;
Uint32 flags(configuration.flags());
if(!(configuration.flags() & Configuration::Flag::Hidden)) flags |= SDL_WINDOW_SHOWN;
if(!(window = SDL_CreateWindow(configuration->title().c_str(),
if(!(window = SDL_CreateWindow(configuration.title().data(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
configuration->size().x(), configuration->size().y(),
configuration.size().x(), configuration.size().y(),
SDL_WINDOW_OPENGL|flags)))
return false;
@ -108,8 +112,8 @@ bool Sdl2Application::tryCreateContext(Configuration* configuration) {
SDL_Event* sizeEvent = new SDL_Event;
sizeEvent->type = SDL_WINDOWEVENT;
sizeEvent->window.event = SDL_WINDOWEVENT_RESIZED;
sizeEvent->window.data1 = configuration->size().x();
sizeEvent->window.data2 = configuration->size().y();
sizeEvent->window.data1 = configuration.size().x();
sizeEvent->window.data2 = configuration.size().y();
SDL_PushEvent(sizeEvent);
c = new Context;

40
src/Platform/Sdl2Application.h

@ -80,11 +80,17 @@ class Sdl2Application {
class MouseEvent;
class MouseMoveEvent;
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
/** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit Sdl2Application(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit Sdl2Application(const Arguments& arguments, const Configuration& configuration);
explicit Sdl2Application(const Arguments& arguments);
#endif
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
explicit Sdl2Application(const Arguments& arguments, Configuration* configuration);
/** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit Sdl2Application(const Arguments& arguments, std::nullptr_t);
/** @copydoc GlutApplication::exec() */
int exec();
@ -98,10 +104,10 @@ class Sdl2Application {
virtual ~Sdl2Application();
/** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration);
void createContext(const Configuration& configuration);
/** @copydoc GlutApplication::tryCreateContext() */
bool tryCreateContext(Configuration* configuration);
bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */
@ -231,13 +237,13 @@ class Sdl2Application::Configuration {
/**
* @brief Set window title
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `"Magnum SDL2 Application"`.
*/
Configuration* setTitle(std::string title) {
Configuration& setTitle(std::string title) {
_title = std::move(title);
return this;
return *this;
}
/** @brief Window size */
@ -245,13 +251,13 @@ class Sdl2Application::Configuration {
/**
* @brief Set window size
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `{800, 600}`.
*/
Configuration* setSize(const Vector2i& size) {
Configuration& setSize(const Vector2i& size) {
_size = size;
return this;
return *this;
}
/** @brief Window flags */
@ -259,13 +265,13 @@ class Sdl2Application::Configuration {
/**
* @brief Set window flags
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is @ref Flag "Flag::Resizable".
*/
Configuration* setFlags(const Flags flags) {
Configuration& setFlags(const Flags flags) {
_flags = flags;
return this;
return *this;
}
/** @brief Sample count */
@ -273,14 +279,14 @@ class Sdl2Application::Configuration {
/**
* @brief Set sample count
* @return Pointer to self (for method chaining)
* @return Reference to self (for method chaining)
*
* Default is `0`, thus no multisampling. See also
* @ref Renderer::Feature "Renderer::Feature::Multisampling".
*/
Configuration* setSampleCount(Int count) {
Configuration& setSampleCount(Int count) {
_sampleCount = count;
return this;
return *this;
}
private:

15
src/Platform/WindowlessGlxApplication.cpp

@ -33,15 +33,19 @@
namespace Magnum { namespace Platform {
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) {
createContext(new Configuration);
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, const Configuration& configuration): c(nullptr) {
createContext(configuration);
}
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, Configuration* configuration): c(nullptr) {
if(configuration) createContext(configuration);
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) {
createContext({});
}
void WindowlessGlxApplication::createContext(Configuration* configuration) {
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, std::nullptr_t): c(nullptr) {}
void WindowlessGlxApplication::createContext(const Configuration&) {
CORRADE_ASSERT(!c, "WindowlessGlxApplication::createContext(): context already created", );
display = XOpenDisplay(nullptr);
@ -100,7 +104,6 @@ void WindowlessGlxApplication::createContext(Configuration* configuration) {
ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable);
c = new Context;
delete configuration;
}
WindowlessGlxApplication::~WindowlessGlxApplication() {

14
src/Platform/WindowlessGlxApplication.h

@ -73,11 +73,17 @@ class WindowlessGlxApplication {
class Configuration;
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
/** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit WindowlessGlxApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit WindowlessGlxApplication(const Arguments& arguments, const Configuration& configuration);
explicit WindowlessGlxApplication(const Arguments& arguments);
#endif
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
explicit WindowlessGlxApplication(const Arguments& arguments, Configuration* configuration);
/** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit WindowlessGlxApplication(const Arguments& arguments, std::nullptr_t);
/**
* @brief Execute application
@ -91,7 +97,7 @@ class WindowlessGlxApplication {
~WindowlessGlxApplication();
/** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration);
void createContext(const Configuration& configuration);
private:
Display* display;

22
src/Platform/WindowlessNaClApplication.cpp

@ -41,33 +41,37 @@ struct WindowlessNaClApplication::ConsoleDebugOutput {
WindowlessNaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance): debugBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Log), warningBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Warning), errorBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Error), debugOutput(&debugBuffer), warningOutput(&warningBuffer), errorOutput(&errorBuffer) {
/* Inform about this change on standard output */
Debug() << "Platform::NaClApplication: redirecting Debug, Warning and Error output to JavaScript console";
Debug() << "Platform::WindowlessNaClApplication: redirecting Debug, Warning and Error output to JavaScript console";
Debug::setOutput(&debugOutput);
Warning::setOutput(&warningOutput);
Error::setOutput(&errorOutput);
}
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(configuration);
}
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(new Configuration);
createContext({});
}
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) {
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, std::nullptr_t): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
if(configuration) createContext(configuration);
}
void WindowlessNaClApplication::createContext(Configuration* configuration) {
void WindowlessNaClApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) {
Error() << "Platform::WindowlessNaClApplication::createContext(): cannot create context";
delete configuration;
std::exit(1);
} else delete configuration;
}
}
bool WindowlessNaClApplication::tryCreateContext(Configuration*) {
bool WindowlessNaClApplication::tryCreateContext(const Configuration&) {
CORRADE_ASSERT(!c, "Platform::WindowlessNaClApplication::tryCreateContext(): context already created", false);
const std::int32_t attributes[] = {

30
src/Platform/WindowlessNaClApplication.h

@ -90,25 +90,17 @@ class WindowlessNaClApplication: public pp::Instance, public pp::Graphics3DClien
class Configuration;
/**
* @brief Default constructor
* @param arguments Application arguments
*
* Creates application with default configuration. See Configuration
* for more information.
*/
/** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration);
explicit WindowlessNaClApplication(const Arguments& arguments);
#endif
/**
* @brief Constructor
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext().
*/
explicit WindowlessNaClApplication(const Arguments& arguments, Configuration* configuration);
/** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit WindowlessNaClApplication(const Arguments& arguments, std::nullptr_t);
/**
* @brief Execute application
@ -122,10 +114,10 @@ class WindowlessNaClApplication: public pp::Instance, public pp::Graphics3DClien
~WindowlessNaClApplication();
/** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration);
void createContext(const Configuration& configuration);
/** @copydoc GlutApplication::tryCreateContext() */
bool tryCreateContext(Configuration* configuration);
bool tryCreateContext(const Configuration& configuration);
private:
struct ConsoleDebugOutput;

8
src/Platform/XEglApplication.h

@ -56,11 +56,11 @@ to simplify porting.
*/
class XEglApplication: public AbstractXApplication {
public:
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
explicit XEglApplication(const Arguments& arguments): AbstractXApplication(new EglContextHandler, arguments) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
explicit XEglApplication(const Arguments& arguments, const Configuration& configuration = Configuration()): AbstractXApplication(new EglContextHandler, arguments, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
explicit XEglApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new EglContextHandler, arguments, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit XEglApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new EglContextHandler, nullptr) {}
protected:
/* Nobody will need to have (and delete) XEglApplication*, thus this is

7
src/Primitives/Capsule.cpp

@ -24,13 +24,14 @@
#include "Capsule.h"
#include "Math/Angle.h"
#include "Math/Vector3.h"
#include "Primitives/Implementation/Spheroid.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
Trade::MeshData3D Capsule::solid(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float length, TextureCoords textureCoords) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", Trade::MeshData3D(Mesh::Primitive::Triangles, nullptr, {}, {}, {}));
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", Trade::MeshData3D(Mesh::Primitive::Triangles, {}, {}, {}, {}));
Implementation::Spheroid capsule(segments, textureCoords == TextureCoords::Generate ?
Implementation::Spheroid::TextureCoords::Generate :
@ -60,7 +61,7 @@ Trade::MeshData3D Capsule::solid(UnsignedInt hemisphereRings, UnsignedInt cylind
capsule.faceRings(hemisphereRings*2-2+cylinderRings);
capsule.topFaceRing();
return std::move(capsule);
return capsule.finalize();
}
}}

22
src/Primitives/Circle.cpp

@ -32,39 +32,39 @@ namespace Magnum { namespace Primitives {
Trade::MeshData2D Circle::solid(UnsignedInt segments) {
CORRADE_ASSERT(segments >= 3, "Primitives::Circle::solid(): segments must be >= 3",
Trade::MeshData2D(Mesh::Primitive::TriangleFan, nullptr, {}, {}));
Trade::MeshData2D(Mesh::Primitive::TriangleFan, {}, {}, {}));
auto positions = new std::vector<Vector2>;
positions->reserve(segments+1);
std::vector<Vector2> positions;
positions.reserve(segments+1);
/* Central point */
positions->emplace_back();
positions.emplace_back();
/* Points on circle */
const Rad angleIncrement(2*Constants::pi()/segments);
for(UnsignedInt i = 0; i != segments; ++i) {
const Rad angle(i*angleIncrement);
positions->emplace_back(Math::cos(angle), Math::sin(angle));
positions.emplace_back(Math::cos(angle), Math::sin(angle));
}
return Trade::MeshData2D(Mesh::Primitive::TriangleFan, nullptr, {positions}, {});
return Trade::MeshData2D(Mesh::Primitive::TriangleFan, {}, {std::move(positions)}, {});
}
Trade::MeshData2D Circle::wireframe(UnsignedInt segments) {
CORRADE_ASSERT(segments >= 3, "Primitives::Circle::wireframe(): segments must be >= 3",
Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {}, {}));
Trade::MeshData2D(Mesh::Primitive::LineLoop, {}, {}, {}));
auto positions = new std::vector<Vector2>;
positions->reserve(segments);
std::vector<Vector2> positions;
positions.reserve(segments);
/* Points on circle */
const Rad angleIncrement(2*Constants::pi()/segments);
for(UnsignedInt i = 0; i != segments; ++i) {
const Rad angle(i*angleIncrement);
positions->emplace_back(Math::cos(angle), Math::sin(angle));
positions.emplace_back(Math::cos(angle), Math::sin(angle));
}
return Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {positions}, {});
return Trade::MeshData2D(Mesh::Primitive::LineLoop, {}, {std::move(positions)}, {});
}
}}

4
src/Primitives/Crosshair.cpp

@ -31,14 +31,14 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Crosshair2D::wireframe() {
return Trade::MeshData2D(Mesh::Primitive::Lines, nullptr, {new std::vector<Vector2>{
return Trade::MeshData2D(Mesh::Primitive::Lines, {}, {{
{-1.0f, 0.0f}, {1.0f, 0.0f},
{ 0.0f, -1.0f}, {0.0f, 1.0f}
}}, {});
}
Trade::MeshData3D Crosshair3D::wireframe() {
return Trade::MeshData3D(Mesh::Primitive::Lines, nullptr, {new std::vector<Vector3>{
return Trade::MeshData3D(Mesh::Primitive::Lines, {}, {{
{-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
{ 0.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f},
{ 0.0f, 0.0f, -1.0f}, {0.0f, 0.0f, 1.0f}

10
src/Primitives/Cube.cpp

@ -30,14 +30,14 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D Cube::solid() {
return Trade::MeshData3D(Mesh::Primitive::Triangles, new std::vector<UnsignedInt>{
return Trade::MeshData3D(Mesh::Primitive::Triangles, {
0, 1, 2, 0, 2, 3, /* +Z */
4, 5, 6, 4, 6, 7, /* +X */
8, 9, 10, 8, 10, 11, /* +Y */
12, 13, 14, 12, 14, 15, /* -Z */
16, 17, 18, 16, 18, 19, /* -Y */
20, 21, 22, 20, 22, 23 /* -X */
}, {new std::vector<Vector3>{
}, {{
{-1.0f, -1.0f, 1.0f},
{ 1.0f, -1.0f, 1.0f},
{ 1.0f, 1.0f, 1.0f}, /* +Z */
@ -67,7 +67,7 @@ Trade::MeshData3D Cube::solid() {
{-1.0f, -1.0f, 1.0f},
{-1.0f, 1.0f, 1.0f}, /* -X */
{-1.0f, 1.0f, -1.0f}
}}, {new std::vector<Vector3>{
}}, {{
{ 0.0f, 0.0f, 1.0f},
{ 0.0f, 0.0f, 1.0f},
{ 0.0f, 0.0f, 1.0f}, /* +Z */
@ -101,12 +101,12 @@ Trade::MeshData3D Cube::solid() {
}
Trade::MeshData3D Cube::wireframe() {
return Trade::MeshData3D(Mesh::Primitive::Lines, new std::vector<UnsignedInt>{
return Trade::MeshData3D(Mesh::Primitive::Lines, {
0, 1, 1, 2, 2, 3, 3, 0, /* +Z */
4, 5, 5, 6, 6, 7, 7, 4, /* -Z */
1, 5, 2, 6, /* +X */
0, 4, 3, 7 /* -X */
}, {new std::vector<Vector3>{
}, {{
{-1.0f, -1.0f, 1.0f},
{ 1.0f, -1.0f, 1.0f},
{ 1.0f, 1.0f, 1.0f},

5
src/Primitives/Cylinder.cpp

@ -26,11 +26,12 @@
#include "Math/Vector3.h"
#include "Primitives/Implementation/Spheroid.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
Trade::MeshData3D Cylinder::solid(UnsignedInt rings, UnsignedInt segments, Float length, Cylinder::Flags flags) {
CORRADE_ASSERT(rings >= 1 && segments >= 3, "Primitives::Cylinder::solid(): cylinder must have at least one ring and three segments", Trade::MeshData3D(Mesh::Primitive::Triangles, nullptr, {}, {}, {}));
CORRADE_ASSERT(rings >= 1 && segments >= 3, "Primitives::Cylinder::solid(): cylinder must have at least one ring and three segments", Trade::MeshData3D(Mesh::Primitive::Triangles, {}, {}, {}, {}));
Implementation::Spheroid cylinder(segments, flags & Flag::GenerateTextureCoords ? Implementation::Spheroid::TextureCoords::Generate : Implementation::Spheroid::TextureCoords::DontGenerate);
@ -57,7 +58,7 @@ Trade::MeshData3D Cylinder::solid(UnsignedInt rings, UnsignedInt segments, Float
cylinder.faceRings(rings, flags & Flag::CapEnds ? 1 : 0);
if(flags & Flag::CapEnds) cylinder.topFaceRing();
return std::move(cylinder);
return cylinder.finalize();
}
}}

6
src/Primitives/Icosphere.cpp

@ -28,7 +28,7 @@
namespace Magnum { namespace Primitives {
Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vector<UnsignedInt>{
Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, {
1, 2, 6,
1, 7, 2,
3, 4, 5,
@ -49,7 +49,7 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vecto
7, 1, 0,
3, 9, 8,
4, 8, 0
}, {new std::vector<Vector3>}, {new std::vector<Vector3>{
}, {}, {{
{0.0f, -0.525731f, 0.850651f},
{0.850651f, 0.0f, 0.525731f},
{0.850651f, 0.0f, -0.525731f},
@ -63,7 +63,7 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vecto
{0.0f, 0.525731f, -0.850651f},
{0.0f, 0.525731f, 0.850651f}
}}, {}) {
positions(0)->assign(normals(0)->begin(), normals(0)->end());
positions(0).assign(normals(0).begin(), normals(0).end());
}
}}

76
src/Primitives/Implementation/Spheroid.cpp

@ -26,17 +26,18 @@
#include "Math/Functions.h"
#include "Math/Vector3.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives { namespace Implementation {
Spheroid::Spheroid(UnsignedInt segments, TextureCoords textureCoords): MeshData3D(Mesh::Primitive::Triangles, new std::vector<UnsignedInt>, {new std::vector<Vector3>()}, {new std::vector<Vector3>()}, textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>*>{new std::vector<Vector2>()} : std::vector<std::vector<Vector2>*>()), segments(segments), textureCoords(textureCoords) {}
Spheroid::Spheroid(UnsignedInt segments, TextureCoords textureCoords): segments(segments), textureCoords(textureCoords) {}
void Spheroid::capVertex(Float y, Float normalY, Float textureCoordsV) {
positions(0)->push_back({0.0f, y, 0.0f});
normals(0)->push_back({0.0f, normalY, 0.0f});
positions.push_back({0.0f, y, 0.0f});
normals.push_back({0.0f, normalY, 0.0f});
if(textureCoords == TextureCoords::Generate)
textureCoords2D(0)->push_back({0.5, textureCoordsV});
textureCoords2D.push_back({0.5, textureCoordsV});
}
void Spheroid::hemisphereVertexRings(UnsignedInt count, Float centerY, Rad startRingAngle, Rad ringAngleIncrement, Float startTextureCoordsV, Float textureCoordsVIncrement) {
@ -49,18 +50,18 @@ void Spheroid::hemisphereVertexRings(UnsignedInt count, Float centerY, Rad start
for(UnsignedInt j = 0; j != segments; ++j) {
Rad segmentAngle = j*segmentAngleIncrement;
positions(0)->push_back({x*Math::sin(segmentAngle), centerY+y, z*Math::cos(segmentAngle)});
normals(0)->push_back({x*Math::sin(segmentAngle), y, z*Math::cos(segmentAngle)});
positions.push_back({x*Math::sin(segmentAngle), centerY+y, z*Math::cos(segmentAngle)});
normals.push_back({x*Math::sin(segmentAngle), y, z*Math::cos(segmentAngle)});
if(textureCoords == TextureCoords::Generate)
textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement});
textureCoords2D.push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement});
}
/* Duplicate first segment in the ring for additional vertex for texture coordinate */
if(textureCoords == TextureCoords::Generate) {
positions(0)->push_back((*positions(0))[positions(0)->size()-segments]);
normals(0)->push_back((*normals(0))[normals(0)->size()-segments]);
textureCoords2D(0)->push_back({1.0f, startTextureCoordsV + i*textureCoordsVIncrement});
positions.push_back(positions[positions.size()-segments]);
normals.push_back(normals[normals.size()-segments]);
textureCoords2D.push_back({1.0f, startTextureCoordsV + i*textureCoordsVIncrement});
}
}
}
@ -70,18 +71,18 @@ void Spheroid::cylinderVertexRings(UnsignedInt count, Float startY, Float yIncre
for(UnsignedInt i = 0; i != count; ++i) {
for(UnsignedInt j = 0; j != segments; ++j) {
Rad segmentAngle = j*segmentAngleIncrement;
positions(0)->push_back({Math::sin(segmentAngle), startY, Math::cos(segmentAngle)});
normals(0)->push_back({Math::sin(segmentAngle), 0.0f, Math::cos(segmentAngle)});
positions.push_back({Math::sin(segmentAngle), startY, Math::cos(segmentAngle)});
normals.push_back({Math::sin(segmentAngle), 0.0f, Math::cos(segmentAngle)});
if(textureCoords == TextureCoords::Generate)
textureCoords2D(0)->push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement});
textureCoords2D.push_back({j*1.0f/segments, startTextureCoordsV + i*textureCoordsVIncrement});
}
/* Duplicate first segment in the ring for additional vertex for texture coordinate */
if(textureCoords == TextureCoords::Generate) {
positions(0)->push_back((*positions(0))[positions(0)->size()-segments]);
normals(0)->push_back((*normals(0))[normals(0)->size()-segments]);
textureCoords2D(0)->push_back({1.0f, startTextureCoordsV + i*textureCoordsVIncrement});
positions.push_back(positions[positions.size()-segments]);
normals.push_back(normals[normals.size()-segments]);
textureCoords2D.push_back({1.0f, startTextureCoordsV + i*textureCoordsVIncrement});
}
startY += yIncrement;
@ -91,14 +92,14 @@ void Spheroid::cylinderVertexRings(UnsignedInt count, Float startY, Float yIncre
void Spheroid::bottomFaceRing() {
for(UnsignedInt j = 0; j != segments; ++j) {
/* Bottom vertex */
indices()->push_back(0);
indices.push_back(0);
/* Top right vertex */
indices()->push_back((j != segments-1 || textureCoords == TextureCoords::Generate) ?
indices.push_back((j != segments-1 || textureCoords == TextureCoords::Generate) ?
j+2 : 1);
/* Top left vertex */
indices()->push_back(j+1);
indices.push_back(j+1);
}
}
@ -113,12 +114,12 @@ void Spheroid::faceRings(UnsignedInt count, UnsignedInt offset) {
UnsignedInt topLeft = bottomLeft+vertexSegments;
UnsignedInt topRight = bottomRight+vertexSegments;
indices()->push_back(bottomLeft);
indices()->push_back(bottomRight);
indices()->push_back(topRight);
indices()->push_back(bottomLeft);
indices()->push_back(topRight);
indices()->push_back(topLeft);
indices.push_back(bottomLeft);
indices.push_back(bottomRight);
indices.push_back(topRight);
indices.push_back(bottomLeft);
indices.push_back(topRight);
indices.push_back(topLeft);
}
}
}
@ -128,14 +129,14 @@ void Spheroid::topFaceRing() {
for(UnsignedInt j = 0; j != segments; ++j) {
/* Bottom left vertex */
indices()->push_back(normals(0)->size()-vertexSegments+j-1);
indices.push_back(normals.size()-vertexSegments+j-1);
/* Bottom right vertex */
indices()->push_back((j != segments-1 || textureCoords == TextureCoords::Generate) ?
normals(0)->size()-vertexSegments+j : normals(0)->size()-segments-1);
indices.push_back((j != segments-1 || textureCoords == TextureCoords::Generate) ?
normals.size()-vertexSegments+j : normals.size()-segments-1);
/* Top vertex */
indices()->push_back(normals(0)->size()-1);
indices.push_back(normals.size()-1);
}
}
@ -144,19 +145,24 @@ void Spheroid::capVertexRing(Float y, Float textureCoordsV, const Vector3& norma
for(UnsignedInt i = 0; i != segments; ++i) {
Rad segmentAngle = i*segmentAngleIncrement;
positions(0)->push_back({Math::sin(segmentAngle), y, Math::cos(segmentAngle)});
normals(0)->push_back(normal);
positions.push_back({Math::sin(segmentAngle), y, Math::cos(segmentAngle)});
normals.push_back(normal);
if(textureCoords == TextureCoords::Generate)
textureCoords2D(0)->push_back({i*1.0f/segments, textureCoordsV});
textureCoords2D.push_back({i*1.0f/segments, textureCoordsV});
}
/* Duplicate first segment in the ring for additional vertex for texture coordinate */
if(textureCoords == TextureCoords::Generate) {
positions(0)->push_back((*positions(0))[positions(0)->size()-segments]);
normals(0)->push_back(normal);
textureCoords2D(0)->push_back({1.0f, textureCoordsV});
positions.push_back(positions[positions.size()-segments]);
normals.push_back(normal);
textureCoords2D.push_back({1.0f, textureCoordsV});
}
}
Trade::MeshData3D Spheroid::finalize() {
return Trade::MeshData3D(Mesh::Primitive::Triangles, std::move(indices), {std::move(positions)}, {std::move(normals)},
textureCoords == TextureCoords::Generate ? std::vector<std::vector<Vector2>>{std::move(textureCoords2D)} : std::vector<std::vector<Vector2>>());
}
}}}

15
src/Primitives/Implementation/Spheroid.h

@ -24,11 +24,14 @@
DEALINGS IN THE SOFTWARE.
*/
#include "Trade/MeshData3D.h"
#include <vector>
#include "Magnum.h"
#include "Trade/Trade.h"
namespace Magnum { namespace Primitives { namespace Implementation {
class Spheroid: public Trade::MeshData3D {
class Spheroid {
public:
enum class TextureCoords: UnsignedByte {
DontGenerate,
@ -45,8 +48,16 @@ class Spheroid: public Trade::MeshData3D {
void topFaceRing();
void capVertexRing(Float y, Float textureCoordsV, const Vector3& normal);
Trade::MeshData3D finalize();
UnsignedInt segments;
TextureCoords textureCoords;
private:
std::vector<UnsignedInt> indices;
std::vector<Vector3> positions;
std::vector<Vector3> normals;
std::vector<Vector2> textureCoords2D;
};
}}}

4
src/Primitives/Line.cpp

@ -31,13 +31,13 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Line2D::wireframe() {
return Trade::MeshData2D(Mesh::Primitive::Lines, nullptr, {new std::vector<Vector2>{
return Trade::MeshData2D(Mesh::Primitive::Lines, {}, {{
{0.0f, 0.0f}, {1.0f, 0.0f}
}}, {});
}
Trade::MeshData3D Line3D::wireframe() {
return Trade::MeshData3D(Mesh::Primitive::Lines, nullptr, {new std::vector<Vector3>{
return Trade::MeshData3D(Mesh::Primitive::Lines, {}, {{
{0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
}}, {}, {});
}

6
src/Primitives/Plane.cpp

@ -30,12 +30,12 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D Plane::solid() {
return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector<Vector3>{
return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, {}, {{
{1.0f, -1.0f, 0.0f},
{1.0f, 1.0f, 0.0f},
{-1.0f, -1.0f, 0.0f},
{-1.0f, 1.0f, 0.0f}
}}, {new std::vector<Vector3>{
}}, {{
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f},
@ -44,7 +44,7 @@ Trade::MeshData3D Plane::solid() {
}
Trade::MeshData3D Plane::wireframe() {
return Trade::MeshData3D(Mesh::Primitive::LineLoop, nullptr, {new std::vector<Vector3>{
return Trade::MeshData3D(Mesh::Primitive::LineLoop, {}, {{
{-1.0f, -1.0f, 0.0f},
{1.0f, -1.0f, 0.0f},
{1.0f, 1.0f, 0.0f},

4
src/Primitives/Square.cpp

@ -30,7 +30,7 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Square::solid() {
return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, nullptr, {new std::vector<Vector2>{
return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, {}, {{
{1.0f, -1.0f},
{1.0f, 1.0f},
{-1.0f, -1.0f},
@ -39,7 +39,7 @@ Trade::MeshData2D Square::solid() {
}
Trade::MeshData2D Square::wireframe() {
return Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {new std::vector<Vector2>{
return Trade::MeshData2D(Mesh::Primitive::LineLoop, {}, {{
{-1.0f, -1.0f},
{1.0f, -1.0f},
{1.0f, 1.0f},

12
src/Primitives/Test/CapsuleTest.cpp

@ -50,7 +50,7 @@ CapsuleTest::CapsuleTest() {
void CapsuleTest::withoutTextureCoords() {
Trade::MeshData3D capsule = Capsule::solid(2, 2, 3, 1.0f);
CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},
{0.0f, -1.20711f, 0.707107f},
@ -76,7 +76,7 @@ void CapsuleTest::withoutTextureCoords() {
{0.0f, 1.5f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*capsule.normals(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(capsule.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -0.707107f, 0.707107f},
@ -102,7 +102,7 @@ void CapsuleTest::withoutTextureCoords() {
{0.0f, 1.0f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*capsule.indices(), (std::vector<UnsignedInt>{
CORRADE_COMPARE_AS(capsule.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 1, 3,
1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6,
4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9,
@ -115,7 +115,7 @@ void CapsuleTest::withoutTextureCoords() {
void CapsuleTest::withTextureCoords() {
Trade::MeshData3D capsule = Capsule::solid(2, 2, 3, 1.0f, Capsule::TextureCoords::Generate);
CORRADE_COMPARE_AS(*capsule.positions(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},
{0.0f, -1.20711f, 0.707107f},
@ -146,7 +146,7 @@ void CapsuleTest::withTextureCoords() {
{0.0f, 1.5f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*capsule.textureCoords2D(0), (std::vector<Vector2>{
CORRADE_COMPARE_AS(capsule.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f},
{0.0f, 0.166667f},
@ -177,7 +177,7 @@ void CapsuleTest::withTextureCoords() {
{0.5f, 1.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*capsule.indices(), (std::vector<UnsignedInt>{
CORRADE_COMPARE_AS(capsule.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 4, 3,
1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11,

4
src/Primitives/Test/CircleTest.cpp

@ -46,7 +46,7 @@ CircleTest::CircleTest() {
void CircleTest::solid() {
Trade::MeshData2D circle = Primitives::Circle::solid(8);
CORRADE_COMPARE(*circle.positions(0), (std::vector<Vector2>{
CORRADE_COMPARE(circle.positions(0), (std::vector<Vector2>{
{ 0.0f, 0.0f},
{ 1.0f, 0.0f}, { Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f},
{ 0.0f, 1.0f}, {-Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f},
@ -58,7 +58,7 @@ void CircleTest::solid() {
void CircleTest::wireframe() {
Trade::MeshData2D circle = Primitives::Circle::wireframe(8);
CORRADE_COMPARE(*circle.positions(0), (std::vector<Vector2>{
CORRADE_COMPARE(circle.positions(0), (std::vector<Vector2>{
{ 1.0f, 0.0f}, { Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f},
{ 0.0f, 1.0f}, {-Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f},
{-1.0f, 0.0f}, {-Constants::sqrt2()/2.0f, -Constants::sqrt2()/2.0f},

14
src/Primitives/Test/CylinderTest.cpp

@ -47,7 +47,7 @@ CylinderTest::CylinderTest() {
void CylinderTest::withoutAnything() {
Trade::MeshData3D cylinder = Cylinder::solid(2, 3, 3.0f);
CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 1.0f},
{0.866025f, -1.5f, -0.5f},
{-0.866025f, -1.5f, -0.5f},
@ -61,7 +61,7 @@ void CylinderTest::withoutAnything() {
{-0.866025f, 1.5f, -0.5f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*cylinder.normals(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector<Vector3>{
{0.0f, 0.0f, 1.0f},
{0.866025f, 0.0f, -0.5f},
{-0.866025f, 0.0f, -0.5f},
@ -75,7 +75,7 @@ void CylinderTest::withoutAnything() {
{-0.866025f, 0.0f, -0.5f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector<UnsignedInt>{
CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5,
3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8
}), TestSuite::Compare::Container);
@ -84,7 +84,7 @@ void CylinderTest::withoutAnything() {
void CylinderTest::withTextureCoordsAndCaps() {
Trade::MeshData3D cylinder = Cylinder::solid(2, 3, 3.0f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds);
CORRADE_COMPARE_AS(*cylinder.positions(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},
{0.0f, -1.5f, 1.0f},
@ -115,7 +115,7 @@ void CylinderTest::withTextureCoordsAndCaps() {
{0.0f, 1.5f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*cylinder.normals(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -1.0f, 0.0f},
@ -146,7 +146,7 @@ void CylinderTest::withTextureCoordsAndCaps() {
{0.0f, 1.0f, 0.0f},
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*cylinder.textureCoords2D(0), (std::vector<Vector2>{
CORRADE_COMPARE_AS(cylinder.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f},
{0.0f, 0.2f},
@ -177,7 +177,7 @@ void CylinderTest::withTextureCoordsAndCaps() {
{0.5f, 1.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector<UnsignedInt>{
CORRADE_COMPARE_AS(cylinder.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 4, 3,
1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7,

12
src/Primitives/Test/UVSphereTest.cpp

@ -47,7 +47,7 @@ UVSphereTest::UVSphereTest() {
void UVSphereTest::withoutTextureCoords() {
Trade::MeshData3D sphere = UVSphere::solid(3, 3);
CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -0.5f, 0.866025f},
@ -61,7 +61,7 @@ void UVSphereTest::withoutTextureCoords() {
{0.0f, 1.0f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*sphere.normals(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(sphere.normals(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -0.5f, 0.866025f},
@ -75,7 +75,7 @@ void UVSphereTest::withoutTextureCoords() {
{0.0f, 1.0f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*sphere.indices(), (std::vector<UnsignedInt>{
CORRADE_COMPARE_AS(sphere.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 1, 3,
1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6,
4, 5, 7, 5, 6, 7, 6, 4, 7
@ -85,7 +85,7 @@ void UVSphereTest::withoutTextureCoords() {
void UVSphereTest::withTextureCoords() {
Trade::MeshData3D sphere = UVSphere::solid(3, 3, UVSphere::TextureCoords::Generate);
CORRADE_COMPARE_AS(*sphere.positions(0), (std::vector<Vector3>{
CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
{0.0f, -0.5f, 0.866025f},
@ -101,7 +101,7 @@ void UVSphereTest::withTextureCoords() {
{0.0f, 1.0f, 0.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*sphere.textureCoords2D(0), (std::vector<Vector2>{
CORRADE_COMPARE_AS(sphere.textureCoords2D(0), (std::vector<Vector2>{
{0.5f, 0.0f},
{0.0f, 0.333333f},
@ -117,7 +117,7 @@ void UVSphereTest::withTextureCoords() {
{0.5f, 1.0f}
}), TestSuite::Compare::Container);
CORRADE_COMPARE_AS(*sphere.indices(), (std::vector<UnsignedInt>{
CORRADE_COMPARE_AS(sphere.indices(), (std::vector<UnsignedInt>{
0, 2, 1, 0, 3, 2, 0, 4, 3,
1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
5, 6, 9, 6, 7, 9, 7, 8, 9

9
src/Primitives/UVSphere.cpp

@ -24,13 +24,14 @@
#include "UVSphere.h"
#include "Math/Angle.h"
#include "Implementation/Spheroid.h"
#include "Math/Vector3.h"
#include "Primitives/Implementation/Spheroid.h"
#include "Trade/MeshData3D.h"
namespace Magnum { namespace Primitives {
Trade::MeshData3D UVSphere::solid(UnsignedInt rings, UnsignedInt segments, TextureCoords textureCoords) {
CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", Trade::MeshData3D(Mesh::Primitive::Triangles, nullptr, {}, {}, {}));
CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", Trade::MeshData3D(Mesh::Primitive::Triangles, {}, {}, {}, {}));
Implementation::Spheroid sphere(segments, textureCoords == TextureCoords::Generate ?
Implementation::Spheroid::TextureCoords::Generate :
@ -53,7 +54,7 @@ Trade::MeshData3D UVSphere::solid(UnsignedInt rings, UnsignedInt segments, Textu
sphere.faceRings(rings-2);
sphere.topFaceRing();
return std::move(sphere);
return sphere.finalize();
}
}}

4
src/SceneGraph/AbstractTransformation.h

@ -62,7 +62,6 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT Abstrac
static const UnsignedInt Dimensions = dimensions;
explicit AbstractBasicTransformation();
virtual ~AbstractBasicTransformation() = 0;
#ifdef DOXYGEN_GENERATING_OUTPUT
/**
@ -143,6 +142,9 @@ template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT Abstrac
return this;
}
protected:
~AbstractBasicTransformation() = default;
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else

3
src/SceneGraph/AbstractTranslationRotation2D.h

@ -73,6 +73,9 @@ template<class T> class AbstractBasicTranslationRotation2D: public AbstractBasic
}
#endif
protected:
~AbstractBasicTranslationRotation2D() = default;
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else

3
src/SceneGraph/AbstractTranslationRotation3D.h

@ -120,6 +120,9 @@ template<class T> class AbstractBasicTranslationRotation3D: public AbstractBasic
}
#endif
protected:
~AbstractBasicTranslationRotation3D() = default;
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else

3
src/SceneGraph/AbstractTranslationRotationScaling2D.h

@ -70,6 +70,9 @@ template<class T> class AbstractBasicTranslationRotationScaling2D: public Abstra
}
#endif
protected:
~AbstractBasicTranslationRotationScaling2D() = default;
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else

3
src/SceneGraph/AbstractTranslationRotationScaling3D.h

@ -82,6 +82,9 @@ template<class T> class AbstractBasicTranslationRotationScaling3D: public Abstra
}
#endif
protected:
~AbstractBasicTranslationRotationScaling3D() = default;
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else

1
src/SceneGraph/Object.hpp

@ -42,7 +42,6 @@ template<UnsignedInt dimensions, class T> AbstractBasicObject<dimensions, T>::Ab
template<UnsignedInt dimensions, class T> AbstractBasicObject<dimensions, T>::~AbstractBasicObject() {}
template<UnsignedInt dimensions, class T> AbstractBasicTransformation<dimensions, T>::AbstractBasicTransformation() {}
template<UnsignedInt dimensions, class T> AbstractBasicTransformation<dimensions, T>::~AbstractBasicTransformation() {}
/* `= default` causes linker errors in GCC 4.4 */
template<class Transformation> Object<Transformation>::~Object() {}

2
src/Shaders/AbstractVector.h

@ -42,7 +42,7 @@ namespace Magnum { namespace Shaders {
template<UnsignedInt dimensions> class AbstractVector: public AbstractShaderProgram {
public:
/** @brief Vertex position */
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
typedef Attribute<0, typename DimensionTraits<dimensions, Float>::VectorType> Position;
/** @brief Texture coordinates */
typedef Attribute<1, Vector2> TextureCoordinates;

2
src/Shaders/DistanceFieldVector.h

@ -52,7 +52,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
DistanceFieldVector();
/** @brief Set transformation and projection matrix */
DistanceFieldVector* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
DistanceFieldVector* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) {
AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix);
return this;
}

4
src/Shaders/Flat.h

@ -47,7 +47,7 @@ Draws whole mesh with one color.
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public AbstractShaderProgram {
public:
/** @brief Vertex position */
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
typedef Attribute<0, typename DimensionTraits<dimensions, Float>::VectorType> Position;
explicit Flat();
@ -55,7 +55,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @brief Set transformation and projection matrix
* @return Pointer to self (for method chaining)
*/
Flat<dimensions>* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
Flat<dimensions>* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) {
setUniform(transformationProjectionMatrixUniform, matrix);
return this;
}

2
src/Shaders/Vector.h

@ -51,7 +51,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
* @brief Set transformation and projection matrix
* @return Pointer to self (for method chaining)
*/
Vector* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
Vector* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) {
AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix);
return this;
}

4
src/Shaders/VertexColor.h

@ -47,7 +47,7 @@ Draws vertex-colored mesh.
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColor: public AbstractShaderProgram {
public:
/** @brief Vertex position */
typedef Attribute<0, typename DimensionTraits<dimensions>::VectorType> Position;
typedef Attribute<0, typename DimensionTraits<dimensions, Float>::VectorType> Position;
/** @brief Vertex color */
typedef Attribute<1, Color3> Color;
@ -60,7 +60,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColor: public
*
* Default is identity matrix.
*/
VertexColor<dimensions>* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
VertexColor<dimensions>* setTransformationProjectionMatrix(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) {
setUniform(transformationProjectionMatrixUniform, matrix);
return this;
}

2
src/Shapes/AxisAlignedBox.cpp

@ -30,7 +30,7 @@
namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> AxisAlignedBox<dimensions> AxisAlignedBox<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> AxisAlignedBox<dimensions> AxisAlignedBox<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return AxisAlignedBox<dimensions>(matrix.transformPoint(_min),
matrix.transformPoint(_max));
}

14
src/Shapes/AxisAlignedBox.h

@ -56,28 +56,28 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT AxisAlignedBox {
constexpr /*implicit*/ AxisAlignedBox() {}
/** @brief Constructor */
constexpr /*implicit*/ AxisAlignedBox(const typename DimensionTraits<dimensions>::VectorType& min, const typename DimensionTraits<dimensions>::VectorType& max): _min(min), _max(max) {}
constexpr /*implicit*/ AxisAlignedBox(const typename DimensionTraits<dimensions, Float>::VectorType& min, const typename DimensionTraits<dimensions, Float>::VectorType& max): _min(min), _max(max) {}
/** @brief Transformed shape */
AxisAlignedBox<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
AxisAlignedBox<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief Minimal coordinates */
constexpr typename DimensionTraits<dimensions>::VectorType min() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType min() const {
return _min;
}
/** @brief Set minimal coordinates */
void setMin(const typename DimensionTraits<dimensions>::VectorType& min) {
void setMin(const typename DimensionTraits<dimensions, Float>::VectorType& min) {
_min = min;
}
/** @brief Maximal coordinates */
constexpr typename DimensionTraits<dimensions>::VectorType max() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType max() const {
return _max;
}
/** @brief Set maximal coordinates */
void setMax(const typename DimensionTraits<dimensions>::VectorType& max) {
void setMax(const typename DimensionTraits<dimensions, Float>::VectorType& max) {
_max = max;
}
@ -85,7 +85,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT AxisAlignedBox {
bool operator%(const Point<dimensions>& other) const;
private:
typename DimensionTraits<dimensions>::VectorType _min, _max;
typename DimensionTraits<dimensions, Float>::VectorType _min, _max;
};
/** @brief Two-dimensional axis-aligned box */

2
src/Shapes/Box.cpp

@ -26,7 +26,7 @@
namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Box<dimensions> Box<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> Box<dimensions> Box<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Box<dimensions>(matrix*_transformation);
}

12
src/Shapes/Box.h

@ -55,26 +55,26 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Box {
*
* Creates zero-sized box positioned at origin.
*/
constexpr /*implicit*/ Box(): _transformation(DimensionTraits<dimensions>::MatrixType::Zero) {}
constexpr /*implicit*/ Box(): _transformation(DimensionTraits<dimensions, Float>::MatrixType::Zero) {}
/** @brief Constructor */
constexpr /*implicit*/ Box(const typename DimensionTraits<dimensions>::MatrixType& transformation): _transformation(transformation) {}
constexpr /*implicit*/ Box(const typename DimensionTraits<dimensions, Float>::MatrixType& transformation): _transformation(transformation) {}
/** @brief Transformed shape */
Box<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
Box<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief Transformation */
constexpr typename DimensionTraits<dimensions>::MatrixType transformation() const {
constexpr typename DimensionTraits<dimensions, Float>::MatrixType transformation() const {
return _transformation;
}
/** @brief Set transformation */
void setTransformation(const typename DimensionTraits<dimensions>::MatrixType& transformation) {
void setTransformation(const typename DimensionTraits<dimensions, Float>::MatrixType& transformation) {
_transformation = transformation;
}
private:
typename DimensionTraits<dimensions>::MatrixType _transformation;
typename DimensionTraits<dimensions, Float>::MatrixType _transformation;
};
/** @brief Two-dimensional box */

4
src/Shapes/Capsule.cpp

@ -36,9 +36,9 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Capsule<dimensions> Capsule<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> Capsule<dimensions> Capsule<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Capsule<dimensions>(matrix.transformPoint(_a), matrix.transformPoint(_b),
(matrix.rotationScaling()*typename DimensionTraits<dimensions>::VectorType(1/Constants::sqrt3())).length()*_radius);
(matrix.rotationScaling()*typename DimensionTraits<dimensions, Float>::VectorType(1/Constants::sqrt3())).length()*_radius);
}
template<UnsignedInt dimensions> bool Capsule<dimensions>::operator%(const Point<dimensions>& other) const {

14
src/Shapes/Capsule.h

@ -58,28 +58,28 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Capsule {
constexpr /*implicit*/ Capsule(): _radius(0.0f) {}
/** @brief Constructor */
constexpr /*implicit*/ Capsule(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b, Float radius): _a(a), _b(b), _radius(radius) {}
constexpr /*implicit*/ Capsule(const typename DimensionTraits<dimensions, Float>::VectorType& a, const typename DimensionTraits<dimensions, Float>::VectorType& b, Float radius): _a(a), _b(b), _radius(radius) {}
/** @brief Transformed shape */
Capsule<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
Capsule<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief Start point */
constexpr typename DimensionTraits<dimensions>::VectorType a() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType a() const {
return _a;
}
/** @brief Set start point */
void setA(const typename DimensionTraits<dimensions>::VectorType& a) {
void setA(const typename DimensionTraits<dimensions, Float>::VectorType& a) {
_a = a;
}
/** @brief End point */
constexpr typename DimensionTraits<dimensions>::VectorType b() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType b() const {
return _b;
}
/** @brief Set end point */
void setB(const typename DimensionTraits<dimensions>::VectorType& b) {
void setB(const typename DimensionTraits<dimensions, Float>::VectorType& b) {
_b = b;
}
@ -96,7 +96,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Capsule {
bool operator%(const Sphere<dimensions>& other) const;
private:
typename DimensionTraits<dimensions>::VectorType _a, _b;
typename DimensionTraits<dimensions, Float>::VectorType _a, _b;
Float _radius;
};

2
src/Shapes/Composition.cpp

@ -125,7 +125,7 @@ template<UnsignedInt dimensions> void Composition<dimensions>::copyNodes(std::si
std::copy(other._nodes, other._nodes+other._nodeCount, _nodes+offset);
}
template<UnsignedInt dimensions> Composition<dimensions> Composition<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> Composition<dimensions> Composition<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
Composition<dimensions> out(*this);
for(std::size_t i = 0; i != _shapeCount; ++i)
_shapes[i]->transform(matrix, out._shapes[i]);

2
src/Shapes/Composition.h

@ -125,7 +125,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Composition {
Composition<dimensions>& operator=(Composition<dimensions>&& other);
/** @brief Transformed shape */
Composition<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
Composition<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief Count of shapes in the hierarchy */
std::size_t size() const { return _shapeCount; }

2
src/Shapes/Line.cpp

@ -29,7 +29,7 @@
namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Line<dimensions> Line<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> Line<dimensions> Line<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Line<dimensions>(matrix.transformPoint(_a),
matrix.transformPoint(_b));
}

14
src/Shapes/Line.h

@ -55,33 +55,33 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Line {
constexpr /*implicit*/ Line() {}
/** @brief Constructor */
constexpr /*implicit*/ Line(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b): _a(a), _b(b) {}
constexpr /*implicit*/ Line(const typename DimensionTraits<dimensions, Float>::VectorType& a, const typename DimensionTraits<dimensions, Float>::VectorType& b): _a(a), _b(b) {}
/** @brief Transformed shape */
Line<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
Line<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief First point */
constexpr typename DimensionTraits<dimensions>::VectorType a() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType a() const {
return _a;
}
/** @brief Set first point */
void setA(const typename DimensionTraits<dimensions>::VectorType& a) {
void setA(const typename DimensionTraits<dimensions, Float>::VectorType& a) {
_a = a;
}
/** @brief Second point */
constexpr typename DimensionTraits<dimensions>::VectorType b() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType b() const {
return _b;
}
/** @brief Set second point */
void setB(const typename DimensionTraits<dimensions>::VectorType& b) {
void setB(const typename DimensionTraits<dimensions, Float>::VectorType& b) {
_b = b;
}
private:
typename DimensionTraits<dimensions>::VectorType _a, _b;
typename DimensionTraits<dimensions, Float>::VectorType _a, _b;
};
/** @brief Infinite two-dimensional line */

4
src/Shapes/LineSegment.h

@ -48,10 +48,10 @@ template<UnsignedInt dimensions> class LineSegment: public Line<dimensions> {
constexpr /*implicit*/ LineSegment() {}
/** @brief Constructor */
constexpr /*implicit*/ LineSegment(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b): Line<dimensions>(a, b) {}
constexpr /*implicit*/ LineSegment(const typename DimensionTraits<dimensions, Float>::VectorType& a, const typename DimensionTraits<dimensions, Float>::VectorType& b): Line<dimensions>(a, b) {}
/** @brief Transformed shape */
LineSegment<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
LineSegment<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Line<dimensions>::transformed(matrix);
}

2
src/Shapes/Point.cpp

@ -29,7 +29,7 @@
namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Point<dimensions> Point<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> Point<dimensions> Point<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Point<dimensions>(matrix.transformPoint(_position));
}

10
src/Shapes/Point.h

@ -54,23 +54,23 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Point {
constexpr /*implicit*/ Point() {}
/** @brief Constructor */
constexpr /*implicit*/ Point(const typename DimensionTraits<dimensions>::VectorType& position): _position(position) {}
constexpr /*implicit*/ Point(const typename DimensionTraits<dimensions, Float>::VectorType& position): _position(position) {}
/** @brief Transformed shape */
Point<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
Point<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief Position */
constexpr typename DimensionTraits<dimensions>::VectorType position() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType position() const {
return _position;
}
/** @brief Set position */
void setPosition(const typename DimensionTraits<dimensions>::VectorType& position) {
void setPosition(const typename DimensionTraits<dimensions, Float>::VectorType& position) {
_position = position;
}
private:
typename DimensionTraits<dimensions>::VectorType _position;
typename DimensionTraits<dimensions, Float>::VectorType _position;
};
/** @brief Two-dimensional point */

2
src/Shapes/Shape.cpp

@ -36,7 +36,7 @@ template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::set(
shape._transformedShape.shape = shape._shape.shape = std::move(composition);
}
template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix) {
template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions, Float>::MatrixType& absoluteTransformationMatrix) {
CORRADE_INTERNAL_ASSERT(shape._shape.shape.size() == shape._transformedShape.shape.size());
for(std::size_t i = 0; i != shape.shape().size(); ++i)
shape._shape.shape._shapes[i]->transform(absoluteTransformationMatrix, shape._transformedShape.shape._shapes[i]);

14
src/Shapes/Shape.h

@ -75,17 +75,17 @@ template<class T> class MAGNUM_SHAPES_EXPORT Shape: public AbstractShape<T::Dime
* @param shape Shape
* @param group Group this shape belongs to
*/
template<class ...U> explicit Shape(SceneGraph::AbstractBasicObject<T::Dimensions, Float>* object, const T& shape, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {
explicit Shape(SceneGraph::AbstractBasicObject<T::Dimensions, Float>* object, const T& shape, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {
Implementation::ShapeHelper<T>::set(*this, shape);
}
/** @overload */
template<class ...U> explicit Shape(SceneGraph::AbstractBasicObject<T::Dimensions, Float>* object, T&& shape, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {
explicit Shape(SceneGraph::AbstractBasicObject<T::Dimensions, Float>* object, T&& shape, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {
Implementation::ShapeHelper<T>::set(*this, std::move(shape));
}
/** @overload */
template<class ...U> explicit Shape(SceneGraph::AbstractBasicObject<T::Dimensions, Float>* object, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {}
explicit Shape(SceneGraph::AbstractBasicObject<T::Dimensions, Float>* object, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {}
/** @brief Shape */
const T& shape() const { return _shape.shape; }
@ -107,7 +107,7 @@ template<class T> class MAGNUM_SHAPES_EXPORT Shape: public AbstractShape<T::Dime
protected:
/** Applies transformation to associated shape. */
void clean(const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) override;
void clean(const typename DimensionTraits<T::Dimensions, Float>::MatrixType& absoluteTransformationMatrix) override;
private:
const Implementation::AbstractShape<T::Dimensions>* abstractTransformedShape() const override {
@ -128,7 +128,7 @@ template<class T> inline const T& Shape<T>::transformedShape() {
return _transformedShape.shape;
}
template<class T> void Shape<T>::clean(const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) {
template<class T> void Shape<T>::clean(const typename DimensionTraits<T::Dimensions, Float>::MatrixType& absoluteTransformationMatrix) {
Implementation::ShapeHelper<T>::transform(*this, absoluteTransformationMatrix);
}
@ -138,7 +138,7 @@ namespace Implementation {
shape._shape.shape = s;
}
static void transform(Shapes::Shape<T>& shape, const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) {
static void transform(Shapes::Shape<T>& shape, const typename DimensionTraits<T::Dimensions, Float>::MatrixType& absoluteTransformationMatrix) {
shape._transformedShape.shape = shape._shape.shape.transformed(absoluteTransformationMatrix);
}
};
@ -147,7 +147,7 @@ namespace Implementation {
static void set(Shapes::Shape<Composition<dimensions>>& shape, const Composition<dimensions>& composition);
static void set(Shapes::Shape<Composition<dimensions>>& shape, Composition<dimensions>&& composition);
static void transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix);
static void transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions, Float>::MatrixType& absoluteTransformationMatrix);
};
}

4
src/Shapes/Sphere.cpp

@ -37,7 +37,7 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Shapes {
namespace {
template<UnsignedInt dimensions> static typename DimensionTraits<dimensions>::VectorType unitVector();
template<UnsignedInt dimensions> static typename DimensionTraits<dimensions, Float>::VectorType unitVector();
template<> inline Vector2 unitVector<2>() {
return Vector2(1/Constants::sqrt2());
@ -48,7 +48,7 @@ namespace {
}
}
template<UnsignedInt dimensions> Sphere<dimensions> Sphere<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
template<UnsignedInt dimensions> Sphere<dimensions> Sphere<dimensions>::transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Sphere<dimensions>(matrix.transformPoint(_position),
(matrix.rotationScaling()*unitVector<dimensions>()).length()*_radius);
}

10
src/Shapes/Sphere.h

@ -58,18 +58,18 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Sphere {
constexpr /*implicit*/ Sphere(): _radius(0.0f) {}
/** @brief Constructor */
constexpr /*implicit*/ Sphere(const typename DimensionTraits<dimensions>::VectorType& position, Float radius): _position(position), _radius(radius) {}
constexpr /*implicit*/ Sphere(const typename DimensionTraits<dimensions, Float>::VectorType& position, Float radius): _position(position), _radius(radius) {}
/** @brief Transformed shape */
Sphere<dimensions> transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const;
Sphere<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const;
/** @brief Position */
constexpr typename DimensionTraits<dimensions>::VectorType position() const {
constexpr typename DimensionTraits<dimensions, Float>::VectorType position() const {
return _position;
}
/** @brief Set position */
void setPosition(const typename DimensionTraits<dimensions>::VectorType& position) {
void setPosition(const typename DimensionTraits<dimensions, Float>::VectorType& position) {
_position = position;
}
@ -92,7 +92,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Sphere {
bool operator%(const Sphere<dimensions>& other) const;
private:
typename DimensionTraits<dimensions>::VectorType _position;
typename DimensionTraits<dimensions, Float>::VectorType _position;
Float _radius;
};

4
src/Shapes/shapeImplementation.h

@ -126,7 +126,7 @@ template<UnsignedInt dimensions> struct MAGNUM_SHAPES_EXPORT AbstractShape {
virtual typename ShapeDimensionTraits<dimensions>::Type MAGNUM_SHAPES_LOCAL type() const = 0;
virtual AbstractShape<dimensions> MAGNUM_SHAPES_LOCAL * clone() const = 0;
virtual void MAGNUM_SHAPES_LOCAL transform(const typename DimensionTraits<dimensions>::MatrixType& matrix, AbstractShape<dimensions>* result) const = 0;
virtual void MAGNUM_SHAPES_LOCAL transform(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix, AbstractShape<dimensions>* result) const = 0;
};
template<class T> struct Shape: AbstractShape<T::Dimensions> {
@ -144,7 +144,7 @@ template<class T> struct Shape: AbstractShape<T::Dimensions> {
return new Shape<T>(shape);
}
void transform(const typename DimensionTraits<T::Dimensions>::MatrixType& matrix, AbstractShape<T::Dimensions>* result) const override {
void transform(const typename DimensionTraits<T::Dimensions, Float>::MatrixType& matrix, AbstractShape<T::Dimensions>* result) const override {
CORRADE_INTERNAL_ASSERT(result->type() == type());
static_cast<Shape<T>*>(result)->shape = shape.transformed(matrix);
}

12
src/Trade/AbstractImageConverter.cpp

@ -34,18 +34,18 @@ AbstractImageConverter::AbstractImageConverter() = default;
AbstractImageConverter::AbstractImageConverter(PluginManager::AbstractManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {}
Image2D* AbstractImageConverter::exportToImage(const Image2D* const image) const {
Image2D* AbstractImageConverter::exportToImage(const ImageReference2D& image) const {
CORRADE_ASSERT(features() & Feature::ConvertImage,
"Trade::AbstractImageConverter::exportToImage(): feature not supported", nullptr);
return doExportToImage(image);
}
Image2D* AbstractImageConverter::doExportToImage(const Image2D*) const {
Image2D* AbstractImageConverter::doExportToImage(const ImageReference2D&) const {
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToImage(): feature advertised but not implemented", nullptr);
}
Containers::Array<unsigned char> AbstractImageConverter::exportToData(const Image2D* const image) const {
Containers::Array<unsigned char> AbstractImageConverter::exportToData(const ImageReference2D& image) const {
#ifndef CORRADE_GCC45_COMPATIBILITY
CORRADE_ASSERT(features() & Feature::ConvertData,
"Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr);
@ -57,7 +57,7 @@ Containers::Array<unsigned char> AbstractImageConverter::exportToData(const Imag
return doExportToData(image);
}
Containers::Array<unsigned char> AbstractImageConverter::doExportToData(const Image2D*) const {
Containers::Array<unsigned char> AbstractImageConverter::doExportToData(const ImageReference2D&) const {
#ifndef CORRADE_GCC45_COMPATIBILITY
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented", nullptr);
#else
@ -65,11 +65,11 @@ Containers::Array<unsigned char> AbstractImageConverter::doExportToData(const Im
#endif
}
bool AbstractImageConverter::exportToFile(const Image2D* const image, const std::string& filename) const {
bool AbstractImageConverter::exportToFile(const ImageReference2D& image, const std::string& filename) const {
return doExportToFile(image, filename);
}
bool AbstractImageConverter::doExportToFile(const Image2D* const image, const std::string& filename) const {
bool AbstractImageConverter::doExportToFile(const ImageReference2D& image, const std::string& filename) const {
CORRADE_ASSERT(features() & Feature::ConvertData, "Trade::AbstractImageConverter::exportToFile(): not implemented", false);
auto data = doExportToData(image);

14
src/Trade/AbstractImageConverter.h

@ -56,7 +56,7 @@ checked by the implementation:
is supported.
*/
class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin {
CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.2")
CORRADE_PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1")
public:
/**
@ -95,7 +95,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* Returns converted image on success, `nullptr` otherwise.
* @see features(), exportToData(), exportToFile()
*/
Image2D* exportToImage(const Image2D* image) const;
Image2D* exportToImage(const ImageReference2D& image) const;
/**
* @brief Export image to raw data
@ -104,7 +104,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* Returns data on success, zero-sized array otherwise.
* @see features(), exportToImage(), exportToFile()
*/
Containers::Array<unsigned char> exportToData(const Image2D* image) const;
Containers::Array<unsigned char> exportToData(const ImageReference2D& image) const;
/**
* @brief Export image to file
@ -112,7 +112,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* Returns `true` on success, `false` otherwise.
* @see features(), exportToImage(), exportToData()
*/
bool exportToFile(const Image2D* image, const std::string& filename) const;
bool exportToFile(const ImageReference2D& image, const std::string& filename) const;
#ifndef DOXYGEN_GENERATING_OUTPUT
private:
@ -123,10 +123,10 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
virtual Features doFeatures() const = 0;
/** @brief Implementation of exportToImage() */
virtual Image2D* doExportToImage(const Image2D* image) const;
virtual Image2D* doExportToImage(const ImageReference2D& image) const;
/** @brief Implementation of exportToData() */
virtual Containers::Array<unsigned char> doExportToData(const Image2D* image) const;
virtual Containers::Array<unsigned char> doExportToData(const ImageReference2D& image) const;
/**
* @brief Implementation of exportToFile()
@ -135,7 +135,7 @@ class MAGNUM_EXPORT AbstractImageConverter: public PluginManager::AbstractPlugin
* implementation calls doExportToData() and saves the result to given
* file.
*/
virtual bool doExportToFile(const Image2D* image, const std::string& filename) const;
virtual bool doExportToFile(const ImageReference2D& image, const std::string& filename) const;
};
CORRADE_ENUMSET_OPERATORS(AbstractImageConverter::Features)

46
src/Trade/MeshData2D.cpp

@ -28,24 +28,44 @@
namespace Magnum { namespace Trade {
MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector<UnsignedInt>* indices, std::vector<std::vector<Vector2>*> positions, std::vector<std::vector<Vector2>*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _textureCoords2D(std::move(textureCoords2D)) {}
MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector<UnsignedInt> indices, std::vector<std::vector<Vector2>> positions, std::vector<std::vector<Vector2>> textureCoords2D): _primitive(primitive), _indices(std::move(indices)), _positions(std::move(positions)), _textureCoords2D(std::move(textureCoords2D)) {
CORRADE_ASSERT(!_positions.empty(), "Trade::MeshData2D: no position array specified", );
}
MeshData2D::MeshData2D(MeshData2D&&) = default;
MeshData2D::~MeshData2D() = default;
MeshData2D& MeshData2D::operator=(MeshData2D&&) = default;
std::vector<UnsignedInt>& MeshData2D::indices() {
CORRADE_ASSERT(isIndexed(), "Trade::MeshData2D::indices(): the mesh is not indexed", _indices);
return _indices;
}
const std::vector<UnsignedInt>& MeshData2D::indices() const {
CORRADE_ASSERT(isIndexed(), "Trade::MeshData2D::indices(): the mesh is not indexed", _indices);
return _indices;
}
std::vector<Vector2>& MeshData2D::positions(const UnsignedInt id) {
CORRADE_ASSERT(id < positionArrayCount(), "Trade::MeshData2D::positions(): index out of range", _positions[id]);
return _positions[id];
}
MeshData2D::MeshData2D(MeshData2D&& other): _primitive(other._primitive), _indices(other._indices), _positions(std::move(other._positions)), _textureCoords2D(std::move(other._textureCoords2D)) {
other._indices = nullptr;
const std::vector<Vector2>& MeshData2D::positions(const UnsignedInt id) const {
CORRADE_ASSERT(id < positionArrayCount(), "Trade::MeshData2D::positions(): index out of range", _positions[id]);
return _positions[id];
}
MeshData2D& MeshData2D::operator=(MeshData2D&& other) {
_primitive = other._primitive;
std::swap(_indices, other._indices);
std::swap(_positions, other._positions);
std::swap(_textureCoords2D, other._textureCoords2D);
return *this;
std::vector<Vector2>& MeshData2D::textureCoords2D(const UnsignedInt id) {
CORRADE_ASSERT(id < textureCoords2DArrayCount(), "Trade::MeshData2D::textureCoords2D(): index out of range", _textureCoords2D[id]);
return _textureCoords2D[id];
}
MeshData2D::~MeshData2D() {
delete _indices;
for(auto it = _positions.begin(); it != _positions.end(); ++it) delete *it;
for(auto it = _textureCoords2D.begin(); it != _textureCoords2D.end(); ++it) delete *it;
const std::vector<Vector2>& MeshData2D::textureCoords2D(const UnsignedInt id) const {
CORRADE_ASSERT(id < textureCoords2DArrayCount(), "Trade::MeshData2D::textureCoords2D(): index out of range", _textureCoords2D[id]);
return _textureCoords2D[id];
}
}}

66
src/Trade/MeshData2D.h

@ -42,70 +42,76 @@ type.
@see MeshData3D
*/
class MAGNUM_EXPORT MeshData2D {
MeshData2D(const MeshData2D&) = delete;
MeshData2D& operator=(const MeshData2D&) = delete;
public:
/**
* @brief Constructor
* @param primitive Primitive
* @param indices Array with indices or 0, if this is not
* indexed mesh
* @param positions Array with vertex positions. At least one
* position array should be present.
* @param textureCoords2D Array with two-dimensional texture
* coordinate arrays or empty array
* @param indices Index array or empty array, if the mesh is
* not indexed
* @param positions Position arrays. At least one position
* array should be present.
* @param textureCoords2D Two-dimensional texture coordinate arrays,
* if present
*/
explicit 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 Copying is not allowed */
MeshData2D(const MeshData2D&) = delete;
/** @brief Move constructor */
MeshData2D(MeshData2D&&);
MeshData2D(MeshData2D&& other);
/** @brief Destructor */
~MeshData2D();
/** @brief Copying is not allowed */
MeshData2D& operator=(const MeshData2D&) = delete;
/** @brief Move assignment */
MeshData2D& operator=(MeshData2D&&);
MeshData2D& operator=(MeshData2D&& other);
/** @brief Primitive */
Mesh::Primitive primitive() const { return _primitive; }
/** @brief Whether the mesh is indexed */
bool isIndexed() const { return !_indices.empty(); }
/**
* @brief Indices
* @return Indices or nullptr if the mesh is not indexed.
*
* @see isIndexed()
*/
std::vector<UnsignedInt>* indices() { return _indices; }
const std::vector<UnsignedInt>* indices() const { return _indices; } /**< @overload */
std::vector<UnsignedInt>& indices();
const std::vector<UnsignedInt>& indices() const; /**< @overload */
/** @brief Count of vertex position arrays */
/** @brief Count of position arrays */
UnsignedInt positionArrayCount() const { return _positions.size(); }
/**
* @brief Positions
* @param id ID of position data array
* @return Positions or nullptr if there is no vertex array with given
* ID.
* @param id Position array ID
*
* @see positionArrayCount()
*/
std::vector<Vector2>* positions(UnsignedInt id) { return _positions[id]; }
const std::vector<Vector2>* positions(UnsignedInt id) const { return _positions[id]; } /**< @overload */
std::vector<Vector2>& positions(UnsignedInt id);
const std::vector<Vector2>& positions(UnsignedInt id) const; /**< @overload */
/** @brief Count of 2D texture coordinate arrays */
UnsignedInt textureCoords2DArrayCount() const { return _textureCoords2D.size(); }
/**
* @brief 2D texture coordinates
* @param id ID of texture coordinates array
* @return %Texture coordinates or nullptr if there is no texture
* coordinates array with given ID.
* @param id Texture coordinate array ID
*
* @see textureCoords2DArrayCount()
*/
std::vector<Vector2>* textureCoords2D(UnsignedInt id) { return _textureCoords2D[id]; }
const std::vector<Vector2>* textureCoords2D(UnsignedInt id) const { return _textureCoords2D[id]; } /**< @overload */
std::vector<Vector2>& textureCoords2D(UnsignedInt id);
const std::vector<Vector2>& textureCoords2D(UnsignedInt id) const; /**< @overload */
private:
Mesh::Primitive _primitive;
std::vector<UnsignedInt>* _indices;
std::vector<std::vector<Vector2>*> _positions;
std::vector<std::vector<Vector2>*> _textureCoords2D;
std::vector<UnsignedInt> _indices;
std::vector<std::vector<Vector2>> _positions;
std::vector<std::vector<Vector2>> _textureCoords2D;
};
}}

58
src/Trade/MeshData3D.cpp

@ -28,26 +28,54 @@
namespace Magnum { namespace Trade {
MeshData3D::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): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _normals(std::move(normals)), _textureCoords2D(std::move(textureCoords2D)) {}
MeshData3D::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): _primitive(primitive), _indices(std::move(indices)), _positions(std::move(positions)), _normals(std::move(normals)), _textureCoords2D(std::move(textureCoords2D)) {
CORRADE_ASSERT(!_positions.empty(), "Trade::MeshData3D: no position array specified", );
}
MeshData3D::MeshData3D(MeshData3D&&) = default;
MeshData3D::~MeshData3D() = default;
MeshData3D& MeshData3D::operator=(MeshData3D&&) = default;
std::vector<UnsignedInt>& MeshData3D::indices() {
CORRADE_ASSERT(isIndexed(), "Trade::MeshData3D::indices(): the mesh is not indexed", _indices);
return _indices;
}
const std::vector<UnsignedInt>& MeshData3D::indices() const {
CORRADE_ASSERT(isIndexed(), "Trade::MeshData3D::indices(): the mesh is not indexed", _indices);
return _indices;
}
std::vector<Vector3>& MeshData3D::positions(const UnsignedInt id) {
CORRADE_ASSERT(id < positionArrayCount(), "Trade::MeshData3D::positions(): index out of range", _positions[id]);
return _positions[id];
}
const std::vector<Vector3>& MeshData3D::positions(const UnsignedInt id) const {
CORRADE_ASSERT(id < positionArrayCount(), "Trade::MeshData3D::positions(): index out of range", _positions[id]);
return _positions[id];
}
std::vector<Vector3>& MeshData3D::normals(const UnsignedInt id) {
CORRADE_ASSERT(id < normalArrayCount(), "Trade::MeshData3D::normals(): index out of range", _normals[id]);
return _normals[id];
}
MeshData3D::MeshData3D(MeshData3D&& other): _primitive(other._primitive), _indices(other._indices), _positions(std::move(other._positions)), _normals(std::move(other._normals)), _textureCoords2D(std::move(other._textureCoords2D)) {
other._indices = nullptr;
const std::vector<Vector3>& MeshData3D::normals(const UnsignedInt id) const {
CORRADE_ASSERT(id < normalArrayCount(), "Trade::MeshData3D::normals(): index out of range", _normals[id]);
return _normals[id];
}
MeshData3D& MeshData3D::operator=(MeshData3D&& other) {
_primitive = other._primitive;
std::swap(_indices, other._indices);
std::swap(_positions, other._positions);
std::swap(_normals, other._normals);
std::swap(_textureCoords2D, other._textureCoords2D);
return *this;
std::vector<Vector2>& MeshData3D::textureCoords2D(const UnsignedInt id) {
CORRADE_ASSERT(id < textureCoords2DArrayCount(), "Trade::MeshData3D::textureCoords2D(): index out of range", _textureCoords2D[id]);
return _textureCoords2D[id];
}
MeshData3D::~MeshData3D() {
delete _indices;
for(auto it = _positions.begin(); it != _positions.end(); ++it) delete *it;
for(auto it = _normals.begin(); it != _normals.end(); ++it) delete *it;
for(auto it = _textureCoords2D.begin(); it != _textureCoords2D.end(); ++it) delete *it;
const std::vector<Vector2>& MeshData3D::textureCoords2D(const UnsignedInt id) const {
CORRADE_ASSERT(id < textureCoords2DArrayCount(), "Trade::MeshData3D::textureCoords2D(): index out of range", _textureCoords2D[id]);
return _textureCoords2D[id];
}
}}

76
src/Trade/MeshData3D.h

@ -42,84 +42,90 @@ type.
@see MeshData2D
*/
class MAGNUM_EXPORT MeshData3D {
MeshData3D(const MeshData3D&) = delete;
MeshData3D& operator=(const MeshData3D&) = delete;
public:
/**
* @brief Constructor
* @param primitive Primitive
* @param indices Array with indices or 0, if this is not
* indexed mesh
* @param positions Array with vertex positions. At least one
* position array should be present.
* @param normals Array with normal arrays or empty array
* @param textureCoords2D Array with two-dimensional texture
* coordinate arrays or empty array
* @param indices Index array or empty array, if the mesh is
* not indexed
* @param positions Position arrays. At least one position
* array should be present.
* @param normals Normal arrays, if present
* @param textureCoords2D Two-dimensional texture coordinate arrays,
* if present
*/
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);
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 Copying is not allowed */
MeshData3D(const MeshData3D&) = delete;
/** @brief Move constructor */
MeshData3D(MeshData3D&&);
/** @brief Destructor */
~MeshData3D();
/** @brief Copying is not allowed */
MeshData3D& operator=(const MeshData3D&) = delete;
/** @brief Move assignment */
MeshData3D& operator=(MeshData3D&&);
/** @brief Primitive */
Mesh::Primitive primitive() const { return _primitive; }
/** @brief Whether the mesh is indexed */
bool isIndexed() const { return !_indices.empty(); }
/**
* @brief Indices
* @return Indices or nullptr if the mesh is not indexed.
*
* @see isIndexed()
*/
std::vector<UnsignedInt>* indices() { return _indices; }
const std::vector<UnsignedInt>* indices() const { return _indices; } /**< @overload */
std::vector<UnsignedInt>& indices();
const std::vector<UnsignedInt>& indices() const; /**< @overload */
/** @brief Count of vertex position arrays */
/** @brief Count of position arrays */
UnsignedInt positionArrayCount() const { return _positions.size(); }
/**
* @brief Positions
* @param id ID of position data array
* @return Positions or nullptr if there is no vertex array with given
* ID.
* @param id Position array ID
*
* @see positionArrayCount()
*/
std::vector<Vector3>* positions(UnsignedInt id) { return _positions[id]; }
const std::vector<Vector3>* positions(UnsignedInt id) const { return _positions[id]; } /**< @overload */
std::vector<Vector3>& positions(UnsignedInt id);
const std::vector<Vector3>& positions(UnsignedInt id) const; /**< @overload */
/** @brief Count of normal arrays */
UnsignedInt normalArrayCount() const { return _normals.size(); }
/**
* @brief Normals
* @param id ID of normal data array
* @return Normals or nullptr if there is no normal array with given
* ID.
* @param id Normal array ID
*
* @see normalArrayCount()
*/
std::vector<Vector3>* normals(UnsignedInt id) { return _normals[id]; }
const std::vector<Vector3>* normals(UnsignedInt id) const { return _normals[id]; } /**< @overload */
std::vector<Vector3>& normals(UnsignedInt id);
const std::vector<Vector3>& normals(UnsignedInt id) const; /**< @overload */
/** @brief Count of 2D texture coordinate arrays */
UnsignedInt textureCoords2DArrayCount() const { return _textureCoords2D.size(); }
/**
* @brief 2D texture coordinates
* @param id ID of texture coordinates array
* @return %Texture coordinates or nullptr if there is no texture
* coordinates array with given ID.
* @param id Texture coordinate array ID
*
* @see textureCoords2DArrayCount()
*/
std::vector<Vector2>* textureCoords2D(UnsignedInt id) { return _textureCoords2D[id]; }
const std::vector<Vector2>* textureCoords2D(UnsignedInt id) const { return _textureCoords2D[id]; } /**< @overload */
std::vector<Vector2>& textureCoords2D(UnsignedInt id);
const std::vector<Vector2>& textureCoords2D(UnsignedInt id) const; /**< @overload */
private:
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;
std::vector<UnsignedInt> _indices;
std::vector<std::vector<Vector3>> _positions;
std::vector<std::vector<Vector3>> _normals;
std::vector<std::vector<Vector2>> _textureCoords2D;
};
}}

12
src/Trade/Test/AbstractImageConverterTest.cpp

@ -27,8 +27,8 @@
#include <TestSuite/Compare/FileToString.h>
#include <Utility/Directory.h>
#include "Image.h"
#include "ImageFormat.h"
#include "ImageReference.h"
#include "Trade/AbstractImageConverter.h"
#include "testConfigure.h"
@ -51,10 +51,10 @@ void AbstractImageConverterTest::exportToFile() {
private:
Features doFeatures() const override { return Feature::ConvertData; }
Containers::Array<unsigned char> doExportToData(const Image2D* image) const override {
Containers::Array<unsigned char> doExportToData(const ImageReference2D& image) const override {
Containers::Array<unsigned char> out(2);
out[0] = image->size().x();
out[1] = image->size().y();
out[0] = image.size().x();
out[1] = image.size().y();
return out;
};
};
@ -64,8 +64,8 @@ void AbstractImageConverterTest::exportToFile() {
/* doExportToFile() should call doExportToData() */
DataExporter exporter;
Image2D image(ImageFormat::RGBA, ImageType::UnsignedByte, {0xfe, 0xed}, nullptr);
CORRADE_VERIFY(exporter.exportToFile(&image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")));
ImageReference2D image(ImageFormat::RGBA, ImageType::UnsignedByte, {0xfe, 0xed}, nullptr);
CORRADE_VERIFY(exporter.exportToFile(image, Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out")));
CORRADE_COMPARE_AS(Utility::Directory::join(TRADE_TEST_OUTPUT_DIR, "image.out"),
"\xFE\xED", TestSuite::Compare::FileToString);
}

Loading…
Cancel
Save