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 = GL_BUFFER_BINDING;
GLint Binding = -1;
GLint ValuesWritten = 0;
glGetProgramResourceiv( GLProgram, GL_UNIFORM_BLOCK, i, 1, &Prop, 1, &ValuesWritten, &Binding );
Unfortunately, there is no such thing as GL_IMAGE_BINDING
. In desktop GL, I am just getting the location of the image uniform using GetUniformLocation
and then bind it to an image slot using glProgramUniform1i
. Unfortunately in OpenGLES, glProgramUniform1i
can be used for sampler uniforms only and does not work for image uniforms. The reason I need this binding point is because I am doing automatic resource binding. My resources can be associated with a uniform variable name. I want them to be automatically assigned to the right image slot. That works fine so far for all resources except for images on GLES.
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 thebinding=...
layout qualifier.This is based on section 7.10 "Images" of the spec. On page 112, it says:
and in the same section on page 113:
Therefore, to get the image unit for variable "MyImage" in program
prog
: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: