How to send basic data to GPU in OpenGL?

For those who came from the fixed functionality pipeline background, and started learning OpenGL 2.0+ (aka GLSL), first few days must have been very confusing. Especially with all the VAO and VBO, etc.
Well, I learned it all by doing mistakes, and rising from them, but let’s make things simpler for those who are new to this glsl world.

First things first, whatever you render onto the screen is with the help of your GPU, (aka OpenGL server), be it the desktop GUI environment you see, or any fancy game you’re playing.

So, how exactly data is passed to the GPU, and how exactly is it stored in the GPU itself? Every GPU these days has a specific amount of buffers. These buffers are nothing but chunks of memory in the GPU which is used to store all the data passed to GPU via OpenGL.

Now given that you can store data in GPU using buffers, you cannot simply use them as pointers, but you will have to use Buffer Objects for that. Here is the official definition of buffer objects according to OpenGL wiki [Buffer Objects are OpenGL Objects that store an array of unformatted memory allocated by the OpenGL context (aka: the GPU). These can be used to store vertex datapixel data retrieved from images or the framebuffer, and a variety of other things.]

Ok, so thats about buffer objects, but there is one more term.. called Vertex Buffer Objects.. The buffer objects that deal with Vertex in shaders are called Vertex Buffer Objects.  OpenGL provides very simple (simple? not really, you might need to read their specifications again and again) functions to create and manipulate GLSL buffers. But for now let us understand the theory behind it.

Whenever you use any buffer object you will have to bind it, so OpenGL will know on what buffer it has to work on for the next few statements. The currently bounded buffer will be bound unless you bind another buffer or pass 0 parameter to glBindBuffer() method. We’ll talk more about binding of a buffer and target specified by buffer later on.

Some buffers, specifically if they’re Vertex Buffers they will need Vertex Array Objects to for the vertex specification. Its nothing but specifying how the data in the buffer is mapped out. According to OpenGL wiki,

[A Vertex Array Object (VAO) is an OpenGL Object that encapsulates all of the state needed to specify vertex data (with one minor exception noted below). They define the format of the vertex data as well as the sources for the vertex arrays. Note that VAOs do not contain the arrays themselves; the arrays are stored in Buffer Objects. The VAOs simply reference already existing buffer objects.]

Think of VAO as an authority which governs the VBO. (VBOs are just slaves) VAOs help specify where in the vertex shader the data for buffers is specified. VAOs can later be used for trasnform feedback and asyn pixel transfers. Some concepts that I still have to assimilate. But anyhow, thats all about the VBO and VAO, next up I will write about how to use them in your programs. and a sample code.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s