gpt4 book ai didi

c++ - 当我在 glTexImage2D 中选择与在着色器中采样不同的内部格式时,情况会怎样?

转载 作者:太空狗 更新时间:2023-10-29 21:13:11 25 4
gpt4 key购买 nike

例如,我在代码中这样写:

glTexImage2D(GL_TEXTURE_2D, i, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

在着色器中:

glFragColor = texture2D(sampler, uv).rgba

会发生什么,官方对这种情况有定义吗?

最佳答案

结果将是相同的,就像您执行以下操作一样:

glFragColor = vec4( texture2D(sampler, uv).rgb, 1.0 );


因为Image Format Khronos 集团的规范说:

Image formats do not have to store each component. When the shader samples such a texture, it will still resolve to a 4-value RGBA vector. The components not stored by the image format are filled in automatically. Zeros are used if R, G, or B is missing, while a missing Alpha always resolves to 1.


进一步查看 OpenGL 4.6 API Core Profile Specification; 15.2. SHADER EXECUTION; page 487 ]:

When a texture lookup is performed in a fragment shader, the GL computes the filtered texture value ... and converts it to a texture base color Cb as shown in table 15.1, ...

Texture Base Texture base color Internal Format    Cb              Ab
RED (Rt, 0, 0) 1
RG (Rt, Gt, 0) 1
RGB (Rt, Gt, Bt) 1
RGBA (Rt, Gt, Bt) At

Table 15.1: Correspondence of filtered texture components to texture base components.

关于c++ - 当我在 glTexImage2D 中选择与在着色器中采样不同的内部格式时,情况会怎样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45141783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com