summaryrefslogtreecommitdiff
path: root/vcl/opengl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-08-24 15:00:26 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-08-24 19:08:10 +0900
commitbdce4e29191aa5bd029efa242e094aba45c44869 (patch)
tree5088ad08e3d44dbda6fc901ae0afe3eaebff56c3 /vcl/opengl
parentb26ba85d04e81f48622dfdbb71d9d80b54dacc40 (diff)
opengl: push mask coords to the shaders along the image coords
If using the same texture to store the image and mask data (for example when using texture atlas) the mask and image (RGB) coords aren't the same anymore. With this commit we always define the mask coords separately. Change-Id: Ie33f87a6e9ab398972c6a3d5938e5f1364c82d36
Diffstat (limited to 'vcl/opengl')
-rw-r--r--vcl/opengl/areaScaleFastFragmentShader.glsl3
-rw-r--r--vcl/opengl/areaScaleFragmentShader.glsl1
-rw-r--r--vcl/opengl/blendedTextureFragmentShader.glsl8
-rw-r--r--vcl/opengl/blendedTextureVertexShader.glsl3
-rw-r--r--vcl/opengl/diffTextureFragmentShader.glsl6
-rw-r--r--vcl/opengl/gdiimpl.cxx37
-rw-r--r--vcl/opengl/maskedTextureFragmentShader.glsl6
-rw-r--r--vcl/opengl/maskedTextureVertexShader.glsl24
-rw-r--r--vcl/opengl/program.cxx6
-rw-r--r--vcl/opengl/transformedTextureVertexShader.glsl3
10 files changed, 83 insertions, 14 deletions
diff --git a/vcl/opengl/areaScaleFastFragmentShader.glsl b/vcl/opengl/areaScaleFastFragmentShader.glsl
index 10ce9f583eeb..f74397bcf4a1 100644
--- a/vcl/opengl/areaScaleFastFragmentShader.glsl
+++ b/vcl/opengl/areaScaleFastFragmentShader.glsl
@@ -21,6 +21,7 @@ varying vec2 tex_coord;
// This mode makes the scaling work like maskedTextureFragmentShader.glsl
// (instead of like plain textureVertexShader.glsl).
#ifdef MASKED
+varying vec2 mask_coord;
uniform sampler2D mask;
#endif
@@ -41,7 +42,7 @@ void main(void)
#else
vec4 texel;
texel = texture2D( sampler, tex_coord.st + offset );
- texel.a = 1.0 - texture2D( mask, tex_coord.st + offset ).r;
+ texel.a = 1.0 - texture2D( mask, mask_coord.st + offset ).r;
sum += texel;
#endif
offset.x += xstep;
diff --git a/vcl/opengl/areaScaleFragmentShader.glsl b/vcl/opengl/areaScaleFragmentShader.glsl
index d72184cc2911..b95b8698a26f 100644
--- a/vcl/opengl/areaScaleFragmentShader.glsl
+++ b/vcl/opengl/areaScaleFragmentShader.glsl
@@ -30,6 +30,7 @@ varying vec2 tex_coord;
// This mode makes the scaling work like maskedTextureFragmentShader.glsl
// (instead of like plain textureVertexShader.glsl).
#ifdef MASKED
+varying vec2 mask_coord;
uniform sampler2D mask;
#endif
diff --git a/vcl/opengl/blendedTextureFragmentShader.glsl b/vcl/opengl/blendedTextureFragmentShader.glsl
index 318023c5bc89..eabb6524b6af 100644
--- a/vcl/opengl/blendedTextureFragmentShader.glsl
+++ b/vcl/opengl/blendedTextureFragmentShader.glsl
@@ -9,14 +9,18 @@
varying vec2 tex_coord;
varying vec2 alpha_coord;
+varying vec2 mask_coord;
+
uniform sampler2D sampler;
uniform sampler2D mask;
uniform sampler2D alpha;
-void main() {
+void main()
+{
vec4 texel0, texel1, texel2;
+
texel0 = texture2D(sampler, tex_coord);
- texel1 = texture2D(mask, tex_coord);
+ texel1 = texture2D(mask, mask_coord);
texel2 = texture2D(alpha, alpha_coord);
gl_FragColor = texel0;
diff --git a/vcl/opengl/blendedTextureVertexShader.glsl b/vcl/opengl/blendedTextureVertexShader.glsl
index 3a9b827d1e19..64bae785aa78 100644
--- a/vcl/opengl/blendedTextureVertexShader.glsl
+++ b/vcl/opengl/blendedTextureVertexShader.glsl
@@ -10,14 +10,17 @@
attribute vec4 position;
attribute vec2 tex_coord_in;
attribute vec2 alpha_coord_in;
+attribute vec2 mask_coord_in;
varying vec2 tex_coord;
varying vec2 alpha_coord;
+varying vec2 mask_coord;
uniform mat4 mvp;
void main() {
gl_Position = mvp * position;
tex_coord = tex_coord_in;
alpha_coord = alpha_coord_in;
+ mask_coord = mask_coord_in;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/diffTextureFragmentShader.glsl b/vcl/opengl/diffTextureFragmentShader.glsl
index c0a982d4ee53..af9a1dce3415 100644
--- a/vcl/opengl/diffTextureFragmentShader.glsl
+++ b/vcl/opengl/diffTextureFragmentShader.glsl
@@ -9,14 +9,16 @@
/*precision mediump float;*/
varying vec2 tex_coord;
+varying vec2 mask_coord;
uniform sampler2D texture; /* white background */
uniform sampler2D mask; /* black background */
-void main() {
+void main()
+{
float alpha;
vec4 texel0, texel1;
texel0 = texture2D(texture, tex_coord);
- texel1 = texture2D(mask, tex_coord);
+ texel1 = texture2D(mask, mask_coord);
alpha = 1.0 - abs(texel0.r - texel1.r);
if(alpha > 0.0)
gl_FragColor = texel1 / alpha;
diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx
index 6a8c58881893..5e2785ce9545 100644
--- a/vcl/opengl/gdiimpl.cxx
+++ b/vcl/opengl/gdiimpl.cxx
@@ -959,6 +959,9 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
"#define MASKED" ) )
return;
mpProgram->SetTexture( "mask", rMask );
+ GLfloat aMaskCoord[8];
+ rMask.GetWholeCoord(aMaskCoord);
+ mpProgram->SetMaskCoord(aMaskCoord);
rMask.SetFilter( GL_LINEAR );
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}
@@ -1027,25 +1030,39 @@ void OpenGLSalGraphicsImpl::DrawTextureDiff( OpenGLTexture& rTexture, OpenGLText
{
OpenGLZone aZone;
- if( !UseProgram( "textureVertexShader", "diffTextureFragmentShader" ) )
+ if( !UseProgram( "maskedTextureVertexShader", "diffTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "texture", rTexture );
mpProgram->SetTexture( "mask", rMask );
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+
+ GLfloat aMaskCoord[8];
+ rMask.GetCoord(aMaskCoord, rPosAry, bInverted);
+ mpProgram->SetMaskCoord(aMaskCoord);
+
DrawTextureRect( rTexture, rPosAry, bInverted );
mpProgram->Clean();
}
-void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& pPosAry )
+void OpenGLSalGraphicsImpl::DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry )
{
OpenGLZone aZone;
- if( !UseProgram( "textureVertexShader", "maskedTextureFragmentShader" ) )
+ if( !UseProgram( "maskedTextureVertexShader", "maskedTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
mpProgram->SetTexture( "mask", rMask );
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- DrawTextureRect( rTexture, pPosAry );
+
+ GLfloat aTexCoord[8];
+ rTexture.GetCoord(aTexCoord, rPosAry);
+ mpProgram->SetTextureCoord(aTexCoord);
+
+ GLfloat aMaskCoord[8];
+ rMask.GetCoord(aMaskCoord, rPosAry);
+ mpProgram->SetMaskCoord(aMaskCoord);
+
+ DrawRect(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight);
mpProgram->Clean();
}
@@ -1053,14 +1070,20 @@ void OpenGLSalGraphicsImpl::DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLT
{
OpenGLZone aZone;
- GLfloat aTexCoord[8];
if( !UseProgram( "blendedTextureVertexShader", "blendedTextureFragmentShader" ) )
return;
mpProgram->SetTexture( "sampler", rTexture );
mpProgram->SetTexture( "mask", rMask );
mpProgram->SetTexture( "alpha", rAlpha );
- rAlpha.GetCoord( aTexCoord, rPosAry );
- mpProgram->SetAlphaCoord( aTexCoord );
+
+ GLfloat aAlphaCoord[8];
+ rAlpha.GetCoord(aAlphaCoord, rPosAry);
+ mpProgram->SetAlphaCoord(aAlphaCoord);
+
+ GLfloat aMaskCoord[8];
+ rMask.GetCoord(aMaskCoord, rPosAry);
+ mpProgram->SetMaskCoord(aMaskCoord);
+
mpProgram->SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
DrawTextureRect( rTexture, rPosAry );
mpProgram->Clean();
diff --git a/vcl/opengl/maskedTextureFragmentShader.glsl b/vcl/opengl/maskedTextureFragmentShader.glsl
index 4d79ae9927cc..75ce4ae76bd4 100644
--- a/vcl/opengl/maskedTextureFragmentShader.glsl
+++ b/vcl/opengl/maskedTextureFragmentShader.glsl
@@ -9,13 +9,15 @@
/*precision mediump float;*/
varying vec2 tex_coord;
+varying vec2 mask_coord;
uniform sampler2D sampler;
uniform sampler2D mask;
-void main() {
+void main()
+{
vec4 texel0, texel1;
texel0 = texture2D(sampler, tex_coord);
- texel1 = texture2D(mask, tex_coord);
+ texel1 = texture2D(mask, mask_coord);
gl_FragColor = texel0;
gl_FragColor.a = 1.0 - texel1.r;
}
diff --git a/vcl/opengl/maskedTextureVertexShader.glsl b/vcl/opengl/maskedTextureVertexShader.glsl
new file mode 100644
index 000000000000..ab225a85a158
--- /dev/null
+++ b/vcl/opengl/maskedTextureVertexShader.glsl
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+attribute vec4 position;
+attribute vec2 tex_coord_in;
+attribute vec2 mask_coord_in;
+varying vec2 tex_coord;
+varying vec2 mask_coord;
+uniform mat4 mvp;
+
+void main()
+{
+ gl_Position = mvp * position;
+ tex_coord = tex_coord_in;
+ mask_coord = mask_coord_in;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx
index 3bfa6c2a453c..ede054816d5f 100644
--- a/vcl/opengl/program.cxx
+++ b/vcl/opengl/program.cxx
@@ -21,6 +21,7 @@ OpenGLProgram::OpenGLProgram() :
mnPositionAttrib( SAL_MAX_UINT32 ),
mnTexCoordAttrib( SAL_MAX_UINT32 ),
mnAlphaCoordAttrib( SAL_MAX_UINT32 ),
+ mnMaskCoordAttrib( SAL_MAX_UINT32 ),
mbBlending( false )
{
}
@@ -112,6 +113,11 @@ void OpenGLProgram::SetAlphaCoord( const GLvoid* pData )
SetVertexAttrib( mnAlphaCoordAttrib, "alpha_coord_in", pData );
}
+void OpenGLProgram::SetMaskCoord(const GLvoid* pData)
+{
+ SetVertexAttrib(mnMaskCoordAttrib, "mask_coord_in", pData);
+}
+
GLuint OpenGLProgram::GetUniformLocation( const OString& rName )
{
auto it = maUniformLocations.find( rName );
diff --git a/vcl/opengl/transformedTextureVertexShader.glsl b/vcl/opengl/transformedTextureVertexShader.glsl
index 3a64fd0a75e6..6f8d5f351cd0 100644
--- a/vcl/opengl/transformedTextureVertexShader.glsl
+++ b/vcl/opengl/transformedTextureVertexShader.glsl
@@ -9,15 +9,18 @@
attribute vec4 position;
attribute vec2 tex_coord_in;
+attribute vec2 mask_coord_in;
uniform vec2 viewport;
uniform mat4 transform;
uniform mat4 mvp;
varying vec2 tex_coord;
+varying vec2 mask_coord;
void main() {
vec4 pos = mvp * transform * position;
gl_Position = pos;
tex_coord = tex_coord_in;
+ mask_coord = mask_coord_in;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */