From d04b308aa3710c784813e968a8a3154cb6362d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Jul 2013 19:26:54 +0200 Subject: [PATCH] Reducing pointer chasings, part 1: method chaining via references. Makes some cases less consistent (and some convenience shortcuts impossible), but goes well with the attitude "don't use pointer when it can't be null". --- doc/debug-tools.dox | 2 +- doc/method-chaining.dox | 45 +++---- doc/scenegraph.dox | 4 +- src/AbstractFramebuffer.cpp | 4 +- src/AbstractFramebuffer.h | 4 +- src/AbstractShaderProgram.h | 18 +-- src/AbstractTexture.cpp | 12 +- src/AbstractTexture.h | 26 ++-- src/Buffer.h | 67 +++++----- src/CubeMapTexture.h | 54 ++++----- src/CubeMapTextureArray.h | 50 ++++---- src/DebugTools/ForceRenderer.cpp | 12 +- src/DebugTools/ForceRenderer.h | 18 +-- .../Implementation/AbstractShapeRenderer.cpp | 8 +- .../Implementation/AxisAlignedBoxRenderer.cpp | 4 +- src/DebugTools/Implementation/BoxRenderer.cpp | 4 +- .../Implementation/LineSegmentRenderer.cpp | 4 +- .../Implementation/PointRenderer.cpp | 4 +- .../Implementation/SphereRenderer.cpp | 4 +- src/DebugTools/ObjectRenderer.cpp | 8 +- src/DebugTools/ObjectRenderer.h | 9 +- src/DebugTools/ShapeRenderer.h | 22 ++-- src/DefaultFramebuffer.cpp | 4 +- src/DefaultFramebuffer.h | 20 +-- src/Framebuffer.cpp | 8 +- src/Framebuffer.h | 48 ++++---- src/Mesh.cpp | 4 +- src/Mesh.h | 114 +++++++++--------- src/MeshTools/CompressIndices.cpp | 2 +- src/Platform/AbstractXApplication.h | 4 +- src/ResourceManager.h | 46 +++---- src/SceneGraph/AbstractCamera.h | 4 +- src/SceneGraph/AbstractCamera.hpp | 4 +- src/SceneGraph/AbstractTransformation.h | 6 +- .../AbstractTranslationRotation2D.h | 16 +-- .../AbstractTranslationRotation3D.h | 34 +++--- .../AbstractTranslationRotationScaling2D.h | 18 +-- .../AbstractTranslationRotationScaling3D.h | 30 ++--- src/SceneGraph/Animable.h | 22 ++-- src/SceneGraph/Animable.hpp | 8 +- src/SceneGraph/Camera2D.h | 14 +-- src/SceneGraph/Camera2D.hpp | 4 +- src/SceneGraph/Camera3D.h | 22 ++-- src/SceneGraph/Camera3D.hpp | 12 +- src/SceneGraph/Drawable.h | 12 +- src/SceneGraph/DualComplexTransformation.h | 42 +++---- src/SceneGraph/DualQuaternionTransformation.h | 42 +++---- src/SceneGraph/FeatureGroup.h | 18 +-- src/SceneGraph/MatrixTransformation2D.h | 40 +++--- src/SceneGraph/MatrixTransformation3D.h | 52 ++++---- src/SceneGraph/Object.h | 8 +- src/SceneGraph/Object.hpp | 14 +-- src/SceneGraph/RigidMatrixTransformation2D.h | 48 ++++---- src/SceneGraph/RigidMatrixTransformation3D.h | 60 ++++----- src/SceneGraph/Test/AnimableTest.cpp | 7 +- .../Test/DualQuaternionTransformationTest.cpp | 12 +- .../Test/MatrixTransformation3DTest.cpp | 12 +- .../Test/RigidMatrixTransformation3DTest.cpp | 12 +- src/Shaders/DistanceFieldVector.h | 33 ++--- src/Shaders/Flat.h | 12 +- src/Shaders/MeshVisualizer.h | 38 +++--- src/Shaders/Phong.h | 60 ++++----- src/Shaders/Vector.h | 12 +- src/Shaders/VertexColor.h | 6 +- src/Shapes/Shape.h | 8 +- src/Text/DistanceFieldGlyphCache.cpp | 6 +- src/Text/GlyphCache.cpp | 6 +- src/Text/TextRenderer.cpp | 6 +- src/Text/TextRenderer.h | 22 ++-- src/Texture.h | 66 +++++----- src/TextureTools/DistanceField.cpp | 18 +-- src/Timeline.h | 8 +- 72 files changed, 754 insertions(+), 753 deletions(-) diff --git a/doc/debug-tools.dox b/doc/debug-tools.dox index afbed3e3e..517fee209 100644 --- a/doc/debug-tools.dox +++ b/doc/debug-tools.dox @@ -63,7 +63,7 @@ SceneGraph::DrawableGroup3D debugDrawables; // Create renderer options which will be referenced later by "my" resource key DebugTools::ResourceManager::instance()->set("my", - (new DebugTools::ObjectRendererOptions)->setSize(0.3f)); + DebugTools::ObjectRendererOptions().setSize(0.3f)); // Create debug renderer for given object, use "my" options for it. The // renderer is automatically added to the object features and also to diff --git a/doc/method-chaining.dox b/doc/method-chaining.dox index 19cc2d7e1..2eb2b8cd2 100644 --- a/doc/method-chaining.dox +++ b/doc/method-chaining.dox @@ -42,17 +42,17 @@ bound somewhere. Method chaining encourages you to configure whole object in one run, effectively reducing the number of needed bindings. Consider the following example: @code -Texture2D *carDiffuseTexture, *carSpecularTexture, *carBumpTexture; +Texture2D carDiffuseTexture, carSpecularTexture, carBumpTexture; -carDiffuseTexture->setStorage(5, TextureFormat::SRGB8); -carSpecularTexture->setStorage(3, TextureFormat::R8); -carBumpTexture->setStorage(5, TextureFormat::RGB8); -carDiffuseTexture->setSubImage(0, {}, diffuse); -carSpecularTexture->setSubImage(0, {}, specular; -carBumpTexture->setSubImage(0, {}, bump); -carDiffuseTexture->generateMipmap(); -carSpecularTexture->generateMipmap(); -carBumpTexture->generateMipmap(); +carDiffuseTexture.setStorage(5, TextureFormat::SRGB8); +carSpecularTexture.setStorage(3, TextureFormat::R8); +carBumpTexture.setStorage(5, TextureFormat::RGB8); +carDiffuseTexture.setSubImage(0, {}, diffuse); +carSpecularTexture.setSubImage(0, {}, specular; +carBumpTexture.setSubImage(0, {}, bump); +carDiffuseTexture.generateMipmap(); +carSpecularTexture.generateMipmap(); +carBumpTexture.generateMipmap(); @endcode This code is written that similar configuration steps are grouped together, @@ -62,15 +62,15 @@ names and after each configuration step the texture must be rebound to another. With method chaining used the code looks much lighter and each object is configured in one run, reducing count of bind calls from 9 to 3. @code -carDiffuseTexture->setStorage(5, TextureFormat::SRGB8) - ->setSubImage(0, {}, diffuse) - ->generateMipmap(); -carSpecularTexture->setStorage(3, TextureFormat::R8) - ->setSubImage(0, {}, diffuse) - ->generateMipmap(); -carBumpTexture->setStorage(5, TextureFormat::RGB8) - ->setSubImage(0, {}, bump) - ->generateMipmap(); +carDiffuseTexture.setStorage(5, TextureFormat::SRGB8) + .setSubImage(0, {}, diffuse) + .generateMipmap(); +carSpecularTexture.setStorage(3, TextureFormat::R8) + .setSubImage(0, {}, diffuse) + .generateMipmap(); +carBumpTexture.setStorage(5, TextureFormat::RGB8) + .setSubImage(0, {}, bump) + .generateMipmap(); @endcode Method chaining is not used on non-configuring functions, such as Framebuffer::clear() @@ -85,12 +85,7 @@ Scene3D scene; (new MyObject(&scene)) ->rotateX(90.0_degf) - ->translate({-1.5f, 0.5f, 7.0f}); + .translate({-1.5f, 0.5f, 7.0f}); @endcode - -In most cases method chaining methods return pointer to the object, because -most of the objects are commonly created on the heap. The only exception are -Shader methods, which return reference, because the class is commonly created -as local variable in shader constructors. */ } diff --git a/doc/scenegraph.dox b/doc/scenegraph.dox index e72d7cf42..9cd506d36 100644 --- a/doc/scenegraph.dox +++ b/doc/scenegraph.dox @@ -109,8 +109,8 @@ transformation. For convenience you can use method chaining: @code Object3D* next = new Object3D; next->setParent(another) - ->translate(Vector3::yAxis(3.0f)) - ->rotateY(35.0_degf); + .translate(Vector3::yAxis(3.0f)) + .rotateY(35.0_degf); @endcode @section scenegraph-features Object features diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index 3a4ba0bb2..4feffb268 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -108,14 +108,14 @@ void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& #endif } -AbstractFramebuffer* AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { +AbstractFramebuffer& AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { _viewport = rectangle; /* Update the viewport if the framebuffer is currently bound */ if(Context::current()->state()->framebuffer->drawBinding == _id) setViewportInternal(); - return this; + return *this; } void AbstractFramebuffer::setViewportInternal() { diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 25f4efa09..8e8df7f9f 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -207,14 +207,14 @@ class MAGNUM_EXPORT AbstractFramebuffer { /** * @brief Set viewport - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Saves the viewport to be used at later time in bind(). If the * framebuffer is currently bound, updates the viewport to given * rectangle. * @see @fn_gl{Viewport} */ - AbstractFramebuffer* setViewport(const Rectanglei& rectangle); + AbstractFramebuffer& setViewport(const Rectanglei& rectangle); /** * @brief Clear specified buffers in framebuffer diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index bf0608108..8f3b0262d 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -101,13 +101,13 @@ MyShader() { protected setUniform() functions. For usability purposes you can implement also method chaining. Example: @code -MyShader* setTransformation(const Matrix4& matrix) { +MyShader& setTransformation(const Matrix4& matrix) { setUniform(TransformationUniform, matrix); - return this; + return *this; } -MyShader* setProjection(const Matrix4& matrix) { +MyShader& setProjection(const Matrix4& matrix) { setUniform(ProjectionUniform, matrix); - return this; + return *this; } @endcode @@ -219,12 +219,12 @@ specific framebuffer (if needed) and bind required textures to their respective layers using AbstractTexture::bind(Int). Then call Mesh::draw(). Example: @code -shader->setTransformation(transformation) - ->setProjection(projection) - ->use(); +shader.setTransformation(transformation) + .setProjection(projection) + .use(); -diffuseTexture->bind(MyShader::DiffuseTextureLayer); -specularTexture->bind(MyShader::SpecularTextureLayer); +diffuseTexture.bind(MyShader::DiffuseTextureLayer); +specularTexture.bind(MyShader::SpecularTextureLayer); mesh.draw(); @endcode diff --git a/src/AbstractTexture.cpp b/src/AbstractTexture.cpp index 3bffa9ed5..6eaf638ac 100644 --- a/src/AbstractTexture.cpp +++ b/src/AbstractTexture.cpp @@ -145,23 +145,23 @@ void AbstractTexture::bindImplementationDSA(GLint layer) { } #endif -AbstractTexture* AbstractTexture::setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap) { +AbstractTexture& AbstractTexture::setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap) { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Sampler::Mipmap::Base, "AbstractTexture: rectangle textures cannot have mipmaps", this); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE || mipmap == Sampler::Mipmap::Base, "AbstractTexture: rectangle textures cannot have mipmaps", *this); #endif (this->*parameteriImplementation)(GL_TEXTURE_MIN_FILTER, static_cast(filter)|static_cast(mipmap)); - return this; + return *this; } -AbstractTexture* AbstractTexture::generateMipmap() { +AbstractTexture& AbstractTexture::generateMipmap() { #ifndef MAGNUM_TARGET_GLES - CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", this); + CORRADE_ASSERT(_target != GL_TEXTURE_RECTANGLE, "AbstractTexture: rectangle textures cannot have mipmaps", *this); #endif (this->*mipmapImplementation)(); - return this; + return *this; } void AbstractTexture::mipmapImplementationDefault() { diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 422086634..9f34b50f5 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -141,7 +141,7 @@ class MAGNUM_EXPORT AbstractTexture { * @param mipmap Mipmap filtering. If set to anything else than * BaseMipLevel, make sure textures for all mip levels are set or * call generateMipmap(). - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Sets filter used when the object pixel size is smaller than the * texture size. If @extension{EXT,direct_state_access} is not @@ -155,12 +155,12 @@ class MAGNUM_EXPORT AbstractTexture { * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_MIN_FILTER} */ - AbstractTexture* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base); + AbstractTexture& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base); /** * @brief Set magnification filter * @param filter Filter - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Sets filter used when the object pixel size is larger than largest * texture size. If @extension{EXT,direct_state_access} is not @@ -170,15 +170,15 @@ class MAGNUM_EXPORT AbstractTexture { * or @fn_gl_extension{TextureParameter,EXT,direct_state_access} * with @def_gl{TEXTURE_MAG_FILTER} */ - AbstractTexture* setMagnificationFilter(Sampler::Filter filter) { + AbstractTexture& setMagnificationFilter(Sampler::Filter filter) { (this->*parameteriImplementation)(GL_TEXTURE_MAG_FILTER, static_cast(filter)); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES3 /** * @brief Set border color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Border color when wrapping is set to @ref Sampler::Wrapping "Sampler::Wrapping::ClampToBorder". * If @extension{EXT,direct_state_access} is not available, the texture @@ -189,18 +189,18 @@ class MAGNUM_EXPORT AbstractTexture { * with @def_gl{TEXTURE_BORDER_COLOR} * @requires_es_extension %Extension @es_extension{NV,texture_border_clamp} */ - AbstractTexture* setBorderColor(const Color4& color) { + AbstractTexture& setBorderColor(const Color4& color) { #ifndef MAGNUM_TARGET_GLES (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR, color.data()); #else (this->*parameterfvImplementation)(GL_TEXTURE_BORDER_COLOR_NV, color.data()); #endif - return this; + return *this; } /** * @brief Set max anisotropy - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default value is `1.0f`, which means no anisotropy. Set to value * greater than `1.0f` for anisotropic filtering. If @@ -213,9 +213,9 @@ class MAGNUM_EXPORT AbstractTexture { * @requires_extension %Extension @extension{EXT,texture_filter_anisotropic} * @requires_es_extension %Extension @es_extension2{EXT,texture_filter_anisotropic,texture_filter_anisotropic} */ - AbstractTexture* setMaxAnisotropy(Float anisotropy) { + AbstractTexture& setMaxAnisotropy(Float anisotropy) { (this->*parameterfImplementation)(GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); - return this; + return *this; } #endif @@ -234,7 +234,7 @@ class MAGNUM_EXPORT AbstractTexture { /** * @brief Generate mipmap - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Can not be used for rectangle textures. If * @extension{EXT,direct_state_access} is not available, the texture @@ -244,7 +244,7 @@ class MAGNUM_EXPORT AbstractTexture { * @fn_gl_extension{GenerateTextureMipmap,EXT,direct_state_access} * @requires_gl30 %Extension @extension{ARB,framebuffer_object} */ - AbstractTexture* generateMipmap(); + AbstractTexture& generateMipmap(); protected: /** diff --git a/src/Buffer.h b/src/Buffer.h index c16ac8c87..4076fa8ea 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -490,7 +490,7 @@ class MAGNUM_EXPORT Buffer { /** * @brief Set target hint - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available, the buffer * must be internally bound to some target before any operation. You @@ -503,9 +503,9 @@ class MAGNUM_EXPORT Buffer { * http://www.opengl.org/wiki/Vertex_Specification#Index_buffers * ... damned GL state */ - Buffer* setTargetHint(Target hint) { + Buffer& setTargetHint(Target hint) { _targetHint = hint; - return this; + return *this; } /** @@ -569,7 +569,7 @@ class MAGNUM_EXPORT Buffer { * @param size Data size * @param data Pointer to data * @param usage %Buffer usage - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * buffer is not already bound somewhere, it is bound to hinted target @@ -577,25 +577,25 @@ class MAGNUM_EXPORT Buffer { * @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferData} or * @fn_gl_extension{NamedBufferData,EXT,direct_state_access} */ - Buffer* setData(GLsizeiptr size, const GLvoid* data, Usage usage) { + Buffer& setData(GLsizeiptr size, const GLvoid* data, Usage usage) { (this->*dataImplementation)(size, data, usage); - return this; + return *this; } /** * @brief Set buffer data * @param data Fixed-size array with data * @param usage %Buffer usage - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setData(GLsizeiptr, const GLvoid*, Usage). */ #ifdef CORRADE_GCC46_COMPATIBILITY #define size size_ /* With GCC 4.6 it conflicts with size(). WTF. */ #endif - template Buffer* setData(const T(&data)[size], Usage usage) { + template Buffer& setData(const T(&data)[size], Usage usage) { setData(size*sizeof(T), data, usage); - return this; + return *this; } #ifdef CORRADE_GCC46_COMPATIBILITY #undef size @@ -605,18 +605,19 @@ class MAGNUM_EXPORT Buffer { * @brief Set buffer data * @param data Vector with data * @param usage %Buffer usage - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setData(GLsizeiptr, const GLvoid*, Usage) */ - template Buffer* setData(const std::vector& data, Usage usage) { + template Buffer& setData(const std::vector& data, Usage usage) { setData(data.size()*sizeof(T), data.data(), usage); - return this; + return *this; } /** @overload */ - template void setData(const std::array& data, Usage usage) { + template Buffer& setData(const std::array& data, Usage usage) { setData(data.size()*sizeof(T), data.data(), usage); + return *this; } /** @@ -624,7 +625,7 @@ class MAGNUM_EXPORT Buffer { * @param offset Offset in the buffer * @param size Data size * @param data Pointer to data - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * buffer is not already bound somewhere, it is bound to hinted target @@ -632,25 +633,25 @@ class MAGNUM_EXPORT Buffer { * @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferSubData} * or @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access} */ - Buffer* setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { + Buffer& setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) { (this->*subDataImplementation)(offset, size, data); - return this; + return *this; } /** * @brief Set buffer subdata * @param offset Offset in the buffer * @param data Fixed-size array with data - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setSubData(GLintptr, GLsizeiptr, const GLvoid*) */ #ifdef CORRADE_GCC46_COMPATIBILITY #define size size_ /* With GCC 4.6 it conflicts with size(). WTF. */ #endif - template Buffer* setSubData(GLintptr offset, const T(&data)[size]) { + template Buffer& setSubData(GLintptr offset, const T(&data)[size]) { setSubData(offset, size*sizeof(T), data); - return this; + return *this; } #ifdef CORRADE_GCC46_COMPATIBILITY #undef size @@ -660,48 +661,48 @@ class MAGNUM_EXPORT Buffer { * @brief Set buffer subdata * @param offset Offset in the buffer * @param data Vector with data - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setSubData(GLintptr, GLsizeiptr, const GLvoid*) */ - template Buffer* setSubData(GLintptr offset, const std::vector& data) { + template Buffer& setSubData(GLintptr offset, const std::vector& data) { setSubData(offset, data.size()*sizeof(T), data.data()); - return this; + return *this; } /** @overload */ - template Buffer* setSubData(GLintptr offset, const std::array& data) { + template Buffer& setSubData(GLintptr offset, const std::array& data) { setSubData(offset, data.size()*sizeof(T), data.data()); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES /** * @brief Invalidate buffer data - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} * is not available, this function does nothing. * @see @ref MapFlag "MapFlag::InvalidateBuffer", @fn_gl{InvalidateBufferData} */ - Buffer* invalidateData() { + Buffer& invalidateData() { (this->*invalidateImplementation)(); - return this; + return *this; } /** * @brief Invalidate buffer subdata * @param offset Offset into the buffer * @param length Length of the invalidated range - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If running on OpenGL ES or extension @extension{ARB,invalidate_subdata} * is not available, this function does nothing. * @see @ref MapFlag "MapFlag::InvalidateRange", @fn_gl{InvalidateBufferData} */ - Buffer* invalidateSubData(GLintptr offset, GLsizeiptr length) { + Buffer& invalidateSubData(GLintptr offset, GLsizeiptr length) { (this->*invalidateSubImplementation)(offset, length); - return this; + return *this; } #endif @@ -772,7 +773,7 @@ class MAGNUM_EXPORT Buffer { * @brief Flush mapped range * @param offset Offset relative to start of mapped range * @param length Length of the flushed memory - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Flushes specified subsection of mapped range. Use only if you called * map() with @ref MapFlag "MapFlag::FlushExplicit" flag. See @@ -786,9 +787,9 @@ class MAGNUM_EXPORT Buffer { * @requires_gl30 %Extension @extension{ARB,map_buffer_range} * @requires_gles30 %Extension @es_extension{EXT,map_buffer_range} */ - Buffer* flushMappedRange(GLintptr offset, GLsizeiptr length) { + Buffer& flushMappedRange(GLintptr offset, GLsizeiptr length) { (this->*flushMappedRangeImplementation)(offset, length); - return this; + return *this; } /** diff --git a/src/CubeMapTexture.h b/src/CubeMapTexture.h index 7d93fbb4a..352223448 100644 --- a/src/CubeMapTexture.h +++ b/src/CubeMapTexture.h @@ -60,9 +60,9 @@ Image2D positiveX({256, 256}, ImageFormat::RGBA, ImageType::UnsignedByte, dataPo CubeMapTexture texture; texture.setMagnificationFilter(Sampler::Filter::Linear) // ... - ->setStorage(Math::log2(256)+1, TextureFormat::RGBA8, {256, 256}) - ->setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, {}, &positiveX) - ->setSubImage(CubeMapTexture::Coordinate::NegativeX, 0, {}, &negativeX) + .setStorage(Math::log2(256)+1, TextureFormat::RGBA8, {256, 256}) + .setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, {}, &positiveX) + .setSubImage(CubeMapTexture::Coordinate::NegativeX, 0, {}, &negativeX) // ... @endcode @@ -101,9 +101,9 @@ class CubeMapTexture: public AbstractTexture { * * See Texture::setWrapping() for more information. */ - CubeMapTexture* setWrapping(const Array3D& wrapping) { + CubeMapTexture& setWrapping(const Array3D& wrapping) { DataHelper<3>::setWrapping(this, wrapping); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES @@ -125,9 +125,9 @@ class CubeMapTexture: public AbstractTexture { * * See Texture::setStorage() for more information. */ - CubeMapTexture* setStorage(Int levels, TextureFormat internalFormat, const Vector2i& size) { + CubeMapTexture& setStorage(Int levels, TextureFormat internalFormat, const Vector2i& size) { DataHelper<2>::setStorage(this, _target, levels, internalFormat, size); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES @@ -166,20 +166,20 @@ class CubeMapTexture: public AbstractTexture { * @param level Mip level * @param internalFormat Internal format * @param image %Image - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * See Texture::setImage() for more information. */ - CubeMapTexture* setImage(Coordinate coordinate, Int level, TextureFormat internalFormat, const ImageReference2D& image) { + CubeMapTexture& setImage(Coordinate coordinate, Int level, TextureFormat internalFormat, const ImageReference2D& image) { DataHelper<2>::setImage(this, static_cast(coordinate), level, internalFormat, image); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES2 /** @overload */ - CubeMapTexture* setImage(Coordinate coordinate, Int level, TextureFormat internalFormat, BufferImage2D& image) { + CubeMapTexture& setImage(Coordinate coordinate, Int level, TextureFormat internalFormat, BufferImage2D& image) { DataHelper<2>::setImage(this, static_cast(coordinate), level, internalFormat, image); - return this; + return *this; } #endif @@ -189,20 +189,20 @@ class CubeMapTexture: public AbstractTexture { * @param level Mip level * @param offset Offset where to put data in the texture * @param image %Image - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * See Texture::setSubImage() for more information. */ - CubeMapTexture* setSubImage(Coordinate coordinate, Int level, const Vector2i& offset, const ImageReference2D& image) { + CubeMapTexture& setSubImage(Coordinate coordinate, Int level, const Vector2i& offset, const ImageReference2D& image) { DataHelper<2>::setSubImage(this, static_cast(coordinate), level, offset, image); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES2 /** @overload */ - CubeMapTexture* setSubImage(Coordinate coordinate, Int level, const Vector2i& offset, BufferImage2D& image) { + CubeMapTexture& setSubImage(Coordinate coordinate, Int level, const Vector2i& offset, BufferImage2D& image) { DataHelper<2>::setSubImage(this, static_cast(coordinate), level, offset, image); - return this; + return *this; } #endif @@ -224,27 +224,27 @@ class CubeMapTexture: public AbstractTexture { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - CubeMapTexture* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { + CubeMapTexture& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { AbstractTexture::setMinificationFilter(filter, mipmap); - return this; + return *this; } - CubeMapTexture* setMagnificationFilter(Sampler::Filter filter) { + CubeMapTexture& setMagnificationFilter(Sampler::Filter filter) { AbstractTexture::setMagnificationFilter(filter); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES3 - CubeMapTexture* setBorderColor(const Color4& color) { + CubeMapTexture& setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); - return this; + return *this; } - CubeMapTexture* setMaxAnisotropy(Float anisotropy) { + CubeMapTexture& setMaxAnisotropy(Float anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); - return this; + return *this; } #endif - CubeMapTexture* generateMipmap() { + CubeMapTexture& generateMipmap() { AbstractTexture::generateMipmap(); - return this; + return *this; } #endif }; diff --git a/src/CubeMapTextureArray.h b/src/CubeMapTextureArray.h index 1529d295a..921a10ad5 100644 --- a/src/CubeMapTextureArray.h +++ b/src/CubeMapTextureArray.h @@ -53,7 +53,7 @@ Image3D dummy({64, 64, 16*6}, ImageFormat::RGBA, ImageType::UnsignedByte, nullpt CubeMapTextureArray texture; texture.setMagnificationFilter(Sampler::Filter::Linear) // ... - ->setStorage(Math::log2(64)+1, TextureFormat::RGBA8, {64, 64, 16}); + .setStorage(Math::log2(64)+1, TextureFormat::RGBA8, {64, 64, 16}); for(std::size_t i = 0; i != 16; ++i) { void* dataPositiveX = ...; @@ -105,9 +105,9 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setWrapping() for more information. */ - CubeMapTextureArray* setWrapping(const Array3D& wrapping) { + CubeMapTextureArray& setWrapping(const Array3D& wrapping) { DataHelper<3>::setWrapping(this, wrapping); - return this; + return *this; } /** @@ -126,9 +126,9 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setStorage() for more information. */ - CubeMapTextureArray* setStorage(Int levels, TextureFormat internalFormat, const Vector3i& size) { + CubeMapTextureArray& setStorage(Int levels, TextureFormat internalFormat, const Vector3i& size) { DataHelper<3>::setStorage(this, _target, levels, internalFormat, size); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES @@ -167,7 +167,7 @@ class CubeMapTextureArray: public AbstractTexture { * @param internalFormat Internal format * @param image Image, ImageReference, BufferImage or * Trade::ImageData of the same dimension count - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Sets texture image data from three-dimensional image for all cube * faces for all layers. Each group of 6 2D images is one cube map @@ -175,15 +175,15 @@ class CubeMapTextureArray: public AbstractTexture { * * See Texture::setImage() for more information. */ - CubeMapTextureArray* setImage(Int level, TextureFormat internalFormat, const ImageReference3D& image) { + CubeMapTextureArray& setImage(Int level, TextureFormat internalFormat, const ImageReference3D& image) { DataHelper<3>::setImage(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, internalFormat, image); - return this; + return *this; } /** @overload */ - CubeMapTextureArray* setImage(Int level, TextureFormat internalFormat, BufferImage3D& image) { + CubeMapTextureArray& setImage(Int level, TextureFormat internalFormat, BufferImage3D& image) { DataHelper<3>::setImage(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, internalFormat, image); - return this; + return *this; } /** @@ -192,7 +192,7 @@ class CubeMapTextureArray: public AbstractTexture { * @param offset Offset where to put data in the texture * @param image Image3D, ImageReference3D, BufferImage3D or * Trade::ImageData3D - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Sets texture image subdata for more than one level/face at once. * @@ -205,15 +205,15 @@ class CubeMapTextureArray: public AbstractTexture { * * @see setSubImage(Int, Coordinate, Int, const Math::Vector<2, Int>&, const Image*) */ - CubeMapTextureArray* setSubImage(Int level, const Vector3i& offset, const ImageReference3D& image) { + CubeMapTextureArray& setSubImage(Int level, const Vector3i& offset, const ImageReference3D& image) { DataHelper<3>::setSubImage(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, offset, image); - return this; + return *this; } /** @overload */ - CubeMapTextureArray* setSubImage(Int level, const Vector3i& offset, BufferImage3D& image) { + CubeMapTextureArray& setSubImage(Int level, const Vector3i& offset, BufferImage3D& image) { DataHelper<3>::setSubImage(this, GL_TEXTURE_CUBE_MAP_ARRAY, level, offset, image); - return this; + return *this; } /** @@ -234,27 +234,27 @@ class CubeMapTextureArray: public AbstractTexture { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - CubeMapTextureArray* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { + CubeMapTextureArray& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { AbstractTexture::setMinificationFilter(filter, mipmap); - return this; + return *this; } - CubeMapTextureArray* setMagnificationFilter(Sampler::Filter filter) { + CubeMapTextureArray& setMagnificationFilter(Sampler::Filter filter) { AbstractTexture::setMagnificationFilter(filter); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES3 - CubeMapTextureArray* setBorderColor(const Color4& color) { + CubeMapTextureArray& setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); - return this; + return *this; } - CubeMapTextureArray* setMaxAnisotropy(Float anisotropy) { + CubeMapTextureArray& setMaxAnisotropy(Float anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); - return this; + return *this; } #endif - CubeMapTextureArray* generateMipmap() { + CubeMapTextureArray& generateMipmap() { AbstractTexture::generateMipmap(); - return this; + return *this; } #endif }; diff --git a/src/DebugTools/ForceRenderer.cpp b/src/DebugTools/ForceRenderer.cpp index c5357f9dd..ac0cf7427 100644 --- a/src/DebugTools/ForceRenderer.cpp +++ b/src/DebugTools/ForceRenderer.cpp @@ -87,17 +87,17 @@ template ForceRenderer::ForceRenderer(SceneG Mesh* mesh = new Mesh; mesh->setPrimitive(Mesh::Primitive::Lines) - ->setIndexCount(indices.size()) - ->addVertexBuffer(vertexBuffer, 0, + .setIndexCount(indices.size()) + .addVertexBuffer(vertexBuffer, 0, typename Shaders::Flat::Position(Shaders::Flat::Position::Components::Two)) - ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size()); - ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); + .setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size()); + ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } template void ForceRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation(transformationMatrix.transformPoint(forcePosition), *force)*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->scale()))) - ->setColor(options->color()) - ->use(); + .setColor(options->color()) + .use(); mesh->draw(); } diff --git a/src/DebugTools/ForceRenderer.h b/src/DebugTools/ForceRenderer.h index 9dacd0986..df5babf4e 100644 --- a/src/DebugTools/ForceRenderer.h +++ b/src/DebugTools/ForceRenderer.h @@ -51,13 +51,13 @@ class ForceRendererOptions { /** * @brief Set color of rendered arrow - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is 100% opaque white. */ - ForceRendererOptions* setColor(const Color4& color) { + ForceRendererOptions& setColor(const Color4& color) { _color = color; - return this; + return *this; } /** @brief Scale of rendered arrow */ @@ -65,13 +65,13 @@ class ForceRendererOptions { /** * @brief Set scale of rendered arrow - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is `1.0f`. */ - ForceRendererOptions* setSize(Float size) { + ForceRendererOptions& setSize(Float size) { _size = size; - return this; + return *this; } private: @@ -89,9 +89,9 @@ See @ref debug-tools-renderers for more information. Example code: @code -// Create some options -DebugTools::ResourceManager::instance()->set("my", (new DebugTools::ForceRendererOptions) - ->setScale(5.0f)->setColor(Color3::fromHSV(120.0_degf, 1.0f, 0.7f))); +DebugTools::ResourceManager::instance()->set("my", DebugTools::ForceRendererOptions() + .setScale(5.0f) + .setColor(Color3::fromHSV(120.0_degf, 1.0f, 0.7f)); // Create debug renderer for given object, use "my" options for it Object3D* object; diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp index 6ee4d5f4c..40ceea33f 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -52,8 +52,8 @@ template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, /* Mesh configuration */ Mesh* mesh = new Mesh; mesh->setPrimitive(data.primitive()) - ->setVertexCount(data.positions(0).size()) - ->addVertexBuffer(buffer, 0, Shaders::Flat2D::Position()); + .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 */ @@ -74,8 +74,8 @@ template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, /* Mesh configuration */ Mesh* mesh = new Mesh; mesh->setPrimitive(data.primitive()) - ->setVertexCount(data.positions(0).size()) - ->addVertexBuffer(vertexBuffer, 0, Shaders::Flat3D::Position()); + .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 */ diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index 60bd5a346..80e90c22d 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -37,8 +37,8 @@ template void AxisAlignedBoxRenderer::draw(R this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* DimensionTraits::MatrixType::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)* DimensionTraits::MatrixType::scaling(axisAlignedBox.max()-axisAlignedBox.min())) - ->setColor(options->color()) - ->use(); + .setColor(options->color()) + .use(); this->wireframeMesh->draw(); } diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index c1e443315..245e112a9 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -35,8 +35,8 @@ template BoxRenderer::BoxRenderer(const Shap template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation()) - ->setColor(options->color()) - ->use(); + .setColor(options->color()) + .use(); this->wireframeMesh->draw(); } diff --git a/src/DebugTools/Implementation/LineSegmentRenderer.cpp b/src/DebugTools/Implementation/LineSegmentRenderer.cpp index b5527d016..8b6cd5020 100644 --- a/src/DebugTools/Implementation/LineSegmentRenderer.cpp +++ b/src/DebugTools/Implementation/LineSegmentRenderer.cpp @@ -57,8 +57,8 @@ template LineSegmentRenderer::LineSegmentRen template void LineSegmentRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* Implementation::lineSegmentRendererTransformation(line.a(), line.b())) - ->setColor(options->color()) - ->use(); + .setColor(options->color()) + .use(); this->wireframeMesh->draw(); } diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp index 6e7ab84e7..43459800c 100644 --- a/src/DebugTools/Implementation/PointRenderer.cpp +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -57,8 +57,8 @@ template void PointRenderer::draw(ResourcewireframeShader->setTransformationProjectionMatrix(projectionMatrix* DimensionTraits::MatrixType::translation(point.position())* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->pointSize()/2))) - ->setColor(options->color()) - ->use(); + .setColor(options->color()) + .use(); this->wireframeMesh->draw(); } diff --git a/src/DebugTools/Implementation/SphereRenderer.cpp b/src/DebugTools/Implementation/SphereRenderer.cpp index 43faf06a1..0a5a25bbb 100644 --- a/src/DebugTools/Implementation/SphereRenderer.cpp +++ b/src/DebugTools/Implementation/SphereRenderer.cpp @@ -49,8 +49,8 @@ template void SphereRenderer::draw(Resource< this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* DimensionTraits::MatrixType::translation(sphere.position())* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(sphere.radius()))) - ->setColor(options->color()) - ->use(); + .setColor(options->color()) + .use(); this->wireframeMesh->draw(); } diff --git a/src/DebugTools/ObjectRenderer.cpp b/src/DebugTools/ObjectRenderer.cpp index 834ce60db..143fcf8b3 100644 --- a/src/DebugTools/ObjectRenderer.cpp +++ b/src/DebugTools/ObjectRenderer.cpp @@ -165,17 +165,17 @@ template ObjectRenderer::ObjectRenderer(Scen ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); mesh->setPrimitive(Mesh::Primitive::Lines) - ->setIndexCount(Renderer::indices.size()) - ->addInterleavedVertexBuffer(vertexBuffer, 0, + .setIndexCount(Renderer::indices.size()) + .addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColor::Position(), typename Shaders::VertexColor::Color()) - ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, Renderer::positions.size()); + .setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, Renderer::positions.size()); ResourceManager::instance()->set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); } template void ObjectRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->size()))) - ->use(); + .use(); mesh->draw(); } diff --git a/src/DebugTools/ObjectRenderer.h b/src/DebugTools/ObjectRenderer.h index cfc48c73e..df99e2b34 100644 --- a/src/DebugTools/ObjectRenderer.h +++ b/src/DebugTools/ObjectRenderer.h @@ -50,13 +50,13 @@ class ObjectRendererOptions { /** * @brief Set size of the rendered axes - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is `1.0f`. */ - ObjectRendererOptions* setSize(Float size) { + ObjectRendererOptions& setSize(Float size) { _size = size; - return this; + return *this; } private: @@ -74,8 +74,7 @@ Visualizes object position, rotation and scale using colored axes. See Example code: @code // Create some options -DebugTools::ResourceManager::instance()->set("my", (new DebugTools::ObjectRendererOptions) - ->setSize(0.3f)); +DebugTools::ResourceManager::instance()->set("my", DebugTools::ObjectRendererOptions().setSize(0.3f)); // Create debug renderer for given object, use "my" options for it Object3D* object; diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index d3af6f438..0da35cf1c 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -73,13 +73,13 @@ class ShapeRendererOptions { /** * @brief Set shape rendering mode - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is @ref RenderMode "RenderMode::Wireframe". */ - ShapeRendererOptions* setRenderMode(RenderMode mode) { + ShapeRendererOptions& setRenderMode(RenderMode mode) { _renderMode = mode; - return this; + return *this; } /** @brief Color of rendered shape */ @@ -87,13 +87,13 @@ class ShapeRendererOptions { /** * @brief Set color of rendered shape - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is 100% opaque white. */ - ShapeRendererOptions* setColor(const Color4& color) { + ShapeRendererOptions& setColor(const Color4& color) { _color = color; - return this; + return *this; } /** @brief Point size */ @@ -101,14 +101,14 @@ class ShapeRendererOptions { /** * @brief Set point size - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Size of rendered crosshairs, representing Shapes::Point shapes. * Default is `0.25f`. */ - ShapeRendererOptions* setPointSize(Float size) { + ShapeRendererOptions& setPointSize(Float size) { _pointSize = size; - return this; + return *this; } private: @@ -128,8 +128,8 @@ Visualizes collision shapes using wireframe primitives. See Example code: @code // Create some options -DebugTools::ResourceManager::instance()->set("red", (new DebugTools::ShapeRendererOptions) - ->setColor({1.0f, 0.0f, 0.0f})); +DebugTools::ResourceManager::instance()->set("red", + DebugTools::ShapeRendererOptions().setColor({1.0f, 0.0f, 0.0f})); // Create debug renderer for given shape, use "red" options for it Shapes::AbstractShape2D* shape; diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 60a628f30..cc6e7789e 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -37,7 +37,7 @@ DefaultFramebuffer defaultFramebuffer; DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } #ifndef MAGNUM_TARGET_GLES2 -DefaultFramebuffer* DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { +DefaultFramebuffer& DefaultFramebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) @@ -52,7 +52,7 @@ DefaultFramebuffer* DefaultFramebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; - return this; + return *this; } #endif diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index a7e4bb7c0..c860e5d3e 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -309,7 +309,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { #ifndef MAGNUM_TARGET_GLES2 /** * @brief Map shader outputs to buffer attachment - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @p attachments is list of shader outputs mapped to buffer * attachments. %Shader outputs which are not listed are not used, you @@ -328,12 +328,12 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - DefaultFramebuffer* mapForDraw(std::initializer_list> attachments); + DefaultFramebuffer& mapForDraw(std::initializer_list> attachments); /** * @brief Map shader output to buffer attachment * @param attachment %Buffer attachment - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -347,16 +347,16 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - DefaultFramebuffer* mapForDraw(DrawAttachment attachment) { + DefaultFramebuffer& mapForDraw(DrawAttachment attachment) { (this->*drawBufferImplementation)(static_cast(attachment)); - return this; + return *this; } #endif /** * @brief Map given attachment for reading * @param attachment %Buffer attachment - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebuffer is not currently bound, it is bound before the @@ -365,9 +365,9 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - DefaultFramebuffer* mapForRead(ReadAttachment attachment) { + DefaultFramebuffer& mapForRead(ReadAttachment attachment) { (this->*readBufferImplementation)(static_cast(attachment)); - return this; + return *this; } /** @@ -403,9 +403,9 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - DefaultFramebuffer* setViewport(const Rectanglei& rectangle) { + DefaultFramebuffer& setViewport(const Rectanglei& rectangle) { AbstractFramebuffer::setViewport(rectangle); - return this; + return *this; } #endif diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 001f8d71a..fcadfd546 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -67,7 +67,7 @@ Framebuffer::~Framebuffer() { glDeleteFramebuffers(1, &_id); } -Framebuffer* Framebuffer::mapForDraw(std::initializer_list> attachments) { +Framebuffer& Framebuffer::mapForDraw(std::initializer_list> attachments) { /* Max attachment location */ std::size_t max = 0; for(const auto& attachment: attachments) @@ -82,7 +82,7 @@ Framebuffer* Framebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; - return this; + return *this; } void Framebuffer::invalidate(std::initializer_list attachments) { @@ -107,10 +107,10 @@ void Framebuffer::invalidate(std::initializer_list attac delete[] _attachments; } -Framebuffer* Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int mipLevel) { +Framebuffer& Framebuffer::attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int mipLevel) { /** @todo Check for texture target compatibility */ (this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel); - return this; + return *this; } void Framebuffer::initializeContextBasedFunctionality(Context* context) { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index d7b66ca3e..8e1c84768 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -304,7 +304,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { /** * @brief Map shader output to attachments - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @p attachments is list of shader outputs mapped to framebuffer * color attachment IDs. %Shader outputs which are not listed are not @@ -322,12 +322,12 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - Framebuffer* mapForDraw(std::initializer_list> attachments); + Framebuffer& mapForDraw(std::initializer_list> attachments); /** * @brief Map shader output to attachment * @param attachment Draw attachment - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -340,9 +340,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl{DrawBuffers} in OpenGL ES 3.0 * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - Framebuffer* mapForDraw(DrawAttachment attachment) { + Framebuffer& mapForDraw(DrawAttachment attachment) { (this->*drawBufferImplementation)(GLenum(attachment)); - return this; + return *this; } /** @@ -379,7 +379,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { /** * @brief Map given color attachment for reading * @param attachment Color attachment - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -388,16 +388,16 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} */ - Framebuffer* mapForRead(ColorAttachment attachment) { + Framebuffer& mapForRead(ColorAttachment attachment) { (this->*readBufferImplementation)(GLenum(attachment)); - return this; + return *this; } /** * @brief Attach renderbuffer to given buffer * @param attachment %Buffer attachment * @param renderbuffer %Renderbuffer - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -405,9 +405,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} */ - Framebuffer* attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { + Framebuffer& attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { (this->*renderbufferImplementation)(attachment, renderbuffer); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES @@ -416,7 +416,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param attachment %Buffer attachment * @param texture 1D texture * @param level Mip level - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -425,9 +425,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access} * @requires_gl Only 2D and 3D textures are available in OpenGL ES. */ - Framebuffer* attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { + Framebuffer& attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { (this->*texture1DImplementation)(attachment, texture, level); - return this; + return *this; } #endif @@ -436,7 +436,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param attachment %Buffer attachment * @param texture 2D texture * @param level Mip level - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -444,7 +444,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - Framebuffer* attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); + Framebuffer& attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); /** * @brief Attach cube map texture to given buffer @@ -452,7 +452,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param texture Cube map texture * @param coordinate Cube map coordinate * @param level Mip level - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -460,9 +460,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - Framebuffer* attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { + Framebuffer& attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { (this->*texture2DImplementation)(attachment, GLenum(coordinate), texture->id(), level); - return this; + return *this; } /** @@ -471,7 +471,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @param texture 3D texture * @param level Mip level * @param layer Layer of 2D image within a 3D texture - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -480,17 +480,17 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - Framebuffer* attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { + Framebuffer& attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { /** @todo Check for texture target compatibility */ (this->*texture3DImplementation)(attachment, texture, level, layer); - return this; + return *this; } /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - Framebuffer* setViewport(const Rectanglei& rectangle) { + Framebuffer& setViewport(const Rectanglei& rectangle) { AbstractFramebuffer::setViewport(rectangle); - return this; + return *this; } #endif diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 368ec21a3..d8d519a57 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -117,7 +117,7 @@ Mesh& Mesh::operator=(Mesh&& other) { return *this; } -Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { +Mesh& Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end) { #ifdef CORRADE_TARGET_NACL CORRADE_ASSERT(buffer->targetHint() == Buffer::Target::ElementArray, "Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer->targetHint(), this); @@ -133,7 +133,7 @@ Mesh* Mesh::setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, Unsi static_cast(end); #endif (this->*bindIndexBufferImplementation)(buffer); - return this; + return *this; } void Mesh::draw() { diff --git a/src/Mesh.h b/src/Mesh.h index 00f744af0..bc37733f1 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -77,19 +77,19 @@ class MyShader: public AbstractShaderProgram { // ... }; -Mesh* mesh; -Buffer* vertexBuffer; +Mesh mesh; +Buffer vertexBuffer; // Fill vertex buffer with position data static constexpr Vector3 positions[30] = { // ... }; -vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); +vertexBuffer.setData(positions, Buffer::Usage::StaticDraw); // Set primitive and vertex count, add the buffer and specify its layout -mesh->setPrimitive(Mesh::Primitive::Triangles) - ->setVertexCount(30) - ->addVertexBuffer(vertexBuffer, 0, MyShader::Position()); +mesh.setPrimitive(Mesh::Primitive::Triangles) + .setVertexCount(30) + .addVertexBuffer(vertexBuffer, 0, MyShader::Position()); @endcode @subsubsection Mesh-configuration-examples-nonindexed-phong Interleaved vertex data @@ -97,8 +97,8 @@ mesh->setPrimitive(Mesh::Primitive::Triangles) @code // Non-indexed primitive with positions and normals Trade::MeshData3D plane = Primitives::Plane::solid(); -Mesh* mesh; -Buffer* vertexBuffer; +Mesh mesh; +Buffer vertexBuffer; // Fill vertex buffer with interleaved position and normal data MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, @@ -106,8 +106,8 @@ MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, // Set primitive and specify layout of interleaved vertex buffer, vertex count // has been already set by MeshTools::interleave() -mesh->setPrimitive(plane.primitive()) - ->addInterleavedVertexBuffer(buffer, 0, +mesh.setPrimitive(plane.primitive()) + .addInterleavedVertexBuffer(buffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); @endcode @@ -122,33 +122,33 @@ class MyShader: public AbstractShaderProgram { // ... }; -Buffer *vertexBuffer, *indexBuffer; -Mesh* mesh; +Buffer vertexBuffer, indexBuffer; +Mesh mesh; // Fill vertex buffer with position data static constexpr Vector3 positions[300] = { // ... }; -vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); +vertexBuffer.setData(positions, Buffer::Usage::StaticDraw); // Fill index buffer with index data static constexpr GLubyte indices[75] = { // ... }; -indexBuffer->setData(indices, Buffer::Usage::StaticDraw); +indexBuffer.setData(indices, Buffer::Usage::StaticDraw); // Set primitive, index count, specify the buffers -mesh->setPrimitive(Mesh::Primitive::Triangles) - ->setIndexCount(75) - ->addVertexBuffer(vertexBuffer, 0, MyShader::Position()) - ->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229); +mesh.setPrimitive(Mesh::Primitive::Triangles) + .setIndexCount(75) + .addVertexBuffer(vertexBuffer, 0, MyShader::Position()) + .setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229); @endcode @code // Indexed primitive Trade::MeshData3D cube = Primitives::Cube::solid(); -Buffer *vertexBuffer, *indexBuffer; -Mesh* mesh; +Buffer vertexBuffer, indexBuffer; +Mesh mesh; // Fill vertex buffer with interleaved position and normal data MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, @@ -160,8 +160,8 @@ MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, // Set primitive and specify layout of interleaved vertex buffer. Index count // and index buffer has been already specified by MeshTools::compressIndices(). -mesh->setPrimitive(plane.primitive()) - ->addInterleavedVertexBuffer(vertexBuffer, 0, +mesh.setPrimitive(plane.primitive()) + .addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); @endcode @@ -366,15 +366,15 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set primitive type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is @ref Primitive "Primitive::Triangles". * @see setVertexCount(), addVertexBuffer(), * addInterleavedVertexBuffer(), addVertexBufferStride() */ - Mesh* setPrimitive(Primitive primitive) { + Mesh& setPrimitive(Primitive primitive) { _primitive = primitive; - return this; + return *this; } /** @brief Vertex count */ @@ -382,15 +382,15 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set vertex count - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is zero. * @see setPrimitive(), addVertexBuffer(), addInterleavedVertexBuffer(), * addVertexBufferStride(), MeshTools::interleave() */ - Mesh* setVertexCount(Int vertexCount) { + Mesh& setVertexCount(Int vertexCount) { _vertexCount = vertexCount; - return this; + return *this; } /** @brief Index count */ @@ -398,19 +398,19 @@ class MAGNUM_EXPORT Mesh { /** * @brief Set index count - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is zero. * @see setIndexBuffer(), MeshTools::compressIndices() */ - Mesh* setIndexCount(Int count) { + Mesh& setIndexCount(Int count) { _indexCount = count; - return this; + return *this; } /** * @brief Add buffer with non-interleaved vertex attributes for use with given shader - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Attribute list is combination of * @ref AbstractShaderProgram::Attribute "attribute definitions" @@ -425,20 +425,20 @@ class MAGNUM_EXPORT Mesh { * but it accepts only position and normal, so you have to skip the * texture coordinate array: * @code - * Mesh* mesh; - * Buffer* buffer; - * mesh->addVertexBuffer(buffer, + * Mesh mesh; + * Buffer buffer; + * mesh.addVertexBuffer(buffer, * 35, // offset of the data * Shaders::PhongShader::Position(), // position array - * sizeof(Vector2)*mesh->vertexCount(), // skip texture coordinate array + * sizeof(Vector2)*mesh.vertexCount(), // skip texture coordinate array * Shaders::PhongShader::Normal()); // normal array * @endcode * * Vou can also achieve the same effect by calling this function more * times with absolute offsets: * @code - * mesh->addVertexBuffer(buffer, 35, Shaders::PhongShader::Position()); - * ->addVertexBuffer(buffer, 35 + (sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2))* + * mesh.addVertexBuffer(buffer, 35, Shaders::PhongShader::Position()); + * .addVertexBuffer(buffer, 35 + (sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2))* * mesh->vertexCount(), Shaders::PhongShader::Normal()); * @endcode * @@ -457,11 +457,11 @@ class MAGNUM_EXPORT Mesh { * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} * if @extension{APPLE,vertex_array_object} is available */ - template Mesh* addVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes); + template Mesh& addVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes); /** * @brief Add buffer with interleaved vertex attributes for use with given shader - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Parameter @p offset is offset of the interleaved array from the * beginning, attribute list is combination of @@ -478,9 +478,9 @@ class MAGNUM_EXPORT Mesh { * position and normal, so you have to skip weight and texture * coordinate in each vertex: * @code - * Mesh* mesh; - * Buffer* buffer; - * mesh->addInterleavedVertexBuffer(buffer, + * Mesh mesh; + * Buffer buffer; + * mesh.addInterleavedVertexBuffer(buffer, * 35, // skip other data * sizeof(Float), // skip vertex weight * Shaders::PhongShader::Position(), // vertex position @@ -498,9 +498,9 @@ class MAGNUM_EXPORT Mesh { * sizeof(Vector2) + * sizeof(Shaders::PhongShader::Normal::Type); * - * mesh->addVertexBufferStride(buffer, 35 + sizeof(Float), + * mesh.addVertexBufferStride(buffer, 35 + sizeof(Float), * stride, Shaders::PhongShader::Position()); - * ->addVertexBufferStride(buffer, 35 + sizeof(Float) + + * .addVertexBufferStride(buffer, 35 + sizeof(Float) + * sizeof(Shaders::PhongShader::Position::Type) + sizeof(Vector2), * stride, Shaders::PhongShader::Normal()); * @endcode @@ -517,20 +517,20 @@ class MAGNUM_EXPORT Mesh { * @fn_gl_extension{VertexArrayVertexAttribOffset,EXT,direct_state_access} * if @extension{APPLE,vertex_array_object} is available */ - template inline Mesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { + template inline Mesh& addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { addInterleavedVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); - return this; + return *this; } /** * @brief Add buffer with interleaved vertex attributes for use with given shader - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * See addInterleavedVertexBuffer() for more information. */ - template inline Mesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { + template inline Mesh& addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { addInterleavedVertexBufferInternal(buffer, offset, stride, attribute); - return this; + return *this; } /** @@ -540,7 +540,7 @@ class MAGNUM_EXPORT Mesh { * @param type Index data type * @param start Minimum array index contained in the buffer * @param end Maximum array index contained in the buffer - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * The smaller range is specified with @p start and @p end the less * memory operations are needed (and possibly some optimizations), @@ -553,14 +553,14 @@ class MAGNUM_EXPORT Mesh { * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end); + Mesh& setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end); /** * @brief Set index buffer * @param buffer Index buffer * @param offset Offset into the buffer * @param type Index data type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Prefer to use setIndexBuffer(Buffer*, GLintptr, IndexType, UnsignedInt, UnsignedInt) * for better performance. @@ -568,7 +568,7 @@ class MAGNUM_EXPORT Mesh { * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - Mesh* setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type) { + Mesh& setIndexBuffer(Buffer* buffer, GLintptr offset, IndexType type) { return setIndexBuffer(buffer, offset, type, 0, 0); } @@ -783,12 +783,12 @@ Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::Primitive value); /** @debugoperator{Magnum::Mesh} */ Debug MAGNUM_EXPORT operator<<(Debug debug, Mesh::IndexType value); -template inline Mesh* Mesh::addVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { +template inline Mesh& Mesh::addVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { CORRADE_ASSERT(sizeof...(attributes) == 1 || _vertexCount != 0, - "Mesh::addVertexBuffer(): vertex count must be set before binding attributes", this); + "Mesh::addVertexBuffer(): vertex count must be set before binding attributes", *this); addVertexBufferInternal(buffer, offset, attributes...); - return this; + return *this; } diff --git a/src/MeshTools/CompressIndices.cpp b/src/MeshTools/CompressIndices.cpp index 2d765bafc..df2e871ed 100644 --- a/src/MeshTools/CompressIndices.cpp +++ b/src/MeshTools/CompressIndices.cpp @@ -80,7 +80,7 @@ void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std: std::tie(indexCount, indexType, data) = compressIndicesInternal(indices, *minmax.second); mesh->setIndexCount(indices.size()) - ->setIndexBuffer(buffer, 0, indexType, *minmax.first, *minmax.second); + .setIndexBuffer(buffer, 0, indexType, *minmax.first, *minmax.second); buffer->setData(indexCount*Mesh::indexSize(indexType), data, usage); delete[] data; diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index ae6d1b01a..0921d2d6c 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -204,7 +204,7 @@ class AbstractXApplication::Configuration { /** * @brief Set window title - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is `"Magnum X Application"`. */ @@ -218,7 +218,7 @@ class AbstractXApplication::Configuration { /** * @brief Set window size - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is `{800, 600}`. */ diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 0752ecb4b..7bb276b23 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -287,7 +287,7 @@ template class ResourceManager: private Implementation::Resource /** * @brief Set resource data - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @p policy is set to `ResourcePolicy::ReferenceCounted`, there * must be already at least one reference to given resource, otherwise @@ -304,19 +304,19 @@ template class ResourceManager: private Implementation::Resource * subsequent updates are not possible. * @see referenceCount(), state() */ - template ResourceManager* set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { + template ResourceManager& set(ResourceKey key, T* data, ResourceDataState state, ResourcePolicy policy) { this->Implementation::ResourceManagerData::set(key, data, state, policy); - return this; + return *this; } /** * @brief Set resource data - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as above function with state set to @ref ResourceDataState "ResourceDataState::Final" * and policy to @ref ResourcePolicy "ResourcePolicy::Resident". */ - template ResourceManager* set(ResourceKey key, T* data) { + template ResourceManager& set(ResourceKey key, T* data) { return set(key, data, ResourceDataState::Final, ResourcePolicy::Resident); } @@ -332,51 +332,51 @@ template class ResourceManager: private Implementation::Resource /** * @brief Set fallback for not found resources - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - template ResourceManager* setFallback(T* data) { + template ResourceManager& setFallback(T* data) { this->Implementation::ResourceManagerData::setFallback(data); - return this; + return *this; } /** * @brief Free all resources of given type which are not referenced - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - template ResourceManager* free() { + template ResourceManager& free() { this->Implementation::ResourceManagerData::free(); - return this; + return *this; } /** * @brief Free all resources which are not referenced - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - ResourceManager* free() { + ResourceManager& free() { freeInternal(); - return this; + return *this; } /** * @brief Clear all resources of given type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Unlike free() this function assumes that no resource is referenced. */ - template ResourceManager* clear() { + template ResourceManager& clear() { this->Implementation::ResourceManagerData::clear(); - return this; + return *this; } /** * @brief Clear all resources - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Unlike free() this function assumes that no resource is referenced. */ - ResourceManager* clear() { + ResourceManager& clear() { clearInternal(); - return this; + return *this; } /** @brief Loader for given type of resources */ @@ -391,15 +391,15 @@ template class ResourceManager: private Implementation::Resource /** * @brief Set loader for given type of resources - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * See AbstractResourceLoader documentation for more information. * @attention The loader is deleted on destruction before unloading * all resources. */ - template ResourceManager* setLoader(AbstractResourceLoader* loader) { + template ResourceManager& setLoader(AbstractResourceLoader* loader) { this->Implementation::ResourceManagerData::setLoader(loader); - return this; + return *this; } private: diff --git a/src/SceneGraph/AbstractCamera.h b/src/SceneGraph/AbstractCamera.h index b66ec8aad..1d5d80bd0 100644 --- a/src/SceneGraph/AbstractCamera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -81,9 +81,9 @@ template class MAGNUM_SCENEGRAPH_EXPORT Abstrac /** * @brief Set aspect ratio policy - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - AbstractCamera* setAspectRatioPolicy(AspectRatioPolicy policy); + AbstractCamera& setAspectRatioPolicy(AspectRatioPolicy policy); /** * @brief Camera matrix diff --git a/src/SceneGraph/AbstractCamera.hpp b/src/SceneGraph/AbstractCamera.hpp index 891108d4a..ba4c48a15 100644 --- a/src/SceneGraph/AbstractCamera.hpp +++ b/src/SceneGraph/AbstractCamera.hpp @@ -74,10 +74,10 @@ template AbstractCamera::Abstrac template AbstractCamera::~AbstractCamera() = default; -template AbstractCamera* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template AbstractCamera& AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); - return this; + return *this; } template void AbstractCamera::setViewport(const Vector2i& size) { diff --git a/src/SceneGraph/AbstractTransformation.h b/src/SceneGraph/AbstractTransformation.h index ee96fc440..baacea042 100644 --- a/src/SceneGraph/AbstractTransformation.h +++ b/src/SceneGraph/AbstractTransformation.h @@ -136,11 +136,11 @@ template class MAGNUM_SCENEGRAPH_EXPORT Abstrac /** * @brief Reset object transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - AbstractTransformation* resetTransformation() { + AbstractTransformation& resetTransformation() { doResetTransformation(); - return this; + return *this; } protected: diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index 2fd787365..de8ca8911 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -46,31 +46,31 @@ template class AbstractBasicTranslationRotation2D: public AbstractTrans * @brief Translate object * @param vector Translation vector * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see Vector2::xAxis(), Vector2::yAxis() */ - AbstractBasicTranslationRotation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation2D& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { doTranslate(vector, type); - return this; + return *this; } /** * @brief Rotate object * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - AbstractBasicTranslationRotation2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation2D& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { doRotate(angle, type); - return this; + return *this; } /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - AbstractBasicTranslationRotation2D* resetTransformation() { + AbstractBasicTranslationRotation2D& resetTransformation() { AbstractTransformation<2, T>::resetTransformation(); - return this; + return *this; } #endif diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index 0e36b0c9b..ffc739852 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -47,13 +47,13 @@ template class AbstractBasicTranslationRotation3D: public AbstractTrans * @brief Translate object * @param vector Translation vector * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() */ - AbstractBasicTranslationRotation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation3D& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { doTranslate(vector, type); - return this; + return *this; } /** @@ -61,63 +61,63 @@ template class AbstractBasicTranslationRotation3D: public AbstractTrans * @param angle Angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis() */ - AbstractBasicTranslationRotation3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation3D& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { doRotate(angle, normalizedAxis, type); - return this; + return *this; } /** * @brief Rotate object around X axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * In some implementations faster than calling * `rotate(angle, Vector3::xAxis())`. */ - AbstractBasicTranslationRotation3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation3D& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { doRotateX(angle, type); - return this; + return *this; } /** * @brief Rotate object around Y axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * In some implementations faster than calling * `rotate(angle, Vector3::yAxis())`. */ - AbstractBasicTranslationRotation3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation3D& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { doRotateX(angle, type); - return this; + return *this; } /** * @brief Rotate object around Z axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * In some implementations faster than calling * `rotate(angle, Vector3::zAxis())`. */ - AbstractBasicTranslationRotation3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotation3D& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { doRotateZ(angle, type); - return this; + return *this; } /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - AbstractBasicTranslationRotation3D* resetTransformation() { + AbstractBasicTranslationRotation3D& resetTransformation() { AbstractTransformation<3, T>::resetTransformation(); - return this; + return *this; } #endif diff --git a/src/SceneGraph/AbstractTranslationRotationScaling2D.h b/src/SceneGraph/AbstractTranslationRotationScaling2D.h index 407ffc365..fa75778cb 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling2D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling2D.h @@ -45,28 +45,28 @@ template class AbstractBasicTranslationRotationScaling2D: public Abstra * @brief Scale object * @param vector Scaling vector * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see Vector2::xScale(), Vector2::yScale() */ - AbstractBasicTranslationRotationScaling2D* scale(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling2D& scale(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { doScale(vector, type); - return this; + return *this; } /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - AbstractBasicTranslationRotationScaling2D* resetTransformation() { + AbstractBasicTranslationRotationScaling2D& resetTransformation() { AbstractBasicTranslationRotation2D::resetTransformation(); - return this; + return *this; } - AbstractBasicTranslationRotationScaling2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling2D& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation2D::translate(vector, type); - return this; + return *this; } - AbstractBasicTranslationRotationScaling2D* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling2D& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation2D::rotate(angle, type); - return this; + return *this; } #endif diff --git a/src/SceneGraph/AbstractTranslationRotationScaling3D.h b/src/SceneGraph/AbstractTranslationRotationScaling3D.h index 11a37b7b4..2074e0a44 100644 --- a/src/SceneGraph/AbstractTranslationRotationScaling3D.h +++ b/src/SceneGraph/AbstractTranslationRotationScaling3D.h @@ -45,40 +45,40 @@ template class AbstractBasicTranslationRotationScaling3D: public Abstra * @brief Scale object * @param vector Scaling vector * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see Vector3::xScale(), Vector3::yScale(), Vector3::zScale() */ - AbstractBasicTranslationRotationScaling3D* scale(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling3D& scale(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { doScale(vector, type); - return this; + return *this; } /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - AbstractBasicTranslationRotationScaling3D* resetTransformation() { + AbstractBasicTranslationRotationScaling3D& resetTransformation() { AbstractBasicTranslationRotation3D::resetTransformation(); - return this; + return *this; } - AbstractBasicTranslationRotationScaling3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling3D& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation3D::translate(vector, type); - return this; + return *this; } - AbstractBasicTranslationRotationScaling3D* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling3D& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation3D::rotate(angle, normalizedAxis, type); - return this; + return *this; } - AbstractBasicTranslationRotationScaling3D* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling3D& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation3D::rotateX(angle, type); - return this; + return *this; } - AbstractBasicTranslationRotationScaling3D* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling3D& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation3D::rotateY(angle, type); - return this; + return *this; } - AbstractBasicTranslationRotationScaling3D* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { + AbstractBasicTranslationRotationScaling3D& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { AbstractBasicTranslationRotation3D::rotateZ(angle, type); - return this; + return *this; } #endif diff --git a/src/SceneGraph/Animable.h b/src/SceneGraph/Animable.h index 3f7ca174b..3221d64de 100644 --- a/src/SceneGraph/Animable.h +++ b/src/SceneGraph/Animable.h @@ -165,7 +165,7 @@ template class MAGNUM_SCENEGRAPH_EXPORT Animabl /** * @brief Set animation state - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Note that changing state from @ref AnimationState "AnimationState::Stopped" * to @ref AnimationState "AnimationState::Paused" is ignored and @@ -174,7 +174,7 @@ template class MAGNUM_SCENEGRAPH_EXPORT Animabl * @see animationStarted(), animationPaused(), animationResumed(), * animationStopped() */ - Animable* setState(AnimationState state); + Animable& setState(AnimationState state); /** * @brief Whether the animation is repeated @@ -185,14 +185,14 @@ template class MAGNUM_SCENEGRAPH_EXPORT Animabl /** * @brief Enable/disable repeated animation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is `false`. * @see setRepeatCount() */ - Animable* setRepeated(bool repeated) { + Animable& setRepeated(bool repeated) { _repeated = repeated; - return this; + return *this; } /** @@ -204,15 +204,15 @@ template class MAGNUM_SCENEGRAPH_EXPORT Animabl /** * @brief Set repeat count - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Has effect only if repeated animation is enabled. `0` means * infinitely repeated animation. Default is `0`. * @see setRepeated() */ - Animable* setRepeatCount(UnsignedShort count) { + Animable& setRepeatCount(UnsignedShort count) { _repeatCount = count; - return this; + return *this; } /** @@ -226,15 +226,15 @@ template class MAGNUM_SCENEGRAPH_EXPORT Animabl protected: /** * @brief Set animation duration - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Sets duration of the animation cycle in seconds. Set to `0.0f` for * infinite non-repeating animation. Default is `0.0f`. */ /* Protected so only animation implementer can change it */ - Animable* setDuration(Float duration) { + Animable& setDuration(Float duration) { _duration = duration; - return this; + return *this; } /** diff --git a/src/SceneGraph/Animable.hpp b/src/SceneGraph/Animable.hpp index 598959bac..9847e2ad8 100644 --- a/src/SceneGraph/Animable.hpp +++ b/src/SceneGraph/Animable.hpp @@ -39,17 +39,17 @@ template Animable::Animable(Abst template Animable::~Animable() {} -template Animable* Animable::setState(AnimationState state) { - if(currentState == state) return this; +template Animable& Animable::setState(AnimationState state) { + if(currentState == state) return *this; /* Not allowed (for sanity) */ if(previousState == AnimationState::Stopped && state == AnimationState::Paused) - return this; + return *this; /* Wake up the group in case no animations are running */ group()->wakeUp = true; currentState = state; - return this; + return *this; } template AnimableGroup* Animable::group() { diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h index 991a6b8e5..3016a405e 100644 --- a/src/SceneGraph/Camera2D.h +++ b/src/SceneGraph/Camera2D.h @@ -39,9 +39,9 @@ See Drawable documentation for introduction. The camera by default displays OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` and doesn't do any aspect ratio correction. Common setup example: @code -SceneGraph::Camera2D* camera = new SceneGraph::Camera2D(&cameraObject); -camera->setProjection({4.0f/3.0f, 1.0f}) - ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); +SceneGraph::Camera2D camera(&cameraObject); +camera.setProjection({4.0f/3.0f, 1.0f}) + .setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); @endcode @section Camera2D-explicit-specializations Explicit template specializations @@ -70,17 +70,17 @@ template class MAGNUM_SCENEGRAPH_EXPORT BasicCamera2D: public AbstractC /** * @brief Set projection * @param size Size of the view - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see Matrix3::projection() */ - BasicCamera2D* setProjection(const Math::Vector2& size); + BasicCamera2D& setProjection(const Math::Vector2& size); /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - BasicCamera2D* setAspectRatioPolicy(AspectRatioPolicy policy) { + BasicCamera2D& setAspectRatioPolicy(AspectRatioPolicy policy) { AbstractCamera<2, T>::setAspectRatioPolicy(policy); - return this; + return *this; } #endif }; diff --git a/src/SceneGraph/Camera2D.hpp b/src/SceneGraph/Camera2D.hpp index 745e2d2f8..447c0aee1 100644 --- a/src/SceneGraph/Camera2D.hpp +++ b/src/SceneGraph/Camera2D.hpp @@ -37,11 +37,11 @@ namespace Magnum { namespace SceneGraph { template BasicCamera2D::BasicCamera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} -template BasicCamera2D* BasicCamera2D::setProjection(const Math::Vector2& size) { +template BasicCamera2D& BasicCamera2D::setProjection(const Math::Vector2& size) { AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3::projection(size); AbstractCamera<2, T>::fixAspectRatio(); - return this; + return *this; } }} diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h index 0a8cb2b0d..234a2ad15 100644 --- a/src/SceneGraph/Camera3D.h +++ b/src/SceneGraph/Camera3D.h @@ -44,9 +44,9 @@ See Drawable documentation for introduction. The camera by default displays OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` with orthographic projection and doesn't do any aspect ratio correction. Common setup example: @code -SceneGraph::Camera3D* camera = new SceneGraph::Camera3D(&cameraObject); -camera->setPerspective({}, 0.001f, 100.0f) - ->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); +SceneGraph::Camera3D camera(&cameraObject); +camera.setPerspective({}, 0.001f, 100.0f) + .setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend); @endcode @section Camera3D-explicit-specializations Explicit template specializations @@ -74,22 +74,22 @@ template class MAGNUM_SCENEGRAPH_EXPORT BasicCamera3D: public AbstractC * @param size Size of the view * @param near Near clipping plane * @param far Far clipping plane - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setPerspective(), Matrix4::orthographicProjection() */ - BasicCamera3D* setOrthographic(const Math::Vector2& size, T near, T far); + BasicCamera3D& setOrthographic(const Math::Vector2& size, T near, T far); /** * @brief Set perspective projection * @param size Size of near clipping plane * @param near Near clipping plane * @param far Far clipping plane - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setOrthographic(), Matrix4::perspectiveProjection() */ - BasicCamera3D* setPerspective(const Math::Vector2& size, T near, T far); + BasicCamera3D& setPerspective(const Math::Vector2& size, T near, T far); /** * @brief Set perspective projection @@ -97,11 +97,11 @@ template class MAGNUM_SCENEGRAPH_EXPORT BasicCamera3D: public AbstractC * @param aspectRatio Aspect ratio * @param near Near clipping plane * @param far Far clipping plane - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setOrthographic(), Matrix4::perspectiveProjection() */ - BasicCamera3D* setPerspective(Math::Rad fov, T aspectRatio, T near, T far); + BasicCamera3D& setPerspective(Math::Rad fov, T aspectRatio, T near, T far); /** @brief Near clipping plane */ T near() const { return _near; } @@ -111,9 +111,9 @@ template class MAGNUM_SCENEGRAPH_EXPORT BasicCamera3D: public AbstractC /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - BasicCamera3D* setAspectRatioPolicy(AspectRatioPolicy policy) { + BasicCamera3D& setAspectRatioPolicy(AspectRatioPolicy policy) { AbstractCamera<3, T>::setAspectRatioPolicy(policy); - return this; + return *this; } #endif diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp index 73fd88b53..c1e5bda74 100644 --- a/src/SceneGraph/Camera3D.hpp +++ b/src/SceneGraph/Camera3D.hpp @@ -37,34 +37,34 @@ namespace Magnum { namespace SceneGraph { template BasicCamera3D::BasicCamera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(T(0)), _far(T(0)) {} -template BasicCamera3D* BasicCamera3D::setOrthographic(const Math::Vector2& size, T near, T far) { +template BasicCamera3D& BasicCamera3D::setOrthographic(const Math::Vector2& size, T near, T far) { /** @todo Get near/far from the matrix */ _near = near; _far = far; AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4::orthographicProjection(size, near, far); AbstractCamera<3, T>::fixAspectRatio(); - return this; + return *this; } -template BasicCamera3D* BasicCamera3D::setPerspective(const Math::Vector2& size, T near, T far) { +template BasicCamera3D& BasicCamera3D::setPerspective(const Math::Vector2& size, T near, T far) { /** @todo Get near/far from the matrix */ _near = near; _far = far; AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4::perspectiveProjection(size, near, far); AbstractCamera<3, T>::fixAspectRatio(); - return this; + return *this; } -template BasicCamera3D* BasicCamera3D::setPerspective(Math::Rad fov, T aspectRatio, T near, T far) { +template BasicCamera3D& BasicCamera3D::setPerspective(Math::Rad fov, T aspectRatio, T near, T far) { /** @todo Get near/far from the matrix */ _near = near; _far = far; AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4::perspectiveProjection(fov, aspectRatio, near, far); AbstractCamera<3, T>::fixAspectRatio(); - return this; + return *this; } }} diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 1678d1ff4..a224f4296 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -68,7 +68,7 @@ SceneGraph::DrawableGroup3D drawables; (new DrawableObject(&scene, &drawables)) ->translate(Vector3::yAxis(-0.3f)) - ->rotateX(30.0_degf); + .rotateX(30.0_degf); (new AnotherDrawableObject(&scene, &drawables)) ->translate(Vector3::zAxis(0.5f)); // ... @@ -96,14 +96,14 @@ setup etc into one group, then put all transparent into another and set common parameters once for whole group instead of setting them again in each draw() implementation. Example: @code -Shaders::PhongShader* shader; +Shaders::PhongShader shader; SceneGraph::DrawableGroup3D phongObjects, transparentObjects; void MyApplication::drawEvent() { - shader->setProjectionMatrix(camera->projectionMatrix()) - ->setLightPosition(lightPosition) - ->setLightColor(lightColor) - ->setAmbientColor(ambientColor); + shader.setProjectionMatrix(camera->projectionMatrix()) + .setLightPosition(lightPosition) + .setLightColor(lightColor) + .setAmbientColor(ambientColor); camera.draw(phongObjects); Renderer::setFeature(Renderer::Feature::Blending, true); diff --git a/src/SceneGraph/DualComplexTransformation.h b/src/SceneGraph/DualComplexTransformation.h index 67cc7e07c..55f149922 100644 --- a/src/SceneGraph/DualComplexTransformation.h +++ b/src/SceneGraph/DualComplexTransformation.h @@ -70,87 +70,87 @@ template class BasicDualComplexTransformation: public AbstractBasicTran /** * @brief Normalize rotation part - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Normalizes the rotation part to prevent rounding errors when rotating * the object subsequently. * @see DualComplex::normalized() */ - Object>* normalizeRotation() { + Object>& normalizeRotation() { setTransformationInternal(_transformation.normalized()); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Set transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the dual complex number is normalized. * @see DualComplex::isNormalized() */ - Object>* setTransformation(const Math::DualComplex& transformation) { + Object>& setTransformation(const Math::DualComplex& transformation) { CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized", - static_cast>*>(this)); + static_cast>&>(*this)); setTransformationInternal(transformation); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ - Object>* resetTransformation() { + Object>& resetTransformation() { setTransformationInternal({}); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Transform object * @param transformation Transformation * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the dual complex number is normalized. * @see DualComplex::isNormalized() */ - Object>* transform(const Math::DualComplex& transformation, TransformationType type = TransformationType::Global) { + Object>& transform(const Math::DualComplex& transformation, TransformationType type = TransformationType::Global) { CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized", - static_cast>*>(this)); + static_cast>&>(*this)); transformInternal(transformation, type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling2D::translate() * Same as calling transform() with DualComplex::translation(). */ - Object>* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + Object>& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { transformInternal(Math::DualComplex::translation(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with DualComplex::rotation(). * @see normalizeRotation() */ - Object>* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { transformInternal(Math::DualComplex::rotation(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Move object in stacking order * @param under Sibling object under which to move or `nullptr`, * if you want to move it above all. - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* move(Object>* under) { + Object>& move(Object>* under) { static_cast*>(this)->Containers::template LinkedList>>::move(this, under); - return static_cast>*>(this); + return static_cast>&>(*this); } protected: diff --git a/src/SceneGraph/DualQuaternionTransformation.h b/src/SceneGraph/DualQuaternionTransformation.h index 0fe666b5d..8394e5bd2 100644 --- a/src/SceneGraph/DualQuaternionTransformation.h +++ b/src/SceneGraph/DualQuaternionTransformation.h @@ -72,62 +72,62 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT /** * @brief Normalize rotation part - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Normalizes the rotation part to prevent rounding errors when rotating * the object subsequently. * @see DualQuaternion::normalized() */ - Object>* normalizeRotation() { + Object>& normalizeRotation() { setTransformation(_transformation.normalized()); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Set transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the dual quaternion is normalized. * @see DualQuaternion::isNormalized() */ - Object>* setTransformation(const Math::DualQuaternion& transformation) { + Object>& setTransformation(const Math::DualQuaternion& transformation) { CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized", - static_cast>*>(this)); + static_cast>&>(*this)); setTransformationInternal(transformation); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ - Object>* resetTransformation() { + Object>& resetTransformation() { setTransformation({}); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Multiply transformation * @param transformation Transformation * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the dual quaternion is normalized. * @see DualQuaternion::isNormalized() */ - Object>* transform(const Math::DualQuaternion& transformation, TransformationType type = TransformationType::Global) { + Object>& transform(const Math::DualQuaternion& transformation, TransformationType type = TransformationType::Global) { CORRADE_ASSERT(transformation.isNormalized(), "SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized", - static_cast>*>(this)); + static_cast>&>(*this)); transformInternal(transformation, type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling3D::translate() * Same as calling transform() with DualQuaternion::translation(). */ - Object>* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + Object>& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { transformInternal(Math::DualQuaternion::translation(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @@ -135,26 +135,26 @@ template class BasicDualQuaternionTransformation: public AbstractBasicT * @param angle Angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with DualQuaternion::rotation(). * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(), * normalizeRotation() */ - Object>* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { + Object>& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { transformInternal(Math::DualQuaternion::rotation(angle, normalizedAxis), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - Object>* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { return rotate(angle, Math::Vector3::xAxis(), type); } - Object>* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { return rotate(angle, Math::Vector3::yAxis(), type); } - Object>* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { return rotate(angle, Math::Vector3::zAxis(), type); } #endif diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 19cf67412..ae5142437 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -91,21 +91,21 @@ template class FeatureGroup: pub /** * @brief Add feature to the group - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If the features is part of another group, it is removed from it. * @see remove(), AbstractGroupedFeature::AbstractGroupedFeature() */ - FeatureGroup* add(Feature* feature); + FeatureGroup& add(Feature* feature); /** * @brief Remove feature from the group - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * The feature must be part of the group. * @see add() */ - FeatureGroup* remove(Feature* feature); + FeatureGroup& remove(Feature* feature); }; #ifndef CORRADE_GCC46_COMPATIBILITY @@ -158,7 +158,7 @@ template FeatureGroupfeatures) static_cast(i)->_group = nullptr; } -template FeatureGroup* FeatureGroup::add(Feature* feature) { +template FeatureGroup& FeatureGroup::add(Feature* feature) { /* Remove from previous group */ if(feature->_group) feature->_group->remove(feature); @@ -166,16 +166,16 @@ template FeatureGroup::add(feature); feature->_group = this; - return this; + return *this; } -template FeatureGroup* FeatureGroup::remove(Feature* feature) { +template FeatureGroup& FeatureGroup::remove(Feature* feature) { CORRADE_ASSERT(feature->_group == this, - "SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", this); + "SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", *this); AbstractFeatureGroup::remove(feature); feature->_group = nullptr; - return this; + return *this; } }} diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index d1f4a144e..a58232845 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -69,9 +69,9 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla /** * @brief Set transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* setTransformation(const Math::Matrix3& transformation) { + Object>& setTransformation(const Math::Matrix3& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -80,52 +80,52 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla static_cast>*>(this)->setDirty(); } - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Transform object * @param transformation Transformation * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { + Object>& transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ - Object>* resetTransformation() { + Object>& resetTransformation() { setTransformation({}); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling2D::translate() * Same as calling transform() with Matrix3::translation(). */ - Object>* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + Object>& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { transform(Math::Matrix3::translation(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling2D::rotate() * Same as calling transform() with Matrix3::rotation(). */ - Object>* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { transform(Math::Matrix3::rotation(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling2D::scale() * Same as calling transform() with Matrix3::scaling(). */ - Object>* scale(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + Object>& scale(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { transform(Math::Matrix3::scaling(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @@ -133,24 +133,24 @@ template class BasicMatrixTransformation2D: public AbstractBasicTransla * @param normal Normal of the line through which to reflect * (normalized) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix3::reflection(). */ - Object>* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { + Object>& reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { transform(Math::Matrix3::reflection(normal), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Move object in stacking order * @param under Sibling object under which to move or `nullptr`, * if you want to move it above all. - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* move(Object>* under) { + Object>& move(Object>* under) { static_cast*>(this)->Containers::template LinkedList>>::move(this, under); - return static_cast>*>(this); + return static_cast>&>(*this); } protected: diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 88ea61e47..a9e4e577b 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -69,9 +69,9 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla /** * @brief Set transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* setTransformation(const Math::Matrix4& transformation) { + Object>& setTransformation(const Math::Matrix4& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ /** @todo Do this in some common code so we don't need to include Object? */ @@ -80,91 +80,91 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla static_cast>*>(this)->setDirty(); } - return static_cast>*>(this); + return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ - Object>* resetTransformation() { + Object>& resetTransformation() { setTransformation({}); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Multiply transformation * @param transformation Transformation * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { + Object>& transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling3D::translate() * Same as calling transform() with Matrix4::translation(). */ - Object>* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + Object>& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::translation(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling3D::rotate() * Same as calling transform() with Matrix4::rotation(). */ - Object>* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { + Object>& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::rotation(angle, normalizedAxis), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object around X axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotationX(). */ - Object>* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::rotationX(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object around Y axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotationY(). */ - Object>* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::rotationY(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object around Z axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotationZ(). */ - Object>* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::rotationZ(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling3D::scale() * Same as calling transform() with Matrix4::scaling(). */ - Object>* scale(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + Object>& scale(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::scaling(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @@ -172,13 +172,13 @@ template class BasicMatrixTransformation3D: public AbstractBasicTransla * @param normal Normal of the plane through which to reflect * (normalized) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::reflection(). */ - Object>* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { + Object>& reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { transform(Math::Matrix4::reflection(normal), type); - return static_cast>*>(this); + return static_cast>&>(*this); } protected: diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 2698c5653..d48fab792 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -190,20 +190,20 @@ template class MAGNUM_SCENEGRAPH_EXPORT Object: public Abs /** * @brief Set parent object - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setParentKeepTransformation() */ - Object* setParent(Object* parent); + Object& setParent(Object* parent); /** * @brief Set parent object and keep absolute transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * While setParent() preserves only relative transformation of the * object, this funcition preserves absolute transformation. */ - Object* setParentKeepTransformation(Object* parent); + Object& setParentKeepTransformation(Object* parent); /*@}*/ diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index ba60a6341..e938c1e19 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -65,16 +65,16 @@ template const Object* Object Object* Object::setParent(Object* parent) { +template Object& Object::setParent(Object* parent) { /* Skip if parent is already parent or this is scene (which cannot have parent) */ /** @todo Assert for setting parent to scene */ - if(this->parent() == parent || isScene()) return this; + if(this->parent() == parent || isScene()) return *this; /* Object cannot be parented to its child */ Object* p = parent; while(p) { /** @todo Assert for this */ - if(p == this) return this; + if(p == this) return *this; p = p->parent(); } @@ -85,18 +85,18 @@ template Object* Object::s if(parent) parent->Containers::LinkedList>::insert(this); setDirty(); - return this; + return *this; } -template Object* Object::setParentKeepTransformation(Object* parent) { - CORRADE_ASSERT(scene() == parent->scene(), "SceneGraph::Object::setParentKeepTransformation(): both parents must be in the same scene", this); +template Object& Object::setParentKeepTransformation(Object* parent) { + CORRADE_ASSERT(scene() == parent->scene(), "SceneGraph::Object::setParentKeepTransformation(): both parents must be in the same scene", *this); const auto transformation = Transformation::compose( Transformation::inverted(parent->absoluteTransformation()), absoluteTransformation()); setParent(parent); this->setTransformation(transformation); - return this; + return *this; } template typename Transformation::DataType Object::absoluteTransformation() const { diff --git a/src/SceneGraph/RigidMatrixTransformation2D.h b/src/SceneGraph/RigidMatrixTransformation2D.h index 0a5e70101..8db697eab 100644 --- a/src/SceneGraph/RigidMatrixTransformation2D.h +++ b/src/SceneGraph/RigidMatrixTransformation2D.h @@ -75,77 +75,77 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr /** * @brief Normalize rotation part - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Normalizes the rotation part using Math::Algorithms::gramSchmidt() * to prevent rounding errors when rotating the object subsequently. */ - Object>* normalizeRotation() { + Object>& normalizeRotation() { setTransformationInternal(Math::Matrix3::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Set transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the matrix represents rigid transformation. * @see Matrix3::isRigidTransformation() */ - Object>* setTransformation(const Math::Matrix3& transformation) { + Object>& setTransformation(const Math::Matrix3& transformation) { CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation", - static_cast>*>(this)); + static_cast>&>(*this)); setTransformationInternal(transformation); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling2D::resetTransformation() */ - Object>* resetTransformation() { + Object>& resetTransformation() { setTransformationInternal({}); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Transform object * @param transformation Transformation * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the matrix represents rigid transformation. * @see Matrix3::isRigidTransformation() */ - Object>* transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { + Object>& transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation", - static_cast>*>(this)); + static_cast>&>(*this)); transformInternal(transformation, type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling2D::translate() * Same as calling transform() with Matrix3::translation(). */ - Object>* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { + Object>& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix3::translation(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix3::rotation(). * @see normalizeRotation() */ - Object>* rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotate(Math::Rad angle, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix3::rotation(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @@ -153,24 +153,24 @@ template class BasicRigidMatrixTransformation2D: public AbstractBasicTr * @param normal Normal of the line through which to reflect * (normalized) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix3::reflection(). */ - Object>* reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { + Object>& reflect(const Math::Vector2& normal, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix3::reflection(normal), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Move object in stacking order * @param under Sibling object under which to move or `nullptr`, * if you want to move it above all. - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Object>* move(Object>* under) { + Object>& move(Object>* under) { static_cast*>(this)->Containers::template LinkedList>>::move(this, under); - return static_cast>*>(this); + return static_cast>&>(*this); } protected: diff --git a/src/SceneGraph/RigidMatrixTransformation3D.h b/src/SceneGraph/RigidMatrixTransformation3D.h index abccc8cbf..becd46ce2 100644 --- a/src/SceneGraph/RigidMatrixTransformation3D.h +++ b/src/SceneGraph/RigidMatrixTransformation3D.h @@ -75,63 +75,63 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr /** * @brief Normalize rotation part - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Normalizes the rotation part using Math::Algorithms::gramSchmidt() * to prevent rounding errors when rotating the object subsequently. */ - Object>* normalizeRotation() { + Object>& normalizeRotation() { setTransformation(Math::Matrix4::from( Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Set transformation - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the matrix represents rigid transformation. * @see Matrix4::isRigidTransformation() */ - Object>* setTransformation(const Math::Matrix4& transformation) { + Object>& setTransformation(const Math::Matrix4& transformation) { CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation", - static_cast>*>(this)); + static_cast>&>(*this)); setTransformationInternal(transformation); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @copydoc AbstractTranslationRotationScaling3D::resetTransformation() */ - Object>* resetTransformation() { + Object>& resetTransformation() { setTransformation({}); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Multiply transformation * @param transformation Transformation * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Expects that the matrix represents rigid transformation. * @see Matrix4::isRigidTransformation() */ - Object>* transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { + Object>& transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { CORRADE_ASSERT(transformation.isRigidTransformation(), "SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation", - static_cast>*>(this)); + static_cast>&>(*this)); transformInternal(transformation, type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @copydoc AbstractTranslationRotationScaling3D::translate() * Same as calling transform() with Matrix4::translation(). */ - Object>* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { + Object>& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix4::translation(vector), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @@ -139,57 +139,57 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * @param angle Angle (counterclockwise) * @param normalizedAxis Normalized rotation axis * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotation(). * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(), * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation() */ - Object>* rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { + Object>& rotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix4::rotation(angle, normalizedAxis), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object around X axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotationX(). * @see normalizeRotation() */ - Object>* rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateX(Math::Rad angle, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix4::rotationX(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object around Y axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotationY(). * @see normalizeRotation() */ - Object>* rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateY(Math::Rad angle, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix4::rotationY(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** * @brief Rotate object around Z axis * @param angle Angle (counterclockwise) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::rotationZ(). * @see normalizeRotation() */ - Object>* rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { + Object>& rotateZ(Math::Rad angle, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix4::rotationZ(angle), type); - return static_cast>*>(this); + return static_cast>&>(*this); } /** @@ -197,13 +197,13 @@ template class BasicRigidMatrixTransformation3D: public AbstractBasicTr * @param normal Normal of the plane through which to reflect * (normalized) * @param type Transformation type - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Same as calling transform() with Matrix4::reflection(). */ - Object>* reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { + Object>& reflect(const Math::Vector3& normal, TransformationType type = TransformationType::Global) { transformInternal(Math::Matrix4::reflection(normal), type); - return static_cast>*>(this); + return static_cast>&>(*this); } protected: diff --git a/src/SceneGraph/Test/AnimableTest.cpp b/src/SceneGraph/Test/AnimableTest.cpp index ed3726ec3..3eba97476 100644 --- a/src/SceneGraph/Test/AnimableTest.cpp +++ b/src/SceneGraph/Test/AnimableTest.cpp @@ -143,8 +143,11 @@ void AnimableTest::state() { CORRADE_COMPARE(group.runningCount(), 0); /* Verify running count can go past 0/1 */ - group.add((new StateTrackingAnimable(&object, &group))->setState(AnimationState::Running)); - group.add((new StateTrackingAnimable(&object, &group))->setState(AnimationState::Running)); + auto a = new StateTrackingAnimable(&object, &group); + auto b = new StateTrackingAnimable(&object, &group); + a->setState(AnimationState::Running); + b->setState(AnimationState::Running); + group.add(a).add(b); group.step(1.0f, 1.0f); CORRADE_COMPARE(group.runningCount(), 2); } diff --git a/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp b/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp index 8433eebbb..fd48a3ac7 100644 --- a/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp +++ b/src/SceneGraph/Test/DualQuaternionTransformationTest.cpp @@ -160,9 +160,9 @@ void DualQuaternionTransformationTest::rotate() { Object3D o; o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f)) - ->rotateY(Deg(25.0f)) - ->rotateZ(Deg(-23.0f)) - ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + .rotateY(Deg(25.0f)) + .rotateZ(Deg(-23.0f)) + .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotationZ(Deg(-23.0f))* @@ -173,9 +173,9 @@ void DualQuaternionTransformationTest::rotate() { Object3D o; o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f), TransformationType::Local) - ->rotateY(Deg(25.0f), TransformationType::Local) - ->rotateZ(Deg(-23.0f), TransformationType::Local) - ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + .rotateY(Deg(25.0f), TransformationType::Local) + .rotateZ(Deg(-23.0f), TransformationType::Local) + .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::rotationX(Deg(17.0f))* diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp index 32a09dbfc..ab9f3f97d 100644 --- a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -145,9 +145,9 @@ void MatrixTransformation3DTest::rotate() { Object3D o; o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f)) - ->rotateY(Deg(25.0f)) - ->rotateZ(Deg(-23.0f)) - ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + .rotateY(Deg(25.0f)) + .rotateZ(Deg(-23.0f)) + .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotationZ(Deg(-23.0f))* @@ -158,9 +158,9 @@ void MatrixTransformation3DTest::rotate() { Object3D o; o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f), TransformationType::Local) - ->rotateY(Deg(25.0f), TransformationType::Local) - ->rotateZ(Deg(-23.0f), TransformationType::Local) - ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + .rotateY(Deg(25.0f), TransformationType::Local) + .rotateZ(Deg(-23.0f), TransformationType::Local) + .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::rotationX(Deg(17.0f))* diff --git a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp index ef56d9d69..fd1a464b0 100644 --- a/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp +++ b/src/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp @@ -165,9 +165,9 @@ void RigidMatrixTransformation3DTest::rotate() { Object3D o; o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f)) - ->rotateY(Deg(25.0f)) - ->rotateZ(Deg(-23.0f)) - ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); + .rotateY(Deg(25.0f)) + .rotateZ(Deg(-23.0f)) + .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotationZ(Deg(-23.0f))* @@ -178,9 +178,9 @@ void RigidMatrixTransformation3DTest::rotate() { Object3D o; o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f), TransformationType::Local) - ->rotateY(Deg(25.0f), TransformationType::Local) - ->rotateZ(Deg(-23.0f), TransformationType::Local) - ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); + .rotateY(Deg(25.0f), TransformationType::Local) + .rotateZ(Deg(-23.0f), TransformationType::Local) + .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::rotationX(Deg(17.0f))* diff --git a/src/Shaders/DistanceFieldVector.h b/src/Shaders/DistanceFieldVector.h index 8d5319deb..be068f2fc 100644 --- a/src/Shaders/DistanceFieldVector.h +++ b/src/Shaders/DistanceFieldVector.h @@ -51,37 +51,40 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector public: DistanceFieldVector(); - /** @brief Set transformation and projection matrix */ - DistanceFieldVector* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + /** + * @brief Set transformation and projection matrix + * @return Reference to self (for method chaining) + */ + DistanceFieldVector& setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { AbstractShaderProgram::setUniform(transformationProjectionMatrixUniform, matrix); - return this; + return *this; } /** * @brief Set fill color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setOutlineColor() */ - DistanceFieldVector* setColor(const Color4& color) { + DistanceFieldVector& setColor(const Color4& color) { AbstractShaderProgram::setUniform(colorUniform, color); - return this; + return *this; } /** * @brief Set outline color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * @see setOutlineRange(), setColor() */ - DistanceFieldVector* setOutlineColor(const Color4& color) { + DistanceFieldVector& setOutlineColor(const Color4& color) { AbstractShaderProgram::setUniform(outlineColorUniform, color); - return this; + return *this; } /** * @brief Set outline range - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Parameter @p start describes where fill ends and possible outline * starts. Initial value is `0.5f`, larger values will make the vector @@ -93,22 +96,22 @@ template class MAGNUM_SHADERS_EXPORT DistanceFieldVector * * @see setOutlineColor() */ - DistanceFieldVector* setOutlineRange(Float start, Float end) { + DistanceFieldVector& setOutlineRange(Float start, Float end) { AbstractShaderProgram::setUniform(outlineRangeUniform, Vector2(start, end)); - return this; + return *this; } /** * @brief Set smoothness radius - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Larger values will make edges look less aliased (but blurry), smaller * values will make them look more crisp (but possibly aliased). Initial * value is `0.04f`. */ - DistanceFieldVector* setSmoothness(Float value) { + DistanceFieldVector& setSmoothness(Float value) { AbstractShaderProgram::setUniform(smoothnessUniform, value); - return this; + return *this; } private: diff --git a/src/Shaders/Flat.h b/src/Shaders/Flat.h index 582378a76..d8efe6abe 100644 --- a/src/Shaders/Flat.h +++ b/src/Shaders/Flat.h @@ -53,20 +53,20 @@ template class MAGNUM_SHADERS_EXPORT Flat: public Abstra /** * @brief Set transformation and projection matrix - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Flat* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + Flat& setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); - return this; + return *this; } /** * @brief Set color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Flat* setColor(const Color4& color) { + Flat& setColor(const Color4& color) { setUniform(colorUniform, color); - return this; + return *this; } private: diff --git a/src/Shaders/MeshVisualizer.h b/src/Shaders/MeshVisualizer.h index e48aaefbd..b30e3c32b 100644 --- a/src/Shaders/MeshVisualizer.h +++ b/src/Shaders/MeshVisualizer.h @@ -114,67 +114,67 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram { /** * @brief Set transformation and projection matrix - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - MeshVisualizer* setTransformationProjectionMatrix(const Matrix4& matrix) { + MeshVisualizer& setTransformationProjectionMatrix(const Matrix4& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); - return this; + return *this; } /** * @brief Set viewport size - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Has effect only if @ref Flag "Flag::Wireframe" is enabled. */ - MeshVisualizer* setViewportSize(const Vector2& size) { + MeshVisualizer& setViewportSize(const Vector2& size) { setUniform(viewportSizeUniform, size); - return this; + return *this; } /** * @brief Set base object color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Initial value is fully opaque white. */ - MeshVisualizer* setColor(const Color4& color) { + MeshVisualizer& setColor(const Color4& color) { setUniform(colorUniform, color); - return this; + return *this; } /** * @brief Set wireframe color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Initial value is fully opaque black. Has effect only if * @ref Flag "Flag::Wireframe" is enabled. */ - MeshVisualizer* setWireframeColor(const Color4& color) { + MeshVisualizer& setWireframeColor(const Color4& color) { if(flags & Flag::Wireframe) setUniform(wireframeColorUniform, color); - return this; + return *this; } /** * @brief Set wireframe width - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Initial value is `1.0f`. Has effect only if * @ref Flag "Flag::Wireframe" is enabled. */ - MeshVisualizer* setWireframeWidth(Float width) { + MeshVisualizer& setWireframeWidth(Float width) { if(flags & Flag::Wireframe) setUniform(wireframeWidthUniform, width); - return this; + return *this; } /** * @brief Set line smoothness - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Initial value is `2.0f`. Has effect only if * @ref Flag "Flag::Wireframe" is enabled. */ - MeshVisualizer* setSmoothness(Float smoothness); + MeshVisualizer& setSmoothness(Float smoothness); private: Flags flags; @@ -188,10 +188,10 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public AbstractShaderProgram { CORRADE_ENUMSET_OPERATORS(MeshVisualizer::Flags) -inline MeshVisualizer* MeshVisualizer::setSmoothness(Float smoothness) { +inline MeshVisualizer& MeshVisualizer::setSmoothness(Float smoothness) { if(flags & Flag::Wireframe) setUniform(smoothnessUniform, smoothness); - return this; + return *this; } }} diff --git a/src/Shaders/Phong.h b/src/Shaders/Phong.h index f5d91e8b8..7a39ffd81 100644 --- a/src/Shaders/Phong.h +++ b/src/Shaders/Phong.h @@ -119,87 +119,87 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { /** * @brief Set ambient color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If not set, default value is `(0.0f, 0.0f, 0.0f)`. Has no effect if * @ref Flag "Flag::AmbientTexture" is set. */ - Phong* setAmbientColor(const Color3& color); + Phong& setAmbientColor(const Color3& color); /** * @brief Set diffuse color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Has no effect if @ref Flag "Flag::AmbientTexture" is used. */ - Phong* setDiffuseColor(const Color3& color); + Phong& setDiffuseColor(const Color3& color); /** * @brief Set specular color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. Has no effect if * @ref Flag "Flag::SpecularTexture" is set. */ - Phong* setSpecularColor(const Color3& color); + Phong& setSpecularColor(const Color3& color); /** * @brief Set shininess - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * The larger value, the harder surface (smaller specular highlight). * If not set, default value is `80.0f`. */ - Phong* setShininess(Float shininess) { + Phong& setShininess(Float shininess) { setUniform(shininessUniform, shininess); - return this; + return *this; } /** * @brief Set transformation matrix - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Phong* setTransformationMatrix(const Matrix4& matrix) { + Phong& setTransformationMatrix(const Matrix4& matrix) { setUniform(transformationMatrixUniform, matrix); - return this; + return *this; } /** * @brief Set normal matrix - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Phong* setNormalMatrix(const Math::Matrix<3, Float>& matrix) { + Phong& setNormalMatrix(const Math::Matrix<3, Float>& matrix) { setUniform(normalMatrixUniform, matrix); - return this; + return *this; } /** * @brief Set projection matrix - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Phong* setProjectionMatrix(const Matrix4& matrix) { + Phong& setProjectionMatrix(const Matrix4& matrix) { setUniform(projectionMatrixUniform, matrix); - return this; + return *this; } /** * @brief Set light position - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Phong* setLightPosition(const Vector3& light) { + Phong& setLightPosition(const Vector3& light) { setUniform(lightUniform, light); - return this; + return *this; } /** * @brief Set light color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If not set, default value is `(1.0f, 1.0f, 1.0f)`. */ - Phong* setLightColor(const Color3& color) { + Phong& setLightColor(const Color3& color) { setUniform(lightColorUniform, color); - return this; + return *this; } private: @@ -218,19 +218,19 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { CORRADE_ENUMSET_OPERATORS(Phong::Flags) -inline Phong* Phong::setAmbientColor(const Color3& color) { +inline Phong& Phong::setAmbientColor(const Color3& color) { if(!(_flags & Flag::AmbientTexture)) setUniform(ambientColorUniform, color); - return this; + return *this; } -inline Phong* Phong::setDiffuseColor(const Color3& color) { +inline Phong& Phong::setDiffuseColor(const Color3& color) { if(!(_flags & Flag::DiffuseTexture)) setUniform(diffuseColorUniform, color); - return this; + return *this; } -inline Phong* Phong::setSpecularColor(const Color3& color) { +inline Phong& Phong::setSpecularColor(const Color3& color) { if(!(_flags & Flag::SpecularTexture)) setUniform(specularColorUniform, color); - return this; + return *this; } }} diff --git a/src/Shaders/Vector.h b/src/Shaders/Vector.h index f33bf468c..92e3b3860 100644 --- a/src/Shaders/Vector.h +++ b/src/Shaders/Vector.h @@ -49,20 +49,20 @@ template class MAGNUM_SHADERS_EXPORT Vector: public Abst /** * @brief Set transformation and projection matrix - * @return Pointer to self (for method chaining) + * @return Reference 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; + return *this; } /** * @brief Set fill color - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) */ - Vector* setColor(const Color4& color) { + Vector& setColor(const Color4& color) { AbstractShaderProgram::setUniform(colorUniform, color); - return this; + return *this; } private: diff --git a/src/Shaders/VertexColor.h b/src/Shaders/VertexColor.h index d19cc87c9..5c32f4b86 100644 --- a/src/Shaders/VertexColor.h +++ b/src/Shaders/VertexColor.h @@ -56,13 +56,13 @@ template class MAGNUM_SHADERS_EXPORT VertexColor: public /** * @brief Set transformation and projection matrix - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default is identity matrix. */ - VertexColor* setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { + VertexColor& setTransformationProjectionMatrix(const typename DimensionTraits::MatrixType& matrix) { setUniform(transformationProjectionMatrixUniform, matrix); - return this; + return *this; } private: diff --git a/src/Shapes/Shape.h b/src/Shapes/Shape.h index 6dbf612f2..71854bd5c 100644 --- a/src/Shapes/Shape.h +++ b/src/Shapes/Shape.h @@ -92,11 +92,11 @@ template class Shape: public AbstractShape { /** * @brief Set shape - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Marks the feature as dirty. */ - Shape* setShape(const T& shape); + Shape& setShape(const T& shape); /** * @brief Transformed shape @@ -117,10 +117,10 @@ template class Shape: public AbstractShape { Implementation::Shape _shape, _transformedShape; }; -template inline Shape* Shape::setShape(const T& shape) { +template inline Shape& Shape::setShape(const T& shape) { Implementation::ShapeHelper::set(*this, shape); this->object()->setDirty(); - return this; + return *this; } template inline const T& Shape::transformedShape() { diff --git a/src/Text/DistanceFieldGlyphCache.cpp b/src/Text/DistanceFieldGlyphCache.cpp index 8de12233e..18dd71ff1 100644 --- a/src/Text/DistanceFieldGlyphCache.cpp +++ b/src/Text/DistanceFieldGlyphCache.cpp @@ -75,9 +75,9 @@ void DistanceFieldGlyphCache::setImage(const Vector2i& offset, const ImageRefere Texture2D input; input.setWrapping(Sampler::Wrapping::ClampToEdge) - ->setMinificationFilter(Sampler::Filter::Linear) - ->setMagnificationFilter(Sampler::Filter::Linear) - ->setImage(0, internalFormat, image); + .setMinificationFilter(Sampler::Filter::Linear) + .setMagnificationFilter(Sampler::Filter::Linear) + .setImage(0, internalFormat, image); /* Create distance field from input texture */ TextureTools::distanceField(&input, texture(), Rectanglei::fromSize(offset*scale, image.size()*scale), radius, image.size()); diff --git a/src/Text/GlyphCache.cpp b/src/Text/GlyphCache.cpp index 78355ad7f..2202c5930 100644 --- a/src/Text/GlyphCache.cpp +++ b/src/Text/GlyphCache.cpp @@ -70,9 +70,9 @@ void GlyphCache::initialize(const Vector2i& size) { void GlyphCache::initialize(const TextureFormat internalFormat, const Vector2i& size) { /* Initialize texture */ _texture.setWrapping(Sampler::Wrapping::ClampToEdge) - ->setMinificationFilter(Sampler::Filter::Linear) - ->setMagnificationFilter(Sampler::Filter::Linear) - ->setStorage(1, internalFormat, size); + .setMinificationFilter(Sampler::Filter::Linear) + .setMagnificationFilter(Sampler::Filter::Linear) + .setStorage(1, internalFormat, size); /* Default "Not Found" glyph */ glyphs.insert({0, {}}); diff --git a/src/Text/TextRenderer.cpp b/src/Text/TextRenderer.cpp index 137da6ba3..12d977741 100644 --- a/src/Text/TextRenderer.cpp +++ b/src/Text/TextRenderer.cpp @@ -187,8 +187,8 @@ std::tuple AbstractTextRenderer::render(AbstractFont* const fon in subclass) */ Mesh mesh; mesh.setPrimitive(Mesh::Primitive::Triangles) - ->setIndexCount(indexCount) - ->setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); + .setIndexCount(indexCount) + .setIndexBuffer(indexBuffer, 0, indexType, 0, vertexCount); delete layouter; return std::make_tuple(std::move(mesh), rectangle); @@ -296,7 +296,7 @@ void AbstractTextRenderer::reserve(const uint32_t glyphCount, const Buffer::Usag } _indexBuffer.setData(indicesSize, nullptr, indexBufferUsage); _mesh.setIndexCount(0) - ->setIndexBuffer(&_indexBuffer, 0, indexType, 0, vertexCount); + .setIndexBuffer(&_indexBuffer, 0, indexType, 0, vertexCount); /* Map buffer for filling */ void* const indices = bufferMapImplementation(_indexBuffer, indicesSize); diff --git a/src/Text/TextRenderer.h b/src/Text/TextRenderer.h index 3c38429ad..7e03902ba 100644 --- a/src/Text/TextRenderer.h +++ b/src/Text/TextRenderer.h @@ -170,10 +170,10 @@ The text can be then drawn by configuring text shader, binding font texture and drawing the mesh: @code Text::AbstractFont* font; -Text::GlyphCache* cache; +Text::GlyphCache cache; -Shaders::VectorShader2D* shader; -Buffer *vertexBuffer, *indexBuffer; +Shaders::VectorShader2D shader; +Buffer vertexBuffer, indexBuffer; Mesh mesh; // Render the text @@ -182,9 +182,9 @@ std::tie(mesh, rectangle) = Text::TextRenderer2D::render(font, cache, 0.15f, "Hello World!", vertexBuffer, indexBuffer, Buffer::Usage::StaticDraw); // Draw white text centered on the screen -shader->setTransformationProjectionMatrix(projection*Matrix3::translation(-rectangle.width()/2.0f)) - ->setColor(Color3(1.0f)); - ->use(); +shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-rectangle.width()/2.0f)) + .setColor(Color3(1.0f)); + .use(); glyphCache->texture()->bind(Shaders::VectorShader2D::FontTextureLayer); mesh.draw(); @endcode @@ -197,8 +197,8 @@ mutable texts (e.g. FPS counters, chat messages) there is another approach that doesn't recreate everything on each text change: @code Text::AbstractFont* font; -Text::GlyphCache* cache; -Shaders::VectorShader2D* shader; +Text::GlyphCache cache; +Shaders::VectorShader2D shader; // Initialize renderer and reserve memory for enough glyphs Text::TextRenderer2D renderer(font, cache, 0.15f); @@ -208,9 +208,9 @@ renderer.reserve(32, Buffer::Usage::DynamicDraw, Buffer::Usage::StaticDraw); renderer.render("Hello World Countdown: 10"); // Draw the text centered on the screen -shader->setTransformationProjectionMatrix(projection*Matrix3::translation(-renderer.rectangle().width()/2.0f)) - ->setColor(Color3(1.0f)); - ->use(); +shader.setTransformationProjectionMatrix(projection*Matrix3::translation(-renderer.rectangle().width()/2.0f)) + .setColor(Color3(1.0f)); + .use(); glyphCache->texture()->bind(Shaders::VectorShader2D::FontTextureLayer); renderer.mesh().draw(); @endcode diff --git a/src/Texture.h b/src/Texture.h index fee04c0e3..eeb87ed36 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -50,12 +50,12 @@ Image2D image({4096, 4096}, ImageFormat::RGBA, ImageType::UnsignedByte, data); Texture2D texture; texture.setMagnificationFilter(Sampler::Filter::Linear) - ->setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear) - ->setWrapping(Sampler::Wrapping::ClampToEdge) - ->setMaxAnisotropy(Sampler::maxSupportedAnisotropy()) - ->setStorage(Math::log2(4096)+1, TextureFormat::RGBA8, {4096, 4096}) - ->setSubImage(0, {}, &image) - ->generateMipmap(); + .setMinificationFilter(Sampler::Filter::Linear, Sampler::Mipmap::Linear) + .setWrapping(Sampler::Wrapping::ClampToEdge) + .setMaxAnisotropy(Sampler::maxSupportedAnisotropy()) + .setStorage(Math::log2(4096)+1, TextureFormat::RGBA8, {4096, 4096}) + .setSubImage(0, {}, &image) + .generateMipmap(); @endcode @attention Don't forget to fully configure the texture before use. Note that @@ -84,7 +84,7 @@ array with 16 layers of 64x64 images: Texture3D texture(Texture3D::Target::Texture2DArray); texture.setMagnificationFilter(Sampler::Filter::Linear) // ... - ->setStorage(levels, TextureFormat::RGBA8, {64, 64,16}); + .setStorage(levels, TextureFormat::RGBA8, {64, 64,16}); for(std::size_t i = 0; i != 16; ++i) { void* data = ...; @@ -249,7 +249,7 @@ template class Texture: public AbstractTexture { /** * @brief Set wrapping * @param wrapping Wrapping type for all texture dimensions - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Sets wrapping type for coordinates out of range (0, 1) for normal * textures and (0, textureSizeInGivenDirection-1) for rectangle @@ -264,9 +264,9 @@ template class Texture: public AbstractTexture { * with @def_gl{TEXTURE_WRAP_S}, @def_gl{TEXTURE_WRAP_T}, * @def_gl{TEXTURE_WRAP_R} */ - Texture* setWrapping(const Array& wrapping) { + Texture& setWrapping(const Array& wrapping) { DataHelper::setWrapping(this, wrapping); - return this; + return *this; } /** @@ -274,7 +274,7 @@ template class Texture: public AbstractTexture { * @param levels Mip level count * @param internalFormat Internal format * @param size Size of largest mip level - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Specifies entire structure of a texture at once, removing the need * for additional consistency checks and memory reallocations when @@ -296,9 +296,9 @@ template class Texture: public AbstractTexture { * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access}. */ - Texture* setStorage(Int levels, TextureFormat internalFormat, const typename DimensionTraits::VectorType& size) { + Texture& setStorage(Int levels, TextureFormat internalFormat, const typename DimensionTraits::VectorType& size) { DataHelper::setStorage(this, _target, levels, internalFormat, size); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES @@ -347,7 +347,7 @@ template class Texture: public AbstractTexture { * @param level Mip level * @param internalFormat Internal format * @param image %Image - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * For better performance when generating mipmaps using * generateMipmap() or calling setImage() more than once use @@ -361,16 +361,16 @@ template class Texture: public AbstractTexture { * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access} */ - Texture* setImage(Int level, TextureFormat internalFormat, const ImageReference& image) { + Texture& setImage(Int level, TextureFormat internalFormat, const ImageReference& image) { DataHelper::setImage(this, _target, level, internalFormat, image); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES2 /** @overload */ - Texture* setImage(Int level, TextureFormat internalFormat, BufferImage& image) { + Texture& setImage(Int level, TextureFormat internalFormat, BufferImage& image) { DataHelper::setImage(this, _target, level, internalFormat, image); - return this; + return *this; } #endif @@ -379,7 +379,7 @@ template class Texture: public AbstractTexture { * @param level Mip level * @param offset Offset where to put data in the texture * @param image %Image - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some layer before the operation. @@ -389,16 +389,16 @@ template class Texture: public AbstractTexture { * @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access} */ - Texture* setSubImage(Int level, const typename DimensionTraits::VectorType& offset, const ImageReference& image) { + Texture& setSubImage(Int level, const typename DimensionTraits::VectorType& offset, const ImageReference& image) { DataHelper::setSubImage(this, _target, level, offset, image); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES2 /** @overload */ - Texture* setSubImage(Int level, const typename DimensionTraits::VectorType& offset, BufferImage& image) { + Texture& setSubImage(Int level, const typename DimensionTraits::VectorType& offset, BufferImage& image) { DataHelper::setSubImage(this, _target, level, offset, image); - return this; + return *this; } #endif @@ -418,27 +418,27 @@ template class Texture: public AbstractTexture { /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - Texture* setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { + Texture& setMinificationFilter(Sampler::Filter filter, Sampler::Mipmap mipmap = Sampler::Mipmap::Base) { AbstractTexture::setMinificationFilter(filter, mipmap); - return this; + return *this; } - Texture* setMagnificationFilter(Sampler::Filter filter) { + Texture& setMagnificationFilter(Sampler::Filter filter) { AbstractTexture::setMagnificationFilter(filter); - return this; + return *this; } #ifndef MAGNUM_TARGET_GLES3 - Texture* setBorderColor(const Color4& color) { + Texture& setBorderColor(const Color4& color) { AbstractTexture::setBorderColor(color); - return this; + return *this; } - Texture* setMaxAnisotropy(Float anisotropy) { + Texture& setMaxAnisotropy(Float anisotropy) { AbstractTexture::setMaxAnisotropy(anisotropy); - return this; + return *this; } #endif - Texture* generateMipmap() { + Texture& generateMipmap() { AbstractTexture::generateMipmap(); - return this; + return *this; } #endif }; diff --git a/src/TextureTools/DistanceField.cpp b/src/TextureTools/DistanceField.cpp index adb552cc9..5c3adbe90 100644 --- a/src/TextureTools/DistanceField.cpp +++ b/src/TextureTools/DistanceField.cpp @@ -47,19 +47,19 @@ class DistanceFieldShader: public AbstractShaderProgram { explicit DistanceFieldShader(); - DistanceFieldShader* setRadius(Int radius) { + DistanceFieldShader& setRadius(Int radius) { setUniform(radiusUniform, radius); - return this; + return *this; } - DistanceFieldShader* setScaling(const Vector2& scaling) { + DistanceFieldShader& setScaling(const Vector2& scaling) { setUniform(scalingUniform, scaling); - return this; + return *this; } - DistanceFieldShader* setImageSizeInverted(const Vector2& size) { + DistanceFieldShader& setImageSizeInverted(const Vector2& size) { setUniform(imageSizeInvertedUniform, size); - return this; + return *this; } private: @@ -158,8 +158,8 @@ void distanceField(Texture2D* input, Texture2D* output, const Rectanglei& rectan DistanceFieldShader shader; shader.setRadius(radius) - ->setScaling(Vector2(imageSize)/rectangle.size()) - ->use(); + .setScaling(Vector2(imageSize)/rectangle.size()) + .use(); input->bind(DistanceFieldShader::TextureLayer); @@ -174,7 +174,7 @@ void distanceField(Texture2D* input, Texture2D* output, const Rectanglei& rectan Mesh mesh; mesh.setPrimitive(Mesh::Primitive::Triangles) - ->setVertexCount(3); + .setVertexCount(3); /* Older GLSL doesn't have gl_VertexID, vertices must be supplied explicitly */ Buffer buffer; diff --git a/src/Timeline.h b/src/Timeline.h index ac67fb5f8..16ead00de 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -63,7 +63,7 @@ MyApplication::MyApplication(const Parameters& parameters): Platform::Applicatio // Initialization ... timeline.setMinimalFrameTime(1/120.0f) // 120 FPS at max - ->start(); + .start(); } void MyApplication::drawEvent() { @@ -96,14 +96,14 @@ class MAGNUM_EXPORT Timeline { /** * @brief Set minimal frame time - * @return Pointer to self (for method chaining) + * @return Reference to self (for method chaining) * * Default value is 0. * @see nextFrame() */ - Timeline* setMinimalFrameTime(Float seconds) { + Timeline& setMinimalFrameTime(Float seconds) { _minimalFrameTime = seconds; - return this; + return *this; } /**