diff options
author | Louis-Francis Ratté-Boulianne <lfrb@collabora.com> | 2014-11-08 22:55:06 -0500 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-11-10 07:59:46 +0100 |
commit | 5302d5a3b7dddc40110674b509068c37ba1fd7b1 (patch) | |
tree | a38e86414fcd010da3de257b41bf788f598bc1db /vcl | |
parent | ab63fe781cc8862e970932df2915982ce4770f92 (diff) |
vcl: Add support for transparent polygon drawing with OpenGL
Change-Id: Iaa7cdcf4742d8148507c69c222bff417b9f9426c
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/openglgdiimpl.hxx | 1 | ||||
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 55 | ||||
-rw-r--r-- | vcl/opengl/solidFragmentShader.glsl | 2 | ||||
-rw-r--r-- | vcl/source/outdev/polygon.cxx | 2 |
4 files changed, 55 insertions, 5 deletions
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx index b05a520d195d..9368a1039bc7 100644 --- a/vcl/inc/openglgdiimpl.hxx +++ b/vcl/inc/openglgdiimpl.hxx @@ -61,6 +61,7 @@ protected: bool CreateMaskProgram( void ); void BeginSolid( SalColor nColor, sal_uInt8 nTransparency ); + void BeginSolid( SalColor nColor, double fTransparency ); void BeginSolid( SalColor nColor ); void EndSolid( void ); void BeginInvert( void ); diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 92882601c306..55b6a93ad61c 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -40,6 +40,13 @@ ((float) SALCOLOR_BLUE( nColor )) / 255, \ (100 - nTransparency) * (1.0 / 100) ) +#define glUniformColorf(nUniform, nColor, fTransparency) \ + glUniform4f( nUniform, \ + ((float) SALCOLOR_RED( nColor )) / 255, \ + ((float) SALCOLOR_GREEN( nColor )) / 255, \ + ((float) SALCOLOR_BLUE( nColor )) / 255, \ + (1.0f - fTransparency) ) + OpenGLSalGraphicsImpl::~OpenGLSalGraphicsImpl() { } @@ -202,18 +209,41 @@ void OpenGLSalGraphicsImpl::BeginSolid( SalColor nColor, sal_uInt8 nTransparency return; } + if( nTransparency > 0 ) + { + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + } glUseProgram( mnSolidProgram ); glUniformColor( mnColorUniform, nColor, nTransparency ); } +void OpenGLSalGraphicsImpl::BeginSolid( SalColor nColor, double fTransparency ) +{ + if( mnSolidProgram == 0 ) + { + if( !CreateSolidProgram() ) + return; + } + + if( fTransparency > 0.0f ) + { + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + } + glUseProgram( mnSolidProgram ); + glUniformColorf( mnColorUniform, nColor, fTransparency ); +} + void OpenGLSalGraphicsImpl::BeginSolid( SalColor nColor ) { - BeginSolid( nColor, 0 ); + BeginSolid( nColor, 0.0f ); } void OpenGLSalGraphicsImpl::EndSolid( void ) { glUseProgram( 0 ); + glDisable( GL_BLEND ); } void OpenGLSalGraphicsImpl::BeginInvert( void ) @@ -592,9 +622,27 @@ void OpenGLSalGraphicsImpl::drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* } } -bool OpenGLSalGraphicsImpl::drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double /*fTransparency*/ ) +bool OpenGLSalGraphicsImpl::drawPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency ) { - return false; + SAL_INFO( "vcl.opengl", "::drawPolyPolygon trans " << fTransparency ); + if( rPolyPolygon.count() <= 0 ) + return true; + + maContext.makeCurrent(); + glViewport( 0, 0, GetWidth(), GetHeight() ); + + if( mnFillColor != SALCOLOR_NONE ) + { + BeginSolid( mnFillColor, fTransparency ); + for( sal_uInt32 i = 0; i < rPolyPolygon.count(); i++ ) + { + const ::basegfx::B2DPolyPolygon aOnePoly( rPolyPolygon.getB2DPolygon( i ) ); + DrawPolyPolygon( aOnePoly ); + } + EndSolid(); + } + + return true; } bool OpenGLSalGraphicsImpl::drawPolyLine( @@ -843,6 +891,7 @@ bool OpenGLSalGraphicsImpl::drawAlphaRect( long nWidth, long nHeight, sal_uInt8 nTransparency ) { + SAL_INFO( "vcl.opengl", "::drawAlphaRect" ); if( mnFillColor != SALCOLOR_NONE && nTransparency < 100 ) { BeginSolid( mnFillColor, nTransparency ); diff --git a/vcl/opengl/solidFragmentShader.glsl b/vcl/opengl/solidFragmentShader.glsl index 94d0de0a09a7..af7533604cef 100644 --- a/vcl/opengl/solidFragmentShader.glsl +++ b/vcl/opengl/solidFragmentShader.glsl @@ -11,7 +11,7 @@ uniform vec4 color; void main() { - gl_FragColor = color; + gl_FragColor = color; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/outdev/polygon.cxx b/vcl/source/outdev/polygon.cxx index 39c2b6807a77..03fa16888ea3 100644 --- a/vcl/source/outdev/polygon.cxx +++ b/vcl/source/outdev/polygon.cxx @@ -231,7 +231,7 @@ void OutputDevice::DrawPolygon( const Polygon& rPoly ) // Caution: This method is nearly the same as // OutputDevice::DrawTransparent( const basegfx::B2DPolyPolygon& rB2DPolyPoly, double fTransparency), -// so when changes are made here do not forget to make change sthere, too +// so when changes are made here do not forget to make changes there, too void OutputDevice::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rB2DPolyPoly ) { |