[vlc-commits] [Git][videolan/vlc][master] Revert "qt: calculate atlas coordinate manually in `ImageExt`"

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Oct 31 19:58:39 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
aae2c5a6 by Fatih Uzunoglu at 2025-10-31T19:42:10+00:00
Revert "qt: calculate atlas coordinate manually in `ImageExt`"

This reverts commit e824b12ab741a1791929ac3a541198ea19ffe25b.

Unfortunately even though `supportsAtlasTextures` is not
required to support atlas textures (meaning, operating on
the atlas texture without needing to call `QSGTexture::
removedFromAtlas()`), not having it set breaks batch
rendering.

The reasoning for this is not really clear, because Qt
could still batch `ShaderEffect`s that support atlas
textures through the uniform sub-rect define, provided
that there is only one source texture and it is the
same (the atlas texture). The only difference of
`supportsAtlasTextures` in this case the texture coordinate
provided to the shader being atlas-relative, which
should not have an effect on batch rendering.

That being said, shadows used underneath, possibly due
to overlapping between other items, already seem to
prevent batching of the delegate image. However, that
is a different concern and should be handled separately.

This brings back the initialization glitch, but batch
rendering is considered more important than the glitch,
and the glitch is not so bad that warrants a workaround
at the moment.

- - - - -


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,19 +83,11 @@ 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) * (atlasCoord - (qt_SubRect_source.zw + qt_SubRect_source.xy)) + vec2(1.0, 1.0);
+    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);
     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;
@@ -112,9 +104,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) * (atlasCoord.x - qt_SubRect_source.x) + l;
+        texCoord.x = (k - l) / (qt_SubRect_source.z) * (qt_TexCoord0.x - qt_SubRect_source.x) + l;
     }
-    // else { texCoord.x = atlasCoord.x; }
+    // else { texCoord.x = qt_TexCoord0.x; }
 
     // if (cropRate.y > 0.0)
     {
@@ -123,13 +115,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) * (atlasCoord.y - qt_SubRect_source.y) + l;
+        texCoord.y = (k - l) / (qt_SubRect_source.w) * (qt_TexCoord0.y - qt_SubRect_source.y) + l;
     }
-    // else { texCoord.y = atlasCoord.y; }
+    // else { texCoord.y = qt_TexCoord0.y; }
 
     vec4 texel = texture(source, texCoord);
 #else
-    vec4 texel = texture(source, atlasCoord);
+    vec4 texel = texture(source, qt_TexCoord0);
 #endif
 
 #ifdef BACKGROUND_SUPPORT


=====================================
modules/gui/qt/shaders/SDFAARoundedTexture_cropsupport_bordersupport.frag
=====================================
@@ -96,19 +96,11 @@ 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) * (atlasCoord - (qt_SubRect_source.zw + qt_SubRect_source.xy)) + vec2(1.0, 1.0);
+    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);
     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;
@@ -125,9 +117,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) * (atlasCoord.x - qt_SubRect_source.x) + l;
+        texCoord.x = (k - l) / (qt_SubRect_source.z) * (qt_TexCoord0.x - qt_SubRect_source.x) + l;
     }
-    // else { texCoord.x = atlasCoord.x; }
+    // else { texCoord.x = qt_TexCoord0.x; }
 
     // if (cropRate.y > 0.0)
     {
@@ -136,13 +128,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) * (atlasCoord.y - qt_SubRect_source.y) + l;
+        texCoord.y = (k - l) / (qt_SubRect_source.w) * (qt_TexCoord0.y - qt_SubRect_source.y) + l;
     }
-    // else { texCoord.y = atlasCoord.y; }
+    // else { texCoord.y = qt_TexCoord0.y; }
 
     vec4 texel = texture(source, texCoord);
 #else
-    vec4 texel = texture(source, atlasCoord);
+    vec4 texel = texture(source, qt_TexCoord0);
 #endif
 
 #ifdef BACKGROUND_SUPPORT


=====================================
modules/gui/qt/widgets/qml/ImageExt.qml
=====================================
@@ -164,16 +164,7 @@ Item {
 
         smooth: root.smooth
 
-        // 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`.
+        supportsAtlasTextures: true
 
         blending: true
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/aae2c5a64c136789deb3581f2841f2f3c3cbe6e6

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/aae2c5a64c136789deb3581f2841f2f3c3cbe6e6
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