mojoshader.c
changeset 1158 94bbbdd9a344
parent 1157 d7282ef4110f
child 1159 d4f97945e2f5
--- a/mojoshader.c	Tue May 17 16:01:06 2016 -0400
+++ b/mojoshader.c	Tue May 17 16:13:05 2016 -0400
@@ -4482,10 +4482,6 @@
             ctx->mainfn = StrDup(ctx, "FragmentShader");
     } // if
 
-    push_output(ctx, &ctx->globals);
-    output_line(ctx, "using namespace metal;");
-    pop_output(ctx);
-
     set_output(ctx, &ctx->mainline);
     ctx->indent++;
 } // emit_METAL_start
@@ -4551,9 +4547,12 @@
 static void emit_METAL_finalize(Context *ctx)
 {
     // throw some blank lines around to make source more readable.
-    push_output(ctx, &ctx->globals);
-    output_blank_line(ctx);
-    pop_output(ctx);
+    if (ctx->globals)  // don't add a blank line if the section is empty.
+    {
+        push_output(ctx, &ctx->globals);
+        output_blank_line(ctx);
+        pop_output(ctx);
+    } // if
 
     // If we had a relative addressing of REG_TYPE_INPUT, we need to build
     //  an array for it at the start of main(). GLSL doesn't let you specify
@@ -4576,6 +4575,8 @@
     INC_METAL_HEADER(texture);
     #undef INC_METAL_HEADER
     output_blank_line(ctx);
+    output_line(ctx, "using namespace metal;");
+    output_blank_line(ctx);
     pop_output(ctx);
 
     // Fill in the shader's mainline function signature.