[vlc-devel] [PATCH 03/16] opengl: handle the viewpoint changes when rendering
Thomas Guillem
thomas at gllm.fr
Wed Nov 9 18:32:57 CET 2016
From: Steve Lhomme <robux4 at videolabs.io>
vout_display_opengl_SetViewpoint is used to convert from the data within a
vlc_viewpoint_t so that it can be, equivalently interpreted by opengl.
The function will be called from the video-output modules that are using our
opengl implementation as their backend.
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
---
modules/video_output/opengl.c | 44 ++++++++++++++++++++++++++++++++++---------
modules/video_output/opengl.h | 3 +++
2 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
index 26aaec9..d4f5662 100644
--- a/modules/video_output/opengl.c
+++ b/modules/video_output/opengl.c
@@ -37,6 +37,7 @@
#include <vlc_subpicture.h>
#include <vlc_opengl.h>
#include <vlc_memory.h>
+#include <vlc_vout.h>
#include "opengl.h"
@@ -205,6 +206,7 @@ struct vout_display_opengl_t {
/* View point */
float f_teta;
float f_phi;
+ float f_roll;
float f_zoom;
};
@@ -422,6 +424,15 @@ 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)
+{
+ vgl->f_teta = f_teta - (float) M_PI / 2;
+ vgl->f_phi = f_phi;
+ vgl->f_roll = f_roll;
+ return VLC_SUCCESS;
+}
+
vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
const vlc_fourcc_t **subpicture_chromas,
vlc_gl_t *gl)
@@ -692,9 +703,9 @@ 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_roll_degrees / 180. * (float) M_PI;
- vgl->f_phi = vgl->fmt.f_pose_yaw_degrees / 180. * (float) M_PI;
- vgl->f_teta -= (float) M_PI/2;
+ SetViewpoint(vgl, vgl->fmt.f_pose_yaw_degrees / 180.f * (float) M_PI,
+ vgl->fmt.f_pose_pitch_degrees / 180.f * (float) M_PI,
+ vgl->fmt.f_pose_roll_degrees / 180.f * (float) M_PI);
}
/* */
@@ -777,6 +788,13 @@ 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, p_viewpoint->yaw / (float) VLC_VIEWPOINT_RADIAN_UNIT,
+ p_viewpoint->pitch / (float) VLC_VIEWPOINT_RADIAN_UNIT,
+ p_viewpoint->roll / (float) VLC_VIEWPOINT_RADIAN_UNIT);
+}
+
picture_pool_t *vout_display_opengl_GetPool(vout_display_opengl_t *vgl, unsigned requested_count)
{
if (vgl->pool)
@@ -1077,17 +1095,25 @@ static void getZoomMatrix(float zoom, GLfloat matrix[static 16]) {
static void getProjectionMatrix(float sar, GLfloat matrix[static 16]) {
- float f = 3;
- float n = 0.1;
+ float zFar = 1000;
+ float zNear = 0.01;
float fovy = (float) M_PI / 3;
float d = 1 / tan(fovy / 2);
+ if (fovy > (float) M_PI -0.001)
+ fovy = (float) M_PI -0.001;
+
+ if (fovy < 0.001)
+ fovy = 0.001;
+
+ float f = 1 / tan(fovy / 2);
+
const GLfloat m[] = {
- d / sar, 0.0, 0.0, 0.0,
- 0.0, d, 0.0, 0.0,
- 0.0, 0.0, (n + f) / (n - f), -1.0,
- 0.0, 0.0, (2 * n * f) / (n - f), 0.0};
+ f / sar, 0.0, 0.0, 0.0,
+ 0.0, f, 0.0, 0.0,
+ 0.0, 0.0, (zNear + zFar) / (zNear - zFar), -1.0,
+ 0.0, 0.0, (2 * zNear * zFar) / (zNear - zFar), 0.0};
memcpy(matrix, m, sizeof(m));
}
diff --git a/modules/video_output/opengl.h b/modules/video_output/opengl.h
index 4ae9400..4d382b5 100644
--- a/modules/video_output/opengl.h
+++ b/modules/video_output/opengl.h
@@ -31,6 +31,7 @@
#include <vlc_common.h>
#include <vlc_picture_pool.h>
+#include <vlc_vout_display.h>
#include <vlc_opengl.h>
/* Change USE_OPENGL_ES value to set the OpenGL ES version (1, 2) you want to use
@@ -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.9.3
More information about the vlc-devel
mailing list