OpenGL 中的 GL_CLAMP 与 GL_CLAMP_TO_EDGE 有何不同?

How is GL_CLAMP in OpenGL different from GL_CLAMP_TO_EDGE?

根据您参考的文档 glTexParameteri(),纹理夹紧有 2 种不同的解释。
Microsoft's documentation, you'll find GL_CLAMP, while in Khronos's documentation 你会发现 GL_CLAMP_TO_EDGE.

我以为它们在功能上是同义词,但似乎并非如此。
在我的 Ubuntu 18.04.2 上,我有以下内容。

/usr/include/GL/gl.h
#define GL_CLAMP_TO_EDGE                        0x812F
#define GL_CLAMP                                0x2900
#define GL_CLAMP_TO_BORDER                      0x812D

而在我的 Windows 10 16299 企业版中,我有以下内容。

C:\Program Files (x86)\Windows Kits\Include.0.16299.0\um\gl\GL.h
#define GL_CLAMP                          0x2900

它们被映射到不同的值,因此人们也会期待不同的行为。
我正在尝试摆脱我们使用 GL_REPEAT 得到的工件。请参见下图中的绿色圆圈(图片来源 - freepik.com)。

GL_CLAMP 确实消除了伪像,但是我无法找到足够的细节来说明各种夹紧模式有何不同,以及什么时候人们更喜欢其中一种模式。

我正在 windows 机器上编码,稍后可能会将相同的应用程序移植到 GNU/Linux。

更新 1GL_CLAMP 消除了大部分伪像,但不是全部,最后我为所有纹理添加了 10px 透明边框。但是问题仍然存在。

更新 2 :问题不在于 GL_CLAMP 实现之间的差异,而是 如何 GL_CLAMP 不同于 GL_CLAMP_TO_EDGE ?

如果您深入研究 Khronos Registry 不同的 GL 规范,您会找到一些解释。

在第一个规范 (1.0 1994) 中,CLAMPREPEATTEXTURE_WRAP_x 参数的唯一选项。

规范 1.2 1998 添加 CLAMP_TO_EDGE。它提供了您需要的线索:

GL normally clamps such that the texture coordinates are limited to exactly the range [0;1]. When a texture coordinate is clamped using this algorithm, the texture sampling filter straddles the edge of the texture image, taking half its sample values from within the texture image, and the other half from the texture border. It is sometimes desirable to clamp a texture without requiring a border, and without using the constant border color.

A new texture clamping algorithm, CLAMP_TO_EDGE, clamps texture coordinates at all mipmap levels such that the texture filter never samples a border texel. The color returned when clamping is derived only from texels at the edge of the texture image.


CLAMP 选项在 spec 3.0 2008 中被弃用, 在 spec 3.2 Core 2009 中被移除。如果(且仅当)您 不这样做,您仍然可以使用它t 设置一个 核心配置文件 上下文。


Microsoft 文档采用旧 CLAMP 的原因是 MS 提供 OpenGL 1.1 而无需检索指向 GL 命令的函数指针。更高版本需要特殊的 headers(除了 gl.h)和其他特殊的东西。