diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-04-14 19:03:45 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-04-16 13:46:30 +0200 |
commit | 641005f821be1bd59dbd380474b076d157a46932 (patch) | |
tree | 6e58ecedeb1f8611bdf5ab8ff76a4254a4ae7d37 /vcl/opengl/shaders | |
parent | 69d0eba7816ea0bfe3be15aba16324d0357ee845 (diff) |
fix areaScaleFragmentShader.glsl with texture atlas (tdf#105277)
With a texture atlas the "texture" is just a subtexture of a larger texture,
so texture coordinates are not the full range between 0 and 1, but just
a part of it. Since areaScaleFragmentShader converts between pixel
and texture coordinates, the conversion needs to take this into account.
Change-Id: I9d29ffea52551d19ba681971a2b4f140a35b491c
Reviewed-on: https://gerrit.libreoffice.org/70774
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/opengl/shaders')
-rw-r--r-- | vcl/opengl/shaders/areaScaleFragmentShader.glsl | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/vcl/opengl/shaders/areaScaleFragmentShader.glsl b/vcl/opengl/shaders/areaScaleFragmentShader.glsl index 07945e3ebe44..5dab5ba0114d 100644 --- a/vcl/opengl/shaders/areaScaleFragmentShader.glsl +++ b/vcl/opengl/shaders/areaScaleFragmentShader.glsl @@ -14,10 +14,12 @@ uniform int swidth; uniform int sheight; uniform float xscale; uniform float yscale; -uniform float xsrcconvert; -uniform float ysrcconvert; -uniform float xdestconvert; -uniform float ydestconvert; +uniform float xoffset; +uniform float yoffset; +uniform float xfrompixelratio; +uniform float yfrompixelratio; +uniform float xtopixelratio; +uniform float ytopixelratio; varying vec2 tex_coord; @@ -28,23 +30,23 @@ varying vec2 mask_coord; uniform sampler2D mask; #endif +#ifdef USE_REDUCED_REGISTER_VARIANT + vec4 getTexel(int x, int y) { - vec2 offset = vec2(x * xsrcconvert, y * ysrcconvert); - vec4 texel = texture2D(sampler, offset); + vec2 pos = vec2( x * xfrompixelratio + xoffset, y * yfrompixelratio + yoffset ); + vec4 texel = texture2D(sampler, pos); #ifdef MASKED - texel.a = 1.0 - texture2D(mask, offset).r; + texel.a = 1.0 - texture2D(mask, pos - tex_coord.st + mask_coord.st).r; #endif return texel; } -#ifdef USE_REDUCED_REGISTER_VARIANT - void main(void) { // Convert to pixel coordinates again. - int dx = int(tex_coord.s * xdestconvert); - int dy = int(tex_coord.t * ydestconvert); + int dx = int(( tex_coord.s - xoffset ) * xtopixelratio ); + int dy = int(( tex_coord.t - yoffset ) * ytopixelratio ); // Compute the range of source pixels which will make up this destination pixel. float fsx1 = min(dx * xscale, float(swidth - 1)); @@ -124,8 +126,8 @@ void main(void) void main(void) { // Convert to pixel coordinates again. - int dx = int( tex_coord.s * xdestconvert ); - int dy = int( tex_coord.t * ydestconvert ); + int dx = int(( tex_coord.s - xoffset ) * xtopixelratio ); + int dy = int(( tex_coord.t - yoffset ) * ytopixelratio ); // How much each column/row will contribute to the resulting pixel. // Note: These values are always the same for the same X (or Y), @@ -218,13 +220,13 @@ void main(void) xpos = 0; for( int x = xstart; x <= xend; ++x, ++xpos ) { - vec2 offset = vec2( x * xsrcconvert, y * ysrcconvert ); + vec2 pos = vec2( x * xfrompixelratio + xoffset, y * yfrompixelratio + yoffset ); #ifndef MASKED - tmp += texture2D( sampler, offset ) * xratio[ xpos ]; + tmp += texture2D( sampler, pos ) * xratio[ xpos ]; #else vec4 texel; - texel = texture2D( sampler, offset ); - texel.a = 1.0 - texture2D( mask, offset ).r; + texel = texture2D( sampler, pos ); + texel.a = 1.0 - texture2D( mask, pos - tex_coord.st + mask_coord.st ).r; tmp += texel * xratio[ xpos ]; #endif } |