GL_IMG_bindless_texture#

Valid APIs#

OpenGL ES 3.1+

Description#

This extension allows OpenGL ES applications to access texture objects in shaders without first binding each texture to one of a limited number of texture image units. Using this extension, an application can query a 64-bit unsigned integer texture handle for each texture that it wants to access and then use that handle directly in GLSL ES. This extension significantly reduces the amount of API and internal GL driver overhead needed to manage resource bindings.

Example#

#define NUM_TEXTURES      256
GLuint   textures[NUM_TEXTURES];
GLuint64 texHandles[NUM_TEXTURES];
// Initialize the texture objects and handles.
glGenTextures(NUM_TEXTURES, textures);
for (int i = 0; i < NUM_TEXTURES; i++) {
    // Initialize the texture images with glTexStorage.
    // Initialize the texture parameters as required.
    //...
    // Get a handle for the texture.
    texHandles[i] = glGetTextureHandleIMG(textures[i]);
    // At this point, it's no longer possible to modify texture parameters
    // for "textures[i]". However, it's still possible to update texture
    // data via glTexSubImage.
}
// Render a little bit using each of the texture handles in turn.
for (int i = 0; i < NUM_TEXTURES; i++) {
    // Update the single sampler uniform <u> to point at "texHandles[i]".
    glUniformHandleui64IMG(location, texHandles[i]);
    drawStuff();
}

Example#

uniform int whichSampler;
in highp vec2 texCoord;
out lowp vec4 finalColor;
uniform Samplers {
    sampler2D allTheSamplers[NUM_TEXTURES];
};
void main()
{
    finalColor = texture(allTheSamplers[whichSampler], texCoord);
}