I am trying to obtain a binding point of an image variable in my GLES shader. I can do this for uniforms or shader storage blocks using that code:
GLenum Prop =
The image unit is the value of the image uniform variable. While the ES 3.1 spec does not allow setting values for these variables with glProgramUniform1i()
, there's nothing I can see that prevents you from getting the value that was set in the GLSL code with the binding=...
layout qualifier.
This is based on section 7.10 "Images" of the spec. On page 112, it says:
The value of an image uniform is an integer specifying the image unit accessed.
and in the same section on page 113:
The location of an image variable is queried with GetUniformLocation, just like any uniform variable.
Therefore, to get the image unit for variable "MyImage" in program prog
:
GLint loc = glGetUniformLocation(prog, "MyImage");
GLint imgUnit = -1;
glGetUniformiv(prog, loc, &imgUnit);
This gives you the image unit that the image variable in the shader is bound to. If you wanted the image name, you can continue the querying:
GLint imgName = -1;
glGetIntegeri_v(GL_IMAGE_BINDING_NAME, imgUnit, &imgName);