Path: blob/main_old/extensions/CHROMIUM_bind_uniform_location.txt
1693 views
Name12CHROMIUM_bind_uniform_location34Name Strings56GL_CHROMIUM_bind_uniform_location78Version910Last Modifed Date: September 8, 20151112Dependencies1314OpenGL ES 2.0 is required.1516Overview1718This extension is simlar to glBindAttribLocation but instead19lets you choose a location for a uniform. This allows you20to not have to query the locations of uniforms.2122This allows the client program to know the locations of uniforms23without having to wait for shaders to compile or GLSL programs to24link to query the locations and therefore have no blocking calls25when initializing programs.2627Issues2829If a uniform is an array you can only call glBindUniformLocation30for the location of the first element. Other elements' locations31must be queried if you need them. Often this is not an issue32because you can set all the elements with a single gl call from33the first location.3435Good Example:3637--shader--38uniform float u_someArray[4];3940--C--41GLint location = 123;42glBindUniformLocation(program, location, "u_someArray");43glLinkProgram(program);44glUseProgram(program);4546// set all 4 floats in u_someArray47float values[] = { 0.1f, 0.2f, 0.3f, 0.4f, };48glUniform1fv(location, 4, values);4950Bad example 1:5152GLint location = 123;53glBindUniformLocation(program, location, "u_someArray");54glLinkProgram(program);55glUseProgram(program);5657// set floats in u_someArray one at a time58glUniform1f(location, 0.1f);59glUniform1f(location + 1, 0.2f); // ERROR! math not allowed on locations6061Bad example 2:6263GLint location0 = 123;64GLint location1 = 124;65glBindUniformLocation(program, location0, "u_someArray[0]");66glBindUniformLocation(program, location1, "u_someArray[1]"); // ERROR!67// not allowed to assign locations to array elements6869If you need to set individual elements of a uniform array you must query the70location of the each element you wish to set.7172If a uniform has its location explicitly set within the shader text and a73different location set via the API, the assignment in the shader text is74used.7576If the location of a statically used uniform set via the API conflicts with77the location of a different uniform set in the shader text, linking must78fail.7980New Tokens8182None8384New Procedures and Functions8586void BindUniformLocationCHROMIUM (GLuint program, GLint location,87const GLhchar* name);8889specifes that the uniform variable named <name> in program <program>90should be bound to uniform location <location> when the program is next91linked. If <name> was bound previously, its assigned binding is replaced92with <location>. <name> must be a null terminated string. The error93INVALID_VALUE is generated if <location> is equal or greater than9495(MAX_VERTEX_UNIFORM_VECTORS + MAX_FRAGMENT_UNIFORM_VECTORS) * 49697or less than 0. BindUniformLocation has no effect until the program is98linked. In particular, it doesn't modify the bindings of uniform99variables in a program that has already been linked.100101The error INVALID_OPERATION is generated if name starts with the reserved102"gl_" prefix. The error INVALID_VALUE is generated if name ends with103an array element expression other than "[0]".104105When a program is linked, any active uniforms without a binding specified106through BindUniformLocation will be automatically be bound to locations by107the GL. Such bindings can be queried using the command108GetUniformLocation.109110BindUniformLocation may be issued before any shader objects are attached111to a program object. Hence it is allowed to bind any name (except a name112starting with "gl_") to an index, including a name that is never used as a113uniform in any shader object. Assigned bindings for uniform variables114that do not exist or are not active are ignored. Using such bindings115behaves as if passed location was -1.116117It is possible for an application to bind more than one uniform name to118the same location. This is referred to as aliasing. This will only work119if only one of the aliased uniforms is statically used in the executable120program. If two statically used uniforms in a program are bound to the same121location, link must fail.122123Errors124125None.126127New State128129None.130131Revision History1321337/20/2012 Documented the extension1349/8/2015 Require program link to fail if two statically used uniforms135are bound to the same location.13611/6/2015 Require inactive and non-existing, bound uniform locations137to behave like location -1.1383/9/2017 Locations set in the shader override ones set by the binding139API.1403/26/2018 Clarify that aliasing rules apply to statically used uniforms.141142