What is the purpose of a Vertex Attribute in OpenGL?

A GPU consists of four shaders:

  • Vertex Shader
  • Fragment Shader
  • Tessellation Shader
  • Geometry Shader

Out of these four, the vertex shader is the only one required in OpenGL. But it will not do you any good until you use the Fragment Shader. In case you forgot, a vertex shader sets the correct coordinate space of your character on the screen. Whereas, the fragment shader adds color to your character.

Character data is sent to the GPU through OpenGL buffers. You load these buffers with data representing the attributes of your character. These attributes can be vertices position, normals or UV coordinates.

A shader receives this information from the buffers through variables known as Vertex Attributes. But here is the interesting part, only the Vertex Shader can receive this information. The tessellation, geometry and fragment shader can't. If these shaders need this data, you must pass it down from the vertex shader.

Believe it or not, the Vertex Attribute is the main contact between the CPU and GPU. It is the variable that connects both worlds. Without them, no characters can appear on the screen. Without them, the vertex shader can't receive data. Which infers that none of the other shaders will receive any data.

This is the purpose of the Vertex Attribute. It receives data from the CPU and provides it to the Vertex Shader which can then share it with the other shaders.

Learn how to use Vertex Attributes in your shaders here,

Hope this helps.

PS. Sign up to my newsletter and get OpenGL development tips.

Harold Serrano

Computer Graphics Enthusiast. Currently developing a 3D Game Engine.