好吧,我对 opengl 着色器有一些抽象,我想以这种方式使用它们:
WITH_SHADER(shader_name) {
// here will be gl commands
}
它应该自动从当前 gl 上下文绑定(bind)/取消绑定(bind)该着色器。 在该复合语句之前绑定(bind),然后解除绑定(bind)。
我能以某种方式在 C++ 中构建这个宏吗?
最佳答案
最接近的是RAII .
构建一个封装着色器的类 WithShader
:
- 在构造函数中绑定(bind)着色器
- 在析构函数中解除绑定(bind)
使用示例:
{
with_shader ws(shader_name)
// use your shader
}
// binding and unbinding occured automatically, thats RAII.
注意:
RAII 不是一般的平凡,注意复制和赋值构造函数
关于python - C++ - 类似于 python 中的关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23975082/