diff options
author | Louis-Francis Ratté-Boulianne <lfrb@collabora.com> | 2014-11-08 23:01:27 -0500 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-11-10 07:59:49 +0100 |
commit | 20328280dc38c80d70a3110e7a3153246b90123f (patch) | |
tree | 2f30da8b022d636689b23f3dc66da672ba599ed0 /vcl/opengl | |
parent | vcl: Fix some viewport issues when rendering with OpenGL (diff) | |
download | core-20328280dc38c80d70a3110e7a3153246b90123f.tar.gz core-20328280dc38c80d70a3110e7a3153246b90123f.zip |
vcl: Add support for alpha mask rendering with OpenGL
Change-Id: I755c2132f143d5ebd69e53bb4d9ae45121ada22a
Diffstat (limited to 'vcl/opengl')
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 16 | ||||
-rw-r--r-- | vcl/opengl/maskedTextureFragmentShader.glsl | 9 |
2 files changed, 16 insertions, 9 deletions
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 74f725249025..0e30f6a68bb6 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -444,7 +444,7 @@ void OpenGLSalGraphicsImpl::DrawTexture( GLuint nTexture, const Size& rSize, con glUseProgram( 0 ); } -void OpenGLSalGraphicsImpl::DrawTextureWithMask( GLuint nTexture, GLuint nMask, const SalTwoRect& /*pPosAry*/ ) +void OpenGLSalGraphicsImpl::DrawTextureWithMask( GLuint nTexture, GLuint nMask, const Size& rSize, const SalTwoRect& pPosAry ) { if( mnMaskedTextureProgram == 0 ) { @@ -460,7 +460,10 @@ void OpenGLSalGraphicsImpl::DrawTextureWithMask( GLuint nTexture, GLuint nMask, glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, nMask ); - //DrawTextureRect( pPosAry ); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + DrawTextureRect( rSize, pPosAry ); + glDisable( GL_BLEND ); glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, 0 ); @@ -758,9 +761,10 @@ void OpenGLSalGraphicsImpl::drawBitmap( const GLuint nTexture( rBitmap.GetTexture( maContext ) ); const GLuint nMask( rMask.GetTexture( maContext ) ); - SAL_INFO( "vcl.opengl", "::drawBitmap" ); + SAL_INFO( "vcl.opengl", "::drawBitmap with MASK" ); maContext.makeCurrent(); - DrawTextureWithMask( nTexture, nMask, rPosAry ); + glViewport( 0, 0, GetWidth(), GetHeight() ); + DrawTextureWithMask( nTexture, nMask, rBitmap.GetSize(), rPosAry ); } void OpenGLSalGraphicsImpl::drawMask( @@ -881,8 +885,10 @@ bool OpenGLSalGraphicsImpl::drawAlphaBitmap( const GLuint nTexture( rBitmap.GetTexture( maContext ) ); const GLuint nAlpha( rAlpha.GetTexture( maContext ) ); + SAL_INFO( "vcl.opengl", "::drawAlphaBitmap" ); maContext.makeCurrent(); - DrawTextureWithMask( nTexture, nAlpha, rPosAry ); + glViewport( 0, 0, GetWidth(), GetHeight() ); + DrawTextureWithMask( nTexture, nAlpha, rBitmap.GetSize(), rPosAry ); return true; } diff --git a/vcl/opengl/maskedTextureFragmentShader.glsl b/vcl/opengl/maskedTextureFragmentShader.glsl index 8f8148aa6dcb..badf91e6edae 100644 --- a/vcl/opengl/maskedTextureFragmentShader.glsl +++ b/vcl/opengl/maskedTextureFragmentShader.glsl @@ -13,10 +13,11 @@ uniform sampler2D sampler; uniform sampler2D mask; void main() { - vec4 texel0, texel1; - texel0 = texture2D(sampler, tex_coord); - texel1 = texture2D(mask, tex_coord); - gl_FragColor = texel0 * texel1.a; + vec4 texel0, texel1; + texel0 = texture2D(sampler, tex_coord); + texel1 = texture2D(mask, tex_coord); + gl_FragColor = texel0; + gl_FragColor.a = texel1.r; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |