[vlc-devel] [PATCH 6/7] opengl: use the projection mode from the display configuration

Steve Lhomme robux4 at videolabs.io
Mon Sep 12 14:01:36 CEST 2016


only auto, flat, sphere, cubemap are currently supported
---
 modules/video_output/gl.c            |  9 ++++++++
 modules/video_output/ios2.m          |  9 ++++++++
 modules/video_output/macosx.m        |  9 ++++++++
 modules/video_output/opengl.c        | 41 ++++++++++++++++++++++++++++++++----
 modules/video_output/opengl.h        |  2 ++
 modules/video_output/win32/glwin32.c |  9 ++++++++
 modules/video_output/xcb/glx.c       |  9 ++++++++
 7 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/modules/video_output/gl.c b/modules/video_output/gl.c
index 4bdeddd..090d47d 100644
--- a/modules/video_output/gl.c
+++ b/modules/video_output/gl.c
@@ -256,6 +256,15 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                                          src->f_pose_pitch_degrees, src->f_pose_roll_degrees);
         return VLC_SUCCESS;
       }
+      case VOUT_DISPLAY_CHANGE_PROJECTION:
+      {
+          const vout_display_cfg_t *p_cfg = va_arg (ap, const vout_display_cfg_t *);
+          int res = vout_display_opengl_SetProjection(sys->vgl, p_cfg->projection);
+
+          if (res != VLC_SUCCESS )
+              msg_Warn(vd, "Failed to set the projection type %d", p_cfg->projection);
+          return res;
+      }
       default:
         msg_Err (vd, "Unknown request %d", query);
     }
diff --git a/modules/video_output/ios2.m b/modules/video_output/ios2.m
index 505d19e..04cbf18 100644
--- a/modules/video_output/ios2.m
+++ b/modules/video_output/ios2.m
@@ -458,6 +458,15 @@ static int Control(vout_display_t *vd, int query, va_list ap)
                                              src->f_pose_pitch_degrees, src->f_pose_roll_degrees);
             return VLC_SUCCESS;
         }
+        case VOUT_DISPLAY_CHANGE_PROJECTION:
+        {
+            const vout_display_cfg_t *p_cfg = va_arg (args, const vout_display_cfg_t *);
+            int res = vout_display_opengl_SetProjection(sys->vgl, p_cfg->projection);
+
+            if (res != VLC_SUCCESS )
+                msg_Warn(vd, "Failed to set the projection type %d", p_cfg->projection);
+            return res;
+        }
 
         case VOUT_DISPLAY_RESET_PICTURES:
             vlc_assert_unreachable ();
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index 56a05d1..9f2079d 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -436,6 +436,15 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                                                  src->f_pose_pitch_degrees, src->f_pose_roll_degrees);
                 return VLC_SUCCESS;
             }
+            case VOUT_DISPLAY_CHANGE_PROJECTION:
+            {
+                const vout_display_cfg_t *p_cfg = va_arg (args, const vout_display_cfg_t *);
+                int res = vout_display_opengl_SetProjection(sys->vgl, p_cfg->projection);
+
+                if (res != VLC_SUCCESS )
+                    msg_Warn(vd, "Failed to set the projection type %d", p_cfg->projection);
+                return res;
+            }
 
             case VOUT_DISPLAY_RESET_PICTURES:
                 vlc_assert_unreachable ();
diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
index ff049a1..4d31e5c 100644
--- a/modules/video_output/opengl.c
+++ b/modules/video_output/opengl.c
@@ -120,6 +120,7 @@ struct vout_display_opengl_t {
 
     video_format_t fmt;
     const vlc_chroma_description_t *chroma;
+    projection_mode projection;
 
     int        tex_target;
     int        tex_format;
@@ -795,6 +796,21 @@ void vout_display_opengl_SetViewpoint(vout_display_opengl_t *vgl,
         vgl->f_roll = -M_PI / 2;
 }
 
+int vout_display_opengl_SetProjection(vout_display_opengl_t *vgl, projection_mode proj_mode)
+{
+    switch (proj_mode)
+    {
+    case PROJECTION_AUTO:
+    case PROJECTION_FLAT:
+    case PROJECTION_SPHERE:
+    case PROJECTION_CUBEMAP:
+        vgl->projection = proj_mode;
+        return VLC_SUCCESS;
+    default:
+        return VLC_EBADVAR;
+    }
+}
+
 picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned requested_count)
 {
     if (vgl->pool)
@@ -1512,21 +1528,38 @@ static void DrawWithShaders(vout_display_opengl_t *vgl,
     unsigned nbVertices, nbIndices;
 
     int i_ret;
-    switch (vgl->fmt.projection_mode)
+    projection_mode proj_mode = vgl->projection;
+    if (vgl->projection == PROJECTION_AUTO)
+    {
+        switch (vgl->fmt.projection_mode)
+        {
+        case PROJECTION_MODE_RECTANGULAR:
+            proj_mode = PROJECTION_FLAT;
+            break;
+        case PROJECTION_MODE_EQUIRECTANGULAR:
+            proj_mode = PROJECTION_SPHERE;
+            break;
+        case PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD:
+            proj_mode = PROJECTION_CUBEMAP;
+            break;
+        }
+    }
+
+    switch (proj_mode)
     {
-    case PROJECTION_MODE_RECTANGULAR:
+    case PROJECTION_FLAT:
         i_ret = BuildRectangle(vgl->chroma->plane_count,
                                &vertexCoord, &textureCoord, &nbVertices,
                                &indices, &nbIndices,
                                left, top, right, bottom);
         break;
-    case PROJECTION_MODE_EQUIRECTANGULAR:
+    case PROJECTION_SPHERE:
         i_ret = BuildSphere(vgl->chroma->plane_count,
                             &vertexCoord, &textureCoord, &nbVertices,
                             &indices, &nbIndices,
                             left, top, right, bottom);
         break;
-    case PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD:
+    case PROJECTION_CUBEMAP:
         i_ret = BuildCube(vgl->chroma->plane_count,
                           (float)vgl->fmt.i_cubemap_padding / vgl->fmt.i_width,
                           (float)vgl->fmt.i_cubemap_padding / vgl->fmt.i_height,
diff --git a/modules/video_output/opengl.h b/modules/video_output/opengl.h
index 9e37f61..4a9b34b 100644
--- a/modules/video_output/opengl.h
+++ b/modules/video_output/opengl.h
@@ -32,6 +32,7 @@
 #include <vlc_common.h>
 #include <vlc_picture_pool.h>
 #include <vlc_opengl.h>
+#include <vlc_vout.h>
 
 /* Change USE_OPENGL_ES value to set the OpenGL ES version (1, 2) you want to use
  * A value of 0 will activate normal OpenGL */
@@ -98,6 +99,7 @@ picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned
 
 void vout_display_opengl_SetViewpoint(vout_display_opengl_t *vgl,
                                       float yaw, float pitch, float roll);
+int vout_display_opengl_SetProjection(vout_display_opengl_t *vgl, projection_mode);
 
 int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
                                 picture_t *picture, subpicture_t *subpicture);
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index 2674531..8a2cb54 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -158,6 +158,15 @@ static int Control(vout_display_t *vd, int query, va_list args)
                                        src->f_pose_pitch_degrees, src->f_pose_roll_degrees);
       return VLC_SUCCESS;
     }
+    else if (query == VOUT_DISPLAY_CHANGE_PROJECTION)
+    {
+        const vout_display_cfg_t *p_cfg = va_arg (args, const vout_display_cfg_t *);
+        int res = vout_display_opengl_SetProjection(sys->vgl, p_cfg->projection);
+
+        if (res != VLC_SUCCESS )
+            msg_Warn(vd, "Failed to set the projection type %d", p_cfg->projection);
+        return res;
+    }
 
     return CommonControl(vd, query, args);
 }
diff --git a/modules/video_output/xcb/glx.c b/modules/video_output/xcb/glx.c
index 3dff282..cf4710d 100644
--- a/modules/video_output/xcb/glx.c
+++ b/modules/video_output/xcb/glx.c
@@ -254,6 +254,15 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                                          src->f_pose_pitch_degrees, src->f_pose_roll_degrees);
         return VLC_SUCCESS;
     }
+    case VOUT_DISPLAY_CHANGE_PROJECTION:
+    {
+        const vout_display_cfg_t *p_cfg = va_arg (args, const vout_display_cfg_t *);
+        int res = vout_display_opengl_SetProjection(sys->vgl, p_cfg->projection);
+
+        if (res != VLC_SUCCESS )
+            msg_Warn(vd, "Failed to set the projection type %d", p_cfg->projection);
+        return res;
+    }
 
     case VOUT_DISPLAY_RESET_PICTURES:
         vlc_assert_unreachable ();
-- 
2.8.2



More information about the vlc-devel mailing list