[vlc-commits] opengl: add vflip option to "draw" filter

Romain Vimont git at videolan.org
Mon Mar 1 17:23:04 UTC 2021


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Fri Feb 26 18:10:34 2021 +0100| [6fb0b411682240b741115fad30e2c2301a6577a4] | committer: Alexandre Janniaux

opengl: add vflip option to "draw" filter

OpenGL renders upside-down. When we retrieve the pixels, we might want
the picture in the normal orientation.

This option will allow to vflip without using an additional filter.

Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6fb0b411682240b741115fad30e2c2301a6577a4
---

 modules/video_output/opengl/filter_draw.c | 19 +++++++++++++++++--
 modules/video_output/opengl/filter_draw.h | 10 +++++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/modules/video_output/opengl/filter_draw.c b/modules/video_output/opengl/filter_draw.c
index 01bd3519ab..60aeddc539 100644
--- a/modules/video_output/opengl/filter_draw.c
+++ b/modules/video_output/opengl/filter_draw.c
@@ -35,6 +35,8 @@
 #include "gl_common.h"
 #include "gl_util.h"
 
+static const char *const filter_options[] = { "vflip", NULL };
+
 struct sys {
     GLuint program_id;
 
@@ -87,7 +89,6 @@ vlc_gl_filter_draw_Open(struct vlc_gl_filter *filter,
                         const config_chain_t *config,
                         struct vlc_gl_tex_size *size_out)
 {
-    (void) config;
     (void) size_out;
 
     struct sys *sys = filter->sys = malloc(sizeof(*sys));
@@ -114,6 +115,16 @@ vlc_gl_filter_draw_Open(struct vlc_gl_filter *filter,
         "                    (vertex_pos.y + 1.0) / 2.0);\n"
         "}\n";
 
+    static const char *const VERTEX_SHADER_VFLIP =
+        SHADER_VERSION
+        "attribute vec2 vertex_pos;\n"
+        "varying vec2 tex_coords;\n"
+        "void main() {\n"
+        "  gl_Position = vec4(vertex_pos, 0.0, 1.0);\n"
+        "  tex_coords = vec2((vertex_pos.x + 1.0) / 2.0,\n"
+        "                    (-vertex_pos.y + 1.0) / 2.0);\n"
+        "}\n";
+
     static const char *const FRAGMENT_SHADER_TEMPLATE =
         SHADER_VERSION
         "%s\n" /* extensions */
@@ -135,9 +146,13 @@ vlc_gl_filter_draw_Open(struct vlc_gl_filter *filter,
 
     const opengl_vtable_t *vt = &filter->api->vt;
 
+    config_ChainParse(filter, DRAW_CFG_PREFIX, filter_options, config);
+    bool vflip = var_InheritBool(filter, DRAW_CFG_PREFIX "vflip");
+
+    const char *vertex_shader = vflip ? VERTEX_SHADER_VFLIP : VERTEX_SHADER;
     GLuint program_id =
         vlc_gl_BuildProgram(VLC_OBJECT(filter), vt,
-                            1, (const char **) &VERTEX_SHADER,
+                            1, &vertex_shader,
                             1, (const char **) &fragment_shader);
 
     free(fragment_shader);
diff --git a/modules/video_output/opengl/filter_draw.h b/modules/video_output/opengl/filter_draw.h
index d458eb9141..64a6991168 100644
--- a/modules/video_output/opengl/filter_draw.h
+++ b/modules/video_output/opengl/filter_draw.h
@@ -24,12 +24,20 @@
 
 #include "filter.h"
 
+#define DRAW_VFLIP_SHORTTEXT "VFlip the video"
+#define DRAW_VFLIP_LONGTEXT \
+    "Apply a vertical flip to the video"
+
+#define DRAW_CFG_PREFIX "draw-"
+
 #define add_opengl_submodule_draw() \
     add_submodule() \
     add_shortcut("draw") \
     set_shortname("draw") \
     set_capability("opengl filter", 0) \
-    set_callback(vlc_gl_filter_draw_Open)
+    set_callback(vlc_gl_filter_draw_Open) \
+    add_bool(DRAW_CFG_PREFIX "vflip", false, \
+             DRAW_VFLIP_SHORTTEXT, DRAW_VFLIP_LONGTEXT, false)
 
 vlc_gl_filter_open_fn vlc_gl_filter_draw_Open;
 



More information about the vlc-commits mailing list