glBindImageTexture() 和 glBindTexture() 有什么区别?

What is the difference between glBindImageTexture() and glBindTexture()?

glBindImageTexture 和 glBindTexture 有什么区别?还有着色器中以下声明之间的区别是什么:

layout (binding = 0, rgba32f) uniform image2D img_input;

uniform sampler2D img_input;
layout(binding = 0) uniform sampler2D img_input;

声明一个 sampler,它从纹理对象获取数据。 0 的绑定(您可以在 GLSL 4.20 的着色器中设置)表示绑定到纹理图像单元 0(通过 glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ...);)的 2D 纹理是将用于此采样器的纹理。

采样器使用 整个 纹理,包括所有 mipmap 级别和阵列层。大多数纹理采样函数使用归一化纹理坐标([0, 1] 映射到纹理的大小)。大多数纹理采样函数也遵守 filtering properties and other sampling parameters.

layout (binding = 0, rgba32f) uniform image2D img_input;

这声明了一个图像,表示来自纹理的单个图像。纹理可以 have multiple images: mipmap levels, array layers,等等。当您使用 glBindImageTexture 时,您是从纹理绑定单个图像。

图像和采样器是完全分开的。他们有自己的一套绑定索引;将纹理绑定到 GL_TEXTURE0 并将来自不同纹理的图像绑定到图像绑定 0 是完全有效的。对关联的采样器使用纹理函数将从绑定到 GL_TEXTURE0 的内容中读取,而图像在关联图像变量将从绑定到图像绑定 0 的图像中读取。

图像访问忽略所有采样参数。 Image accessing functions 始终使用整数纹素坐标。

采样器只能从纹理中读取数据;图像变量可以读取 and/or 写入数据,以及对它们执行原子操作。当然,从着色器写入数据需要特别小心,特别是 someone goes to read that data.