27

I was confused about the VBO,

glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);

Besides GL_ARRAY_BUFFER, there are other target types: GL_ATOMIC_COUNTER_BUFFER, GL_COPY_READ_BUFFER...

However, the Opengl manual doesn't mention what these targets mean. I checked the glew.h:

#define GL_ARRAY_BUFFER 0x8892

Does this mean the targets (like GL_ARRAY_BUFFER) are addresses?

What does the target--GL_ARRAY_BUFFER mean in glBindBuffer?

1

3 Answers 3

58

In General

Most OpenGL objects must be bound to locations in the OpenGL context called "targets" for them to be used. A target is nothing more than a place in the context where objects are bound.

Different object types (buffers, textures, etc) have different sets of targets. Generally speaking, each target has a specific meaning: to bind one object to one target means that you want to use that object in whatever manner that target uses objects bound to it.

Binding an object to one target does not affect whether the object is bound to another target (unless it's a texture object; they treat targets differently).

There are functions that modify objects or query data from bound objects. They take a target to which the object they are modifying/querying has been bound.

GL_ARRAY_BUFFER

The GL_ARRAY_BUFFER target for buffer objects represents the intent to use that buffer object for vertex attribute data. However, binding to this target alone doesn't do anything; it's only the call to glVertexAttribPointer (or equivalent functions) that uses whatever buffer was bound to that target for the attribute data for that attribute.

Sign up to request clarification or add additional context in comments.

2 Comments

but if I want to use MULTIPLE buffers (vbo's) one for vertex coord and other say for texture coord should I bind both of them to GL_ARRAY_BUFFER??
One bound object per target at a given time. If you want to operate on a second one, the first one is replaced when you bind the second - think of the targets as addresses that store a value.
4

However, the Opengl manual doesn't mention what these targets mean.

OpenGL 2.1 spec, page 38, section 2.9.1: "Vertex Arrays In Buffer Objects"

Does this mean the targets (like GL_ARRAY_BUFFER) are addresses?

Nope, they're just unsigned ints used like enums.

1 Comment

You can absolutely think of these as addresses; the GL specification itself encourages this metaphor explicitly.
1

I will try my best to explain in short.

In OpenGL the target is a specific interface, which can deal with one object of its type at the time. Each target has a set of parameters affecting all its objects, which are stored internally, revealing only their ids. The API never allows the user to directly access those objects, because the wrong pointer can lead to much more damage than the wrong id.

Targets are not connected, so you can use the objects of different types simultaneously. The object id allows you to switch between the objects of the same type while using the same interface. You have to bind the object id to the specific target prior to deal with it, and then unbind it to free its interface, or directly bind another object id to the same target, which automatically unbinds previous object. Note that after binding an id to a target for the first time, the object becomes active, and can no longer be bound to another target. This is the basic concept of the API.

The first line in your code gets the buffer id. The second line binds the id to GL_ARRAY_BUFFER target, which may by described as setting up internally the Vertex attributes buffer object, or VBO. Now using this id you can refer to a particular internally stored VBO.

Hope that helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.