#if __VERSION__ < 130
#define TEXTURE2D texture2D
#else
#define TEXTURE2D texture
#endif
#if __VERSION__ > 120
color = texture(sampler, texCoord);
#else
color = texture2D(sampler, texCoord);
#endif
本文介绍了一种在不同OpenGL版本间实现纹理采样兼容性的方法。通过预处理器指令判断OpenGL版本,并根据版本使用不同的函数调用(texture2D或texture)。确保了在不同版本的OpenGL中都能正确地从纹理采样器中获取颜色。
#if __VERSION__ < 130
#define TEXTURE2D texture2D
#else
#define TEXTURE2D texture
#endif
#if __VERSION__ > 120
color = texture(sampler, texCoord);
#else
color = texture2D(sampler, texCoord);
#endif

被折叠的 条评论
为什么被折叠?