OpenGL/GLEW:如何选择正确/现有的枚举而不引发编译时错误
我目前正在使用 glew 来检测绑定 openGL 上下文的一些 GPU 功能。
想象一个纹理类,如果可用,我想使用 openGL 3.0 枚举,如果 opengl 3.0 未到位但扩展名是 ie,则回退到扩展名:
uint32 chooseGlInternalFormat(uint32 _pixelType, uint32 _pixelFormat)
{
uint32 ret;
//...
if(GLEW_EXT_texture_integer || GLEW_VERSION_3_0)
{
bool bUseExt = !GLEW_VERSION_3_0; //if only the extension is available but not gl 3.0, fallback
ret = bUseIntEXT ? GL_LUMINANCE8UI_EXT : GL_R8UI;
}
//...
}
显然这会导致编译时错误,因为 GL_R8UI
won'如果不支持 opengl 3.0,则不存在。- 解决此问题的常用方法是什么?
I am currently using glew to detect some GPU features of the bound openGL context.
Imagine a texture class where I want to use the openGL 3.0 enums if available and fallback to extensions if opengl 3.0 is not in place but the extension is i.e:
uint32 chooseGlInternalFormat(uint32 _pixelType, uint32 _pixelFormat)
{
uint32 ret;
//...
if(GLEW_EXT_texture_integer || GLEW_VERSION_3_0)
{
bool bUseExt = !GLEW_VERSION_3_0; //if only the extension is available but not gl 3.0, fallback
ret = bUseIntEXT ? GL_LUMINANCE8UI_EXT : GL_R8UI;
}
//...
}
obviously this causes a compile time error since GL_R8UI
won't exist if opengl 3.0 is not supported.- What is the common way to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些较大的应用程序采用最新的枚举规范并基于它添加自己的枚举。如果您只需要一次,您可以为这种情况定义自己的枚举。
Some larger applications take the newest enum specification and add their own enums based on it. If you only need it this one time you can just define your own enum for this single case.