diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2014-12-15 20:00:45 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2014-12-15 22:15:01 +0100 |
commit | 5e7709c5e9c1a5f444b1bff4096b0d3d3a541235 (patch) | |
tree | 8c37a448b1790fddfe5e7215450f89c1227a424f /vcl/opengl/gdiimpl.cxx | |
parent | 8286e92417794e68f6a53f887a426d5708fef0f6 (diff) |
use AA for lines only when AA is active
Change-Id: I9965f58b8f06f1cec2c419dcf16d8aebf9cd97b8
Diffstat (limited to 'vcl/opengl/gdiimpl.cxx')
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 70 |
1 files changed, 53 insertions, 17 deletions
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 09ffbf655dbf..69db79b052fc 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -36,9 +36,10 @@ #include <vector> -OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl(SalGeometryProvider* pParent) +OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl(SalGraphics& rParent, SalGeometryProvider *pProvider) : mpContext(0) - , mpParent(pParent) + , mrParent(rParent) + , mpProvider(pProvider) , mpFramebuffer(NULL) , mpProgram(NULL) , mbUseScissor(false) @@ -381,6 +382,18 @@ bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor ) return UseSolid( nColor, 0.0f ); } +// Like UseSolid(), but sets up for AA drawing, which uses gradients to create the AA. +bool OpenGLSalGraphicsImpl::UseSolidAA( SalColor nColor ) +{ + if( !mrParent.getAntiAliasB2DDraw()) + return UseSolid( nColor ); + if( !UseProgram( "textureVertexShader", "linearGradientFragmentShader" ) ) + return false; + mpProgram->SetColorf( "start_color", nColor, 0.0f ); + mpProgram->SetColorf( "end_color", nColor, 1.0f ); + return true; +} + bool OpenGLSalGraphicsImpl::UseInvert() { if( !UseSolid( MAKE_SALCOLOR( 255, 255, 255 ) ) ) @@ -402,8 +415,24 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY ) void OpenGLSalGraphicsImpl::DrawLine( long nX1, long nY1, long nX2, long nY2 ) { + GLfloat pPoints[4]; + + pPoints[0] = (2 * nX1) / GetWidth() - 1.0; + pPoints[1] = 1.0f - 2 * nY1 / GetHeight(); + pPoints[2] = (2 * nX2) / GetWidth() - 1.0;; + pPoints[3] = 1.0f - 2 * nY2 / GetHeight(); + + mpProgram->SetVertices( pPoints ); + glDrawArrays( GL_LINES, 0, 2 ); +} + +void OpenGLSalGraphicsImpl::DrawLineAA( long nX1, long nY1, long nX2, long nY2 ) +{ + if( !mrParent.getAntiAliasB2DDraw()) + return DrawLine( nX1, nY1, nX2, nY2 ); + if( nX1 == nX2 || nY1 == nY2 ) - { // horizontal/vertical, no need for AA + { // Horizontal/vertical, no need for AA, both points have normal color. GLfloat pPoints[4]; pPoints[0] = (2 * nX1) / GetWidth() - 1.0; @@ -412,6 +441,10 @@ void OpenGLSalGraphicsImpl::DrawLine( long nX1, long nY1, long nX2, long nY2 ) pPoints[3] = 1.0f - 2 * nY2 / GetHeight(); mpProgram->SetVertices( pPoints ); + // Still set up for the trivial "gradients", because presumably UseSolidAA() has been called. + GLfloat aTexCoord[4] = { 0, 1, 1, 1 }; + mpProgram->SetTextureCoord( aTexCoord ); + glDrawArrays( GL_LINES, 0, 2 ); return; } @@ -425,11 +458,6 @@ void OpenGLSalGraphicsImpl::DrawLine( long nX1, long nY1, long nX2, long nY2 ) * * Enjoy. Chris Tsang.*/ - if( !UseProgram( "textureVertexShader", "linearGradientFragmentShader" ) ) - return; - mpProgram->SetColorf( "start_color", mnLineColor, 0.0f ); - mpProgram->SetColorf( "end_color", mnLineColor, 1.0f ); - double x1 = nX1; double y1 = nY1; double x2 = nX2; @@ -546,6 +574,14 @@ void OpenGLSalGraphicsImpl::DrawLines( sal_uInt32 nPoints, const SalPoint* pPtAr DrawLine( pPtAry[ nPoints - 1 ].mnX, pPtAry[ nPoints - 1 ].mnY, pPtAry[ 0 ].mnX, pPtAry[ 0 ].mnY ); } +void OpenGLSalGraphicsImpl::DrawLinesAA( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose ) +{ + for( int i = 0; i < int(nPoints) - 1; ++i ) + DrawLineAA( pPtAry[ i ].mnX, pPtAry[ i ].mnY, pPtAry[ i + 1 ].mnX, pPtAry[ i + 1 ].mnY ); + if( bClose ) + DrawLineAA( pPtAry[ nPoints - 1 ].mnX, pPtAry[ nPoints - 1 ].mnY, pPtAry[ 0 ].mnX, pPtAry[ 0 ].mnY ); +} + void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) { std::vector<GLfloat> aVertices(nPoints * 2); @@ -925,8 +961,8 @@ void OpenGLSalGraphicsImpl::drawLine( long nX1, long nY1, long nX2, long nY2 ) if( mnLineColor != SALCOLOR_NONE ) { PreDraw(); - if( UseSolid( mnLineColor ) ) - DrawLine( nX1, nY1, nX2, nY2 ); + if( UseSolidAA( mnLineColor ) ) + DrawLineAA( nX1, nY1, nX2, nY2 ); PostDraw(); } } @@ -947,7 +983,7 @@ void OpenGLSalGraphicsImpl::drawRect( long nX, long nY, long nWidth, long nHeigh const long nY2( nY + nHeight ); const SalPoint aPoints[] = { { nX1, nY1 }, { nX2, nY1 }, { nX2, nY2 }, { nX1, nY2 } }; - DrawLines( 4, aPoints, true ); + DrawLines( 4, aPoints, true ); // No need for AA. } PostDraw(); @@ -960,8 +996,8 @@ void OpenGLSalGraphicsImpl::drawPolyLine( sal_uInt32 nPoints, const SalPoint* pP if( mnLineColor != SALCOLOR_NONE && nPoints > 1 ) { PreDraw(); - if( UseSolid( mnLineColor ) ) - DrawLines( nPoints, pPtAry, false ); + if( UseSolidAA( mnLineColor ) ) + DrawLinesAA( nPoints, pPtAry, false ); PostDraw(); } } @@ -988,8 +1024,8 @@ void OpenGLSalGraphicsImpl::drawPolygon( sal_uInt32 nPoints, const SalPoint* pPt if( UseSolid( mnFillColor ) ) DrawPolygon( nPoints, pPtAry ); - if( UseSolid( mnLineColor ) ) - DrawLines( nPoints, pPtAry, true ); + if( UseSolidAA( mnLineColor ) ) + DrawLinesAA( nPoints, pPtAry, true ); PostDraw(); } @@ -1008,11 +1044,11 @@ void OpenGLSalGraphicsImpl::drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* DrawPolygon( pPoints[i], pPtAry[i] ); } - if( UseSolid( mnLineColor ) ) + if( UseSolidAA( mnLineColor ) ) { // TODO Use glMultiDrawElements or primitive restart for( sal_uInt32 i = 0; i < nPoly; i++ ) - DrawLines( pPoints[i], pPtAry[i], true ); + DrawLinesAA( pPoints[i], pPtAry[i], true ); } PostDraw(); |