1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133

gpu / GLES2 / extensions / CHROMIUM / CHROMIUM_bind_uniform_location.txt [blame]

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.

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.