How to get a binding point of an image variable in OpenGLES

前端 未结 1 465
长发绾君心
长发绾君心 2021-01-21 15:46

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 =          


        
相关标签:
1条回答
  • 2021-01-21 16:15

    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);
    
    0 讨论(0)
提交回复
热议问题