[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - vcl/inc vcl/opengl

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon May 30 15:04:13 UTC 2016


 vcl/inc/opengl/program.hxx |    1 
 vcl/inc/openglgdiimpl.hxx  |    1 
 vcl/opengl/gdiimpl.cxx     |   81 ++++++++++++++++++++++++++++++++-------------
 vcl/opengl/program.cxx     |   23 ++++++++++--
 4 files changed, 78 insertions(+), 28 deletions(-)

New commits:
commit 16f87e808942a88c935754c2aabef86ee379b9b7
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri May 27 14:24:38 2016 +0900

    tdf#100080 set unused shader attribs with values, fixes GL on AMD
    
    AMD drivers don't work well if a shader has a defined but not
    enabled shader attributes. For this reason we need to make sure
    that all attributes are set to some value even if the shader
    doesn't use that attribute. Intel drivers, on the other hand,
    crash if you enable an attribute and don't set it (set it
    to null) - so we can't use this workaround.
    
    (cherry picked from commit fdcd13c1c2b8b9fbc3480c8fa92920d8c8d4e5a7)
    
    Change-Id: If0abcfb664c3b71bb657b9a810d2d2a14fe5d9b4
    Reviewed-on: https://gerrit.libreoffice.org/25592
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
index 2fab98c..3c194d8 100644
--- a/vcl/inc/opengl/program.hxx
+++ b/vcl/inc/opengl/program.hxx
@@ -106,6 +106,7 @@ public:
     void DrawArrays(GLenum GLenum, std::vector<GLfloat>& aVertices);
 
 protected:
+    bool EnableVertexAttrib(GLuint& rAttrib, const OString& rName);
     void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData, GLint nSize = 2 );
     GLuint GetUniformLocation( const OString& rName );
 };
diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx
index da0fe69..df7b9e9 100644
--- a/vcl/inc/openglgdiimpl.hxx
+++ b/vcl/inc/openglgdiimpl.hxx
@@ -119,7 +119,6 @@ public:
     bool UseInvert(SalInvert nFlags);
 
     void DrawPoint( long nX, long nY );
-    void DrawLine( double nX1, double nY1, double nX2, double nY2 );
     void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA = false );
     void DrawConvexPolygon( const tools::Polygon& rPolygon, bool blockAA = false );
     void DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA = false );
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 40df037..39ae806 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -613,25 +613,13 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY )
         GLfloat(nX), GLfloat(nY)
     };
 
+    std::vector<GLfloat> aExtrusion(3, 0);
+    mpProgram->SetExtrusionVectors(aExtrusion.data());
     ApplyProgramMatrices(0.5f);
     mpProgram->DrawArrays(GL_POINTS, pPoint);
     CHECK_GL_ERROR();
 }
 
-void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, double nY2 )
-{
-    OpenGLZone aZone;
-
-    std::vector<GLfloat> pPoint {
-        GLfloat(nX1), GLfloat(nY1),
-        GLfloat(nX2), GLfloat(nY2)
-    };
-
-    ApplyProgramMatrices(0.5f);
-    mpProgram->DrawArrays(GL_LINES, pPoint);
-    CHECK_GL_ERROR();
-}
-
 namespace
 {
 
@@ -959,6 +947,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin
     }
 
     ApplyProgramMatrices();
+    std::vector<GLfloat> aExtrusion(nPoints * 3, 0);
+    mpProgram->SetExtrusionVectors(aExtrusion.data());
     mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
     CHECK_GL_ERROR();
 
@@ -1002,6 +992,8 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const tools::Polygon& rPolygon, b
     }
 
     ApplyProgramMatrices();
+    std::vector<GLfloat> aExtrusion(nPoints * 3, 0);
+    mpProgram->SetExtrusionVectors(aExtrusion.data());
     mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
     CHECK_GL_ERROR();
 
@@ -1051,6 +1043,8 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoi
         return;
     }
 
+    std::vector<GLfloat> aExtrusion(nPoints * 3, 0);
+    mpProgram->SetExtrusionVectors(aExtrusion.data());
     ApplyProgramMatrices();
     mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices);
     CHECK_GL_ERROR();
@@ -1164,24 +1158,23 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion )
     }
 #undef ADD_VERTICE
 
+    std::vector<GLfloat> aExtrusion(aRects.size() * 6 * 3, 0);
+    mpProgram->SetExtrusionVectors(aExtrusion.data());
     ApplyProgramMatrices();
     mpProgram->DrawArrays(GL_TRIANGLES, aVertices);
     CHECK_GL_ERROR();
 }
 
