next up previous contents index
Next: 2.9 Rectangles Up: 2 OpenGL Operation Previous: 2.7 Vertex Specification

2.8 Vertex Arrays

 

The vertex specification commands described in section 2.7 accept data in almost any format, but their use requires many command executions to specify even simple geometry. Vertex data may also be placed into arrays that are stored in the client's address space. Blocks of data in these arrays may then be used to specify multiple geometric primitives through the execution of a single GL command. The client may specify up to six arrays: one each to store edge flags, texture coordinates, colors, color indices, normals, and vertices. The commands

void EdgeFlagPointer ( sizei stride, void *pointer ) ;

void TexCoordPointer ( int size, enum type, sizei stride, void *pointer ) ;

void ColorPointer ( int size, enum type, sizei stride, void *pointer ) ;

void IndexPointer ( enum type, sizei stride, void *pointer ) ;

void NormalPointer ( enum type, sizei stride, void *pointer ) ;

void VertexPointer ( int size, enum type, sizei stride, void *pointer ) ;

describe the locations and organizations of these arrays. For each command, type specifies the data type of the values stored in the array. Because edge flags are always type boolean, EdgeFlagPointer  has no type argument. size, when present, indicates the number of values per vertex that are stored in the array. Because normals are always specified with three values, NormalPointer  has no size argument. Likewise, because color indices and edge flags are always specified with a single value, IndexPointer  and EdgeFlagPointer  also have no size argument. Table 2.4 indicates the allowable values for size and type (when present). For type the values BYTE, SHORT, INT, FLOAT, and DOUBLE indicate types byte, short, int, float, and double, respectively; and the values UNSIGNED_BYTE, UNSIGNED_SHORT, and UNSIGNED_INT indicate types ubyte, ushort, and uint, respectively. The error INVALID_VALUE is generated if size is specified with a value other than that indicated in the table.

  
Table 2.4: Vertex array sizes (values per vertex) and data types.

The one, two, three, or four values in an array that correspond to a single vertex comprise an array element. The values within each array element are stored sequentially in memory. If stride is specified as zero, then array elements are stored sequentially as well. Otherwise pointers to the ith and st elements of an array differ by stride basic machine units (typically unsigned bytes), the pointer to the st element being greater. For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.

An individual array is enabled or disabled by calling one of

void EnableClientState ( enum array ) ;
void DisableClientState ( enum array ) ;

with array set to EDGE_FLAG_ARRAY, TEXTURE_COORD_ARRAY, COLOR_ARRAY, INDEX_ARRAY, NORMAL_ARRAY, or VERTEX_ARRAY, for the edge flag, texture coordinate, color, color index, normal, or vertex array, respectively.

The ith element of every enabled array is transferred to the GL by calling

void ArrayElement ( int i ) ;

For each enabled array, it is as though the corresponding command from section 2.7 or section 2.6.2 were called with a pointer to element i. For the vertex array, the corresponding command is Vertex[ size][ type]v, where size is one of [2,3,4], and type is one of [s,i,f,d], corresponding to array types short, int, float, and double respectively. The corresponding commands for the edge flag, texture coordinate, color, color index, and normal arrays are EdgeFlagv, TexCoord[ size][ type]v, Color[ size][ type]v, Index[ type]v, and Normal[ type]v, respectively. If the vertex array is enabled, it is as though Vertex[ size][ type]v is executed last, after the executions of the other corresponding commands.

Changes made to array data between the execution of Begin  and the corresponding execution of End  may affect calls to ArrayElement  that are made within the same Begin / End  period in non-sequential ways. That is, a call to ArrayElement  that precedes a change to array data may access the changed data, and a call that follows a change to array data may access original data.

The command

void DrawArrays ( enum mode, int first, sizei count ) ;

constructs a sequence of geometric primitives using elements through of each enabled array. mode specifies what kind of primitives are constructed; it accepts the same token values as the mode parameter of the Begin  command. The effect of

is the same as the effect of the command sequence

with one exception: the current edge flag, texture coordinates, color, color index, and normal coordinates are each indeterminate after the execution of DrawArrays , if the corresponding array is enabled. Current values corresponding to disabled arrays are not modified by the execution of DrawArrays .

The command

void DrawElements ( enum mode, sizei count, enum type, void *indices ) ;

constructs a sequence of geometric primitives using the count elements whose indices are stored in *indices. type must be one of UNSIGNED_BYTE, UNSIGNED_SHORT, or UNSIGNED_INT, indicating that the values in *indices are indices of GL type ubyte, ushort, or uint respectively. mode specifies what kind of primitives are constructed; it accepts the same token values as the mode parameter of the Begin  command. The effect of

is the same as the effect of the command sequence

with one exception: the current edge flag, texture coordinates, color, color index, and normal coordinates are each indeterminate after the execution of DrawElements , if the corresponding array is enabled. Current values corresponding to disabled arrays are not modified by the execution of DrawElements .

The command

void InterleavedArrays ( enum format, sizei stride, void *pointer ) ;

efficiently initializes the six arrays and their enables to one of 14 configurations. format must be one of 14 symbolic constants: V2F, V3F, C4UB_V2F, C4UB_V3F, C3F_V3F, N3F_V3F, C4F_N3F_V3F, T2F_V3F, T4F_V4F, T2F_C4UB_V3F, T2F_C3F_V3F, T2F_N3F_V3F, T2F_C4F_N3F_V3F, or T4F_C4F_N3F_V4F.

  
Table 2.5: Variables that direct the execution of InterleavedArrays . f is sizeof(FLOAT). c is 4 times sizeof(UNSIGNED_BYTE), rounded up to the nearest multiple of f. All pointer arithmetic is performed in units of sizeof(UNSIGNED_BYTE).

The effect of

is the same as the effect of the command sequence

The client state required to implement vertex arrays consists of six boolean values, six memory pointers, six integer stride values, five symbolic constants representing array types, and three integers representing values per element. In the initial state the boolean values are each disabled, the memory pointers are each null, the strides are each zero, the array types are each FLOAT, and the integers representing values per element are each four.



next up previous contents index
Next: 2.9 Rectangles Up: 2 OpenGL Operation Previous: 2.7 Vertex Specification



David Blythe
Sat Mar 29 02:23:21 PST 1997