PDA

View Full Version : Attribute buffer



Itun.itu
10-11-2010, 10:12 AM
Can Somebody explain me how to create an attribute buffer in OpenGL?
If Somebody doesn`t understand what I mean:
|1 Face|2 Face|3 Face|... - GL_ELEMENT_ARRAY_BUFFER
|1 Attr|3 Attr|1 Attr|...

Everyone Attrs contain textures and materials.

BionicBytes
10-12-2010, 01:27 AM
You create attribute buffers to hold data per vertex.
For a model you'll typically create a vertex, texture coordinate, normal and some other per-vertex buffers.
In modern OpenGL, you create these buffers on the memory of the graphics card and these are called vertex buffer objetcs (VBO).
There is also a set of state (pointers) used to setup these vertex buffers, and this state can be saved too (Vertex Array Object) or VAO.

Here's the basics of creating a buffer Object, and there are several ways to do this. It's quite a large topic, so I suggest you read up on it.

glGenBuffers (1, @VertexVBO); //create a VBO buffer
glBindBuffer (GL_ARRAY_BUFFER, VertexVBO); //specify this VBIO is to hold per-vertex attributes
glBindBufferData (GL_ARRAY_BUFFER, sizeinBytes, @src_data_pointer, GL_STATIC_DRAW); //upload data to VBO. Hint for GL: draw/read but not modify
glBindBuffer(GL_ARRAY_BUFFER, 0); //finished with this VBO


Render loop:

glBindBuffer (GL_ARRAY_BUFFER, VertexVBO); //specify this VBIO is to hold per-vertex attributes
glEnableVertexAttribArray (0); //0= Vertex data (special meaning to GL. Vertex data is always index 0)
glVertexAttribPointer (0,3,GL_FLOAT,GL_FALSE,0, pointer(0) ); //data in VBO is 3 component float, no interleaving and no offset.

glDrawArrays.....

glBindBuffer(GL_ARRAY_BUFFER, 0); //finished with this VBO



As i said, much more to this....You can have many (16) vertex attributes on the go at any one time.
The state can be encapsulated in a VAO - required for Core GL 3+ profiles.