GCC, stringification, and inline GLSL?

前端 未结 5 978
孤城傲影
孤城傲影 2020-11-29 08:37

I\'d like to declare GLSL shader strings inline using macro stringification:

#define STRINGIFY(A)  #A
const GLchar* vert = STRINGIFY(
#version 120\\n
attribu         


        
5条回答
  •  情书的邮戳
    2020-11-29 08:58

    Unfortunately, having preprocessor directives in the argument of a macro is undefined, so you can't do this directly. But as long as none of your shaders need preprocessor directives other than #version, you could do something like:

    #define GLSL(version, shader)  "#version " #version "\n" #shader
    
    const GLchar* vert = GLSL(120,
        attribute vec2 position;
        void main()
        {
            gl_Position = vec4( position, 0.0, 1.0 );
        }
    );
    

提交回复
热议问题