GCC,字符串和内联GLSL? [英] GCC, stringification, and inline GLSL?
本文介绍了GCC,字符串和内联GLSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用宏字符串来声明GLSL着色器字符串:
I'd like to declare GLSL shader strings inline using macro stringification:
#define STRINGIFY(A) #A
const GLchar* vert = STRINGIFY(
#version 120\n
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
);
这使用VS2010构建并运行良好,但无法在 gcc
与:
This builds and runs fine using VS2010 but fails to compile on gcc
with:
error: invalid preprocessing directive #version
有没有办法以可移植的方式使用这样的字符串?
Is there a way to use stringification like this in a portable manner?
我试图避免每行引号:
const GLchar* vert =
"#version 120\n"
"attribute vec2 position;"
"void main()"
"{"
" gl_Position = vec4( position, 0.0, 1.0 );"
"}"
;
...和/或换行符:
...and/or line continuation:
const GLchar* vert = "\
#version 120\n \
attribute vec2 position; \
void main() \
{ \
gl_Position = vec4( position, 0.0, 1.0 ); \
} \
";
推荐答案
是未定义的,所以你不能这样做直接。但是,只要没有任何一个着色器需要 #version
之外的预处理器指令,就可以这样做:
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 );
}
);
这篇关于GCC,字符串和内联GLSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文