[vlc-devel] [PATCH 09/17] opengl: handle the viewpoint changes when rendering
Steve Lhomme
robux4 at videolabs.io
Mon Nov 14 15:16:18 CET 2016
--
replaces https://patches.videolan.org/patch/14910/
* squashed with https://patches.videolan.org/patch/14910/
* use M_PI as a float to avoid double math
replaces https://patches.videolan.org/patch/14960/
* use vout_viewpoint_t with float values rather than integers
replaces https://patches.videolan.org/patch/14975/
* use macros to simplify degree/radians conversions
---
modules/video_output/opengl.c | 41 ++++++++++++++++++++++++++++++++++++-----
modules/video_output/opengl.h | 3 +++
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
index 16c6592..348a52c 100644
--- a/modules/video_output/opengl.c
+++ b/modules/video_output/opengl.c
@@ -424,6 +424,27 @@ static void BuildXYZFragmentShader(vout_display_opengl_t *vgl,
#endif
+static int
+SetViewpoint(vout_display_opengl_t *vgl, float f_teta, float f_phi, float f_roll,
+ float f_fov, float f_zoom)
+{
+ if (f_fov > (float) M_PI -0.001f)
+ return VLC_EBADVAR;
+ if (f_fov < 0.001f)
+ return VLC_EBADVAR;
+ vgl->f_teta = f_teta - (float) M_PI / 2;
+ vgl->f_phi = f_phi;
+ vgl->f_roll = f_roll;
+ vgl->f_fov = f_fov;
+ vgl->f_zoom = f_zoom;
+
+ return VLC_SUCCESS;
+}
+
+#define FROM_RADIANS(d) (d * 180.f / (float) M_PI)
+#define TO_RADIANS(d) (d * (float) M_PI / 180.f)
+#define MILLI_TO_RADIANS(vdg) TO_RADIANS(FROM_MILLI_INT(vdg))
+
vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
const vlc_fourcc_t **subpicture_chromas,
vlc_gl_t *gl)
@@ -694,11 +715,11 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
if (vgl->fmt.projection_mode == PROJECTION_MODE_EQUIRECTANGULAR
|| vgl->fmt.projection_mode == PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD)
{
- vgl->f_teta = vgl->fmt.f_pose_yaw_degrees / 180. * (float) M_PI;
- vgl->f_phi = vgl->fmt.f_pose_pitch_degrees / 180. * (float) M_PI;
- vgl->f_roll = vgl->fmt.f_pose_roll_degrees / 180. * (float) M_PI;
- vgl->f_fov = vgl->fmt.f_pose_fov_degrees / 180. * (float) M_PI;
- vgl->f_teta -= (float) M_PI/2;
+ SetViewpoint(vgl, TO_RADIANS(vgl->fmt.f_pose_yaw_degrees),
+ TO_RADIANS(vgl->fmt.f_pose_pitch_degrees),
+ TO_RADIANS(vgl->fmt.f_pose_roll_degrees),
+ TO_RADIANS(vgl->fmt.f_pose_fov_degrees),
+ 0.f);
}
/* */
@@ -781,6 +802,16 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl)
free(vgl);
}
+int vout_display_opengl_SetViewpoint(vout_display_opengl_t *vgl,
+ const vlc_viewpoint_t *p_viewpoint)
+{
+ return SetViewpoint(vgl, MILLI_TO_RADIANS(p_viewpoint->yaw),
+ MILLI_TO_RADIANS(p_viewpoint->pitch),
+ MILLI_TO_RADIANS(p_viewpoint->roll),
+ MILLI_TO_RADIANS(p_viewpoint->fov),
+ FROM_MILLI_INT(p_viewpoint->zoom));
+}
+
picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned requested_count)
{
if (vgl->pool)
diff --git a/modules/video_output/opengl.h b/modules/video_output/opengl.h
index 4ae9400..ff76902 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 */
@@ -96,6 +97,8 @@ void vout_display_opengl_Delete(vout_display_opengl_t *vgl);
picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned);
+int vout_display_opengl_SetViewpoint(vout_display_opengl_t *vgl, const vlc_viewpoint_t*);
+
int vout_display_opengl_Prepare(vout_display_opengl_t *vgl,
picture_t *picture, subpicture_t *subpicture);
int vout_display_opengl_Display(vout_display_opengl_t *vgl,
--
2.10.1
More information about the vlc-devel
mailing list