Difference between revisions of "Primitive Assembly"

From OpenGL Wiki
Jump to navigation Jump to search
(→‎Rasterizer discard: No clearing with rasterizer discard.)
(→‎Early primitive assembly: Location of primitive assembly corrected.)
 
(10 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
== Early primitive assembly ==
 
== Early primitive assembly ==
  
The purpose of the primitive assembly step is to convert a primitive stream into a sequence of base primitives. For example, a primitive composed of [[Line Primitive|line list of 12 vertices]] needs to generate 11 line primitives.
+
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 Primitive|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.
+
The full primitive assembly step (including the processing below) will happen during [[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.
 
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 Primitive]]s are always sequences of patches.
 
Such early processing must happen if a [[Geometry Shader]] or [[Tessellation]] is active. The early assembly step for Tessellation is simplified, since [[Patch Primitive]]s 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 [[Vertex Rendering]] command are ordered before any primitives from later such commands.
 +
** If the drawing command is a [[Multidraw Rendering|multi-draw command]], then all primitives for one sub-draw are ordered before primitives from subsequent sub-draws.
 +
** Within a draw or a multidraw's sub-draw, if the drawing command is an [[Instanced Rendering]] command, then all primitives in one instance are ordered before the primitives with larger {{code|gl_InstanceID}} values.
 +
** Within a particular draw/sub-draw/instance, the primitives are ordered based on the [[Vertex Specification|vertex stream]] and the rendering parameters for that draw, as interpreted by the [[Primitive]] type provided by the rendering command.
 +
* If a [[Tessellation Evaluation Shader]] is active, all primitives generated by tessellating a single patch are ordered before any primitives generated by patches with larger {{code|gl_PrimitiveID}} values.
 +
** The order of any given primitive generated by tessellation a given patch is undefined relative to other primitives generated from that patch.
 +
* If a [[Geometry Shader]] is active, primitives generated from a particular input primitive are ordered before primitives generated by a later input primitive, per the above ordering rules.
 +
** For a particular input primitive, if the GS uses [[Geometry Shader Instancing]], then all primitives generated by an instance are ordered before primitives generated by instances with larger {{code|gl_InvocationID​}} values.
 +
** Within a GS invocation, primitives generated by a GS are ordered as the GS invocation produces them.
  
 
== Rasterizer discard ==
 
== Rasterizer discard ==
Line 20: Line 34:
 
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.
 
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 fail if rasterizer discard is enabled.}}
+
{{warning|[[Framebuffer Clearing]] functions will do nothing if rasterizer discard is enabled.}}
  
 
== Face culling ==
 
== Face culling ==

Latest revision as of 04:38, 11 February 2021

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 happen during 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 Vertex Rendering command are ordered before any primitives from later such commands.
    • If the drawing command is a multi-draw command, then all primitives for one sub-draw are ordered before primitives from subsequent sub-draws.
    • Within a draw or a multidraw's sub-draw, if the drawing command is an Instanced Rendering command, then all primitives in one instance are ordered before the primitives with larger gl_InstanceID values.
    • Within a particular draw/sub-draw/instance, the primitives are ordered based on the vertex stream and the rendering parameters for that draw, as interpreted by the Primitive type provided by the rendering command.
  • If a Tessellation Evaluation Shader is active, all primitives generated by tessellating a single patch are ordered before any primitives generated by patches with larger gl_PrimitiveID values.
    • The order of any given primitive generated by tessellation a given patch is undefined relative to other primitives generated from that patch.
  • If a Geometry Shader is active, primitives generated from a particular input primitive are ordered before primitives generated by a later input primitive, per the above ordering rules.
    • For a particular input primitive, if the GS uses Geometry Shader Instancing, then all primitives generated by an instance are ordered before primitives generated by instances with larger gl_InvocationID​ values.
    • Within a GS invocation, primitives generated by a GS are ordered as the GS invocation produces 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.