Master the fundamental concepts of modern graphics apis (low level) through this focused micro-challenge.
Shaders need data constant for all vertices or fragments in a draw call: MVP matrices, light positions, material properties, elapsed time. Early OpenGL passed these one at a time via glUniform. Modern OpenGL and Vulkan use Uniform Buffer Objects (UBOs) for one bind instead of dozens of API calls.
A UBO is a GPU memory block bound to a shader binding point. The shader declares a uniform block and reads fields by name.
UBOs follow std140 packing rules for predictable alignment:
cLoading…
For example, a vec3 followed by a float in the same struct may waste padding because vec3 already occupies 16 bytes in std140. Misaligned CPU structs cause shaders to read garbage silently. Engines like Unreal auto-generate reflection metadata to avoid this.
glUniform callsYou will define a UBO struct in C with correct std140 padding and print each field's byte offset. This task asks you to compute alignment for matrices, vec3/float pairs, and arrays. Getting struct layout wrong is a classic bug where the GPU reads garbage because CPU-side packing does not match the shader's expected layout.
Write a C program that defines and analyzes a Uniform Buffer Object layout.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github