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
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
"
"attribute vec2 position;"
"void main()"
"{"
" gl_Position = vec4( position, 0.0, 1.0 );"
"}"
;
...和/或续行:
const GLchar* vert = "
#version 120
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
";
推荐答案
你会使用 C++11 吗?如果是这样,您可以使用 原始字符串文字:
Can you use C++11? If so you could use raw string literals:
const GLchar* vert = R"END(
#version 120
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
)END";
无需转义或显式换行.这些字符串以 R(或 r)开头.您需要在引号和第一个括号之间使用分隔符(我选择了 END)来转义代码片段中的括号.
No need for escapes or explicit newlines. These strings start with an R (or r). You need a delimiter (I chose END) between the quote and the first parenthesis to escape parenthesis which you have in the code snippet.
这篇关于GCC、字符串化和内联 GLSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GCC、字符串化和内联 GLSL?
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
