[cogl/wip/cogl-gst: 13/27] cogl-gst: Use the global declarations snippet hook



commit e2175560c3c5a3ecc0de334e9a9043226f6ed240
Author: Neil Roberts <neil linux intel com>
Date:   Tue Feb 26 19:14:35 2013 +0000

    cogl-gst: Use the global declarations snippet hook
    
    Instead of adding the default sampling and the global function
    declaration to a single snippet, they are now split into two. The
    declaration is added to the global function declarations hook and the
    default sampling is set as the replace string for the last layer that
    CoglGst is using. That way the application can't add a layer or a
    snippet which causes the generated snippet to be skipped.
    
    Now that the last layer is using replace it also means that Cogl won't
    redundantly write to cogl_color_out for all of the other layers when
    using multiple textures.

 cogl-gst/cogl-gst-shader.c     |    4 ++--
 cogl-gst/cogl-gst-shader.h     |    2 +-
 cogl-gst/cogl-gst-video-sink.c |   35 ++++++++++++++++++++++++++++-------
 3 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/cogl-gst/cogl-gst-shader.c b/cogl-gst/cogl-gst-shader.c
index cb5d9ee..d964c72 100644
--- a/cogl-gst/cogl-gst-shader.c
+++ b/cogl-gst/cogl-gst-shader.c
@@ -65,5 +65,5 @@ _cogl_gst_shader_ayuv_to_rgba_decl[] =
   "}";
 
 const char
-_cogl_gst_shader_default_post[] =
-  "cogl_color_out = cogl_gst_sample_video (cogl_tex_coord0_in.st);";
+_cogl_gst_shader_default_sample[] =
+  "cogl_layer = cogl_gst_sample_video (cogl_tex_coord0_in.st);";
diff --git a/cogl-gst/cogl-gst-shader.h b/cogl-gst/cogl-gst-shader.h
index ac45a8c..e380814 100644
--- a/cogl-gst/cogl-gst-shader.h
+++ b/cogl-gst/cogl-gst-shader.h
@@ -40,6 +40,6 @@ extern const char
 _cogl_gst_shader_ayuv_to_rgba_decl[];
 
 extern const char
-_cogl_gst_shader_default_post[];
+_cogl_gst_shader_default_sample[];
 
 #endif /* __COGL_GST_SHADER_PRIVATE_H__ */
diff --git a/cogl-gst/cogl-gst-video-sink.c b/cogl-gst/cogl-gst-video-sink.c
index 2acafc9..61b2e3f 100644
--- a/cogl-gst/cogl-gst-video-sink.c
+++ b/cogl-gst/cogl-gst-video-sink.c
@@ -292,7 +292,6 @@ cogl_gst_video_sink_set_priority (CoglGstVideoSink *sink,
 static void
 create_template_pipeline (CoglGstVideoSink *sink,
                           const char *decl,
-                          const char *post,
                           int n_layers)
 {
   CoglGstVideoSinkPrivate *priv = sink->priv;
@@ -307,11 +306,36 @@ create_template_pipeline (CoglGstVideoSink *sink,
   else
     priv->pipeline = cogl_pipeline_new (priv->ctx);
 
-  if (decl && post)
+  if (decl)
     {
-      CoglSnippet *snippet = cogl_snippet_new (priv->hook, decl, post);
+      CoglSnippet *snippet;
+
+      /* The global sampling function gets added to both the fragment
+       * and vertex stages. The hope is that the GLSL compiler will
+       * easily remove the dead code if it's not actually used */
+      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX_GLOBALS,
+                                  decl,
+                                  NULL /* post */);
       cogl_pipeline_add_snippet (priv->pipeline, snippet);
       cogl_object_unref (snippet);
+
+      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT_GLOBALS,
+                                  decl,
+                                  NULL /* post */);
+      cogl_pipeline_add_snippet (priv->pipeline, snippet);
+      cogl_object_unref (snippet);
+
+      /* Set the replace string for the last layer so that no
+       * redundant code for the previous layers will be generated. The
+       * application can also replace this default sampling by adding
+       * another layer */
+      snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_LAYER_FRAGMENT,
+                                  NULL,
+                                  NULL);
+      cogl_snippet_set_replace (snippet,
+                                _cogl_gst_shader_default_sample);
+      cogl_pipeline_add_layer_snippet (priv->pipeline, n_layers - 1, snippet);
+      cogl_object_unref (snippet);
     }
 
   g_signal_emit_by_name (sink, "cogl-pipeline-ready", 0);
@@ -354,7 +378,7 @@ cogl_gst_dummy_deinit (CoglGstVideoSink *sink)
 static void
 cogl_gst_rgb_init (CoglGstVideoSink *sink)
 {
-  create_template_pipeline (sink, NULL, NULL, 1);
+  create_template_pipeline (sink, NULL, 1);
 }
 
 static void
@@ -459,7 +483,6 @@ cogl_gst_yv12_glsl_init (CoglGstVideoSink *sink)
 {
   create_template_pipeline (sink,
                             _cogl_gst_shader_yv12_to_rgba_decl,
-                            _cogl_gst_shader_default_post,
                             3);
 }
 
@@ -479,7 +502,6 @@ cogl_gst_i420_glsl_init (CoglGstVideoSink *sink)
 {
   create_template_pipeline (sink,
                             _cogl_gst_shader_yv12_to_rgba_decl,
-                            _cogl_gst_shader_default_post,
                             3);
 }
 
@@ -499,7 +521,6 @@ cogl_gst_ayuv_glsl_init (CoglGstVideoSink *sink)
 {
   create_template_pipeline (sink,
                             _cogl_gst_shader_ayuv_to_rgba_decl,
-                            _cogl_gst_shader_default_post,
                             1);
 }
 


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