What does the GL_ARRAY_BUFFER target mean in glBindBuffer?
Asked Answered
M

3

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?

Moorer answered 10/2, 2013 at 21:36 Comment(1)
The OpenGL Wiki page on buffer objects covers this.Laomedon
L
57

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.

Laomedon answered 10/2, 2013 at 22:39 Comment(2)
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??Commiserate
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.Exergue
I
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.

Inapproachable answered 10/2, 2013 at 22:8 Comment(1)
You can absolutely think of these as addresses; the GL specification itself encourages this metaphor explicitly.Exergue
E
0

I will try my best to explain in short. In OpenGL the target (also called context) 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 its specific target prior to deal with it, and then unbind it in order to deal with the other objects, or directly bind another object id to the same target, which automatically unbinds previous object. 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 internally setting up the Vertex attributes buffer object, or VBO. Now using this id you can refer to an internally stored VBO.

Hope that helps!

Eisenach answered 9/4, 2023 at 22:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.