基本内部格式如何工作?

How do base internal formats work?

glTexImage2D 函数接受以下所谓的 "base internal formats":

GL_DEPTH_COMPONENT
GL_DEPTH_STENCIL
GL_RED
GL_RG
GL_RGB
GL_RGB

这些似乎缺少任何类型或尺寸信息。引用文档:

If an application wants to store the texture at a certain resolution or in a certain format, it can request the resolution and format with internalFormat. The GL will choose an internal representation that closely approximates that requested by internalFormat, but it may not match exactly. (The representations specified by GL_RED, GL_RG, GL_RGB, and GL_RGBA must match exactly.)

glTexStorage2D 的文档中没有列出这些格式,而且我找不到关于它们的更准确信息。我显然是 GL_RGBA 靠运气工作,但我想更好地理解我在这里做的事情。

当我使用基本内部格式时到底发生了什么?
如何选择存储的类型、大小和布局?
之后我是否需要查询所选格式并调整程序的其余部分,例如 GLSL 采样器类型?

glTexStorage* 不允许 "base internal formats" 的原因是您 不应该 使用它们。它仅支持具有 well-defined 行为的内部格式。

What exactly happens when I use a base internal format?

您将获得 driver 想要给您的任何图像格式,在下面列出的限制范围内。

How are the type, size and layout of storage chosen?

对于此类纹理,"type" 将始终是无符号的规范化整数。它将至少具有基本内部格式的频道。

其他一切完全取决于 driver。如果 driver 想要添加比您指定的更多的频道,它可以这样做。如果 driver 想给你一个 16-bit-per-channel 格式,它可以这样做。

Am I expected to query the chosen format afterwards and adjust the rest of my program, such as GLSL sampler types?

没有什么可查询的,因为它们始终是未签名的规范化图像。所以你在着色器中使用 sampler*,而不是 usampler*isampler*