From 0f2a1661d9e6d8c2c189275ecf3a6744bbd7f784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Jul 2013 11:35:46 +0200 Subject: [PATCH 1/6] SceneGraph: use protected destructor rather than pure virtual one. The Transformation classes are always instantiated by inheritance, thus we don't need any virtual deletion capabilities. --- src/SceneGraph/AbstractTransformation.h | 4 +++- src/SceneGraph/AbstractTranslationRotation2D.h | 3 +++ src/SceneGraph/AbstractTranslationRotation3D.h | 3 +++ src/SceneGraph/AbstractTranslationRotationScaling2D.h | 3 +++ src/SceneGraph/AbstractTranslationRotationScaling3D.h | 3 +++ src/SceneGraph/Object.hpp | 1 - 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index 95dfbbeff..f429a021e 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -62,7 +62,6 @@ template class MAGNUM_SCENEGRAPH_EXPORT Abstrac static const UnsignedInt Dimensions = dimensions; explicit AbstractBasicTransformation(); - virtual ~AbstractBasicTransformation() = 0; #ifdef DOXYGEN_GENERATING_OUTPUT /** @@ -143,6 +142,9 @@ template class MAGNUM_SCENEGRAPH_EXPORT Abstrac return this; } + protected: + ~AbstractBasicTransformation() = default; + #ifdef DOXYGEN_GENERATING_OUTPUT protected: #else diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index 995cb6c60..661400784 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -73,6 +73,9 @@ template class AbstractBasicTranslationRotation2D: public AbstractBasic } #endif + protected: + ~AbstractBasicTranslationRotation2D() = default; + #ifdef DOXYGEN_GENERATING_OUTPUT protected: #else diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index d26e34cbc..604e3cc66 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -120,6 +120,9 @@ template class AbstractBasicTranslationRotation3D: public AbstractBasic } #endif + protected: + ~AbstractBasicTranslationRotation3D() = default; + #ifdef DOXYGEN_GENERATING_OUTPUT protected: #else diff --git a/src/SceneGraph/AbstractTranslationRotationScaling2D.h b/src/SceneGraph/AbstractTranslationRotationScaling2D.h index 5be4b55ec..407ffc365 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling2D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling2D.h @@ -70,6 +70,9 @@ template class AbstractBasicTranslationRotationScaling2D: public Abstra } #endif + protected: + ~AbstractBasicTranslationRotationScaling2D() = default; + #ifdef DOXYGEN_GENERATING_OUTPUT protected: #else diff --git a/src/SceneGraph/AbstractTranslationRotationScaling3D.h b/src/SceneGraph/AbstractTranslationRotationScaling3D.h index c9164190f..63719fa38 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling3D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling3D.h @@ -82,6 +82,9 @@ template class AbstractBasicTranslationRotationScaling3D: public Abstra } #endif + protected: + ~AbstractBasicTranslationRotationScaling3D() = default; + #ifdef DOXYGEN_GENERATING_OUTPUT protected: #else diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index fc30805bc..1dd120ce5 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -42,7 +42,6 @@ template AbstractBasicObject::Ab template AbstractBasicObject::~AbstractBasicObject() {} template AbstractBasicTransformation::AbstractBasicTransformation() {} -template AbstractBasicTransformation::~AbstractBasicTransformation() {} template Object::~Object() = default; From 4197e1688aba0e125ecab1c33844c6d8949c1e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Jul 2013 11:41:02 +0200 Subject: [PATCH 2/6] Shapes: WHY there is that. --- src/Shapes/Shape.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Shapes/Shape.h b/src/Shapes/Shape.h index c2073baff..c42e91099 100644 --- a/src/Shapes/Shape.h +++ b/src/Shapes/Shape.h @@ -75,17 +75,17 @@ template class MAGNUM_SHAPES_EXPORT Shape: public AbstractShape explicit Shape(SceneGraph::AbstractBasicObject* object, const T& shape, ShapeGroup* group = nullptr): AbstractShape(object, group) { + explicit Shape(SceneGraph::AbstractBasicObject* object, const T& shape, ShapeGroup* group = nullptr): AbstractShape(object, group) { Implementation::ShapeHelper::set(*this, shape); } /** @overload */ - template explicit Shape(SceneGraph::AbstractBasicObject* object, T&& shape, ShapeGroup* group = nullptr): AbstractShape(object, group) { + explicit Shape(SceneGraph::AbstractBasicObject* object, T&& shape, ShapeGroup* group = nullptr): AbstractShape(object, group) { Implementation::ShapeHelper::set(*this, std::move(shape)); } /** @overload */ - template explicit Shape(SceneGraph::AbstractBasicObject* object, ShapeGroup* group = nullptr): AbstractShape(object, group) {} + explicit Shape(SceneGraph::AbstractBasicObject* object, ShapeGroup* group = nullptr): AbstractShape(object, group) {} /** @brief Shape */ const T& shape() const { return _shape.shape; } From 2eb4e3c8ba98630b54e98090a08d8ba69253c351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Jul 2013 14:45:56 +0200 Subject: [PATCH 3/6] Removed default template argument from DimensionTraits. It's not obvious what should be the default and thus it is confusing. Sometimes Int, sometimes Float, no clear winner. --- src/DebugTools/ForceRenderer.cpp | 4 ++-- .../Implementation/AbstractShapeRenderer.h | 2 +- .../Implementation/AxisAlignedBoxRenderer.cpp | 6 +++--- .../Implementation/AxisAlignedBoxRenderer.h | 2 +- src/DebugTools/Implementation/BoxRenderer.cpp | 2 +- src/DebugTools/Implementation/BoxRenderer.h | 2 +- .../Implementation/ForceRendererTransformation.h | 2 +- .../Implementation/LineSegmentRenderer.cpp | 2 +- .../Implementation/LineSegmentRenderer.h | 2 +- .../LineSegmentRendererTransformation.h | 4 ++-- src/DebugTools/Implementation/PointRenderer.cpp | 6 +++--- src/DebugTools/Implementation/PointRenderer.h | 2 +- src/DebugTools/Implementation/SphereRenderer.cpp | 6 +++--- src/DebugTools/Implementation/SphereRenderer.h | 2 +- src/DebugTools/ObjectRenderer.cpp | 4 ++-- src/DebugTools/ShapeRenderer.cpp | 4 ++-- src/DimensionTraits.h | 4 ++-- src/Shaders/AbstractVector.h | 2 +- src/Shaders/DistanceFieldVector.h | 2 +- src/Shaders/Flat.h | 4 ++-- src/Shaders/Vector.h | 2 +- src/Shaders/VertexColor.h | 4 ++-- src/Shapes/AxisAlignedBox.cpp | 2 +- src/Shapes/AxisAlignedBox.h | 14 +++++++------- src/Shapes/Box.cpp | 2 +- src/Shapes/Box.h | 12 ++++++------ src/Shapes/Capsule.cpp | 4 ++-- src/Shapes/Capsule.h | 14 +++++++------- src/Shapes/Composition.cpp | 2 +- src/Shapes/Composition.h | 2 +- src/Shapes/Line.cpp | 2 +- src/Shapes/Line.h | 14 +++++++------- src/Shapes/LineSegment.h | 4 ++-- src/Shapes/Point.cpp | 2 +- src/Shapes/Point.h | 10 +++++----- src/Shapes/Shape.cpp | 2 +- src/Shapes/Shape.h | 8 ++++---- src/Shapes/Sphere.cpp | 4 ++-- src/Shapes/Sphere.h | 10 +++++----- src/Shapes/shapeImplementation.h | 4 ++-- 40 files changed, 91 insertions(+), 91 deletions(-) diff --git a/src/DebugTools/ForceRenderer.cpp b/src/DebugTools/ForceRenderer.cpp index 800b0747b..5ee1f2179 100644 --- a/src/DebugTools/ForceRenderer.cpp +++ b/src/DebugTools/ForceRenderer.cpp @@ -94,8 +94,8 @@ template ForceRenderer::ForceRenderer(SceneG ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } -template void ForceRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera* camera) { - shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation(transformationMatrix.transformPoint(forcePosition), *force)*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->scale()))) +template void ForceRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera* camera) { + shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation(transformationMatrix.transformPoint(forcePosition), *force)*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->scale()))) ->setColor(options->color()) ->use(); mesh->draw(); diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index bbc96185b..837724f70 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -49,7 +49,7 @@ template class AbstractShapeRenderer { AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer); virtual ~AbstractShapeRenderer(); - virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) = 0; + virtual void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) = 0; protected: /* Call only if the mesh resource isn't already present */ diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index faaf5cb5c..60bd5a346 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -33,10 +33,10 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape* axisAlignedBox): axisAlignedBox(static_cast>*>(axisAlignedBox)->shape) {} -template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - DimensionTraits::MatrixType::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)* - DimensionTraits::MatrixType::scaling(axisAlignedBox.max()-axisAlignedBox.min())) + DimensionTraits::MatrixType::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)* + DimensionTraits::MatrixType::scaling(axisAlignedBox.max()-axisAlignedBox.min())) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index 2af4617cd..b50cb5777 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -36,7 +36,7 @@ template class AxisAlignedBoxRenderer: public AbstractBo public: AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape* axisAlignedBox); - void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: const Shapes::AxisAlignedBox& axisAlignedBox; diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index 87b64ae26..c1e443315 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -33,7 +33,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template BoxRenderer::BoxRenderer(const Shapes::Implementation::AbstractShape* box): box(static_cast>*>(box)->shape) {} -template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation()) ->setColor(options->color()) ->use(); diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index 20afc7ee9..c027ae6d8 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -36,7 +36,7 @@ template class BoxRenderer: public AbstractBoxRenderer* box); - void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: const Shapes::Box& box; diff --git a/src/DebugTools/Implementation/ForceRendererTransformation.h b/src/DebugTools/Implementation/ForceRendererTransformation.h index 13cf870e7..83879104c 100644 --- a/src/DebugTools/Implementation/ForceRendererTransformation.h +++ b/src/DebugTools/Implementation/ForceRendererTransformation.h @@ -31,7 +31,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template typename DimensionTraits::MatrixType forceRendererTransformation(const typename DimensionTraits::VectorType& forcePosition, const typename DimensionTraits::VectorType& force); +template typename DimensionTraits::MatrixType forceRendererTransformation(const typename DimensionTraits::VectorType& forcePosition, const typename DimensionTraits::VectorType& force); template<> inline Matrix3 forceRendererTransformation<2>(const Vector2& forcePosition, const Vector2& force) { return Matrix3::from({force, Vector2(-force.y(), force.x())}, forcePosition); diff --git a/src/DebugTools/Implementation/LineSegmentRenderer.cpp b/src/DebugTools/Implementation/LineSegmentRenderer.cpp index 4436c3064..b5527d016 100644 --- a/src/DebugTools/Implementation/LineSegmentRenderer.cpp +++ b/src/DebugTools/Implementation/LineSegmentRenderer.cpp @@ -54,7 +54,7 @@ template LineSegmentRenderer::LineSegmentRen if(!this->wireframeMesh) this->createResources(meshData()); } -template void LineSegmentRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void LineSegmentRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* Implementation::lineSegmentRendererTransformation(line.a(), line.b())) ->setColor(options->color()) diff --git a/src/DebugTools/Implementation/LineSegmentRenderer.h b/src/DebugTools/Implementation/LineSegmentRenderer.h index 550557dc9..946870cc2 100644 --- a/src/DebugTools/Implementation/LineSegmentRenderer.h +++ b/src/DebugTools/Implementation/LineSegmentRenderer.h @@ -36,7 +36,7 @@ template class LineSegmentRenderer: public AbstractShape public: LineSegmentRenderer(const Shapes::Implementation::AbstractShape* line); - void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: const Shapes::LineSegment& line; diff --git a/src/DebugTools/Implementation/LineSegmentRendererTransformation.h b/src/DebugTools/Implementation/LineSegmentRendererTransformation.h index fc94a1bfe..4d0927cd6 100644 --- a/src/DebugTools/Implementation/LineSegmentRendererTransformation.h +++ b/src/DebugTools/Implementation/LineSegmentRendererTransformation.h @@ -28,8 +28,8 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template typename DimensionTraits::MatrixType lineSegmentRendererTransformation(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b) { - auto transformation = DimensionTraits::MatrixType::translation(a); +template typename DimensionTraits::MatrixType lineSegmentRendererTransformation(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b) { + auto transformation = DimensionTraits::MatrixType::translation(a); transformation.right() = b - a; return transformation; } diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp index 7827ca856..6e7ab84e7 100644 --- a/src/DebugTools/Implementation/PointRenderer.cpp +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -52,11 +52,11 @@ template PointRenderer::PointRenderer(const if(!this->wireframeMesh) this->createResources(meshData()); } -template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the point is 2x2(x2) */ this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - DimensionTraits::MatrixType::translation(point.position())* - DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->pointSize()/2))) + DimensionTraits::MatrixType::translation(point.position())* + DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->pointSize()/2))) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/PointRenderer.h b/src/DebugTools/Implementation/PointRenderer.h index a017c1649..2b194e663 100644 --- a/src/DebugTools/Implementation/PointRenderer.h +++ b/src/DebugTools/Implementation/PointRenderer.h @@ -36,7 +36,7 @@ template class PointRenderer: public AbstractShapeRender public: PointRenderer(const Shapes::Implementation::AbstractShape* point); - void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: const Shapes::Point& point; diff --git a/src/DebugTools/Implementation/SphereRenderer.cpp b/src/DebugTools/Implementation/SphereRenderer.cpp index 3649d05b0..6452e9e8e 100644 --- a/src/DebugTools/Implementation/SphereRenderer.cpp +++ b/src/DebugTools/Implementation/SphereRenderer.cpp @@ -39,10 +39,10 @@ AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("s template SphereRenderer::SphereRenderer(const Shapes::Implementation::AbstractShape* sphere): sphere(static_cast>*>(sphere)->shape) {} -template void SphereRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { +template void SphereRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - DimensionTraits::MatrixType::translation(sphere.position())* - DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(sphere.radius()))) + DimensionTraits::MatrixType::translation(sphere.position())* + DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(sphere.radius()))) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/SphereRenderer.h b/src/DebugTools/Implementation/SphereRenderer.h index 3c1a89649..15d12048c 100644 --- a/src/DebugTools/Implementation/SphereRenderer.h +++ b/src/DebugTools/Implementation/SphereRenderer.h @@ -43,7 +43,7 @@ template class SphereRenderer: public AbstractSphereRend public: SphereRenderer(const Shapes::Implementation::AbstractShape* sphere); - void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: const Shapes::Sphere& sphere; diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 96461e6a9..94194bc4c 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -173,8 +173,8 @@ template ObjectRenderer::ObjectRenderer(Scen ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } -template void ObjectRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera* camera) { - shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->size()))) +template void ObjectRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera* camera) { + shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->size()))) ->use(); mesh->draw(); diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index a15ae1d3c..d1843d0d1 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -102,8 +102,8 @@ template ShapeRenderer::~ShapeRenderer() { for(auto i: renderers) delete i; } -template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType&, SceneGraph::AbstractBasicCamera* camera) { - typename DimensionTraits::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix(); +template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType&, SceneGraph::AbstractBasicCamera* camera) { + typename DimensionTraits::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix(); for(auto i: renderers) i->draw(options, projectionMatrix); } diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index d729aca74..6ca6df1ad 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -33,8 +33,8 @@ namespace Magnum { -/** @brief Matrix, point and vector specializations for given dimension count */ -template struct DimensionTraits { +/** @brief Matrix and vector specializations for given dimension count */ +template struct DimensionTraits { DimensionTraits() = delete; #ifdef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Shaders/AbstractVector.h b/src/Shaders/AbstractVector.h index 1337e7ae0..2d23586e4 100644 --- a/src/Shaders/AbstractVector.h +++ b/src/Shaders/AbstractVector.h @@ -42,7 +42,7 @@ namespace Magnum { namespace Shaders { template class AbstractVector: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::VectorType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Texture coordinates */ typedef Attribute<1, Vector2> TextureCoordinates; diff --git a/src/Shaders/DistanceFieldVector.h b/src/Shaders/DistanceFieldVector.h index 50ad57051..8d5319deb 100644 --- a/src/Shaders/DistanceFieldVector.h +++ b/src/Shaders/DistanceFieldVector.h @@ -52,7 +52,7 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector DistanceFieldVector(); /** @brief Set transformation and projection matrix */ - DistanceFieldVector* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + DistanceFieldVector* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); return this; } diff --git a/src/Shaders/Flat.h b/src/Shaders/Flat.h index 69e9cccf0..582378a76 100644 --- a/src/Shaders/Flat.h +++ b/src/Shaders/Flat.h @@ -47,7 +47,7 @@ Draws whole mesh with one color. template class MAGNUM_SHADERS_EXPORT Flat: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::VectorType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; explicit Flat(); @@ -55,7 +55,7 @@ template class MAGNUM_SHADERS_EXPORT Flat: public Abstra * @brief Set transformation and projection matrix * @return Pointer to self (for method chaining) */ - Flat* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + Flat* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); return this; } diff --git a/src/Shaders/Vector.h b/src/Shaders/Vector.h index f4d7e61c2..f33bf468c 100644 --- a/src/Shaders/Vector.h +++ b/src/Shaders/Vector.h @@ -51,7 +51,7 @@ template 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::MatrixType& matrix) { + Vector* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); return this; } diff --git a/src/Shaders/VertexColor.h b/src/Shaders/VertexColor.h index d50eea060..d19cc87c9 100644 --- a/src/Shaders/VertexColor.h +++ b/src/Shaders/VertexColor.h @@ -47,7 +47,7 @@ Draws vertex-colored mesh. template class MAGNUM_SHADERS_EXPORT VertexColor: public AbstractShaderProgram { public: /** @brief Vertex position */ - typedef Attribute<0, typename DimensionTraits::VectorType> Position; + typedef Attribute<0, typename DimensionTraits::VectorType> Position; /** @brief Vertex color */ typedef Attribute<1, Color3> Color; @@ -60,7 +60,7 @@ template class MAGNUM_SHADERS_EXPORT VertexColor: public * * Default is identity matrix. */ - VertexColor* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + VertexColor* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); return this; } diff --git a/src/Shapes/AxisAlignedBox.cpp b/src/Shapes/AxisAlignedBox.cpp index d5474755f..75c7df465 100644 --- a/src/Shapes/AxisAlignedBox.cpp +++ b/src/Shapes/AxisAlignedBox.cpp @@ -30,7 +30,7 @@ namespace Magnum { namespace Shapes { -template AxisAlignedBox AxisAlignedBox::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template AxisAlignedBox AxisAlignedBox::transformed(const typename DimensionTraits::MatrixType& matrix) const { return AxisAlignedBox(matrix.transformPoint(_min), matrix.transformPoint(_max)); } diff --git a/src/Shapes/AxisAlignedBox.h b/src/Shapes/AxisAlignedBox.h index b65f89e98..750689828 100644 --- a/src/Shapes/AxisAlignedBox.h +++ b/src/Shapes/AxisAlignedBox.h @@ -56,28 +56,28 @@ template class MAGNUM_SHAPES_EXPORT AxisAlignedBox { constexpr /*implicit*/ AxisAlignedBox() {} /** @brief Constructor */ - constexpr /*implicit*/ AxisAlignedBox(const typename DimensionTraits::VectorType& min, const typename DimensionTraits::VectorType& max): _min(min), _max(max) {} + constexpr /*implicit*/ AxisAlignedBox(const typename DimensionTraits::VectorType& min, const typename DimensionTraits::VectorType& max): _min(min), _max(max) {} /** @brief Transformed shape */ - AxisAlignedBox transformed(const typename DimensionTraits::MatrixType& matrix) const; + AxisAlignedBox transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief Minimal coordinates */ - constexpr typename DimensionTraits::VectorType min() const { + constexpr typename DimensionTraits::VectorType min() const { return _min; } /** @brief Set minimal coordinates */ - void setMin(const typename DimensionTraits::VectorType& min) { + void setMin(const typename DimensionTraits::VectorType& min) { _min = min; } /** @brief Maximal coordinates */ - constexpr typename DimensionTraits::VectorType max() const { + constexpr typename DimensionTraits::VectorType max() const { return _max; } /** @brief Set maximal coordinates */ - void setMax(const typename DimensionTraits::VectorType& max) { + void setMax(const typename DimensionTraits::VectorType& max) { _max = max; } @@ -85,7 +85,7 @@ template class MAGNUM_SHAPES_EXPORT AxisAlignedBox { bool operator%(const Point& other) const; private: - typename DimensionTraits::VectorType _min, _max; + typename DimensionTraits::VectorType _min, _max; }; /** @brief Two-dimensional axis-aligned box */ diff --git a/src/Shapes/Box.cpp b/src/Shapes/Box.cpp index 6282784ee..202344c1c 100644 --- a/src/Shapes/Box.cpp +++ b/src/Shapes/Box.cpp @@ -26,7 +26,7 @@ namespace Magnum { namespace Shapes { -template Box Box::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template Box Box::transformed(const typename DimensionTraits::MatrixType& matrix) const { return Box(matrix*_transformation); } diff --git a/src/Shapes/Box.h b/src/Shapes/Box.h index 22750192d..f7abec1d2 100644 --- a/src/Shapes/Box.h +++ b/src/Shapes/Box.h @@ -55,26 +55,26 @@ template class MAGNUM_SHAPES_EXPORT Box { * * Creates zero-sized box positioned at origin. */ - constexpr /*implicit*/ Box(): _transformation(DimensionTraits::MatrixType::Zero) {} + constexpr /*implicit*/ Box(): _transformation(DimensionTraits::MatrixType::Zero) {} /** @brief Constructor */ - constexpr /*implicit*/ Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation) {} + constexpr /*implicit*/ Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation) {} /** @brief Transformed shape */ - Box transformed(const typename DimensionTraits::MatrixType& matrix) const; + Box transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief Transformation */ - constexpr typename DimensionTraits::MatrixType transformation() const { + constexpr typename DimensionTraits::MatrixType transformation() const { return _transformation; } /** @brief Set transformation */ - void setTransformation(const typename DimensionTraits::MatrixType& transformation) { + void setTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformation = transformation; } private: - typename DimensionTraits::MatrixType _transformation; + typename DimensionTraits::MatrixType _transformation; }; /** @brief Two-dimensional box */ diff --git a/src/Shapes/Capsule.cpp b/src/Shapes/Capsule.cpp index 69c543ec9..497696d09 100644 --- a/src/Shapes/Capsule.cpp +++ b/src/Shapes/Capsule.cpp @@ -36,9 +36,9 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Shapes { -template Capsule Capsule::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template Capsule Capsule::transformed(const typename DimensionTraits::MatrixType& matrix) const { return Capsule(matrix.transformPoint(_a), matrix.transformPoint(_b), - (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length()*_radius); + (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length()*_radius); } template bool Capsule::operator%(const Point& other) const { diff --git a/src/Shapes/Capsule.h b/src/Shapes/Capsule.h index 4eb91869d..2d85ddd97 100644 --- a/src/Shapes/Capsule.h +++ b/src/Shapes/Capsule.h @@ -58,28 +58,28 @@ template class MAGNUM_SHAPES_EXPORT Capsule { constexpr /*implicit*/ Capsule(): _radius(0.0f) {} /** @brief Constructor */ - constexpr /*implicit*/ Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, Float radius): _a(a), _b(b), _radius(radius) {} + constexpr /*implicit*/ Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, Float radius): _a(a), _b(b), _radius(radius) {} /** @brief Transformed shape */ - Capsule transformed(const typename DimensionTraits::MatrixType& matrix) const; + Capsule transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief Start point */ - constexpr typename DimensionTraits::VectorType a() const { + constexpr typename DimensionTraits::VectorType a() const { return _a; } /** @brief Set start point */ - void setA(const typename DimensionTraits::VectorType& a) { + void setA(const typename DimensionTraits::VectorType& a) { _a = a; } /** @brief End point */ - constexpr typename DimensionTraits::VectorType b() const { + constexpr typename DimensionTraits::VectorType b() const { return _b; } /** @brief Set end point */ - void setB(const typename DimensionTraits::VectorType& b) { + void setB(const typename DimensionTraits::VectorType& b) { _b = b; } @@ -96,7 +96,7 @@ template class MAGNUM_SHAPES_EXPORT Capsule { bool operator%(const Sphere& other) const; private: - typename DimensionTraits::VectorType _a, _b; + typename DimensionTraits::VectorType _a, _b; Float _radius; }; diff --git a/src/Shapes/Composition.cpp b/src/Shapes/Composition.cpp index 3bc721b73..9f4fc5707 100644 --- a/src/Shapes/Composition.cpp +++ b/src/Shapes/Composition.cpp @@ -125,7 +125,7 @@ template void Composition::copyNodes(std::si std::copy(other._nodes, other._nodes+other._nodeCount, _nodes+offset); } -template Composition Composition::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template Composition Composition::transformed(const typename DimensionTraits::MatrixType& matrix) const { Composition out(*this); for(std::size_t i = 0; i != _shapeCount; ++i) _shapes[i]->transform(matrix, out._shapes[i]); diff --git a/src/Shapes/Composition.h b/src/Shapes/Composition.h index 6f6abdbf6..c2530c1fc 100644 --- a/src/Shapes/Composition.h +++ b/src/Shapes/Composition.h @@ -125,7 +125,7 @@ template class MAGNUM_SHAPES_EXPORT Composition { Composition& operator=(Composition&& other); /** @brief Transformed shape */ - Composition transformed(const typename DimensionTraits::MatrixType& matrix) const; + Composition transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief Count of shapes in the hierarchy */ std::size_t size() const { return _shapeCount; } diff --git a/src/Shapes/Line.cpp b/src/Shapes/Line.cpp index abbdb5d9a..9a39dbf94 100644 --- a/src/Shapes/Line.cpp +++ b/src/Shapes/Line.cpp @@ -29,7 +29,7 @@ namespace Magnum { namespace Shapes { -template Line Line::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template Line Line::transformed(const typename DimensionTraits::MatrixType& matrix) const { return Line(matrix.transformPoint(_a), matrix.transformPoint(_b)); } diff --git a/src/Shapes/Line.h b/src/Shapes/Line.h index eb9f5afba..f908860fc 100644 --- a/src/Shapes/Line.h +++ b/src/Shapes/Line.h @@ -55,33 +55,33 @@ template class MAGNUM_SHAPES_EXPORT Line { constexpr /*implicit*/ Line() {} /** @brief Constructor */ - constexpr /*implicit*/ Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _b(b) {} + constexpr /*implicit*/ Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _b(b) {} /** @brief Transformed shape */ - Line transformed(const typename DimensionTraits::MatrixType& matrix) const; + Line transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief First point */ - constexpr typename DimensionTraits::VectorType a() const { + constexpr typename DimensionTraits::VectorType a() const { return _a; } /** @brief Set first point */ - void setA(const typename DimensionTraits::VectorType& a) { + void setA(const typename DimensionTraits::VectorType& a) { _a = a; } /** @brief Second point */ - constexpr typename DimensionTraits::VectorType b() const { + constexpr typename DimensionTraits::VectorType b() const { return _b; } /** @brief Set second point */ - void setB(const typename DimensionTraits::VectorType& b) { + void setB(const typename DimensionTraits::VectorType& b) { _b = b; } private: - typename DimensionTraits::VectorType _a, _b; + typename DimensionTraits::VectorType _a, _b; }; /** @brief Infinite two-dimensional line */ diff --git a/src/Shapes/LineSegment.h b/src/Shapes/LineSegment.h index a79bc0d4d..ee0f22dbc 100644 --- a/src/Shapes/LineSegment.h +++ b/src/Shapes/LineSegment.h @@ -48,10 +48,10 @@ template class LineSegment: public Line { constexpr /*implicit*/ LineSegment() {} /** @brief Constructor */ - constexpr /*implicit*/ LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} + constexpr /*implicit*/ LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} /** @brief Transformed shape */ - LineSegment transformed(const typename DimensionTraits::MatrixType& matrix) const { + LineSegment transformed(const typename DimensionTraits::MatrixType& matrix) const { return Line::transformed(matrix); } diff --git a/src/Shapes/Point.cpp b/src/Shapes/Point.cpp index 5631e1137..4badc0565 100644 --- a/src/Shapes/Point.cpp +++ b/src/Shapes/Point.cpp @@ -29,7 +29,7 @@ namespace Magnum { namespace Shapes { -template Point Point::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template Point Point::transformed(const typename DimensionTraits::MatrixType& matrix) const { return Point(matrix.transformPoint(_position)); } diff --git a/src/Shapes/Point.h b/src/Shapes/Point.h index a03a2c676..47cdb89e0 100644 --- a/src/Shapes/Point.h +++ b/src/Shapes/Point.h @@ -54,23 +54,23 @@ template class MAGNUM_SHAPES_EXPORT Point { constexpr /*implicit*/ Point() {} /** @brief Constructor */ - constexpr /*implicit*/ Point(const typename DimensionTraits::VectorType& position): _position(position) {} + constexpr /*implicit*/ Point(const typename DimensionTraits::VectorType& position): _position(position) {} /** @brief Transformed shape */ - Point transformed(const typename DimensionTraits::MatrixType& matrix) const; + Point transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief Position */ - constexpr typename DimensionTraits::VectorType position() const { + constexpr typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - void setPosition(const typename DimensionTraits::VectorType& position) { + void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } private: - typename DimensionTraits::VectorType _position; + typename DimensionTraits::VectorType _position; }; /** @brief Two-dimensional point */ diff --git a/src/Shapes/Shape.cpp b/src/Shapes/Shape.cpp index ed8d477a2..a302db9aa 100644 --- a/src/Shapes/Shape.cpp +++ b/src/Shapes/Shape.cpp @@ -36,7 +36,7 @@ template void ShapeHelper>::set( shape._transformedShape.shape = shape._shape.shape = std::move(composition); } -template void ShapeHelper>::transform(Shapes::Shape>& shape, const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { +template void ShapeHelper>::transform(Shapes::Shape>& shape, const typename DimensionTraits::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]); diff --git a/src/Shapes/Shape.h b/src/Shapes/Shape.h index c42e91099..7d1774f91 100644 --- a/src/Shapes/Shape.h +++ b/src/Shapes/Shape.h @@ -107,7 +107,7 @@ template class MAGNUM_SHAPES_EXPORT Shape: public AbstractShape::MatrixType& absoluteTransformationMatrix) override; + void clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) override; private: const Implementation::AbstractShape* abstractTransformedShape() const override { @@ -128,7 +128,7 @@ template inline const T& Shape::transformedShape() { return _transformedShape.shape; } -template void Shape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { +template void Shape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { Implementation::ShapeHelper::transform(*this, absoluteTransformationMatrix); } @@ -138,7 +138,7 @@ namespace Implementation { shape._shape.shape = s; } - static void transform(Shapes::Shape& shape, const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { + static void transform(Shapes::Shape& shape, const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { shape._transformedShape.shape = shape._shape.shape.transformed(absoluteTransformationMatrix); } }; @@ -147,7 +147,7 @@ namespace Implementation { static void set(Shapes::Shape>& shape, const Composition& composition); static void set(Shapes::Shape>& shape, Composition&& composition); - static void transform(Shapes::Shape>& shape, const typename DimensionTraits::MatrixType& absoluteTransformationMatrix); + static void transform(Shapes::Shape>& shape, const typename DimensionTraits::MatrixType& absoluteTransformationMatrix); }; } diff --git a/src/Shapes/Sphere.cpp b/src/Shapes/Sphere.cpp index 154641c09..f1af70317 100644 --- a/src/Shapes/Sphere.cpp +++ b/src/Shapes/Sphere.cpp @@ -37,7 +37,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Shapes { namespace { - template static typename DimensionTraits::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Constants::sqrt2()); @@ -48,7 +48,7 @@ namespace { } } -template Sphere Sphere::transformed(const typename DimensionTraits::MatrixType& matrix) const { +template Sphere Sphere::transformed(const typename DimensionTraits::MatrixType& matrix) const { return Sphere(matrix.transformPoint(_position), (matrix.rotationScaling()*unitVector()).length()*_radius); } diff --git a/src/Shapes/Sphere.h b/src/Shapes/Sphere.h index d9792109b..c100f90b3 100644 --- a/src/Shapes/Sphere.h +++ b/src/Shapes/Sphere.h @@ -58,18 +58,18 @@ template class MAGNUM_SHAPES_EXPORT Sphere { constexpr /*implicit*/ Sphere(): _radius(0.0f) {} /** @brief Constructor */ - constexpr /*implicit*/ Sphere(const typename DimensionTraits::VectorType& position, Float radius): _position(position), _radius(radius) {} + constexpr /*implicit*/ Sphere(const typename DimensionTraits::VectorType& position, Float radius): _position(position), _radius(radius) {} /** @brief Transformed shape */ - Sphere transformed(const typename DimensionTraits::MatrixType& matrix) const; + Sphere transformed(const typename DimensionTraits::MatrixType& matrix) const; /** @brief Position */ - constexpr typename DimensionTraits::VectorType position() const { + constexpr typename DimensionTraits::VectorType position() const { return _position; } /** @brief Set position */ - void setPosition(const typename DimensionTraits::VectorType& position) { + void setPosition(const typename DimensionTraits::VectorType& position) { _position = position; } @@ -92,7 +92,7 @@ template class MAGNUM_SHAPES_EXPORT Sphere { bool operator%(const Sphere& other) const; private: - typename DimensionTraits::VectorType _position; + typename DimensionTraits::VectorType _position; Float _radius; }; diff --git a/src/Shapes/shapeImplementation.h b/src/Shapes/shapeImplementation.h index 0731cfad0..ecf028570 100644 --- a/src/Shapes/shapeImplementation.h +++ b/src/Shapes/shapeImplementation.h @@ -126,7 +126,7 @@ template struct MAGNUM_SHAPES_EXPORT AbstractShape { virtual typename ShapeDimensionTraits::Type MAGNUM_SHAPES_LOCAL type() const = 0; virtual AbstractShape MAGNUM_SHAPES_LOCAL * clone() const = 0; - virtual void MAGNUM_SHAPES_LOCAL transform(const typename DimensionTraits::MatrixType& matrix, AbstractShape* result) const = 0; + virtual void MAGNUM_SHAPES_LOCAL transform(const typename DimensionTraits::MatrixType& matrix, AbstractShape* result) const = 0; }; template struct Shape: AbstractShape { @@ -144,7 +144,7 @@ template struct Shape: AbstractShape { return new Shape(shape); } - void transform(const typename DimensionTraits::MatrixType& matrix, AbstractShape* result) const override { + void transform(const typename DimensionTraits::MatrixType& matrix, AbstractShape* result) const override { CORRADE_INTERNAL_ASSERT(result->type() == type()); static_cast*>(result)->shape = shape.transformed(matrix); } From 1d6015e95b201316fd81fa84421455ab244acc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Jul 2013 15:05:33 +0200 Subject: [PATCH 4/6] Trade: pass ImageReference2D to image converter. Also not through pointer, but throught const&, allows implicit conversion from Image2D and Trade::ImageData2D, which is good. Bumped plugin interface version a bit, as this is not so drastic change in behavior. --- src/Trade/AbstractImageConverter.cpp | 12 ++++++------ src/Trade/AbstractImageConverter.h | 14 +++++++------- src/Trade/Test/AbstractImageConverterTest.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Trade/AbstractImageConverter.cpp b/src/Trade/AbstractImageConverter.cpp index 225895af5..5bdf5e8b4 100644 --- a/src/Trade/AbstractImageConverter.cpp +++ b/src/Trade/AbstractImageConverter.cpp @@ -34,33 +34,33 @@ 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 AbstractImageConverter::exportToData(const Image2D* const image) const { +Containers::Array AbstractImageConverter::exportToData(const ImageReference2D& image) const { CORRADE_ASSERT(features() & Feature::ConvertData, "Trade::AbstractImageConverter::exportToData(): feature not supported", nullptr); return doExportToData(image); } -Containers::Array AbstractImageConverter::doExportToData(const Image2D*) const { +Containers::Array AbstractImageConverter::doExportToData(const ImageReference2D&) const { CORRADE_ASSERT(false, "Trade::AbstractImageConverter::exportToData(): feature advertised but not implemented", nullptr); } -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); diff --git a/src/Trade/AbstractImageConverter.h b/src/Trade/AbstractImageConverter.h index 126964286..5b40c8cd3 100644 --- a/src/Trade/AbstractImageConverter.h +++ b/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 exportToData(const Image2D* image) const; + Containers::Array 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 doExportToData(const Image2D* image) const; + virtual Containers::Array 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) diff --git a/src/Trade/Test/AbstractImageConverterTest.cpp b/src/Trade/Test/AbstractImageConverterTest.cpp index 7fbfae7c3..e03d441d9 100644 --- a/src/Trade/Test/AbstractImageConverterTest.cpp +++ b/src/Trade/Test/AbstractImageConverterTest.cpp @@ -27,8 +27,8 @@ #include #include -#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 doExportToData(const Image2D* image) const override { + Containers::Array doExportToData(const ImageReference2D& image) const override { Containers::Array 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); } From aacb6b7041967b83f881627dd78d368801757833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Jul 2013 20:09:11 +0200 Subject: [PATCH 5/6] Trade: return references, not pointers from MeshData. The access methods assert that the user is querying only available data. Also updated Primitives implementation to create MeshData when everything is done, not creating empty MeshData and then shooting the data through interface intended for end users. --- .../Implementation/AbstractShapeRenderer.cpp | 16 ++-- src/Primitives/Capsule.cpp | 7 +- src/Primitives/Circle.cpp | 22 +++--- src/Primitives/Crosshair.cpp | 4 +- src/Primitives/Cube.cpp | 10 +-- src/Primitives/Cylinder.cpp | 5 +- src/Primitives/Icosphere.cpp | 6 +- src/Primitives/Implementation/Spheroid.cpp | 76 ++++++++++--------- src/Primitives/Implementation/Spheroid.h | 15 +++- src/Primitives/Line.cpp | 4 +- src/Primitives/Plane.cpp | 6 +- src/Primitives/Square.cpp | 4 +- src/Primitives/Test/CapsuleTest.cpp | 12 +-- src/Primitives/Test/CircleTest.cpp | 4 +- src/Primitives/Test/CylinderTest.cpp | 14 ++-- src/Primitives/Test/UVSphereTest.cpp | 12 +-- src/Primitives/UVSphere.cpp | 9 ++- src/Trade/MeshData2D.cpp | 46 +++++++---- src/Trade/MeshData2D.h | 66 ++++++++-------- src/Trade/MeshData3D.cpp | 58 ++++++++++---- src/Trade/MeshData3D.h | 76 ++++++++++--------- 21 files changed, 276 insertions(+), 196 deletions(-) diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index c11985bd5..6ee4d5f4c 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -46,21 +46,21 @@ template void create(typename MeshData::Type template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, Resource& vertexBufferResource, Resource& indexBufferResource) { /* Vertex buffer */ Buffer* buffer = new Buffer(Buffer::Target::Array); - buffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); + 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& meshResource, template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, Resource& vertexBufferResource, Resource& indexBufferResource) { /* Vertex buffer */ Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); - vertexBuffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); + 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); } } diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index 1447e2e16..d0128ba53 100644 --- a/src/Primitives/Capsule.cpp +++ b/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(); } }} diff --git a/src/Primitives/Circle.cpp b/src/Primitives/Circle.cpp index 3ad904ca4..e6b019410 100644 --- a/src/Primitives/Circle.cpp +++ b/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; - positions->reserve(segments+1); + std::vector 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; - positions->reserve(segments); + std::vector 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)}, {}); } }} diff --git a/src/Primitives/Crosshair.cpp b/src/Primitives/Crosshair.cpp index c20fe61fe..a03aa2292 100644 --- a/src/Primitives/Crosshair.cpp +++ b/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{ + 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{ + 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} diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index eb369ce23..084a2e9b2 100644 --- a/src/Primitives/Cube.cpp +++ b/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{ + 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{ + }, {{ {-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{ + }}, {{ { 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{ + 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{ + }, {{ {-1.0f, -1.0f, 1.0f}, { 1.0f, -1.0f, 1.0f}, { 1.0f, 1.0f, 1.0f}, diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 13c043b3a..a750715ae 100644 --- a/src/Primitives/Cylinder.cpp +++ b/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(); } }} diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index b5ddc86ea..56a10f776 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -28,7 +28,7 @@ namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, new std::vector{ +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}, {new std::vector{ +}, {}, {{ {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()); } }} diff --git a/src/Primitives/Implementation/Spheroid.cpp b/src/Primitives/Implementation/Spheroid.cpp index 288279160..506221c73 100644 --- a/src/Primitives/Implementation/Spheroid.cpp +++ b/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, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), 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::move(textureCoords2D)} : std::vector>()); +} + }}} diff --git a/src/Primitives/Implementation/Spheroid.h b/src/Primitives/Implementation/Spheroid.h index 9a3f89203..b493ee42e 100644 --- a/src/Primitives/Implementation/Spheroid.h +++ b/src/Primitives/Implementation/Spheroid.h @@ -24,11 +24,14 @@ DEALINGS IN THE SOFTWARE. */ -#include "Trade/MeshData3D.h" +#include + +#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 indices; + std::vector positions; + std::vector normals; + std::vector textureCoords2D; }; }}} diff --git a/src/Primitives/Line.cpp b/src/Primitives/Line.cpp index 53926a9f6..fc0da8207 100644 --- a/src/Primitives/Line.cpp +++ b/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{ + 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{ + return Trade::MeshData3D(Mesh::Primitive::Lines, {}, {{ {0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, }}, {}, {}); } diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index 3ff7488a5..d3fe3787e 100644 --- a/src/Primitives/Plane.cpp +++ b/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{ + 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{ + }}, {{ {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{ + return Trade::MeshData3D(Mesh::Primitive::LineLoop, {}, {{ {-1.0f, -1.0f, 0.0f}, {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index f17646966..e5bfda106 100644 --- a/src/Primitives/Square.cpp +++ b/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{ + 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{ + return Trade::MeshData2D(Mesh::Primitive::LineLoop, {}, {{ {-1.0f, -1.0f}, {1.0f, -1.0f}, {1.0f, 1.0f}, diff --git a/src/Primitives/Test/CapsuleTest.cpp b/src/Primitives/Test/CapsuleTest.cpp index 33b3da9f2..4e41eae02 100644 --- a/src/Primitives/Test/CapsuleTest.cpp +++ b/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{ + CORRADE_COMPARE_AS(capsule.positions(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(capsule.normals(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(capsule.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, @@ -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{ + CORRADE_COMPARE_AS(capsule.positions(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(capsule.textureCoords2D(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(capsule.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, diff --git a/src/Primitives/Test/CircleTest.cpp b/src/Primitives/Test/CircleTest.cpp index 58c763af2..4395086f3 100644 --- a/src/Primitives/Test/CircleTest.cpp +++ b/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{ + CORRADE_COMPARE(circle.positions(0), (std::vector{ { 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{ + CORRADE_COMPARE(circle.positions(0), (std::vector{ { 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}, diff --git a/src/Primitives/Test/CylinderTest.cpp b/src/Primitives/Test/CylinderTest.cpp index f999cde89..33e8a7d43 100644 --- a/src/Primitives/Test/CylinderTest.cpp +++ b/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{ + CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector{ {0.0f, -1.5f, 1.0f}, {0.866025f, -1.5f, -0.5f}, {-0.866025f, -1.5f, -0.5f}, @@ -61,7 +61,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 1.5f, -0.5f} }), TestSuite::Compare::Container); - CORRADE_COMPARE_AS(*cylinder.normals(0), (std::vector{ + CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector{ {0.0f, 0.0f, 1.0f}, {0.866025f, 0.0f, -0.5f}, {-0.866025f, 0.0f, -0.5f}, @@ -75,7 +75,7 @@ void CylinderTest::withoutAnything() { {-0.866025f, 0.0f, -0.5f} }), TestSuite::Compare::Container); - CORRADE_COMPARE_AS(*cylinder.indices(), (std::vector{ + CORRADE_COMPARE_AS(cylinder.indices(), (std::vector{ 0, 1, 4, 0, 4, 3, 1, 2, 5, 1, 5, 4, 2, 0, 3, 2, 3, 5, 3, 4, 7, 3, 7, 6, 4, 5, 8, 4, 8, 7, 5, 3, 6, 5, 6, 8 }), 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{ + CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(cylinder.normals(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(cylinder.textureCoords2D(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(cylinder.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, diff --git a/src/Primitives/Test/UVSphereTest.cpp b/src/Primitives/Test/UVSphereTest.cpp index 9403d79ff..46f25bbf0 100644 --- a/src/Primitives/Test/UVSphereTest.cpp +++ b/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{ + CORRADE_COMPARE_AS(sphere.positions(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(sphere.normals(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(sphere.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 4, 5, 7, 5, 6, 7, 6, 4, 7 @@ -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{ + CORRADE_COMPARE_AS(sphere.positions(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(sphere.textureCoords2D(0), (std::vector{ {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{ + CORRADE_COMPARE_AS(sphere.indices(), (std::vector{ 0, 2, 1, 0, 3, 2, 0, 4, 3, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 5, 6, 9, 6, 7, 9, 7, 8, 9 diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 5ec1d72c5..b4003300f 100644 --- a/src/Primitives/UVSphere.cpp +++ b/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(); } }} diff --git a/src/Trade/MeshData2D.cpp b/src/Trade/MeshData2D.cpp index 44ea06609..4e06a1b00 100644 --- a/src/Trade/MeshData2D.cpp +++ b/src/Trade/MeshData2D.cpp @@ -28,24 +28,44 @@ namespace Magnum { namespace Trade { -MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _textureCoords2D(std::move(textureCoords2D)) {} +MeshData2D::MeshData2D(Mesh::Primitive primitive, std::vector indices, std::vector> positions, std::vector> 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& MeshData2D::indices() { + CORRADE_ASSERT(isIndexed(), "Trade::MeshData2D::indices(): the mesh is not indexed", _indices); + return _indices; +} + +const std::vector& MeshData2D::indices() const { + CORRADE_ASSERT(isIndexed(), "Trade::MeshData2D::indices(): the mesh is not indexed", _indices); + return _indices; +} + +std::vector& 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& 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& 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 i: _positions) delete i; - for(auto i: _textureCoords2D) delete i; +const std::vector& MeshData2D::textureCoords2D(const UnsignedInt id) const { + CORRADE_ASSERT(id < textureCoords2DArrayCount(), "Trade::MeshData2D::textureCoords2D(): index out of range", _textureCoords2D[id]); + return _textureCoords2D[id]; } }} diff --git a/src/Trade/MeshData2D.h b/src/Trade/MeshData2D.h index d8a910460..7f50ce820 100644 --- a/src/Trade/MeshData2D.h +++ b/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* indices, std::vector*> positions, std::vector*> textureCoords2D); + explicit MeshData2D(Mesh::Primitive primitive, std::vector indices, std::vector> positions, std::vector> 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* indices() { return _indices; } - const std::vector* indices() const { return _indices; } /**< @overload */ + std::vector& indices(); + const std::vector& 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* positions(UnsignedInt id) { return _positions[id]; } - const std::vector* positions(UnsignedInt id) const { return _positions[id]; } /**< @overload */ + std::vector& positions(UnsignedInt id); + const std::vector& 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* textureCoords2D(UnsignedInt id) { return _textureCoords2D[id]; } - const std::vector* textureCoords2D(UnsignedInt id) const { return _textureCoords2D[id]; } /**< @overload */ + std::vector& textureCoords2D(UnsignedInt id); + const std::vector& textureCoords2D(UnsignedInt id) const; /**< @overload */ private: Mesh::Primitive _primitive; - std::vector* _indices; - std::vector*> _positions; - std::vector*> _textureCoords2D; + std::vector _indices; + std::vector> _positions; + std::vector> _textureCoords2D; }; }} diff --git a/src/Trade/MeshData3D.cpp b/src/Trade/MeshData3D.cpp index 5ad47c640..a483521ec 100644 --- a/src/Trade/MeshData3D.cpp +++ b/src/Trade/MeshData3D.cpp @@ -28,26 +28,54 @@ namespace Magnum { namespace Trade { -MeshData3D::MeshData3D(Mesh::Primitive primitive, std::vector* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D): _primitive(primitive), _indices(indices), _positions(std::move(positions)), _normals(std::move(normals)), _textureCoords2D(std::move(textureCoords2D)) {} +MeshData3D::MeshData3D(Mesh::Primitive primitive, std::vector indices, std::vector> positions, std::vector> normals, std::vector> 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& MeshData3D::indices() { + CORRADE_ASSERT(isIndexed(), "Trade::MeshData3D::indices(): the mesh is not indexed", _indices); + return _indices; +} + +const std::vector& MeshData3D::indices() const { + CORRADE_ASSERT(isIndexed(), "Trade::MeshData3D::indices(): the mesh is not indexed", _indices); + return _indices; +} + +std::vector& MeshData3D::positions(const UnsignedInt id) { + CORRADE_ASSERT(id < positionArrayCount(), "Trade::MeshData3D::positions(): index out of range", _positions[id]); + return _positions[id]; +} + +const std::vector& MeshData3D::positions(const UnsignedInt id) const { + CORRADE_ASSERT(id < positionArrayCount(), "Trade::MeshData3D::positions(): index out of range", _positions[id]); + return _positions[id]; +} + +std::vector& 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& 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& 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 i: _positions) delete i; - for(auto i: _normals) delete i; - for(auto i: _textureCoords2D) delete i; +const std::vector& MeshData3D::textureCoords2D(const UnsignedInt id) const { + CORRADE_ASSERT(id < textureCoords2DArrayCount(), "Trade::MeshData3D::textureCoords2D(): index out of range", _textureCoords2D[id]); + return _textureCoords2D[id]; } }} diff --git a/src/Trade/MeshData3D.h b/src/Trade/MeshData3D.h index 64271f2a0..c1cffca6f 100644 --- a/src/Trade/MeshData3D.h +++ b/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* indices, std::vector*> positions, std::vector*> normals, std::vector*> textureCoords2D); + explicit MeshData3D(Mesh::Primitive primitive, std::vector indices, std::vector> positions, std::vector> normals, std::vector> 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* indices() { return _indices; } - const std::vector* indices() const { return _indices; } /**< @overload */ + std::vector& indices(); + const std::vector& 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* positions(UnsignedInt id) { return _positions[id]; } - const std::vector* positions(UnsignedInt id) const { return _positions[id]; } /**< @overload */ + std::vector& positions(UnsignedInt id); + const std::vector& 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* normals(UnsignedInt id) { return _normals[id]; } - const std::vector* normals(UnsignedInt id) const { return _normals[id]; } /**< @overload */ + std::vector& normals(UnsignedInt id); + const std::vector& 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* textureCoords2D(UnsignedInt id) { return _textureCoords2D[id]; } - const std::vector* textureCoords2D(UnsignedInt id) const { return _textureCoords2D[id]; } /**< @overload */ + std::vector& textureCoords2D(UnsignedInt id); + const std::vector& textureCoords2D(UnsignedInt id) const; /**< @overload */ private: Mesh::Primitive _primitive; - std::vector* _indices; - std::vector*> _positions; - std::vector*> _normals; - std::vector*> _textureCoords2D; + std::vector _indices; + std::vector> _positions; + std::vector> _normals; + std::vector> _textureCoords2D; }; }} From 4222d8a297ce2fe897261366c0dcb3d14d1eecbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Jul 2013 01:07:52 +0200 Subject: [PATCH 6/6] Platform: pass application configuration via reference, not pointer. Removes the need for explicit new/delete calls. --- src/Platform/AbstractXApplication.cpp | 21 ++++---- src/Platform/AbstractXApplication.h | 28 ++++++----- src/Platform/GlutApplication.cpp | 26 +++++----- src/Platform/GlutApplication.h | 56 +++++++++++----------- src/Platform/GlxApplication.h | 8 ++-- src/Platform/NaClApplication.cpp | 30 +++++++----- src/Platform/NaClApplication.h | 42 +++++++--------- src/Platform/Sdl2Application.cpp | 36 +++++++------- src/Platform/Sdl2Application.h | 40 +++++++++------- src/Platform/WindowlessGlxApplication.cpp | 15 +++--- src/Platform/WindowlessGlxApplication.h | 14 ++++-- src/Platform/WindowlessNaClApplication.cpp | 22 +++++---- src/Platform/WindowlessNaClApplication.h | 30 +++++------- src/Platform/XEglApplication.h | 8 ++-- 14 files changed, 201 insertions(+), 175 deletions(-) diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 6a38ad9ec..8a7a1217a 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -36,18 +36,22 @@ namespace Magnum { namespace Platform { -AbstractXApplication::AbstractXApplication(AbstractContextHandler* 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* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { + createContext(configuration); } -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { - if(configuration) createContext(configuration); +AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { + createContext({}); } -void AbstractXApplication::createContext(AbstractXApplication::Configuration* configuration) { +AbstractXApplication::AbstractXApplication(AbstractContextHandler* 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() { diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index ba5bb5680..bf9b46a29 100644 --- a/src/Platform/AbstractXApplication.h +++ b/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* contextHandler, const Arguments& arguments, const Configuration& configuration = Configuration()); + #else + /* To avoid "invalid use of incomplete type" */ + explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments, const Configuration& configuration); explicit AbstractXApplication(AbstractContextHandler* 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* contextHandler, const Arguments& arguments, Configuration* configuration); + explicit AbstractXApplication(AbstractContextHandler* 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: diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index 65ea0566c..fb92c6c3e 100644 --- a/src/Platform/GlutApplication.cpp +++ b/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); diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 9f01f6053..e037a849b 100644 --- a/src/Platform/GlutApplication.h +++ b/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: diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index d48975e01..b3aeb562a 100644 --- a/src/Platform/GlxApplication.h +++ b/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 diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index c00ee9df5..b4a5ba4c2 100644 --- a/src/Platform/NaClApplication.cpp +++ b/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 }; diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 75b65d68c..367baad35 100644 --- a/src/Platform/NaClApplication.h +++ b/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: diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 803928ece..734f6312c 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/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; diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 06c5319db..1fd62c431 100644 --- a/src/Platform/Sdl2Application.h +++ b/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: diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index 0108bc2ca..00fe92feb 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/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() { diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index df11f2dda..ed9831b83 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/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; diff --git a/src/Platform/WindowlessNaClApplication.cpp b/src/Platform/WindowlessNaClApplication.cpp index a890b2c91..5336ba23c 100644 --- a/src/Platform/WindowlessNaClApplication.cpp +++ b/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[] = { diff --git a/src/Platform/WindowlessNaClApplication.h b/src/Platform/WindowlessNaClApplication.h index 54de3ea05..1fe6e6b81 100644 --- a/src/Platform/WindowlessNaClApplication.h +++ b/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; diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index c2c708b4e..1b99b87f1 100644 --- a/src/Platform/XEglApplication.h +++ b/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