C++11 raw string literal & GLSL shaders indentation in 4coder

Maybe this will fix 4coder indentation issues in Handmade Hero code with C++11 raw string literals:

1
2
3
4
5
6
7
char* ShaderCode = R"FOO"(
    void main()
    {
        v2 foo = v2(1,2);
        ....
    }
)FOO"";

Instead of using FOO as begin/end marker try using FOO" as begin/end marker. This is legal in C++11, and VS2013 supports this. My assumption is that 4coder will see "FOO" just as a normal string, then it will see GLSL code outside of string literal, and at the end it will see just an empty "" string literal. Nothing will be inside string literal from 4coder's point of view.

I don't have 4coder myself so I cannot try if this will really work. Maybe 4coder now will be confused about parenthesis around GLSL code which are outside of string literal.

Edited by Mārtiņš Možeiko on
It doesn't work.

Right, it doesn't :(
4coder is too smart, I guess it recognizes C++11 raw string literals.

Maybe alternative is to do this:
1
2
3
4
5
6
#define SHADER_CODE2(x) #x
#define SHADER_CODE(x) SHADER_CODE2(x)

const char* foo =
#include "shader.h"
;

And in shader.h this:
1
2
3
4
5
6
7
8
SHADER_CODE(

void main()
{
  v2 foo = v2(1,2);
}

)

But this will loose newlines in GLSL source.


Edited by Mārtiņš Možeiko on
But at that point wouldn't it be simpler to use shader files and load them at run time ?

Edit: This solution doesn't indent properly

Edited by Simon Anciaux on Reason: typo
Ok, then I'm out of ideas :)

At this point loading shaders at runtime or doing meta-programming for converting glsl files to C strings at compile time is more reasonable.