Binding Textures to Image Units

Just as sampler variables represent texture units in the OpenGL API, so do image variables represent a binding to an image unit in the OpenGL API. Image uniforms declared in a shader have a location that may be retrieved by calling glGetUniformLocation(). This is passed in a call to glUniform1i() to set the index of the image unit to which the image uniform refers. This binding may also be specified directly1 in the shader using a binding layout qualifier as shown in the declaration of image4 in Example 11.1. By default, an image uniform has the binding 0, and so if only one image is used in a shader, there is no need to explicitly set its binding to 0. The number of image units supported by the OpenGL implementation ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.