Official
Name
glDrawArraysrender primitives from array data.
C Specification
voidglDrawArrays(
GLenum mode
, GLint first
, GLsizei count
);
mode \specifies what kind of primitives to render
first \specifies the starting index in the enabled arrays.
count \specifies the number of indices to be rendered.
Description
glDrawArrays
specifies multiple geometric primitives with very few subroutine calls. Instead of calling a GL procedure to pass each individual vertex, normal, texture coordinate, edge flag, or color, you can prespecify separate arrays of vertices, normals, and colors and use them to construct a sequence of primitives with a single call to glDrawArrays
.
When
glDrawArrays
is called, it uses count
sequential elements from each enabled array to construct a sequence of geometric primitives, beginning with element first
. mode
specifies what kind of primitives are constructed and how the array elements construct those primitives.
Vertex attributes that are modified by
glDrawArrays
have an unspecified value after glDrawArrays
returns. Attributes that aren't modified remain well defined.How :-)
The call to
glBindBuffer
tells OpenGL to use vertexBufferObject
whenever it needs the GL_ARRAY_BUFFER
.glEnableVertexAttribArray
means that you want OpenGL to use vertex attribute arrays; without this call the data you supplied will be ignored.glVertexAttribPointer
, as you said, tells OpenGL what to do with the supplied array data, since OpenGL doesn't inherently know what format that data will be in.glDrawArrays
uses all of the above data to draw points.
Remember that OpenGL is a big state machine. Most calls to OpenGL functions modify a global state that you can't directly access. That's why the code ends with
glDisableVertexAttribArray
and glBindBuffer(..., 0)
: you have to put that global state back when you're done using it.
@handuel: It uses all enabled vertex attributes. What each attribute means exactly defined through the programming of the vertex shader.
@handuel: Actually the vertex shader gets into action after glDrawArrays gets called. glDrawArrays simply passes the data for each active vertex attribute enabled using
glEnableVertexAttribArray
into the drawing queue. In the vertex shader there's a binding for each vertex attribute array, and the shader determines what becomes screen position, what color and so on.
@handuel: When
glVertexAttribPointer(attrib_index, …)
is called the buffer bound byglBindBuffer(GL_ARRAY_BUFFER, …)
gets bound to the vertex attribute specified by the first parameter of glVertexAttribPointer
. To bind another buffer to another attribute you do anotherglBindBuffer(GL_ARRAY_BUFFER, …); glVertexAttribPointer(…);
. –– The call ofglEnableVertexAttribArray
is not required to make the binding between buffer and attribute. But enabling a vertex attribute array makes the glDraw…
calls use the enabled attributes.
DrawArrays takes data from
ARRAY_BUFFER
.
Data are 'mapped' according to your setup in
glVertexAttribPointer
which tells what is the definition of your vertex.
In your example you have one vertex attrib (glEnableVertexAttribArray) at position
0
(you can normally have 16 vertex attribs, each 4 floats). Then you tell that each attrib will be obtained by reading 3 GL_FLOATS from the buffer starting from position 0.
No comments:
Post a Comment