OpenGL 中 NPOT 纹理的现状
我目前正在编写一个在 sdl 下使用 2D OpenGL 输出的游戏,并且我正在尝试使用 SDL_ttf 加载文本。然而,我必须用空白像素填充文本,因为普通 OpenGL 似乎不支持两个纹理的非幂。我听说有一个名为 GL_ARB_texture_non_power_of_two 的 OpenGL 扩展,它可以实现两个纹理的非幂运算。截至今天,有多少卡与此扩展不兼容?我如何加载它?
I'm currently writing a game that uses 2D OpenGL output under sdl, and I'm trying to load text using SDL_ttf. However I have to pad the text with blank pixels as it appears that plain OpenGL doesn't support non-power of two textures. I've heard that there is an OpenGL extension called GL_ARB_texture_non_power_of_two
that enables non power of two textures. How many cards are incompatible with this extension as of today and how do I load it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任何 OpenGL 2.0 或更高版本都支持非二次方纹理。这几乎意味着 2005 年左右生产的所有显卡。其中包括 GeForce FX 和 6xxx 及更高版本。它还包括 Radeon 9500 及更高版本(尽管在 Radeon HD 系列之前,Radeon 不允许 NPOT 具有 mipmap)。
顺便说一句,我希望您不要尝试将每个角色放入单独的纹理中。因为从性能的角度来看,这会很糟糕。将您想要使用的所有角色放入单个纹理中,然后挑选出您需要的角色。您甚至不需要 NPOT。
至于 mrazza 关于仅使用 POT 的评论,对于 NPOT 纹理没有什么好害怕的(只要你的硬件可以支持它)。它不应该是您的第一选择,因为它们可能会造成轻微性能损失,但对于填充或重新缩放不合适的明显情况(渲染目标等),使用它们没有什么可担心的。
Any OpenGL version 2.0 or greater supports non-power-of-two textures. That means pretty much any card made after around 2005. This includes GeForce FX's and 6xxx and above. It also includes Radeon 9500's and above (though until the Radeon HD series, Radeons do not allow NPOTs to have mipmaps).
BTW, I hope that you aren't trying to put each character into a separate texture. Because that would be terrible from a performance standpoint. Put all of the characters you want to use in a single texture and pick out the ones you need. You don't even need an NPOT for that.
As for mrazza's comment about just using POTs, there's nothing to be afraid of with NPOT textures (as long as your hardware can support it). It shouldn't be something you go to as a first resort, because there may be a minor performance penalty with them, but for obvious cases where padding or rescaling would be inappropriate (render targets, etc), there's nothing to fear from using them.
一般来说,这些问题在 opengl 规范中得到解答。
然而,NPOT 纹理很久以前就已经集成在 OpenGL 中,以至于您需要查看旧版本才能找到对此的引用。在3.0规范中,例如您将在L.3中看到附录显示,从 GL 2.0 开始,NPOT 扩展已集成到 GL 核心中。因此,任何支持 GL 2.0(自 2004 年底以来几乎所有 PC GPU)的实现都支持该功能。
至于如何“加载”它:没有什么可做的。只需将非二次方尺寸传递给 glTexImage 即可。
In general, those questions are answered in the opengl specification.
However, the NPOT textures were integrated in OpenGL long ago enough that you need to look at an older version to even find a reference to this. In the 3.0 spec, e.g. you'll see in the L.3 appendix that the NPOT extension was integrated into the GL core starting with GL 2.0. So any implementation that supports GL 2.0 (that's pretty much all PC GPUs since end of 2004) supports the feature.
As to how to "load" it: there's nothing to do. Just pass non-power-of-two sizes to glTexImage.