summaryrefslogtreecommitdiff
path: root/vcl/opengl
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>2014-11-08 22:55:06 -0500
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-11-10 07:59:46 +0100
commit5302d5a3b7dddc40110674b509068c37ba1fd7b1 (patch)
treea38e86414fcd010da3de257b41bf788f598bc1db /vcl/opengl
parentab63fe781cc8862e970932df2915982ce4770f92 (diff)
vcl: Add support for transparent polygon drawing with OpenGL
Change-Id: Iaa7cdcf4742d8148507c69c222bff417b9f9426c
Diffstat (limited to 'vcl/opengl')
-rw-r--r--vcl/opengl/gdiimpl.cxx55
-rw-r--r--vcl/opengl/solidFragmentShader.glsl2
2 files changed, 53 insertions, 4 deletions
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: */