[vlc-commits] [Git][videolan/vlc][master] opengl: simplify generated GLSL code

Romain Vimont (@rom1v) gitlab at videolan.org
Mon Oct 4 09:50:43 UTC 2021



Romain Vimont pushed to branch master at VideoLAN / VLC


Commits:
606648f4 by Romain Vimont at 2021-10-04T09:28:52+00:00
opengl: simplify generated GLSL code

Now that TexCoordsMap is the same for all planes, initializing the pixel
vec4 in several steps is not necessary anymore.

Concretely, replace:

    vec4 texel;
    vec4 pixel = vec4(0.0, 0.0, 0.0, 1.0);
    texel = texture2D(Textures[0], tex_coords);
    pixel[0] = texel.r;
    texel = texture2D(Textures[1], tex_coords);
    pixel[1] = texel.r;
    texel = texture2D(Textures[2], tex_coords);
    pixel[2] = texel.r;

by:

    vec4 pixel = vec4(
     texture2D(Textures[0], tex_coords).r,
     texture2D(Textures[1], tex_coords).r,
     texture2D(Textures[2], tex_coords).r,
     1.0);

- - - - -


1 changed file:

- modules/video_output/opengl/sampler.c


Changes:

=====================================
modules/video_output/opengl/sampler.c
=====================================
@@ -1022,32 +1022,26 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
 
     unsigned color_count;
     if (is_yuv) {
-        ADD(" vec4 texel;\n"
-            " vec4 pixel = vec4(0.0, 0.0, 0.0, 1.0);\n");
-        unsigned color_idx = 0;
+        ADD(" vec4 pixel = vec4(\n");
+        color_count = 0;
         for (unsigned i = 0; i < tex_count; ++i)
         {
             const char *swizzle = swizzle_per_tex[i];
             assert(swizzle);
-            size_t swizzle_count = strlen(swizzle);
+            color_count += strlen(swizzle);
+            assert(color_count < PICTURE_PLANE_MAX);
             if (tex_target == GL_TEXTURE_RECTANGLE)
             {
                 /* The coordinates are in texels values, not normalized */
-                ADDF(" texel = %s(Textures[%u], TexSizes[%u] * tex_coords);\n", lookup, i, i);
+                ADDF("  %s(Textures[%u], TexSizes[%u] * tex_coords).%s;\n", lookup, i, i, swizzle);
             }
             else
             {
-                ADDF(" texel = %s(Textures[%u], tex_coords);\n", lookup, i);
-            }
-            for (unsigned j = 0; j < swizzle_count; ++j)
-            {
-                ADDF(" pixel[%u] = texel.%c;\n", color_idx, swizzle[j]);
-                color_idx++;
-                assert(color_idx <= PICTURE_PLANE_MAX);
+                ADDF("  %s(Textures[%u], tex_coords).%s,\n", lookup, i, swizzle);
             }
         }
+        ADD("  1.0);\n");
         ADD(" vec4 result = ConvMatrix * pixel;\n");
-        color_count = color_idx;
     }
     else
     {



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

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/606648f488e3ed0cb25e01b73703ca7d1084d185
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list