[clutter-gst/clutter-gst-2.0] video-sink: fix shaders with the removal of luminance texture in GL3



commit 767225ebba3034bdcf16ae8101146495deb7d679
Author: Fabrice Bellet <fabrice bellet info>
Date:   Wed Mar 2 00:32:56 2016 +0100

    video-sink: fix shaders with the removal of luminance texture in GL3
    
    This patch uses the alpha component instead of the lumimance
    component, and fixes glsl fragment shaders and ARB fragment
    programs accordingly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762764

 clutter-gst/clutter-gst-video-sink.c |   34 +++++++++++++++++++++++++---------
 clutter-gst/shaders/I420.h           |   28 ++++++++++++++--------------
 clutter-gst/shaders/YV12.h           |   28 ++++++++++++++--------------
 3 files changed, 53 insertions(+), 37 deletions(-)
---
diff --git a/clutter-gst/clutter-gst-video-sink.c b/clutter-gst/clutter-gst-video-sink.c
index ef6d996..d5b8204 100644
--- a/clutter-gst/clutter-gst-video-sink.c
+++ b/clutter-gst/clutter-gst-video-sink.c
@@ -99,7 +99,7 @@ static gchar *nv12_to_rgba_shader =
     "uniform sampler2D utex;"
     "void main () {"
     "  vec2 coord = vec2(cogl_tex_coord_in[0]);"
-    "  float y = 1.1640625 * (texture2D (ytex, coord).x - 0.0625);"
+    "  float y = 1.1640625 * (texture2D (ytex, coord).a - 0.0625);"
     "  float uvr = int (texture2D (utex, coord).r * 32);"
     "  float uvg = int (texture2D (utex, coord).g * 64);"
     "  float uvb = int (texture2D (utex, coord).b * 32);"
@@ -121,9 +121,25 @@ static gchar *yv12_to_rgba_shader =
     "uniform sampler2D vtex;"
     "void main () {"
     "  vec2 coord = vec2(cogl_tex_coord_in[0]);"
-    "  float y = 1.1640625 * (texture2D (ytex, coord).g - 0.0625);"
-    "  float u = texture2D (utex, coord).g - 0.5;"
-    "  float v = texture2D (vtex, coord).g - 0.5;"
+    "  float y = 1.1640625 * (texture2D (ytex, coord).a - 0.0625);"
+    "  float v = texture2D (utex, coord).a - 0.5;"
+    "  float u = texture2D (vtex, coord).a - 0.5;"
+    "  vec4 color;"
+    "  color.r = y + 1.59765625 * v;"
+    "  color.g = y - 0.390625 * u - 0.8125 * v;"
+    "  color.b = y + 2.015625 * u;"
+    "  color.a = 1.0;"
+    "  cogl_color_out = color;}";
+
+static gchar *i420_to_rgba_shader =
+    "uniform sampler2D ytex;"
+    "uniform sampler2D utex;"
+    "uniform sampler2D vtex;"
+    "void main () {"
+    "  vec2 coord = vec2(cogl_tex_coord_in[0]);"
+    "  float y = 1.1640625 * (texture2D (ytex, coord).a - 0.0625);"
+    "  float u = texture2D (utex, coord).a - 0.5;"
+    "  float v = texture2D (vtex, coord).a - 0.5;"
     "  vec4 color;"
     "  color.r = y + 1.59765625 * v;"
     "  color.g = y - 0.390625 * u - 0.8125 * v;"
@@ -997,8 +1013,8 @@ clutter_gst_yv12_upload (ClutterGstVideoSink * sink, GstBuffer * buffer)
       cogl_texture_new_from_data (GST_VIDEO_FRAME_COMP_WIDTH (&frame, i),
       GST_VIDEO_FRAME_COMP_HEIGHT (&frame, i),
       CLUTTER_GST_TEXTURE_FLAGS,
-      COGL_PIXEL_FORMAT_G_8,
-      COGL_PIXEL_FORMAT_G_8,
+      COGL_PIXEL_FORMAT_A_8,
+      COGL_PIXEL_FORMAT_A_8,
       GST_VIDEO_FRAME_PLANE_STRIDE (&frame, i),
       GST_VIDEO_FRAME_PLANE_DATA (&frame, i));
   }
@@ -1056,8 +1072,8 @@ clutter_gst_nv12_upload (ClutterGstVideoSink * sink, GstBuffer * buffer)
     cogl_texture_new_from_data (GST_VIDEO_FRAME_COMP_WIDTH (&frame, 0),
     GST_VIDEO_FRAME_COMP_HEIGHT (&frame, 0),
     CLUTTER_GST_TEXTURE_FLAGS,
-    COGL_PIXEL_FORMAT_G_8,
-    COGL_PIXEL_FORMAT_G_8,
+    COGL_PIXEL_FORMAT_A_8,
+    COGL_PIXEL_FORMAT_A_8,
     GST_VIDEO_FRAME_PLANE_STRIDE (&frame, 0),
     GST_VIDEO_FRAME_PLANE_DATA (&frame, 0));
 
