Sending additional data to the GPU
The data sent from the vertex buffer has one important drawback: it changes for every vertex. If we need some sort of values to remain constant during a frame, such as a transformation matrix, we must take a different approach. Using the CPU for this has already been ruled out as it would be too expensive and time-consuming, so we will utilize the GPU for this task.
Both OpenGL and Vulkan have a special type of buffer for this use case: the uniform buffer.
Using uniform buffers to upload constant data
Uniform buffers have two important properties:
- They are shared among all shaders on the graphics card
- They are read-only inside the shaders
Any data, such as the aforementioned transformation matrices, needs to be uploaded only once per frame before the drawing starts. In the shader code, the data can be referenced like local variables, but in contrast to vertex positions, colors, and so on, it is the same for every vertex...