|
openwallpaper
|
So far we have only used vertex attributes as shader input data. Uniforms are another kind of input data that act like global variables in shaders. They are common for all vertex/fragment shader passes and can be updated quickly without beginning a copy pass.
Uniforms are declared in GLSL using the uniform keyword like this:
Contrary to vertex attributes, you don't need to provide data types and offsets to the API. Instead, you just push raw uniform data before draw call. The data that is being pushed must respect std140 layout conventions.
Typically you want to make a struct equivalent of uniform block type to fill the data conveniently. As C structs are not compatible with std140 layout, sometimes you need to reorder uniforms or add offset fields to align data properly. Here is a C struct equivalent of uniforms_t block described earlier:
To push uniform data, call ow_push_vertex_uniform_data or ow_push_fragment_uniform_data before draw call, specifying the binding index and data to push.
What to specify in layout(std140, set = ...)? By convention: