From 23ba74c8c32863f420a7346e6dc416219832b450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 Mar 2013 15:21:24 +0100 Subject: [PATCH] Added missing method chaining to framebuffer configuration functions. --- src/AbstractFramebuffer.cpp | 4 +++- src/AbstractFramebuffer.h | 3 ++- src/DefaultFramebuffer.cpp | 3 ++- src/DefaultFramebuffer.h | 19 ++++++++++++++++--- src/Framebuffer.cpp | 6 ++++-- src/Framebuffer.h | 38 +++++++++++++++++++++++++++++-------- 6 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/AbstractFramebuffer.cpp b/src/AbstractFramebuffer.cpp index e0855a4de..ef5761a97 100644 --- a/src/AbstractFramebuffer.cpp +++ b/src/AbstractFramebuffer.cpp @@ -92,12 +92,14 @@ void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& #endif } -void 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; } #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/AbstractFramebuffer.h b/src/AbstractFramebuffer.h index 443d5982b..3d1d1b76a 100644 --- a/src/AbstractFramebuffer.h +++ b/src/AbstractFramebuffer.h @@ -195,13 +195,14 @@ class MAGNUM_EXPORT AbstractFramebuffer { /** * @brief Set viewport + * @return Pointer 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} */ - void setViewport(const Rectanglei& rectangle); + AbstractFramebuffer* setViewport(const Rectanglei& rectangle); /** * @brief Clear specified buffers in framebuffer diff --git a/src/DefaultFramebuffer.cpp b/src/DefaultFramebuffer.cpp index 0303e3e2e..6b1f61b69 100644 --- a/src/DefaultFramebuffer.cpp +++ b/src/DefaultFramebuffer.cpp @@ -28,7 +28,7 @@ DefaultFramebuffer defaultFramebuffer; DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } #ifndef MAGNUM_TARGET_GLES2 -void 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) @@ -42,6 +42,7 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; + return this; } #endif diff --git a/src/DefaultFramebuffer.h b/src/DefaultFramebuffer.h index 6bbb736bd..a6fd57dc1 100644 --- a/src/DefaultFramebuffer.h +++ b/src/DefaultFramebuffer.h @@ -264,6 +264,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) * * @p attachments is list of shader outputs mapped to buffer * attachments. %Shader outputs which are not listed are not used, you @@ -282,11 +283,12 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - void 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) * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -299,14 +301,16 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { * @requires_gles30 Draw attachments for default framebuffer are * available only in OpenGL ES 3.0. */ - inline void mapForDraw(DrawAttachment attachment) { + inline DefaultFramebuffer* mapForDraw(DrawAttachment attachment) { (this->*drawBufferImplementation)(static_cast(attachment)); + return this; } #endif /** * @brief Map given attachment for reading * @param attachment %Buffer attachment + * @return Pointer 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 @@ -315,8 +319,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} */ - inline void mapForRead(ReadAttachment attachment) { + inline DefaultFramebuffer* mapForRead(ReadAttachment attachment) { (this->*readBufferImplementation)(static_cast(attachment)); + return this; } /** @@ -350,6 +355,14 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { */ void invalidate(std::initializer_list attachments, const Rectanglei& rectangle); + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline DefaultFramebuffer* setViewport(const Rectanglei& rectangle) { + AbstractFramebuffer::setViewport(rectangle); + return this; + } + #endif + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); }; diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index 89ee445e5..a4f5e0102 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -58,7 +58,7 @@ Framebuffer::~Framebuffer() { glDeleteFramebuffers(1, &_id); } -void 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) @@ -72,6 +72,7 @@ void Framebuffer::mapForDraw(std::initializer_list*drawBuffersImplementation)(max+1, _attachments); delete[] _attachments; + return this; } void Framebuffer::invalidate(std::initializer_list attachments) { @@ -94,9 +95,10 @@ void Framebuffer::invalidate(std::initializer_list attac delete[] _attachments; } -void 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; } void Framebuffer::initializeContextBasedFunctionality(Context* context) { diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 706374210..78ebbcc95 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -221,6 +221,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { /** * @brief Map shader output to attachments + * @return Pointer 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 @@ -238,11 +239,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} */ - void 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) * * Similar to above function, can be used in cases when shader has * only one (unnamed) output. @@ -254,8 +256,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} */ - inline void mapForDraw(DrawAttachment attachment) { + inline Framebuffer* mapForDraw(DrawAttachment attachment) { (this->*drawBufferImplementation)(GLenum(attachment)); + return this; } /** @@ -292,6 +295,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) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -300,14 +304,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} */ - inline void mapForRead(ColorAttachment attachment) { + inline Framebuffer* mapForRead(ColorAttachment attachment) { (this->*readBufferImplementation)(GLenum(attachment)); + return this; } /** * @brief Attach renderbuffer to given buffer * @param attachment %Buffer attachment * @param renderbuffer %Renderbuffer + * @return Pointer 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 @@ -315,8 +321,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or * @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} */ - inline void attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { + inline Framebuffer* attachRenderbuffer(BufferAttachment attachment, Renderbuffer* renderbuffer) { (this->*renderbufferImplementation)(attachment, renderbuffer); + return this; } #ifndef MAGNUM_TARGET_GLES @@ -325,6 +332,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) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -333,8 +341,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. */ - inline void attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { + inline Framebuffer* attachTexture1D(BufferAttachment attachment, Texture1D* texture, Int level) { (this->*texture1DImplementation)(attachment, texture, level); + return this; } #endif @@ -343,6 +352,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) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -350,7 +360,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - void attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); + Framebuffer* attachTexture2D(BufferAttachment attachment, Texture2D* texture, Int level); /** * @brief Attach cube map texture to given buffer @@ -358,6 +368,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) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -365,8 +376,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture} * or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} */ - inline void attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { + inline Framebuffer* attachCubeMapTexture(BufferAttachment attachment, CubeMapTexture* texture, CubeMapTexture::Coordinate coordinate, Int level) { (this->*texture2DImplementation)(attachment, GLenum(coordinate), texture->id(), level); + return this; } /** @@ -375,6 +387,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) * * If @extension{EXT,direct_state_access} is not available and the * framebufferbuffer is not currently bound, it is bound before the @@ -383,11 +396,20 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer { * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access} * @requires_es_extension %Extension @es_extension{OES,texture_3D} */ - inline void attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { + inline Framebuffer* attachTexture3D(BufferAttachment attachment, Texture3D* texture, Int level, Int layer) { /** @todo Check for texture target compatibility */ (this->*texture3DImplementation)(attachment, texture, level, layer); + return this; } + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Framebuffer* setViewport(const Rectanglei& rectangle) { + AbstractFramebuffer::setViewport(rectangle); + return this; + } + #endif + private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);