Explanation of what the VAO does in this code

I’ve followed a few tutorials for opengl, and once it gets to the shaders, we always create a VAO, bind it, create a VBO to hold the vertex data, and bind that, and everything flows and it mostly makes sense.

Well, I’m following this one that puts the vertex data directly in the shader, like this:


#version 420 core

void main(void)										
{				
	const vec4 vertices[3] = vec4[3]
	(
		vec4(0.25, -0.25, 0.5, 1.0),
		vec4(-0.25, -0.25, 0.5, 1.0),
		vec4(0.25, 0.25, 0.5, 1.0)
	);
	
	gl_Position = vertices[gl_VertexID];
}

And in the setup, we create the VAO:


vertexArrayObject = glGenVertexArrays();
glBindVertexArray(vertexArrayObject);

But, then that’s it. The VAO is not referenced again until we destroy it when the program shuts down. The only thing that happens in the rendering function is:


glClearBufferfv(GL11.GL_COLOR, 0, redColor);
		
glUseProgram(program);
	
glDrawArrays(GL11.GL_TRIANGLES, 0, 3);

So what exactly is the VAO’s role here? Why does it need to exist if everything is happening in the shader? I tried commenting the VAO lines out and the triangle didn’t show, so it definitely does something.

Thanks in advance for any help.

The compatibility profile has a default VAO which is used if no other VAO is bound. The core profile doesn’t, a VAO must be bound explicitly.