Skip to content

Commit

Permalink
Adds gl::ScopedColorMask and gl::ScopedStencilMask.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhoux committed Dec 29, 2023
1 parent e10faeb commit fc38549
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions include/cinder/gl/scoped.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,57 @@ struct CI_API ScopedFrontFace : private Noncopyable {
Context *mCtx;
};

//!
class ScopedColorMask {
public:
ScopedColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha )
{
glGetBooleanv( GL_COLOR_WRITEMASK, mMask );
glColorMask( red, green, blue, alpha );
}
~ScopedColorMask() { glColorMask( mMask[0], mMask[1], mMask[2], mMask[3] ); }

ScopedColorMask( const ScopedColorMask & ) = delete;
ScopedColorMask( ScopedColorMask && ) = delete;
ScopedColorMask &operator=( const ScopedColorMask & ) = delete;
ScopedColorMask &operator=( ScopedColorMask && ) = delete;

private:
GLboolean mMask[4] = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
};

//!
class ScopedStencilMask {
public:
ScopedStencilMask( GLuint mask )
{
glGetIntegerv( GL_STENCIL_WRITEMASK , &mFrontMask);
glGetIntegerv( GL_STENCIL_BACK_WRITEMASK, &mBackMask );
glStencilMask( mask );
}
ScopedStencilMask( GLuint front, GLuint back )
{
glGetIntegerv( GL_STENCIL_WRITEMASK , &mFrontMask);
glGetIntegerv( GL_STENCIL_BACK_WRITEMASK, &mBackMask );
glStencilMaskSeparate( GL_FRONT, front );
glStencilMaskSeparate( GL_BACK, back );
}
~ScopedStencilMask()
{
glStencilMaskSeparate( GL_FRONT, mFrontMask );
glStencilMaskSeparate( GL_BACK, mBackMask );
}

ScopedStencilMask( const ScopedStencilMask & ) = delete;
ScopedStencilMask( ScopedStencilMask && ) = delete;
ScopedStencilMask &operator=( const ScopedStencilMask & ) = delete;
ScopedStencilMask &operator=( ScopedStencilMask && ) = delete;

private:
GLint mFrontMask = 0xFF;
GLint mBackMask = 0xFF;
};

#if defined( CINDER_GL_HAS_KHR_DEBUG )

//! Scopes debug group message
Expand Down

0 comments on commit fc38549

Please sign in to comment.