Browse Source

Added missing method chaining to framebuffer configuration functions.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
23ba74c8c3
  1. 4
      src/AbstractFramebuffer.cpp
  2. 3
      src/AbstractFramebuffer.h
  3. 3
      src/DefaultFramebuffer.cpp
  4. 19
      src/DefaultFramebuffer.h
  5. 6
      src/Framebuffer.cpp
  6. 38
      src/Framebuffer.h

4
src/AbstractFramebuffer.cpp

@ -92,12 +92,14 @@ void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer&
#endif #endif
} }
void AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { AbstractFramebuffer* AbstractFramebuffer::setViewport(const Rectanglei& rectangle) {
_viewport = rectangle; _viewport = rectangle;
/* Update the viewport if the framebuffer is currently bound */ /* Update the viewport if the framebuffer is currently bound */
if(Context::current()->state()->framebuffer->drawBinding == _id) if(Context::current()->state()->framebuffer->drawBinding == _id)
setViewportInternal(); setViewportInternal();
return this;
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

3
src/AbstractFramebuffer.h

@ -195,13 +195,14 @@ class MAGNUM_EXPORT AbstractFramebuffer {
/** /**
* @brief Set viewport * @brief Set viewport
* @return Pointer to self (for method chaining)
* *
* Saves the viewport to be used at later time in bind(). If the * Saves the viewport to be used at later time in bind(). If the
* framebuffer is currently bound, updates the viewport to given * framebuffer is currently bound, updates the viewport to given
* rectangle. * rectangle.
* @see @fn_gl{Viewport} * @see @fn_gl{Viewport}
*/ */
void setViewport(const Rectanglei& rectangle); AbstractFramebuffer* setViewport(const Rectanglei& rectangle);
/** /**
* @brief Clear specified buffers in framebuffer * @brief Clear specified buffers in framebuffer

3
src/DefaultFramebuffer.cpp

@ -28,7 +28,7 @@ DefaultFramebuffer defaultFramebuffer;
DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } DefaultFramebuffer::DefaultFramebuffer() { _id = 0; }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
void DefaultFramebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments) { DefaultFramebuffer* DefaultFramebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments) {
/* Max attachment location */ /* Max attachment location */
std::size_t max = 0; std::size_t max = 0;
for(const auto& attachment: attachments) for(const auto& attachment: attachments)
@ -42,6 +42,7 @@ void DefaultFramebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt,
(this->*drawBuffersImplementation)(max+1, _attachments); (this->*drawBuffersImplementation)(max+1, _attachments);
delete[] _attachments; delete[] _attachments;
return this;
} }
#endif #endif

19
src/DefaultFramebuffer.h

@ -264,6 +264,7 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer {
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/** /**
* @brief Map shader outputs to buffer attachment * @brief Map shader outputs to buffer attachment
* @return Pointer to self (for method chaining)
* *
* @p attachments is list of shader outputs mapped to buffer * @p attachments is list of shader outputs mapped to buffer
* attachments. %Shader outputs which are not listed are not used, you * 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 * @requires_gles30 Draw attachments for default framebuffer are
* available only in OpenGL ES 3.0. * available only in OpenGL ES 3.0.
*/ */
void mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments); DefaultFramebuffer* mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments);
/** /**
* @brief Map shader output to buffer attachment * @brief Map shader output to buffer attachment
* @param attachment %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 * Similar to above function, can be used in cases when shader has
* only one (unnamed) output. * only one (unnamed) output.
@ -299,14 +301,16 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer {
* @requires_gles30 Draw attachments for default framebuffer are * @requires_gles30 Draw attachments for default framebuffer are
* available only in OpenGL ES 3.0. * available only in OpenGL ES 3.0.
*/ */
inline void mapForDraw(DrawAttachment attachment) { inline DefaultFramebuffer* mapForDraw(DrawAttachment attachment) {
(this->*drawBufferImplementation)(static_cast<GLenum>(attachment)); (this->*drawBufferImplementation)(static_cast<GLenum>(attachment));
return this;
} }
#endif #endif
/** /**
* @brief Map given attachment for reading * @brief Map given attachment for reading
* @param attachment %Buffer attachment * @param attachment %Buffer attachment
* @return Pointer to self (for method chaining)
* *
* If @extension{EXT,direct_state_access} is not available and the * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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} * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access}
* @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} * @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<GLenum>(attachment)); (this->*readBufferImplementation)(static_cast<GLenum>(attachment));
return this;
} }
/** /**
@ -350,6 +355,14 @@ class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer {
*/ */
void invalidate(std::initializer_list<InvalidationAttachment> attachments, const Rectanglei& rectangle); void invalidate(std::initializer_list<InvalidationAttachment> 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: private:
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);
}; };

6
src/Framebuffer.cpp

