=== removed file 'data/shaders/conditionals-epilogue.frag'
--- data/shaders/conditionals-epilogue.frag	2011-07-04 14:31:07 +0000
+++ data/shaders/conditionals-epilogue.frag	1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
-    gl_FragColor = vec4(n, n, n, 1.0);
-}
-

=== removed file 'data/shaders/conditionals-epilogue.vert'
--- data/shaders/conditionals-epilogue.vert	2011-07-05 09:06:52 +0000
+++ data/shaders/conditionals-epilogue.vert	1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
-    vec4 pos = vec4(position.x,
-                    position.y + 0.1 * d * fract(position.x),
-                    position.z, 1.0);
-
-    // Transform the position to clip coordinates
-    gl_Position = ModelViewProjectionMatrix * pos;
-}
-

=== removed file 'data/shaders/conditionals-prologue.frag'
--- data/shaders/conditionals-prologue.frag	2011-07-05 12:23:55 +0000
+++ data/shaders/conditionals-prologue.frag	1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-#ifdef GL_ES
-precision mediump float;
-#endif
-
-varying vec4 dummy;
-
-void main(void)
-{
-    float n = fract(gl_FragCoord.x * gl_FragCoord.y * 0.0001);

=== removed file 'data/shaders/conditionals-prologue.vert'
--- data/shaders/conditionals-prologue.vert	2011-07-05 09:06:52 +0000
+++ data/shaders/conditionals-prologue.vert	1970-01-01 00:00:00 +0000
@@ -1,14 +0,0 @@
-attribute vec3 position;
-
-uniform mat4 ModelViewProjectionMatrix;
-
-// Removing this varying causes an inexplicable performance regression
-// with r600g... Keeping it for now.
-varying vec4 dummy;
-
-void main(void)
-{
-    dummy = vec4(1.0);
-
-    float d = fract(position.x);
-

=== added file 'data/shaders/conditionals-step-conditional.all'
--- data/shaders/conditionals-step-conditional.all	1970-01-01 00:00:00 +0000
+++ data/shaders/conditionals-step-conditional.all	2011-07-07 13:59:05 +0000
@@ -0,0 +1,4 @@
+    if (d >= 0.5)
+        d = fract(2.0 * d);
+    else
+        d = fract(3.0 * d);

=== removed file 'data/shaders/conditionals-step-conditional.frag'
--- data/shaders/conditionals-step-conditional.frag	2011-07-04 14:31:07 +0000
+++ data/shaders/conditionals-step-conditional.frag	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-if (n >= 0.5)
-   n = fract(2.0 * n);
-else
-   n = fract(3.0 * n);

=== removed file 'data/shaders/conditionals-step-conditional.vert'
--- data/shaders/conditionals-step-conditional.vert	2011-07-05 09:06:52 +0000
+++ data/shaders/conditionals-step-conditional.vert	1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
-    if (d >= 0.5)
-        d = fract(2.0 * d);
-    else
-        d = fract(3.0 * d);
-

=== added file 'data/shaders/conditionals-step-simple.all'
--- data/shaders/conditionals-step-simple.all	1970-01-01 00:00:00 +0000
+++ data/shaders/conditionals-step-simple.all	2011-07-07 13:59:05 +0000
@@ -0,0 +1,1 @@
+    d = fract(3.0 * d);

=== removed file 'data/shaders/conditionals-step-simple.frag'
--- data/shaders/conditionals-step-simple.frag	2011-07-04 14:31:07 +0000
+++ data/shaders/conditionals-step-simple.frag	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-n = fract(3.0 * n);

=== removed file 'data/shaders/conditionals-step-simple.vert'
--- data/shaders/conditionals-step-simple.vert	2011-07-05 09:06:52 +0000
+++ data/shaders/conditionals-step-simple.vert	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-    d = fract(3.0 * d);

=== added file 'data/shaders/conditionals.frag'
--- data/shaders/conditionals.frag	1970-01-01 00:00:00 +0000
+++ data/shaders/conditionals.frag	2011-07-07 13:59:05 +0000
@@ -0,0 +1,15 @@
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+varying vec4 dummy;
+
+void main(void)
+{
+    float d = fract(gl_FragCoord.x * gl_FragCoord.y * 0.0001);
+
+$MAIN$
+
+    gl_FragColor = vec4(d, d, d, 1.0);
+}
+

=== added file 'data/shaders/conditionals.vert'
--- data/shaders/conditionals.vert	1970-01-01 00:00:00 +0000
+++ data/shaders/conditionals.vert	2011-07-07 13:59:05 +0000
@@ -0,0 +1,25 @@
+attribute vec3 position;
+
+uniform mat4 ModelViewProjectionMatrix;
+
+// Removing this varying causes an inexplicable performance regression
+// with r600g... Keeping it for now.
+varying vec4 dummy;
+
+void main(void)
+{
+    dummy = vec4(1.0);
+
+    float d = fract(position.x);
+
+$MAIN$
+
+    vec4 pos = vec4(position.x,
+                    position.y + 0.1 * d * fract(position.x),
+                    position.z, 1.0);
+
+    // Transform the position to clip coordinates
+    gl_Position = ModelViewProjectionMatrix * pos;
+}
+
+

=== modified file 'src/scene-conditionals.cpp'
--- src/scene-conditionals.cpp	2011-07-07 13:45:19 +0000
+++ src/scene-conditionals.cpp	2011-07-07 13:59:05 +0000
@@ -28,17 +28,12 @@
 #include <cmath>
 #include <sstream>
 
-static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/conditionals-");
-
-static const std::string vtx_file_prologue(shader_file_base + "prologue.vert");
-static const std::string vtx_file_step_conditional(shader_file_base + "step-conditional.vert");
-static const std::string vtx_file_step_simple(shader_file_base + "step-simple.vert");
-static const std::string vtx_file_epilogue(shader_file_base + "epilogue.vert");
-
-static const std::string frg_file_prologue(shader_file_base + "prologue.frag");
-static const std::string frg_file_step_conditional(shader_file_base + "step-conditional.frag");
-static const std::string frg_file_step_simple(shader_file_base + "step-simple.frag");
-static const std::string frg_file_epilogue(shader_file_base + "epilogue.frag");
+static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/conditionals");
+
+static const std::string vtx_file(shader_file_base + ".vert");
+static const std::string frg_file(shader_file_base + ".frag");
+static const std::string step_conditional_file(shader_file_base + "-step-conditional.all");
+static const std::string step_simple_file(shader_file_base + "-step-simple.all");
 
 SceneConditionals::SceneConditionals(Canvas &pCanvas) :
     SceneGrid(pCanvas, "conditionals")
@@ -57,58 +52,69 @@
 {
 }
 
+static std::string &
+replace_string(std::string &str, const std::string &remove, const std::string &insert)
+{
+    std::string::size_type pos = 0;
+
+    while ((pos = str.find(remove, pos)) != std::string::npos) {
+        str.replace(pos, remove.size(), insert);
+        pos++;
+    }
+
+    return str;
+}
+
 static std::string
 get_vertex_shader_source(int steps, bool conditionals)
 {
-    std::string vtx_prologue, vtx_step_conditional, vtx_step_simple, vtx_epilogue;
+    std::string vtx_string, step_conditional_string, step_simple_string;
 
-    if (!gotSource(vtx_file_prologue, vtx_prologue) ||
-        !gotSource(vtx_file_step_conditional, vtx_step_conditional) ||
-        !gotSource(vtx_file_step_simple, vtx_step_simple) ||
-        !gotSource(vtx_file_epilogue, vtx_epilogue))
+    if (!gotSource(vtx_file, vtx_string) ||
+        !gotSource(step_conditional_file, step_conditional_string) ||
+        !gotSource(step_simple_file, step_simple_string))
     {
         return "";
     }
 
-    std::stringstream ss;
+    std::stringstream ss_main;
 
-    ss << vtx_prologue;
     for (int i = 0; i < steps; i++) {
         if (conditionals)
-            ss << vtx_step_conditional;
+            ss_main << step_conditional_string;
         else
-            ss << vtx_step_simple;
+            ss_main  << step_simple_string;
     }
-    ss << vtx_epilogue;
-
-    return ss.str();
+
+    replace_string(vtx_string, "$MAIN$", ss_main.str());
+
+    return vtx_string;
 }
 
 static std::string
 get_fragment_shader_source(int steps, bool conditionals)
 {
-    std::string frg_prologue, frg_step_conditional, frg_step_simple, frg_epilogue;
+    std::string frg_string, step_conditional_string, step_simple_string;
 
-    if (!gotSource(frg_file_prologue, frg_prologue) ||
-        !gotSource(frg_file_step_conditional, frg_step_conditional) ||
-        !gotSource(frg_file_step_simple, frg_step_simple) ||
-        !gotSource(frg_file_epilogue, frg_epilogue))
+    if (!gotSource(frg_file, frg_string) ||
+        !gotSource(step_conditional_file, step_conditional_string) ||
+        !gotSource(step_simple_file, step_simple_string))
     {
         return "";
     }
 
-    std::stringstream ss;
+    std::stringstream ss_main;
 
-    ss << frg_prologue;
     for (int i = 0; i < steps; i++) {
         if (conditionals)
-            ss << frg_step_conditional;
+            ss_main << step_conditional_string;
         else
-            ss << frg_step_simple;
+            ss_main  << step_simple_string;
     }
-    ss << frg_epilogue;
-
-    return ss.str();
+
+    replace_string(frg_string, "$MAIN$", ss_main.str());
+
+    return frg_string;
 }
 
 void SceneConditionals::setup()

