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

What is the difference between glBindImageTexture and glBindTexture? And also what is the difference between the following declarations in the shader:

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

and

 uniform sampler2D img_input; 
+7
opengl
source share
1 answer
 layout(binding = 0) uniform sampler2D img_input; 

This declares a sampler that gets its data from a texture object. Linking 0 (you can set this in the shader in GLSL 4.20) means that the 2D texture bound to the image module of texture 0 (via glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ...); ), is a texture, which will be used for this sampler.

Samplers use all texture, including all mipmap levels and array levels. Most texture selection functions use normalized texture coordinates ([0, 1] are mapped to texture size). Most texture sampling functions also relate to filtering properties and other sampling options .

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

This declares an image representing a single image from a texture. Textures can have several images : mipmap levels, massive layers , etc. When you use glBindTextureImage , you are linking a single image to a texture.

Images and samplers are completely separate. They have their own set of binding indexes; it is ideal for snapping a texture to GL_TEXTURE0 and an image from another texture to snapping to image 0. The use of texture functions for the associated sampler will be read from what is associated with GL_TEXTURE0 , while the image functions on the associated image variable will be read from the image associated with snapping to image 0.

Image access ignores all selections. Image access functions always use texel integer coordinates.

Samplers can only read data from textures; variable images can read and / or write data, as well as perform atomic operations on them. Of course, special care is required to write data from shaders, especially when someone is reading this data .

+10
source share

All Articles