-void OpenGLSalGraphicsImpl::DrawTextureRect( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted )
+void OpenGLSalGraphicsImpl::DrawTextureRect( OpenGLTexture& /*rTexture*/, const SalTwoRect& rPosAry, bool /*bInverted*/ )
 {
     OpenGLZone aZone;
 
     SAL_INFO("vcl.opengl", "draw texture rect");
 
-    GLfloat aTexCoord[8];
-    rTexture.GetCoord( aTexCoord, rPosAry, bInverted );
-    mpProgram->SetTextureCoord( aTexCoord );
     DrawRect( rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight );
 }
 
-void OpenGLSalGraphicsImpl::DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& pPosAry, bool bInverted )
+void OpenGLSalGraphicsImpl::DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted )
 {
     OpenGLZone aZone;
 
@@ -1192,7 +1185,14 @@ void OpenGLSalGraphicsImpl::DrawTexture( OpenGLTexture& rTexture, const SalTwoRe
     mpProgram->SetShaderType(TextureShaderType::Normal);
     mpProgram->SetIdentityTransform("transform");
     mpProgram->SetTexture("texture", rTexture);
-    DrawTextureRect( rTexture, pPosAry, bInverted );
+
+    GLfloat aTexCoord[8];
+    rTexture.GetCoord(aTexCoord, rPosAry, bInverted);
+    mpProgram->SetTextureCoord(aTexCoord);
+    mpProgram->SetMaskCoord(aTexCoord);
+    mpProgram->SetAlphaCoord(aTexCoord);
+
+    DrawTextureRect( rTexture, rPosAry, bInverted );
     mpProgram->Clean();
 }
 
@@ -1405,6 +1405,13 @@ void OpenGLSalGraphicsImpl::DrawAlphaTexture( OpenGLTexture& rTexture, const Sal
     mpProgram->SetTexture("texture", rTexture);
     mpProgram->SetBlendMode( bPremultiplied ? GL_ONE : GL_SRC_ALPHA,
                              GL_ONE_MINUS_SRC_ALPHA );
+
+    GLfloat aTexCoord[8];
+    rTexture.GetCoord(aTexCoord, rPosAry, bInverted);
+    mpProgram->SetTextureCoord(aTexCoord);
+    mpProgram->SetMaskCoord(aTexCoord);
+    mpProgram->SetAlphaCoord(aTexCoord);
+
     DrawTextureRect( rTexture, rPosAry, bInverted );
     mpProgram->Clean();
 }
@@ -1421,6 +1428,11 @@ void OpenGLSalGraphicsImpl::DrawTextureDiff( OpenGLTexture& rTexture, OpenGLText
     mpProgram->SetTexture( "mask", rMask );
     mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
 
+    GLfloat aTexCoord[8];
+    rTexture.GetCoord(aTexCoord, rPosAry, bInverted);
+    mpProgram->SetTextureCoord(aTexCoord);
+    mpProgram->SetAlphaCoord(aTexCoord);
+
     GLfloat aMaskCoord[8];
     rMask.GetCoord(aMaskCoord, rPosAry, bInverted);
     mpProgram->SetMaskCoord(aMaskCoord);
@@ -1444,6 +1456,7 @@ void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGL
     GLfloat aTexCoord[8];
     rTexture.GetCoord(aTexCoord, rPosAry);
     mpProgram->SetTextureCoord(aTexCoord);
+    mpProgram->SetAlphaCoord(aTexCoord);
 
     GLfloat aMaskCoord[8];
     rMask.GetCoord(aMaskCoord, rPosAry);
@@ -1464,6 +1477,10 @@ void OpenGLSalGraphicsImpl::DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLT
     mpProgram->SetTexture( "mask", rMask );
     mpProgram->SetTexture( "alpha", rAlpha );
 
+    GLfloat aTexCoord[8];
+    rTexture.GetCoord(aTexCoord, rPosAry);
+    mpProgram->SetTextureCoord(aTexCoord);
+
     GLfloat aAlphaCoord[8];
     rAlpha.GetCoord(aAlphaCoord, rPosAry);
     mpProgram->SetAlphaCoord(aAlphaCoord);
@@ -1477,7 +1494,7 @@ void OpenGLSalGraphicsImpl::DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLT
     mpProgram->Clean();
 }
 
-void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, SalColor nMaskColor, const SalTwoRect& pPosAry )
+void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, SalColor nMaskColor, const SalTwoRect& rPosAry )
 {
     OpenGLZone aZone;
 
@@ -1487,8 +1504,15 @@ void OpenGLSalGraphicsImpl::DrawMask( OpenGLTexture& rMask, SalColor nMaskColor,
     mpProgram->SetIdentityTransform("transform");
     mpProgram->SetColor( "color", nMaskColor, 0 );
     mpProgram->SetTexture("texture", rMask);
+
+    GLfloat aTexCoord[8];
+    rMask.GetCoord(aTexCoord, rPosAry);
+    mpProgram->SetTextureCoord(aTexCoord);
+    mpProgram->SetMaskCoord(aTexCoord);
+    mpProgram->SetAlphaCoord(aTexCoord);
+
     mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
-    DrawTextureRect( rMask, pPosAry );
+    DrawTextureRect(rMask, rPosAry);
     mpProgram->Clean();
 }
 
@@ -1559,6 +1583,8 @@ void OpenGLSalGraphicsImpl::FlushDeferredDrawing()
             TextureDrawParameters& rParameters = rColorTwoRectPair.second;
             ApplyProgramMatrices();
             mpProgram->SetTextureCoord(rParameters.maTextureCoords.data());
+            mpProgram->SetMaskCoord(rParameters.maTextureCoords.data());
+            mpProgram->SetAlphaCoord(rParameters.maTextureCoords.data());
             mpProgram->DrawArrays(GL_TRIANGLES, rParameters.maVertices);
         }
     }
