diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-05-27 17:54:50 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-05-29 06:20:36 +0000 |
commit | fdcd13c1c2b8b9fbc3480c8fa92920d8c8d4e5a7 (patch) | |
tree | 9089dc479bb52f5157f6a3fa6598284e01ab84dd /vcl | |
parent | 8915919b57473fd88e338e874652d0b87e0c2482 (diff) |
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.
Change-Id: Ic076cf8a5fac8ef048d0054e6e4340b47b4d5188
Reviewed-on: https://gerrit.libreoffice.org/25591
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/opengl/program.hxx | 1 | ||||
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 68 | ||||
-rw-r--r-- | vcl/opengl/program.cxx | 23 |
3 files changed, 78 insertions, 14 deletions
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx index 2fab98c6b4d5..3c194d887ba9 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/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 58b4d62cca2e..720aa19411c7 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -615,6 +615,8 @@ 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(); @@ -959,6 +961,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 +1006,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(); @@ -1052,6 +1058,8 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoi } ApplyProgramMatrices(); + std::vector<GLfloat> aExtrusion(nPoints * 3, 0); + mpProgram->SetExtrusionVectors(aExtrusion.data()); mpProgram->DrawArrays(GL_TRIANGLE_FAN, aVertices); CHECK_GL_ERROR(); @@ -1163,25 +1171,23 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion ) ADD_VERTICE( rRect.BottomRight() ); } #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 +1198,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 +1418,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 +1441,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 +1469,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 +1490,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 +1507,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 +1517,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(); } @@ -1560,6 +1597,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); } } @@ -2069,6 +2108,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(); @@ -2363,7 +2409,9 @@ void OpenGLSalGraphicsImpl::doFlush() GLfloat aTexCoord[8]; maOffscreenTex.GetCoord( aTexCoord, aPosAry ); - 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 2331080d28c1..de6cec774840 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 ) |