Graphics Reference
In-Depth Information
Example 4-3
Querying for Active Uniforms (continued)
default:
// Unknown type
break;
}
}
Uniform Buffer Objects
You can share uniforms between shaders in a program or even between
programs by using a buffer object to store uniform data. Such buffer
objects are called uniform buffer objects. Using uniform buffer objects, you
can potentially reduce the API overhead when updating large blocks of
uniforms. In addition, this approach increases the potential storage available
for uniforms because you are not limited by the default uniform block size.
To update the uniform data in a uniform buffer object, you can modify
the contents of the buffer object using commands such as glBufferData ,
glBufferSubData , glMapBufferRange , and glUnmapBuffer (these
commands are described in Chapter 6, “Vertex Attributes, Vertex Arrays,
and Buffer Objects”) rather than using the glUniform* commands
described in the previous section.
In the uniform buffer objects, uniforms are represented in memory as follows:
• Members of type bool , int , uint , and float are stored in memory at
the specified offset as single uint -typed, int -typed, uint -typed, and
float -typed components, respectively.
• Vectors with basic data types of bool , int , uint , or float are stored
in consecutive memory locations beginning at the specified offset,
with the first component at the lowest offset.
• Column-major matrices with C columns and R rows are treated as
an array of C floating-point column vectors, each consisting of R
components. Similarly, row-major matrices with R rows and C columns
are treated as an array of R floating-point row vectors, each consisting
of C components. While the column or row vectors are stored
consecutively, they may be stored with gaps by the implementation. The
offset between two vectors in the matrix is referred to as the column or
row stride ( GL_UNIFORM_MATRIX_STRIDE ) and can be queried in a linked
program using glGetActiveUniformsiv .
 
 
 
Search WWH ::




Custom Search