[vlc-devel] [PATCH] Support for rotated MP4 Movies (bug #2882)

Matthias Keiser matthias at tristan-inc.com
Thu Feb 6 23:21:35 CET 2014


From 573546cac0a680566e304da341bed83d6555f1ba Mon Sep 17 00:00:00 2001
From: Matthias Keiser <matthias at tristan-inc.com>
Date: Thu, 6 Feb 2014 16:28:26 +0100
Subject: [PATCH 11/13] If the video formats orientation is rotated, apply a
 rotation transform matrix, both when using the fixed pipeline and the shader.

---
 modules/video_output/opengl.c | 59 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
index 33db19d..d786cb6 100644
--- a/modules/video_output/opengl.c
+++ b/modules/video_output/opengl.c
@@ -35,6 +35,7 @@
 #include <vlc_opengl.h>
 
 #include "opengl.h"
+#include "math.h"
 
 #ifndef GL_CLAMP_TO_EDGE
 # define GL_CLAMP_TO_EDGE 0x812F
@@ -51,6 +52,7 @@
 #   define PFNGLENABLEVERTEXATTRIBARRAYPROC  typeof(glEnableVertexAttribArray)*
 #   define PFNGLUNIFORM4FVPROC               typeof(glUniform4fv)*
 #   define PFNGLUNIFORM4FPROC                typeof(glUniform4f)*
+#   define PFNGLUNIFORM1FPROC                typeof(glUniform1f)*
 #   define PFNGLUNIFORM1IPROC                typeof(glUniform1i)*
 #   define PFNGLCREATESHADERPROC             typeof(glCreateShader)*
 #   define PFNGLSHADERSOURCEPROC             typeof(glShaderSource)*
@@ -148,6 +150,7 @@ struct vout_display_opengl_t {
 
     PFNGLUNIFORM4FVPROC   Uniform4fv;
     PFNGLUNIFORM4FPROC    Uniform4f;
+    PFNGLUNIFORM1FPROC    Uniform1f;
     PFNGLUNIFORM1IPROC    Uniform1i;
 
     /* Shader command */
@@ -222,11 +225,17 @@ static void BuildVertexShader(vout_display_opengl_t *vgl,
         "varying vec4 TexCoord0,TexCoord1, TexCoord2;"
         "attribute vec4 MultiTexCoord0,MultiTexCoord1,MultiTexCoord2;"
         "attribute vec4 VertexPosition;"
+        "uniform float zRotation;"
         "void main() {"
         " TexCoord0 = MultiTexCoord0;"
         " TexCoord1 = MultiTexCoord1;"
         " TexCoord2 = MultiTexCoord2;"
-        " gl_Position = VertexPosition;"
+        " mat3 zRotMatrix = mat3("
+        "   vec3( cos(zRotation),  -sin(zRotation),  0.0),"
+        "   vec3(sin(zRotation),  cos(zRotation),  0.0),"
+        "   vec3(        0.0,         0.0,  1.0)"
+        " );"
+        " gl_Position = vec4(zRotMatrix * VertexPosition.xyz, VertexPosition.w);"
         "}";
 
     *shader = vgl->CreateShader(GL_VERTEX_SHADER);
@@ -460,6 +469,7 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
     vgl->EnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)vlc_gl_GetProcAddress(vgl->gl, "glEnableVertexAttribArray");
     vgl->Uniform4fv    = (PFNGLUNIFORM4FVPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform4fv");
     vgl->Uniform4f     = (PFNGLUNIFORM4FPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform4f");
+    vgl->Uniform1f     = (PFNGLUNIFORM1FPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform1f");
     vgl->Uniform1i     = (PFNGLUNIFORM1IPROC)vlc_gl_GetProcAddress(vgl->gl,"glUniform1i");
 
     vgl->CreateProgram = (PFNGLCREATEPROGRAMPROC)vlc_gl_GetProcAddress(vgl->gl, "glCreateProgram");
@@ -965,6 +975,29 @@ static void DrawWithoutShaders(vout_display_opengl_t *vgl,
         right[0], top[0]
     };
 
+    GLdouble angle;
+
+    switch (vgl->fmt.orientation) {
+
+        case ORIENT_ROTATED_90:
+            angle = 270.0;
+            break;
+        case ORIENT_ROTATED_180:
+            angle = 180.0;
+            break;
+        case ORIENT_ROTATED_270:
+            angle = 90.0;
+            break;
+        default:
+            angle = 0.0;
+            break;
+    }
+
+    glPushMatrix();
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+    glRotated(angle, 0, 0, 1);
+
     glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
     glEnable(vgl->tex_target);
     glActiveTexture(GL_TEXTURE0 + 0);
@@ -983,6 +1016,9 @@ static void DrawWithoutShaders(vout_display_opengl_t *vgl,
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
     glDisableClientState(GL_VERTEX_ARRAY);
     glDisable(vgl->tex_target);
+
+    glPopMatrix();
+
 }
 #endif
 
@@ -1030,10 +1066,31 @@ static void DrawWithShaders(vout_display_opengl_t *vgl,
         vgl->EnableVertexAttribArray(vgl->GetAttribLocation(vgl->program[program], attribute));
         vgl->VertexAttribPointer(vgl->GetAttribLocation(vgl->program[program], attribute), 2, GL_FLOAT, 0, 0, textureCoord);
     }
+
+    float angle;
+
+    switch (vgl->fmt.orientation) {
+
+        case ORIENT_ROTATED_90:
+            angle = M_PI_2;
+            break;
+        case ORIENT_ROTATED_180:
+            angle = M_PI;
+            break;
+        case ORIENT_ROTATED_270:
+            angle = -M_PI_2;
+            break;
+        default:
+            angle = 0.0;
+            break;
+    }
+
     glActiveTexture(GL_TEXTURE0 + 0);
     glClientActiveTexture(GL_TEXTURE0 + 0);
     vgl->EnableVertexAttribArray(vgl->GetAttribLocation(vgl->program[program], "VertexPosition"));
     vgl->VertexAttribPointer(vgl->GetAttribLocation(vgl->program[program], "VertexPosition"), 2, GL_FLOAT, 0, 0, vertexCoord);
+    vgl->EnableVertexAttribArray(vgl->GetUniformLocation(vgl->program[program], "zRotation"));
+    vgl->Uniform1f(vgl->GetUniformLocation(vgl->program[program], "zRotation"), angle);
 
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 }
-- 
1.8.3.4 (Apple Git-47)





More information about the vlc-devel mailing list