@@ -2060,6 +2086,13 @@ bool OpenGLSalGraphicsImpl::blendBitmap(
     mpProgram->SetShaderType(TextureShaderType::Normal);
     mpProgram->SetIdentityTransform("transform");
     mpProgram->SetTexture("texture", rTexture);
+
+    GLfloat aTexCoord[8];
+    rTexture.GetCoord(aTexCoord, rPosAry);
+    mpProgram->SetTextureCoord(aTexCoord);
+    mpProgram->SetMaskCoord(aTexCoord);
+    mpProgram->SetAlphaCoord(aTexCoord);
+
     mpProgram->SetBlendMode(GL_ZERO, GL_SRC_COLOR);
     DrawTextureRect(rTexture, rPosAry);
     mpProgram->Clean();
@@ -2344,7 +2377,9 @@ void OpenGLSalGraphicsImpl::doFlush()
 
         GLfloat aTexCoord[8];
         maOffscreenTex.GetCoord( aTexCoord, aPosAry, false );
-        pProgram->SetTextureCoord( aTexCoord );
+        pProgram->SetTextureCoord(aTexCoord);
+        pProgram->SetMaskCoord(aTexCoord);
+        pProgram->SetAlphaCoord(aTexCoord);
 
         GLfloat fWidth( maOffscreenTex.GetWidth() );
         GLfloat fHeight( maOffscreenTex.GetHeight() );
diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx
index 563a295..4f56832 100644
--- a/vcl/opengl/program.cxx
+++ b/vcl/opengl/program.cxx
@@ -93,12 +93,15 @@ bool OpenGLProgram::Clean()
     return true;
 }
 
-void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData, GLint nSize )
+bool OpenGLProgram::EnableVertexAttrib(GLuint& rAttrib, const OString& rName)
 {
     if( rAttrib == SAL_MAX_UINT32 )
     {
-        rAttrib = glGetAttribLocation( mnId, rName.getStr() );
+        GLint aLocation = glGetAttribLocation(mnId, rName.getStr());
         CHECK_GL_ERROR();
+        if (aLocation < 0)
+            return false;
+        rAttrib = GLuint(aLocation);
     }
     if( (mnEnabledAttribs & ( 1 << rAttrib )) == 0 )
     {
@@ -106,8 +109,20 @@ void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, cons
         CHECK_GL_ERROR();
         mnEnabledAttribs |= ( 1 << rAttrib );
     }
-    glVertexAttribPointer( rAttrib, nSize, GL_FLOAT, GL_FALSE, 0, pData );
-    CHECK_GL_ERROR();
+    return true;
+}
+
+void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData, GLint nSize )
+{
+    if (EnableVertexAttrib(rAttrib, rName))
+    {
+        glVertexAttribPointer( rAttrib, nSize, GL_FLOAT, GL_FALSE, 0, pData );
+        CHECK_GL_ERROR();
+    }
+    else
+    {
+        VCL_GL_INFO("Vertex attribute '" << rName << "' doesn't exist in this program (" << mnId << ")");
+    }
 }
 
 void OpenGLProgram::SetVertices( const GLvoid* pData )


More information about the Libreoffice-commits mailing list