What is the difference between glBindImageTexture and glBindTexture? And also what is the difference between the following declarations in a shader:
layout (binding = 0, rgba32f) uniform image2D img_input;
and
uniform sampler2D img_input;
What is the difference between glBindImageTexture and glBindTexture? And also what is the difference between the following declarations in a shader:
layout (binding = 0, rgba32f) uniform image2D img_input;
and
uniform sampler2D img_input;
layout(binding = 0) uniform sampler2D img_input;
That declares a sampler, which gets its data from a texture object. The binding of 0 (you can set that in the shader in GLSL 4.20) says that the 2D texture bound to texture image unit 0 (via glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ...);
) is the texture that will be used for this sampler.
Samplers use the entire texture, including all mipmap levels and array layers. Most texture sampling functions use normalized texture coordinates ([0, 1] map to the size of the texture). Most texture sampling functions also respect filtering properties and other sampling parameters.
layout (binding = 0, rgba32f) uniform image2D img_input;
This declares an image, which represents a single image from a texture. Textures can have multiple images: mipmap levels, array layers, etc. When you use glBindImageTexture
, you are binding a single image from a texture.
Images and samplers are completely separate. They have their own set of binding indices; it's perfectly valid to bind a texture to GL_TEXTURE0
and an image from a different texture to image binding 0. Using texture functions for the associated sampler will read from what is bound to GL_TEXTURE0
, while image functions on the associated image variable will read from the image bound to image binding 0.
Image access ignores all sampling parameters. Image accessing functions always use integer texel coordinates.
Samplers can only read data from textures; image variables can read and/or write data, as well as perform atomic operations on them. Of course, writing data from shaders requires special care, specifically when someone goes to read that data.
© 2022 - 2024 — McMap. All rights reserved.