[vlc-commits] [Git][videolan/vlc][master] qt: calculate atlas coordinate manually in `ImageExt`
Steve Lhomme (@robUx4)
gitlab at videolan.org
Thu Oct 23 18:27:23 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
e824b12a by Fatih Uzunoglu at 2025-10-23T15:13:19+00:00
qt: calculate atlas coordinate manually in `ImageExt`
Instead of relying on `supportsAtlasTextures`, we now
calculate the atlas coordinate manually because the
proper coordinate is provided after the texture is
already painted during initialization otherwise.
We can do this without worrying about atlas textures
getting detached from the atlas because having
`qt_SubRect_source` in the uniform block serves the
same purpose, except the coordinate in the atlas must
be calculated manually in that case.
- - - - -
3 changed files:
- modules/gui/qt/shaders/SDFAARoundedTexture.frag
- modules/gui/qt/shaders/SDFAARoundedTexture_cropsupport_bordersupport.frag
- modules/gui/qt/widgets/qml/ImageExt.qml
Changes:
=====================================
modules/gui/qt/shaders/SDFAARoundedTexture.frag
=====================================
@@ -83,11 +83,19 @@ float sdRoundBox( in vec2 p, in vec2 b, in vec4 r )
void main()
{
+ // This is what `qt_TexCoord0` is when `supportsAtlasTextures` is true.
+ // We do not want to rely on that but rather calculate manually because
+ // it is provided by Qt with a delay. The uniform block already defines
+ // `qt_SubRect_source` so there is no problem of using the atlas texture
+ // even when `supportsAtlasTextures` is false. The texture does not need
+ // to be independent if the uniform block defines `qt_SubRect_source`:
+ vec2 atlasCoord = qt_SubRect_source.xy + qt_SubRect_source.zw * qt_TexCoord0;
+
// The signed distance function works when the primitive is centered.
// If the texture is in the atlas, this condition is not satisfied.
// Therefore, we have to normalize the coordinate for the distance
// function to [0, 1]:
- vec2 normalCoord = vec2(1.0, 1.0) / (qt_SubRect_source.zw) * (qt_TexCoord0 - (qt_SubRect_source.zw + qt_SubRect_source.xy)) + vec2(1.0, 1.0);
+ vec2 normalCoord = vec2(1.0, 1.0) / (qt_SubRect_source.zw) * (atlasCoord - (qt_SubRect_source.zw + qt_SubRect_source.xy)) + vec2(1.0, 1.0);
normalCoord.y = (1.0 - normalCoord.y); // invert y-axis because texture coordinates have origin at the top
vec2 p = (size.xy * ((2.0 * normalCoord) - 1)) / size.y;
@@ -104,9 +112,9 @@ void main()
float k = qt_SubRect_source.z + qt_SubRect_source.x - normalCropRate;
float l = qt_SubRect_source.x + normalCropRate;
- texCoord.x = (k - l) / (qt_SubRect_source.z) * (qt_TexCoord0.x - qt_SubRect_source.x) + l;
+ texCoord.x = (k - l) / (qt_SubRect_source.z) * (atlasCoord.x - qt_SubRect_source.x) + l;
}
- // else { texCoord.x = qt_TexCoord0.x; }
+ // else { texCoord.x = atlasCoord.x; }
// if (cropRate.y > 0.0)
{
@@ -115,13 +123,13 @@ void main()
float k = qt_SubRect_source.w + qt_SubRect_source.y - normalCropRate;
float l = qt_SubRect_source.y + normalCropRate;
- texCoord.y = (k - l) / (qt_SubRect_source.w) * (qt_TexCoord0.y - qt_SubRect_source.y) + l;
+ texCoord.y = (k - l) / (qt_SubRect_source.w) * (atlasCoord.y - qt_SubRect_source.y) + l;
}
- // else { texCoord.y = qt_TexCoord0.y; }
+ // else { texCoord.y = atlasCoord.y; }
vec4 texel = texture(source, texCoord);
#else
- vec4 texel = texture(source, qt_TexCoord0);
+ vec4 texel = texture(source, atlasCoord);
#endif
#ifdef BACKGROUND_SUPPORT
=====================================
modules/gui/qt/shaders/SDFAARoundedTexture_cropsupport_bordersupport.frag
=====================================
@@ -96,11 +96,19 @@ float sdRoundBox( in vec2 p, in vec2 b, in vec4 r )
void main()
{
+ // This is what `qt_TexCoord0` is when `supportsAtlasTextures` is true.
+ // We do not want to rely on that but rather calculate manually because
+ // it is provided by Qt with a delay. The uniform block already defines
+ // `qt_SubRect_source` so there is no problem of using the atlas texture
+ // even when `supportsAtlasTextures` is false. The texture does not need
+ // to be independent if the uniform block defines `qt_SubRect_source`:
+ vec2 atlasCoord = qt_SubRect_source.xy + qt_SubRect_source.zw * qt_TexCoord0;
+
// The signed distance function works when the primitive is centered.
// If the texture is in the atlas, this condition is not satisfied.
// Therefore, we have to normalize the coordinate for the distance
// function to [0, 1]:
- vec2 normalCoord = vec2(1.0, 1.0) / (qt_SubRect_source.zw) * (qt_TexCoord0 - (qt_SubRect_source.zw + qt_SubRect_source.xy)) + vec2(1.0, 1.0);
+ vec2 normalCoord = vec2(1.0, 1.0) / (qt_SubRect_source.zw) * (atlasCoord - (qt_SubRect_source.zw + qt_SubRect_source.xy)) + vec2(1.0, 1.0);
normalCoord.y = (1.0 - normalCoord.y); // invert y-axis because texture coordinates have origin at the top
vec2 p = (size.xy * ((2.0 * normalCoord) - 1)) / size.y;
@@ -117,9 +125,9 @@ void main()
float k = qt_SubRect_source.z + qt_SubRect_source.x - normalCropRate;
float l = qt_SubRect_source.x + normalCropRate;
- texCoord.x = (k - l) / (qt_SubRect_source.z) * (qt_TexCoord0.x - qt_SubRect_source.x) + l;
+ texCoord.x = (k - l) / (qt_SubRect_source.z) * (atlasCoord.x - qt_SubRect_source.x) + l;
}
- // else { texCoord.x = qt_TexCoord0.x; }
+ // else { texCoord.x = atlasCoord.x; }
// if (cropRate.y > 0.0)
{
@@ -128,13 +136,13 @@ void main()
float k = qt_SubRect_source.w + qt_SubRect_source.y - normalCropRate;
float l = qt_SubRect_source.y + normalCropRate;
- texCoord.y = (k - l) / (qt_SubRect_source.w) * (qt_TexCoord0.y - qt_SubRect_source.y) + l;
+ texCoord.y = (k - l) / (qt_SubRect_source.w) * (atlasCoord.y - qt_SubRect_source.y) + l;
}
- // else { texCoord.y = qt_TexCoord0.y; }
+ // else { texCoord.y = atlasCoord.y; }
vec4 texel = texture(source, texCoord);
#else
- vec4 texel = texture(source, qt_TexCoord0);
+ vec4 texel = texture(source, atlasCoord);
#endif
#ifdef BACKGROUND_SUPPORT
=====================================
modules/gui/qt/widgets/qml/ImageExt.qml
=====================================
@@ -164,7 +164,16 @@ Item {
smooth: root.smooth
- supportsAtlasTextures: true
+ // NOTE: There are two ways to support atlas textures, one is by setting `supportsAtlasTextures`
+ // and the other is by defining `qt_SubRect_source` in the shader uniform block. If either
+ // of these is satisfied, the atlas texture will be used (`removedFromAtlas()` not called).
+ // Even though the shader uses `qt_SubRect_source`, `supportsAtlasTextures` also used to
+ // be set, mainly for indication and also to make Qt calculate the atlas coordinate for
+ // the texture coordinate (location 0) itself rather than doing it manually. However, it
+ // was observed that Qt fails to provide the proper coordinate where atlas is taken into
+ // account initially. In order to fix it, we now calculate the coordinate in the shader
+ // manually so that there is no glitch on initialization.
+ supportsAtlasTextures: false // WARNING: We *do* support atlas textures through `qt_SubRect_source`.
blending: true
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e824b12ab741a1791929ac3a541198ea19ffe25b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e824b12ab741a1791929ac3a541198ea19ffe25b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list