[vlc-devel] [PATCH 05/10] opengl: move orientation matrix init to sampler
Romain Vimont
rom1v at videolabs.io
Wed May 20 16:08:16 CEST 2020
The orientation matrix is managed by the sampler. Move its
initialization to opengl_fragment_shader_init() (called by the sampler).
---
.../video_output/opengl/fragment_shaders.c | 72 ++++++++++++++++++-
modules/video_output/opengl/internal.h | 3 +-
modules/video_output/opengl/renderer.c | 68 ------------------
modules/video_output/opengl/sampler.c | 3 +-
4 files changed, 75 insertions(+), 71 deletions(-)
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index c775daa050b1..1bfae8b2d425 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -499,9 +499,77 @@ opengl_init_swizzle(const struct vlc_gl_interop *interop,
return VLC_SUCCESS;
}
+static void
+InitOrientationMatrix(GLfloat matrix[static 4*4],
+ video_orientation_t orientation)
+{
+ memcpy(matrix, MATRIX4_IDENTITY, sizeof(MATRIX4_IDENTITY));
+
+ const int k_cos_pi = -1;
+ const int k_cos_pi_2 = 0;
+ const int k_cos_n_pi_2 = 0;
+
+ const int k_sin_pi = 0;
+ const int k_sin_pi_2 = 1;
+ const int k_sin_n_pi_2 = -1;
+
+ switch (orientation) {
+
+ case ORIENT_ROTATED_90:
+ matrix[0 * 4 + 0] = k_cos_pi_2;
+ matrix[0 * 4 + 1] = -k_sin_pi_2;
+ matrix[1 * 4 + 0] = k_sin_pi_2;
+ matrix[1 * 4 + 1] = k_cos_pi_2;
+ matrix[3 * 4 + 1] = 1;
+ break;
+ case ORIENT_ROTATED_180:
+ matrix[0 * 4 + 0] = k_cos_pi;
+ matrix[0 * 4 + 1] = -k_sin_pi;
+ matrix[1 * 4 + 0] = k_sin_pi;
+ matrix[1 * 4 + 1] = k_cos_pi;
+ matrix[3 * 4 + 0] = 1;
+ matrix[3 * 4 + 1] = 1;
+ break;
+ case ORIENT_ROTATED_270:
+ matrix[0 * 4 + 0] = k_cos_n_pi_2;
+ matrix[0 * 4 + 1] = -k_sin_n_pi_2;
+ matrix[1 * 4 + 0] = k_sin_n_pi_2;
+ matrix[1 * 4 + 1] = k_cos_n_pi_2;
+ matrix[3 * 4 + 0] = 1;
+ break;
+ case ORIENT_HFLIPPED:
+ matrix[0 * 4 + 0] = -1;
+ matrix[3 * 4 + 0] = 1;
+ break;
+ case ORIENT_VFLIPPED:
+ matrix[1 * 4 + 1] = -1;
+ matrix[3 * 4 + 1] = 1;
+ break;
+ case ORIENT_TRANSPOSED:
+ matrix[0 * 4 + 0] = 0;
+ matrix[1 * 4 + 1] = 0;
+ matrix[2 * 4 + 2] = -1;
+ matrix[0 * 4 + 1] = 1;
+ matrix[1 * 4 + 0] = 1;
+ break;
+ case ORIENT_ANTI_TRANSPOSED:
+ matrix[0 * 4 + 0] = 0;
+ matrix[1 * 4 + 1] = 0;
+ matrix[2 * 4 + 2] = -1;
+ matrix[0 * 4 + 1] = -1;
+ matrix[1 * 4 + 0] = -1;
+ matrix[3 * 4 + 0] = 1;
+ matrix[3 * 4 + 1] = 1;
+ break;
+ default:
+ break;
+ }
+}
+
int
opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
- vlc_fourcc_t chroma, video_color_space_t yuv_space)
+ vlc_fourcc_t chroma, video_color_space_t yuv_space,
+ video_orientation_t orientation)
{
struct vlc_gl_interop *interop = sampler->interop;
@@ -513,6 +581,8 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
if (desc == NULL)
return VLC_EGENERIC;
+ InitOrientationMatrix(sampler->var.OrientationMatrix, orientation);
+
if (chroma == VLC_CODEC_XYZ12)
return xyz12_shader_init(sampler);
diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h
index 14946de3f9c5..a8d8975f5516 100644
--- a/modules/video_output/opengl/internal.h
+++ b/modules/video_output/opengl/internal.h
@@ -30,7 +30,8 @@ opengl_interop_init_impl(struct vlc_gl_interop *interop, GLenum tex_target,
int
opengl_fragment_shader_init(struct vlc_gl_sampler *sampler,
- GLenum, vlc_fourcc_t, video_color_space_t);
+ GLenum, vlc_fourcc_t, video_color_space_t,
+ video_orientation_t);
int
opengl_interop_generic_init(struct vlc_gl_interop *interop, bool);
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index a8f71fea037a..983429badd58 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -99,72 +99,6 @@ static void getViewpointMatrixes(struct vlc_gl_renderer *renderer,
}
-static void getOrientationTransformMatrix(video_orientation_t orientation,
- GLfloat matrix[static 16])
-{
- memcpy(matrix, MATRIX4_IDENTITY, sizeof(MATRIX4_IDENTITY));
-
- const int k_cos_pi = -1;
- const int k_cos_pi_2 = 0;
- const int k_cos_n_pi_2 = 0;
-
- const int k_sin_pi = 0;
- const int k_sin_pi_2 = 1;
- const int k_sin_n_pi_2 = -1;
-
- switch (orientation) {
-
- case ORIENT_ROTATED_90:
- matrix[0 * 4 + 0] = k_cos_pi_2;
- matrix[0 * 4 + 1] = -k_sin_pi_2;
- matrix[1 * 4 + 0] = k_sin_pi_2;
- matrix[1 * 4 + 1] = k_cos_pi_2;
- matrix[3 * 4 + 1] = 1;
- break;
- case ORIENT_ROTATED_180:
- matrix[0 * 4 + 0] = k_cos_pi;
- matrix[0 * 4 + 1] = -k_sin_pi;
- matrix[1 * 4 + 0] = k_sin_pi;
- matrix[1 * 4 + 1] = k_cos_pi;
- matrix[3 * 4 + 0] = 1;
- matrix[3 * 4 + 1] = 1;
- break;
- case ORIENT_ROTATED_270:
- matrix[0 * 4 + 0] = k_cos_n_pi_2;
- matrix[0 * 4 + 1] = -k_sin_n_pi_2;
- matrix[1 * 4 + 0] = k_sin_n_pi_2;
- matrix[1 * 4 + 1] = k_cos_n_pi_2;
- matrix[3 * 4 + 0] = 1;
- break;
- case ORIENT_HFLIPPED:
- matrix[0 * 4 + 0] = -1;
- matrix[3 * 4 + 0] = 1;
- break;
- case ORIENT_VFLIPPED:
- matrix[1 * 4 + 1] = -1;
- matrix[3 * 4 + 1] = 1;
- break;
- case ORIENT_TRANSPOSED:
- matrix[0 * 4 + 0] = 0;
- matrix[1 * 4 + 1] = 0;
- matrix[2 * 4 + 2] = -1;
- matrix[0 * 4 + 1] = 1;
- matrix[1 * 4 + 0] = 1;
- break;
- case ORIENT_ANTI_TRANSPOSED:
- matrix[0 * 4 + 0] = 0;
- matrix[1 * 4 + 1] = 0;
- matrix[2 * 4 + 2] = -1;
- matrix[0 * 4 + 1] = -1;
- matrix[1 * 4 + 0] = -1;
- matrix[3 * 4 + 0] = 1;
- matrix[3 * 4 + 1] = 1;
- break;
- default:
- break;
- }
-}
-
static void
InitStereoMatrix(GLfloat matrix_out[static 3*3],
video_multiview_mode_t multiview_mode)
@@ -431,8 +365,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
InitStereoMatrix(renderer->var.StereoMatrix, fmt->multiview_mode);
- getOrientationTransformMatrix(fmt->orientation,
- sampler->var.OrientationMatrix);
getViewpointMatrixes(renderer, fmt->projection_mode);
renderer->fmt = *fmt;
diff --git a/modules/video_output/opengl/sampler.c b/modules/video_output/opengl/sampler.c
index a3f1405bd704..93cc24956e31 100644
--- a/modules/video_output/opengl/sampler.c
+++ b/modules/video_output/opengl/sampler.c
@@ -85,7 +85,8 @@ vlc_gl_sampler_New(struct vlc_gl_interop *interop)
int ret =
opengl_fragment_shader_init(sampler, interop->tex_target,
interop->sw_fmt.i_chroma,
- interop->sw_fmt.space);
+ interop->sw_fmt.space,
+ interop->sw_fmt.orientation);
if (ret != VLC_SUCCESS)
{
free(sampler);
--
2.27.0.rc0
More information about the vlc-devel
mailing list