[Libreoffice-commits] core.git: Branch 'feature/opengl-vcl' - 2 commits - vcl/inc vcl/opengl

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Wed Nov 12 15:12:42 PST 2014


 vcl/inc/openglgdiimpl.hxx |    2 
 vcl/opengl/gdiimpl.cxx    |   96 +++++++++++++++++++++++++++-------------------
 2 files changed, 59 insertions(+), 39 deletions(-)

New commits:
commit b334ac1f891eaa5b8cea17ea7d71e2e51b0d1f12
Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Wed Nov 12 18:12:00 2014 -0500

    vcl: Fix several coordinates calculations
    
    Change-Id: I15878b4d91081a7ac880713ad278893aaad4a844

diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 9b17d98..c4e8bb4 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -447,7 +447,7 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
     GLfloat pPoint[2];
 
     pPoint[0] = 2 * nX / GetWidth() - 1.0f;
-    pPoint[1] = 2 * (GetHeight() - nY) / GetHeight() - 1.0f;
+    pPoint[1] = 1.0f - 2 * nY / GetHeight();
 
     glEnableVertexAttribArray( GL_ATTRIB_POS );
     glVertexAttribPointer( GL_ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pPoint );
@@ -462,9 +462,9 @@ void OpenGLSalGraphicsImpl::DrawLine( long nX1, long nY1, long nX2, long nY2 )
     GLfloat pPoints[4];
 
     pPoints[0] = (2 * nX1) / GetWidth() - 1.0;
-    pPoints[1] = (2 * (GetHeight() - nY1)) / GetHeight() - 1.0;
+    pPoints[1] = 1.0f - 2 * nY1 / GetHeight();
     pPoints[2] = (2 * nX2) / GetWidth() - 1.0;;
-    pPoints[3] = (2 * (GetHeight() - nY2)) / GetHeight() - 1.0;
+    pPoints[3] = 1.0f - 2 * nY2 / GetHeight();
 
     glEnableVertexAttribArray( GL_ATTRIB_POS );
     glVertexAttribPointer( GL_ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pPoints );
@@ -504,7 +504,7 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin
     for( i = 0, j = 0; i < nPoints; i++, j += 2 )
     {
         aVertices[j] = (2 * pPtAry[i].mnX) / GetWidth() - 1.0;
-        aVertices[j+1] = (2 * pPtAry[i].mnY) / GetHeight() - 1.0;
+        aVertices[j+1] = 1.0 - (2 * pPtAry[i].mnY / GetHeight());
     }
 
     glEnableVertexAttribArray( GL_ATTRIB_POS );
@@ -525,7 +525,7 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const Polygon& rPolygon )
     {
         const Point& rPt = rPolygon.GetPoint( i );
         aVertices[j] = (2 * rPt.X()) / GetWidth() - 1.0;
-        aVertices[j+1] = (2 * (GetHeight() - rPt.Y())) / GetHeight() - 1.0;
+        aVertices[j+1] = 1.0 - (2 * rPt.Y() / GetHeight());
     }
 
     glEnableVertexAttribArray( GL_ATTRIB_POS );
@@ -539,9 +539,9 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const Polygon& rPolygon )
 void OpenGLSalGraphicsImpl::DrawRect( long nX, long nY, long nWidth, long nHeight )
 {
     long nX1( nX );
-    long nY1( GetHeight() - nY );
+    long nY1( nY );
     long nX2( nX + nWidth );
-    long nY2( GetHeight() - nY - nHeight );
+    long nY2( nY + nHeight );
     const SalPoint aPoints[] = { { nX1, nY2 }, { nX1, nY1 },
                                  { nX2, nY1 }, { nX2, nY2 }};
 
@@ -551,9 +551,9 @@ void OpenGLSalGraphicsImpl::DrawRect( long nX, long nY, long nWidth, long nHeigh
 void OpenGLSalGraphicsImpl::DrawRect( const Rectangle& rRect )
 {
     long nX1( rRect.Left() );
-    long nY1( GetHeight() - rRect.Top() );
+    long nY1( rRect.Top() );
     long nX2( rRect.Right() );
-    long nY2( GetHeight() - rRect.Bottom() );
+    long nY2( rRect.Bottom() );
     const SalPoint aPoints[] = { { nX1, nY2 }, { nX1, nY1 },
                                  { nX2, nY1 }, { nX2, nY2 }};
 
commit 0774719910e808bcf7ef3e891b7456e05d3deae6
Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Wed Nov 12 18:11:34 2014 -0500

    vcl: Use stencil mask to clip gradient shape
    
    Change-Id: I5dc17a20ab65f0b0bad4741a7d1ec76a0e028e23

diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 82bb919..167fe60 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -74,6 +74,8 @@ protected:
     GLuint mnRadialGradientEndColorUniform;
     GLuint mnRadialGradientCenterUniform;
 
+    void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
+
     bool CreateSolidProgram( void );
     bool CreateTextureProgram( void );
     bool CreateMaskedTextureProgram( void );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 661a197..9b17d98 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -102,7 +102,10 @@ void OpenGLSalGraphicsImpl::PreDraw()
     if( mbUseScissor )
         glEnable( GL_SCISSOR_TEST );
     if( mbUseStencil )
+    {
+        glStencilFunc( GL_EQUAL, 1, 0x1 );
         glEnable( GL_STENCIL_TEST );
+    }
 
     CHECK_GL_ERROR();
 }
@@ -125,6 +128,24 @@ void OpenGLSalGraphicsImpl::freeResources()
     // TODO Delete shaders, programs and textures if not shared
 }
 
+void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMask )
+{
+    glEnable( GL_STENCIL_TEST );
+    glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
+    glStencilMask( nMask );
+    glStencilFunc( GL_NEVER, nMask, 0xFF );
+    glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP );
+
+    glClear( GL_STENCIL_BUFFER_BIT );
+    BeginSolid( MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF ) );
+    DrawPolyPolygon( rClip.GetAsB2DPolyPolygon() );
+    EndSolid();
+
+    glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
+    glStencilMask( 0x00 );
+    glDisable( GL_STENCIL_TEST );
+}
+
 bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
 {
     SAL_INFO( "vcl.opengl", "::setClipRegion " << rClip );
@@ -150,22 +171,7 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
         mbUseScissor = false;
         maContext.makeCurrent();
         glViewport( 0, 0, GetWidth(), GetHeight() );
-
-        glEnable( GL_STENCIL_TEST );
-        glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
-        glStencilMask( 0xFF );
-        glStencilFunc( GL_NEVER, 1, 0xFF );
-        glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP );
-
-        glClear( GL_STENCIL_BUFFER_BIT );
-        BeginSolid( SALCOLOR_NONE );
-        DrawPolyPolygon( rClip.GetAsB2DPolyPolygon() );
-        EndSolid();
-
-        glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
-        glStencilMask( 0x00 );
-        glStencilFunc( GL_EQUAL, 1, 0xFF );
-        glDisable( GL_STENCIL_TEST );
+        ImplSetClipBit( rClip, 0x01 );
     }
 
     return true;
@@ -1333,42 +1339,54 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly,
     if( aBoundRect.IsEmpty() )
         return true;
 
+    if( rGradient.GetStyle() != GradientStyle_LINEAR &&
+        rGradient.GetStyle() != GradientStyle_RADIAL )
+        return false;
+
     aBoundRect.Left()--;
     aBoundRect.Top()--;
     aBoundRect.Right()++;
     aBoundRect.Bottom()++;
+    //TODO: lfrb: some missing transformation with the polygon in outdev
+
+    PreDraw();
+
+    ImplSetClipBit( vcl::Region( rPolyPoly ), 0x02 );
+    if( mbUseStencil )
+    {
+        glEnable( GL_STENCIL_TEST );
+        glStencilFunc( GL_EQUAL, 3, 0xFF );
+    }
+    else
+    {
+        glEnable( GL_STENCIL_TEST );
+        glStencilFunc( GL_EQUAL, 2, 0xFF );
+    }
 
     // if border >= 100%, draw solid rectangle with start color
     if( rGradient.GetBorder() >= 100.0 )
     {
         Color aCol = rGradient.GetStartColor();
         long nF = rGradient.GetStartIntensity();
-        PreDraw();
         BeginSolid( MAKE_SALCOLOR( aCol.GetRed() * nF / 100,
                                    aCol.GetGreen() * nF / 100,
                                    aCol.GetBlue() * nF / 100 ) );
         DrawRect( aBoundRect );
-        EndSolid();
-        PostDraw();
-        return true;
     }
-
-    //TODO: lfrb: some missing transformation with the polygon in outdev
-    if( rGradient.GetStyle() == GradientStyle_LINEAR )
+    else if( rGradient.GetStyle() == GradientStyle_LINEAR )
     {
-        PreDraw();
         DrawLinearGradient( rGradient, aBoundRect );
-        PostDraw();
-        return true;
     }
     else if( rGradient.GetStyle() == GradientStyle_RADIAL )
     {
-        PreDraw();
         DrawRadialGradient( rGradient, aBoundRect );
-        PostDraw();
-        return true;
     }
-    return false;
+
+    if( !mbUseStencil )
+        glDisable( GL_STENCIL_TEST );
+    PostDraw();
+
+    return true;
 }
 
 void OpenGLSalGraphicsImpl::beginPaint()


More information about the Libreoffice-commits mailing list