[Libreoffice-commits] core.git: vcl/inc vcl/opengl
Luboš Luňák
l.lunak at collabora.com
Thu Dec 18 03:06:05 PST 2014
vcl/inc/openglgdiimpl.hxx | 10 ++++-
vcl/opengl/gdiimpl.cxx | 78 ++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 79 insertions(+), 9 deletions(-)
New commits:
commit 783ba49aa0cd068c7e3dacdd3c13e9c37cf52e22
Author: Luboš Luňák <l.lunak at collabora.com>
Date: Thu Dec 18 11:47:58 2014 +0100
draw also opengl polygon with AA edges if AA is wanted
Especially given that lines are sometimes actually drawn using polygons.
Change-Id: I429a24faff94f8b9accc20bdee3ff66f47669bde
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 2c911ee..4ca30b3 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -56,6 +56,9 @@ protected:
SalColor mnLineColor;
SalColor mnFillColor;
+#ifdef DBG_UTIL
+ bool mProgramIsSolidLineColor;
+#endif
void ImplInitClipRegion();
void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
@@ -67,20 +70,21 @@ public:
bool UseSolid( SalColor nColor, sal_uInt8 nTransparency );
bool UseSolid( SalColor nColor, double fTransparency );
bool UseSolid( SalColor nColor );
+ bool UseSolidAA( SalColor nColor, double fTransparency );
bool UseSolidAA( SalColor nColor );
bool UseInvert();
void DrawPoint( long nX, long nY );
- void DrawLine( long nX1, long nY1, long nX2, long nY2 );
+ void DrawLine( double nX1, double nY1, double nX2, double nY2 );
void DrawLines( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
- void DrawLineAA( long nX1, long nY1, long nX2, long nY2 );
+ void DrawLineAA( double nX1, double nY1, double nX2, double nY2 );
void DrawLinesAA( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
void DrawConvexPolygon( const Polygon& rPolygon );
void DrawRect( long nX, long nY, long nWidth, long nHeight );
void DrawRect( const Rectangle& rRect );
void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
- void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon );
+ void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false );
void DrawRegionBand( const RegionBand& rRegion );
void DrawTextureRect( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
void DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 69db79b..f75966f 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -47,6 +47,9 @@ OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl(SalGraphics& rParent, SalGeometryPr
, mbOffscreen(false)
, mnLineColor(SALCOLOR_NONE)
, mnFillColor(SALCOLOR_NONE)
+#ifdef DBG_UTIL
+ , mProgramIsSolidLineColor(false)
+#endif
{
}
@@ -162,6 +165,9 @@ void OpenGLSalGraphicsImpl::PostDraw()
{
mpProgram->Clean();
mpProgram = NULL;
+#ifdef DBG_UTIL
+ mProgramIsSolidLineColor = false;
+#endif
}
CHECK_GL_ERROR();
@@ -192,7 +198,7 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa
if( rClip.getRegionBand() )
DrawRegionBand( *rClip.getRegionBand() );
else
- DrawPolyPolygon( rClip.GetAsB2DPolyPolygon() );
+ DrawPolyPolygon( rClip.GetAsB2DPolyPolygon(), true );
}
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
@@ -354,6 +360,9 @@ bool OpenGLSalGraphicsImpl::UseProgram( const OUString& rVertexShader, const OUS
if( mpProgram != NULL )
mpProgram->Clean();
mpProgram = mpContext->UseProgram( rVertexShader, rFragmentShader );
+#ifdef DBG_UTIL
+ mProgramIsSolidLineColor = false; // UseSolid() will set to true if needed
+#endif
return ( mpProgram != NULL );
}
@@ -364,6 +373,9 @@ bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor, sal_uInt8 nTransparency )
if( !UseProgram( "dumbVertexShader", "solidFragmentShader" ) )
return false;
mpProgram->SetColor( "color", nColor, nTransparency );
+#ifdef DBG_UTIL
+ mProgramIsSolidLineColor = true;
+#endif
return true;
}
@@ -374,6 +386,9 @@ bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor, double fTransparency )
if( !UseProgram( "dumbVertexShader", "solidFragmentShader" ) )
return false;
mpProgram->SetColorf( "color", nColor, fTransparency );
+#ifdef DBG_UTIL
+ mProgramIsSolidLineColor = true;
+#endif
return true;
}
@@ -383,17 +398,22 @@ bool OpenGLSalGraphicsImpl::UseSolid( SalColor nColor )
}
// Like UseSolid(), but sets up for AA drawing, which uses gradients to create the AA.
-bool OpenGLSalGraphicsImpl::UseSolidAA( SalColor nColor )
+bool OpenGLSalGraphicsImpl::UseSolidAA( SalColor nColor, double fTransparency )
{
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 );
+ mpProgram->SetColorf( "end_color", nColor, fTransparency );
return true;
}
+bool OpenGLSalGraphicsImpl::UseSolidAA( SalColor nColor )
+{
+ return UseSolidAA( nColor, 1.0 );
+}
+
bool OpenGLSalGraphicsImpl::UseInvert()
{
if( !UseSolid( MAKE_SALCOLOR( 255, 255, 255 ) ) )
@@ -413,7 +433,7 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
glDrawArrays( GL_POINTS, 0, 1 );
}
-void OpenGLSalGraphicsImpl::DrawLine( long nX1, long nY1, long nX2, long nY2 )
+void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, double nY2 )
{
GLfloat pPoints[4];
@@ -426,7 +446,7 @@ void OpenGLSalGraphicsImpl::DrawLine( long nX1, long nY1, long nX2, long nY2 )
glDrawArrays( GL_LINES, 0, 2 );
}
-void OpenGLSalGraphicsImpl::DrawLineAA( long nX1, long nY1, long nX2, long nY2 )
+void OpenGLSalGraphicsImpl::DrawLineAA( double nX1, double nY1, double nX2, double nY2 )
{
if( !mrParent.getAntiAliasB2DDraw())
return DrawLine( nX1, nY1, nX2, nY2 );
@@ -612,6 +632,27 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const Polygon& rPolygon )
mpProgram->SetVertices( &aVertices[0] );
glDrawArrays( GL_TRIANGLE_FAN, 0, nPoints );
+
+ if( mrParent.getAntiAliasB2DDraw())
+ {
+ // Make the edges antialiased by drawing the edge lines again with AA.
+ // TODO: If transparent drawing is set up, drawing the lines themselves twice
+ // may be a problem, if that is a real problem, the polygon areas itself needs to be
+ // masked out for this or something.
+#ifdef DBG_UTIL
+ assert( mProgramIsSolidLineColor );
+#endif
+ UseSolidAA( mnLineColor );
+ for( i = 0; i < nPoints; ++i )
+ {
+ const Point& rPt1 = rPolygon.GetPoint( i );
+ const Point& rPt2 = rPolygon.GetPoint(( i + 1 ) % nPoints );
+ if( rPt1.getX() == rPt2.getX() || rPt1.getY() == rPt2.getY())
+ continue; //horizontal/vertical, no need for AA
+ DrawLineAA( rPt1.getX(), rPt1.getY(), rPt2.getX(), rPt2.getY());
+ }
+ UseSolid( mnLineColor );
+ }
}
void OpenGLSalGraphicsImpl::DrawRect( long nX, long nY, long nWidth, long nHeight )
@@ -658,7 +699,7 @@ void OpenGLSalGraphicsImpl::DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPt
}
}
-void OpenGLSalGraphicsImpl::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon )
+void OpenGLSalGraphicsImpl::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA )
{
::std::vector< GLfloat > aVertices;
GLfloat nWidth = GetWidth();
@@ -682,6 +723,31 @@ void OpenGLSalGraphicsImpl::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPol
mpProgram->SetVertices( aVertices.data() );
glDrawArrays( GL_TRIANGLES, 0, aVertices.size() / 2 );
+ if( !blockAA && mrParent.getAntiAliasB2DDraw())
+ {
+ // Make the edges antialiased by drawing the edge lines again with AA.
+ // TODO: If transparent drawing is set up, drawing the lines themselves twice
+ // may be a problem, if that is a real problem, the polygon areas itself needs to be
+ // masked out for this or something.
+#ifdef DBG_UTIL
+ assert( mProgramIsSolidLineColor );
+#endif
+ UseSolidAA( mnLineColor );
+ for( sal_uInt32 i = 0; i < aSimplePolyPolygon.count(); i++ )
+ {
+ const basegfx::B2DPolygon& rPolygon( aSimplePolyPolygon.getB2DPolygon( i ) );
+ for( sal_uInt32 j = 0; j < rPolygon.count(); j++ )
+ {
+ const ::basegfx::B2DPoint& rPt1( rPolygon.getB2DPoint( j ) );
+ const ::basegfx::B2DPoint& rPt2( rPolygon.getB2DPoint(( j + 1 ) % rPolygon.count()) );
+ if( rPt1.getX() == rPt2.getX() || rPt1.getY() == rPt2.getY())
+ continue; //horizontal/vertical, no need for AA
+ DrawLineAA( rPt1.getX(), rPt1.getY(), rPt2.getX(), rPt2.getY());
+ }
+ }
+ UseSolid( mnLineColor );
+ }
+
CHECK_GL_ERROR();
}
More information about the Libreoffice-commits
mailing list