• No results found

Primitives and Vertices

In document glspec31.20090324.pdf (Page 32-36)

Error Description Offending com-

mand ignored?

INVALID ENUM enumargument out of range Yes

INVALID VALUE Numeric argument out of range Yes

INVALID OPERATION Operation illegal in current state Yes

INVALID FRAMEBUFFER OPERATION Framebuffer object is not com- plete

Yes

OUT OF MEMORY Not enough memory left to exe-

cute command

Unknown

Table 2.3: Summary of GL errors

• If memory is exhausted as a side effect of the execution of a command, the errorOUT OF MEMORYmay be generated.

Otherwise, errors are generated only for conditions that are explicitly described in this specification.

2.6

Primitives and Vertices

In the GL, most geometric objects are drawn by specifying a series of generic attribute sets usingDrawArraysor one of the other drawing commands defined in section2.8.2. There are seven geometric objects that are drawn this way: points, line segment strips, line segment loops, separated line segments, triangle strips, triangle fans, and separated triangles,

Each vertex is specified with one or more generic vertex attributes. Each at- tribute is specified with one, two, three, or four scalar values. Generic vertex attributes can be accessed from within vertex shaders (section 2.11) and used to compute values for consumption by later processing stages.

The methods by which generic attributes are sent to the GL, as well as how attributes are used by vertex shaders to generate vertices mapped to the two- dimensional screen, are discussed later.

Before vertex shader execution, the state required by a vertex is its generic vertex attributes. Vertex shader execution processes vertices producing a homo- geneous vertex position and any varying outputs explicitly written by the vertex shader.

Figure2.2shows the sequence of operations that builds aprimitive(point, line segment, or polygon) from a sequence of vertices. After a primitive is formed, it

2.6. PRIMITIVES AND VERTICES 20 Point, Line Segment, or Triangle (Primitive) Assembly Point culling, Line Segment or Triangle clipping Rasterization Shaded Vertices Coordinates Varying Outputs Primitive type (from DrawArrays or DrawElements mode) Vertex Shader Execution Generic Vertex Attributes

2.6. PRIMITIVES AND VERTICES 21

is clipped to a viewing volume. This may alter the primitive by altering vertex coordinates and varying vertex shader outputs. In the case of line and polygon primitives, clipping may insert new vertices into the primitive. The vertices defin- ing a primitive to be rasterized have varying outputs associated with them.

2.6.1 Primitive Types

A sequence of vertices is passed to the GL usingDrawArraysor one of the other drawing commands defined in section2.8.2. There is no limit to the number of vertices that may be specified, other than the size of the vertex arrays. Themode

parameter of these commands determines the type of primitives to be drawn using the vertices. The types, and the correspondingmodeparameters, are:

Points. A series of individual points may be specified with mode POINTS. Each vertex defines a separate point.

Line Strips.A series of one or more connected line segments may be specified withmode LINE STRIP. In this case, the first vertex specifies the first segment’s start point while the second vertex specifies the first segment’s endpoint and the second segment’s start point. In general, theith vertex (fori > 1) specifies the beginning of theith segment and the end of thei−1st. The last vertex specifies the end of the last segment. If only one vertex is specified, then no primitive is generated.

The required state consists of the processed vertex produced from the last ver- tex that was sent (so that a line segment can be generated from it to the current vertex), and a boolean flag indicating if the current vertex is the first vertex.

Line Loops. Line loops may be specified with modeLINE LOOP. Loops are the same as line strips except that a final segment is added from the final specified vertex to the first vertex. The required state consists of the processed first vertex, in addition to the state required for line strips.

Separate Lines. Individual line segments, each specified by a pair of vertices, may be specified withmodeLINES. The first two vertices passed define the first segment, with subsequent pairs of vertices each defining one more segment. If the number of specified vertices is odd, then the last one is ignored. The state required is the same as for line strips but it is used differently: a processed vertex holding the first vertex of the current segment, and a boolean flag indicating whether the current vertex is odd or even (a segment start or end).

Triangle strips.A triangle strip is a series of triangles connected along shared edges, and may be specified withmode TRIANGLE STRIP. In this case, the first three vertices define the first triangle (and their order is significant). Each subse- quent vertex defines a new triangle using that point along with two vertices from the previous triangle. If fewer than three vertices are specified, no primitive is

2.6. PRIMITIVES AND VERTICES 22 (a) (b) (c) 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 6

Figure 2.3. (a) A triangle strip. (b) A triangle fan. (c) Independent triangles. The numbers give the sequencing of the vertices in order within the vertex arrays. Note that in (a) and (b) triangle edge ordering is determined by the first triangle, while in (c) the order of each triangle’s edges is independent of the other triangles.

produced. See figure2.3.

The required state consists of a flag indicating if the first triangle has been completed, two stored processed vertices, (called vertex A and vertex B), and a one bit pointer indicating which stored vertex will be replaced with the next vertex. The pointer is initialized to point to vertex A. Each successive vertex toggles the pointer. Therefore, the first vertex is stored as vertex A, the second stored as vertex B, the third stored as vertex A, and so on. Any vertex after the second one sent forms a triangle from vertex A, vertex B, and the current vertex (in that order).

Triangle fans.A triangle fan is the same as a triangle strip with one exception: each vertex after the first always replaces vertex B of the two stored vertices. A triangle fan may be specified withmodeTRIANGLE FAN.

Separate Triangles. Separate triangles are specified with modeTRIANGLES. In this case, The3i+ 1st,3i+ 2nd, and3i+ 3rd vertices (in that order) determine a triangle for eachi= 0,1, . . . , n−1, where there are3n+kvertices drawn. kis either 0, 1, or 2; ifkis not zero, the finalkvertices are ignored. For each triangle, vertex A is vertex3iand vertex B is vertex3i+ 1. Otherwise, separate triangles are the same as a triangle strip.

Depending on the current state of the GL, apolygon primitivegenerated from a drawing command withmode TRIANGLE FAN,TRIANGLE STRIP, orTRIANGLES

may be rendered in one of several ways, such as outlining its border or filling its interior. The order of vertices in such a primitive is significant in polygon

In document glspec31.20090324.pdf (Page 32-36)