Primitive Assembly

From OpenGL Wiki
Revision as of 18:00, 25 February 2017 by Alfonse (talk | contribs) (Added a section on primitive ordering)
Jump to navigation Jump to search

Primitive Assembly is the stage in the OpenGL rendering pipeline where Primitives are divided into a sequence of individual base primitives. After some minor processing, as described below, they are passed along to the rasterizer to be rendered.

Early primitive assembly

The purpose of the primitive assembly step is to convert a vertex stream into a sequence of base primitives. For example, a primitive which is a line list of 12 vertices needs to generate 11 line base primitives.

The full primitive assembly step (including the processing below) will always happen after Vertex Post-Processing. However, some Vertex Processing steps require that a primitive be decomposed into a sequence of base primitives. For example, a Geometry Shader operates on each input base primitive in the primitive sequence. Therefore, a form of primitive assembly must happen before the GS can execute.

This early primitive assembly only performs the conversion to base primitives. It does not perform any of the below processing steps.

Such early processing must happen if a Geometry Shader or Tessellation is active. The early assembly step for Tessellation is simplified, since Patch Primitives are always sequences of patches.

Primitive order

The order in which primitives are processed is well-defined (in most cases). The order is defined as follows:

  • All primitives from a single primitive Drawing Command are ordered before primitives from later drawing commands.
    • If the drawing command is a Multidraw Rendering, then all primitives in one sub-draw are each individual sub-draw is handled in the order they are specified.
    • If the drawing command is an Instanced Rendering command, then all primitives in one instance are ordered before the primitives in later instances.
    • The primitives within a draw/instance are ordered based on the order of the vertices taken from the buffer, as processed based on the primitive type.
  • If a Tessellation Evaluation Shader is active, each primitive is tessellated in the above order. The order of primitives generated by tessellation is undefined. However, all primitives generated by tessellating a single patch are ordered before any primitives from later patches.
  • If a Geometry Shader is active, each primitive input to a GS is processed in the order they are received, per the above ordering rules.
    • If the GS uses Geometry Shader Instancing, then all primitives generated by an instance are ordered before primitives generated by instances with a larger `gl_InstanceID` value. All primitives generated by GS invocations that share the same input primitive are ordered before primitives generated by GS invocations from later input primitives.
    • Within a GS invocation, primitives generated by a GS are taken in the order that GS invocation gives them.

Rasterizer discard

All primitives can be discarded by enabling GL_RASTERIZER_DISCARD. This prevents any primitives from being rasterized.

This is useful for testing the performance of prior rendering stages, but it is also useful to prevent rendering of primitives generated during Transform Feedback operations.

Warning: Framebuffer Clearing functions will do nothing if rasterizer discard is enabled.

Face culling

The culling of triangle primitives happens during this point in the pipeline.