Name

    CHROMIUM_bind_uniform_location

Name Strings

    GL_CHROMIUM_bind_uniform_location

Version

    Last Modifed Date: September 8, 2015

Dependencies

    OpenGL ES 2.0 is required.

Overview

    This extension is simlar to glBindAttribLocation but instead
    lets you choose a location for a uniform. This allows you
    to not have to query the locations of uniforms.

    This allows the client program to know the locations of uniforms
    without having to wait for shaders to compile or GLSL programs to
    link to query the locations and therefore have no blocking calls
    when initializing programs.

Issues

    If a uniform is an array you can only call glBindUniformLocation
    for the location of the first element. Other elements' locations
    must be queried if you need them. Often this is not an issue
    because you can set all the elements with a single gl call from
    the first location.

    Good Example:

        --shader--
        uniform float u_someArray[4];

        --C--
        GLint location = 123;
        glBindUniformLocation(program, location, "u_someArray");
        glLinkProgram(program);
        glUseProgram(program);

        // set all 4 floats in u_someArray
        float values[] = { 0.1f, 0.2f, 0.3f, 0.4f, };
        glUniform1fv(location, 4, values);

    Bad example 1:

        GLint location = 123;
        glBindUniformLocation(program, location, "u_someArray");
        glLinkProgram(program);
        glUseProgram(program);

        // set floats in u_someArray one at a time
        glUniform1f(location, 0.1f);
        glUniform1f(location + 1, 0.2f);  // ERROR! math not allowed on locations

    Bad example 2:

        GLint location0 = 123;
        GLint location1 = 124;
        glBindUniformLocation(program, location0, "u_someArray[0]");
        glBindUniformLocation(program, location1, "u_someArray[1]"); // ERROR!
        // not allowed to assign locations to array elements

    If you need to set individual elements of a uniform array you must query the
    location of the each element you wish to set.

    If a uniform has its location explicitly set within the shader text and a
    different location set via the API, the assignment in the shader text is
    used.

    If the location of a statically used uniform set via the API conflicts with
    the location of a different uniform set in the shader text, linking must
    fail.

New Tokens

    None

New Procedures and Functions

    void BindUniformLocationCHROMIUM (GLuint program, GLint location,
                                      const GLhchar* name);

    specifes that the uniform variable named <name> in program <program>
    should be bound to uniform location <location> when the program is next
    linked.  If <name> was bound previously, its assigned binding is replaced
    with <location>. <name> must be a null terminated string.  The error
    INVALID_VALUE is generated if <location> is equal or greater than

    (MAX_VERTEX_UNIFORM_VECTORS + MAX_FRAGMENT_UNIFORM_VECTORS) * 4

    or less than 0. BindUniformLocation has no effect until the program is
    linked. In particular, it doesn't modify the bindings of active uniforms
    variables in a program that has already been linked.

    The error INVALID_OPERATION is generated if name starts with the reserved
    "gl_" prefix. The error INVALID_VALUE is generated if name ends with
    an array element expression other than "[0]".

    When a program is linked, any active uniforms without a binding specified
    through BindUniformLocation will be automatically be bound to locations by
    the GL.  Such bindings can be queried using the command
    GetUniformLocation.

    BindUniformLocation may be issued before any shader objects are attached
    to a program object.  Hence it is allowed to bind any name (except a name
    starting with "gl_") to an index, including a name that is never used as a
    uniform in any shader object.  Assigned bindings for uniform variables
    that do not exist or are not active are ignored. Using such bindings
    behaves as if passed location was -1.

    It is possible for an application to bind more than one uniform name to
    the same location.  This is referred to as aliasing.  This will only work
    if only one of the aliased uniforms is active in the executable program,
    or if no path through the shader consumes more than one uniform of a set
    of uniforms aliased to the same location.  If two statically used uniforms
    in a program are bound to the name location, link must fail.

Errors

    None.

New State

    None.

Revision History

    7/20/2012    Documented the extension
    9/8/2015     Require program link to fail if two statically used uniforms
                 are bound to the same location.
    11/6/2015    Require inactive and non-existing, bound uniform locations
                 to behave like location -1.
    3/9/2017     Locations set in the shader override ones set by the binding
                 API.
