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

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Thu Nov 13 22:17:02 PST 2014


 vcl/inc/openglgdiimpl.hxx                    |    1 
 vcl/opengl/gdiimpl.cxx                       |   67 +++++++++++++++++++++++++++
 vcl/opengl/linearGradientFragmentShader.glsl |    2 
 3 files changed, 69 insertions(+), 1 deletion(-)

New commits:
commit fdbc95ee2a80b3660802cea5ac40e2032d78e15f
Author: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Date:   Fri Nov 14 01:16:28 2014 -0500

    vcl: Implement axial gradients in OpenGL backend
    
    Change-Id: I93b8c3c076c79d992d467b01ca5f5eca1ed626d3

diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index 65ec12e..fa88a2a 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -108,6 +108,7 @@ public:
     void DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry );
     void DrawMask( OpenGLTexture& rTexture, SalColor nMaskColor, const SalTwoRect& rPosAry );
     void DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect );
+    void DrawAxialGradient( const Gradient& rGradient, const Rectangle& rRect );
     void DrawRadialGradient( const Gradient& rGradient, const Rectangle& rRect );
 
 public:
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 0c47f33..09e80f8 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -772,6 +772,68 @@ void OpenGLSalGraphicsImpl::DrawLinearGradient( const Gradient& rGradient, const
     CHECK_GL_ERROR();
 }
 
+void OpenGLSalGraphicsImpl::DrawAxialGradient( const Gradient& rGradient, const Rectangle& rRect )
+{
+    if( mnLinearGradientProgram == 0 )
+    {
+        if( !CreateLinearGradientProgram() )
+            return;
+    }
+
+    glUseProgram( mnLinearGradientProgram );
+
+    Color aStartCol = rGradient.GetStartColor();
+    Color aEndCol = rGradient.GetEndColor();
+    long nFactor = rGradient.GetStartIntensity();
+    glUniformColorIntensity( mnLinearGradientStartColorUniform, aStartCol, nFactor );
+    nFactor = rGradient.GetEndIntensity();
+    glUniformColorIntensity( mnLinearGradientEndColorUniform, aEndCol, nFactor );
+
+    /**
+     * Draw two rectangles with linear gradient.
+     *
+     *  1 *---* 2
+     *    |  /|
+     *    | / |     Points 0 and 3 have start color
+     *  0 |/__| 3   Points 1, 2, 4 and 5 have end color
+     *    |\  |
+     *    | \ |
+     *    |  \|
+     *  5 *---* 4
+     *
+     */
+
+    Rectangle aRect;
+    Point aCenter;
+    rGradient.GetBoundRect( rRect, aRect, aCenter );
+
+    // determine points 0 and 3
+    Point aPt0( aRect.Left(), (aRect.Top() + aRect.Bottom() + 1) / 2 );
+    Point aPt3( aRect.Right(), (aRect.Top() + aRect.Bottom() + 1) / 2 );
+
+    Polygon aPoly( 7 );
+    aPoly.SetPoint( aPt0,                0 );
+    aPoly.SetPoint( aRect.TopLeft(),     1 );
+    aPoly.SetPoint( aRect.TopRight(),    2 );
+    aPoly.SetPoint( aPt3,                3 );
+    aPoly.SetPoint( aRect.BottomRight(), 4 );
+    aPoly.SetPoint( aRect.BottomLeft(),  5 );
+    aPoly.SetPoint( aPt0,                6 );
+    aPoly.Rotate( aCenter, rGradient.GetAngle() % 3600 );
+
+    GLfloat aTexCoord[12] = { 0, 1, 1, 0, 2, 0, 3, 1, 4, 0, 5, 0 };
+    GLfloat fMin = 1.0 - 100.0 / (100.0 - rGradient.GetBorder());
+    aTexCoord[3] = aTexCoord[5] = aTexCoord[9] = aTexCoord[11] = fMin;
+    glEnableVertexAttribArray( GL_ATTRIB_TEX );
+    glVertexAttribPointer( GL_ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, aTexCoord );
+
+    DrawConvexPolygon( aPoly );
+
+    glDisableVertexAttribArray( GL_ATTRIB_TEX );
+    glUseProgram( 0 );
+    CHECK_GL_ERROR();
+}
+
 void OpenGLSalGraphicsImpl::DrawRadialGradient( const Gradient& rGradient, const Rectangle& rRect )
 {
     if( mnRadialGradientProgram == 0 )
@@ -1365,6 +1427,7 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly,
         return true;
 
     if( rGradient.GetStyle() != GradientStyle_LINEAR &&
+        rGradient.GetStyle() != GradientStyle_AXIAL &&
         rGradient.GetStyle() != GradientStyle_RADIAL )
         return false;
 
@@ -1402,6 +1465,10 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly,
     {
         DrawLinearGradient( rGradient, aBoundRect );
     }
+    else if( rGradient.GetStyle() == GradientStyle_AXIAL )
+    {
+        DrawAxialGradient( rGradient, aBoundRect );
+    }
     else if( rGradient.GetStyle() == GradientStyle_RADIAL )
     {
         DrawRadialGradient( rGradient, aBoundRect );
diff --git a/vcl/opengl/linearGradientFragmentShader.glsl b/vcl/opengl/linearGradientFragmentShader.glsl
index 7b84c06..bd1137c 100644
--- a/vcl/opengl/linearGradientFragmentShader.glsl
+++ b/vcl/opengl/linearGradientFragmentShader.glsl
@@ -16,7 +16,7 @@ varying vec2   tex_coord;
 
 void main(void)
 {
-    gl_FragColor = mix(start_color, end_color,
+    gl_FragColor = mix(end_color, start_color,
             clamp(tex_coord.t, 0.0, 1.0));
 }
 


More information about the Libreoffice-commits mailing list