@@ -1153,7 +1169,7 @@ static ClutterGstRenderer yv12_fp_renderer = {
 static void
 clutter_gst_i420_glsl_init (ClutterGstVideoSink * sink)
 {
-  _create_template_material (sink, yv12_to_rgba_shader, TRUE, 3);
+  _create_template_material (sink, i420_to_rgba_shader, TRUE, 3);
 }
 
 static ClutterGstRenderer i420_glsl_renderer = {
diff --git a/clutter-gst/shaders/I420.h b/clutter-gst/shaders/I420.h
index 474f6e2..a3e35c4 100644
--- a/clutter-gst/shaders/I420.h
+++ b/clutter-gst/shaders/I420.h
@@ -9,27 +9,27 @@
  * This define is the size of the shader in bytes.  More precisely it's the
  * sum of strlen() of every string in the array.
  */
-#define I420_FP_SZ    564
+#define I420_FP_SZ    572
 
 static const char *I420_fp[] =
 {
   "!!ARBfp1.0\n",
-  "PARAM c[2] = { { 1.1640625, 0.0625, 2.015625, 0.5 },\n",
-  "{ 0.390625, 0.8125, 1.5976562 } };\n",
+  "PARAM c[2] = { { 1.1640625, 0.5, 2.015625, 0.0625 },\n",
+  "{ 0.390625, 0, 1.5976562, 0.8125 } };\n",
   "TEMP R0;\n",
   "TEMP R1;\n",
-  "TEX R1.y, fragment.texcoord[0], texture[0], 2D;\n",
-  "ADD R0.x, R1.y, -c[0].y;\n",
-  "TEX R0.y, fragment.texcoord[0], texture[2], 2D;\n",
-  "TEX R1.y, fragment.texcoord[0], texture[1], 2D;\n",
+  "TEX R1.w, fragment.texcoord[0], texture[0], 2D;\n",
+  "ADD R0.x, R1.w, -c[0].w;\n",
+  "TEX R0.w, fragment.texcoord[0], texture[2], 2D;\n",
+  "TEX R1.w, fragment.texcoord[0], texture[1], 2D;\n",
   "MUL R0.x, R0, c[0];\n",
-  "ADD R0.w, R1.y, -c[0];\n",
-  "MAD R0.z, R0.w, c[0], R0.x;\n",
-  "ADD R0.y, R0, -c[0].w;\n",
-  "MAD R0.w, -R0, c[1].x, R0.x;\n",
-  "MAD R0.x, R0.y, c[1].z, R0;\n",
-  "MAD R0.y, -R0, c[1], R0.w;\n",
-  "MUL result.color.xyz, fragment.color.primary.w, R0;\n",
+  "ADD R0.y, R1.w, -c[0];\n",
+  "MAD R0.z, R0.y, c[0], R0.x;\n",
+  "ADD R0.w, R0, -c[0].y;\n",
+  "MAD R0.y, -R0, c[1].x, R0.x;\n",
+  "MAD R0.x, R0.w, c[1].z, R0;\n",
+  "MAD R0.w, -R0, c[1], R0.y;\n",
+  "MUL result.color.xyz, fragment.color.primary.w, R0.xwzy;\n",
   "MOV result.color.w, fragment.color.primary;\n",
   "END\n",
   NULL
diff --git a/clutter-gst/shaders/YV12.h b/clutter-gst/shaders/YV12.h
index dbc56fe..36cade6 100644
--- a/clutter-gst/shaders/YV12.h
+++ b/clutter-gst/shaders/YV12.h
@@ -9,27 +9,27 @@
  * This define is the size of the shader in bytes.  More precisely it's the
  * sum of strlen() of every string in the array.
  */
-#define YV12_FP_SZ    564
+#define YV12_FP_SZ    572
 
 static const char *YV12_fp[] =
 {
   "!!ARBfp1.0\n",
-  "PARAM c[2] = { { 1.1640625, 0.0625, 2.015625, 0.5 },\n",
-  "{ 0.390625, 0.8125, 1.5976562 } };\n",
+  "PARAM c[2] = { { 1.1640625, 0.5, 2.015625, 0.0625 },\n",
+  "{ 0.390625, 0, 1.5976562, 0.8125 } };\n",
   "TEMP R0;\n",
   "TEMP R1;\n",
-  "TEX R1.y, fragment.texcoord[0], texture[0], 2D;\n",
-  "ADD R0.x, R1.y, -c[0].y;\n",
-  "TEX R0.y, fragment.texcoord[0], texture[1], 2D;\n",
-  "TEX R1.y, fragment.texcoord[0], texture[2], 2D;\n",
+  "TEX R1.w, fragment.texcoord[0], texture[0], 2D;\n",
+  "ADD R0.x, R1.w, -c[0].w;\n",
+  "TEX R0.w, fragment.texcoord[0], texture[1], 2D;\n",
+  "TEX R1.w, fragment.texcoord[0], texture[2], 2D;\n",
   "MUL R0.x, R0, c[0];\n",
-  "ADD R0.w, R1.y, -c[0];\n",
-  "MAD R0.z, R0.w, c[0], R0.x;\n",
-  "ADD R0.y, R0, -c[0].w;\n",
-  "MAD R0.w, -R0, c[1].x, R0.x;\n",
-  "MAD R0.x, R0.y, c[1].z, R0;\n",
-  "MAD R0.y, -R0, c[1], R0.w;\n",
-  "MUL result.color.xyz, fragment.color.primary.w, R0;\n",
+  "ADD R0.y, R1.w, -c[0];\n",
+  "MAD R0.z, R0.y, c[0], R0.x;\n",
+  "ADD R0.w, R0, -c[0].y;\n",
+  "MAD R0.y, -R0, c[1].x, R0.x;\n",
+  "MAD R0.x, R0.w, c[1].z, R0;\n",
+  "MAD R0.w, -R0, c[1], R0.y;\n",
+  "MUL result.color.xyz, fragment.color.primary.w, R0.xwzy;\n",
   "MOV result.color.w, fragment.color.primary;\n",
   "END\n",
   NULL


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]