@ -58,7 +58,7 @@ Framebuffer::~Framebuffer() {
glDeleteFramebuffers(1, &_id); glDeleteFramebuffers(1, &_id);
} }
void Framebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments) { Framebuffer* Framebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments) {
/* Max attachment location */ /* Max attachment location */
std::size_t max = 0; std::size_t max = 0;
for(const auto& attachment: attachments) for(const auto& attachment: attachments)
@ -72,6 +72,7 @@ void Framebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAt
(this->*drawBuffersImplementation)(max+1, _attachments); (this->*drawBuffersImplementation)(max+1, _attachments);
delete[] _attachments; delete[] _attachments;
return this;
} }
void Framebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments) { void Framebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments) {
@ -94,9 +95,10 @@ void Framebuffer::invalidate(std::initializer_list<InvalidationAttachment> attac
delete[] _attachments; 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 */ /** @todo Check for texture target compatibility */
(this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel); (this->*texture2DImplementation)(attachment, GLenum(texture->target()), texture->id(), mipLevel);
return this;
} }
void Framebuffer::initializeContextBasedFunctionality(Context* context) { void Framebuffer::initializeContextBasedFunctionality(Context* context) {

38
src/Framebuffer.h

@ -221,6 +221,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
/** /**
* @brief Map shader output to attachments * @brief Map shader output to attachments
* @return Pointer to self (for method chaining)
* *
* @p attachments is list of shader outputs mapped to framebuffer * @p attachments is list of shader outputs mapped to framebuffer
* color attachment IDs. %Shader outputs which are not listed are not * 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} * @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access}
* @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} * @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers}
*/ */
void mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments); Framebuffer* mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments);
/** /**
* @brief Map shader output to attachment * @brief Map shader output to attachment
* @param attachment Draw attachment * @param attachment Draw attachment
* @return Pointer to self (for method chaining)
* *
* Similar to above function, can be used in cases when shader has * Similar to above function, can be used in cases when shader has
* only one (unnamed) output. * only one (unnamed) output.
@ -254,8 +256,9 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
* @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} * @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access}
* @requires_gles30 %Extension @es_extension2{NV,draw_buffers,GL_NV_draw_buffers} * @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)); (this->*drawBufferImplementation)(GLenum(attachment));
return this;
} }
/** /**
@ -292,6 +295,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
/** /**
* @brief Map given color attachment for reading * @brief Map given color attachment for reading
* @param attachment Color attachment * @param attachment Color attachment
* @return Pointer to self (for method chaining)
* *
* If @extension{EXT,direct_state_access} is not available and the * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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} * @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access}
* @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} * @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)); (this->*readBufferImplementation)(GLenum(attachment));
return this;
} }
/** /**
* @brief Attach renderbuffer to given buffer * @brief Attach renderbuffer to given buffer
* @param attachment %Buffer attachment * @param attachment %Buffer attachment
* @param renderbuffer %Renderbuffer * @param renderbuffer %Renderbuffer
* @return Pointer to self (for method chaining)
* *
* If @extension{EXT,direct_state_access} is not available and the * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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 * @see @fn_gl{BindFramebuffer}, @fn_gl{FramebufferRenderbuffer} or
* @fn_gl_extension{NamedFramebufferRenderbuffer,EXT,direct_state_access} * @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); (this->*renderbufferImplementation)(attachment, renderbuffer);
return this;
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -325,6 +332,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
* @param attachment %Buffer attachment * @param attachment %Buffer attachment
* @param texture 1D texture * @param texture 1D texture
* @param level Mip level * @param level Mip level
* @return Pointer to self (for method chaining)
* *
* If @extension{EXT,direct_state_access} is not available and the * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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} * @fn_gl_extension{NamedFramebufferTexture1D,EXT,direct_state_access}
* @requires_gl Only 2D and 3D textures are available in OpenGL ES. * @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); (this->*texture1DImplementation)(attachment, texture, level);
return this;
} }
#endif #endif
@ -343,6 +352,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
* @param attachment %Buffer attachment * @param attachment %Buffer attachment
* @param texture 2D texture * @param texture 2D texture
* @param level Mip level * @param level Mip level
* @return Pointer to self (for method chaining)
* *
* If @extension{EXT,direct_state_access} is not available and the * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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} * @see attachCubeMapTexture(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture}
* or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} * 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 * @brief Attach cube map texture to given buffer
@ -358,6 +368,7 @@ class MAGNUM_EXPORT Framebuffer: public AbstractFramebuffer {
* @param texture Cube map texture * @param texture Cube map texture
* @param coordinate Cube map coordinate * @param coordinate Cube map coordinate
* @param level Mip level * @param level Mip level
* @return Pointer to self (for method chaining)
* *
* If @extension{EXT,direct_state_access} is not available and the * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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} * @see attachTexture2D(), @fn_gl{BindFramebuffer}, @fn_gl{FramebufferTexture}
* or @fn_gl_extension{NamedFramebufferTexture2D,EXT,direct_state_access} * 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); (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 texture 3D texture
* @param level Mip level * @param level Mip level
* @param layer Layer of 2D image within a 3D texture * @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 * If @extension{EXT,direct_state_access} is not available and the
* framebufferbuffer is not currently bound, it is bound before 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} * @fn_gl_extension{NamedFramebufferTexture3D,EXT,direct_state_access}
* @requires_es_extension %Extension @es_extension{OES,texture_3D} * @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 */ /** @todo Check for texture target compatibility */
(this->*texture3DImplementation)(attachment, texture, level, layer); (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: private:
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context);

Loading…
Cancel
Save