Primitive rasterization functions.
More...
|
| struct | SRPLine |
| |
| struct | SRPPoint |
| |
| struct | SRPTriangle |
| |
| typedef struct SRPLine | SRPLine |
| |
| typedef struct SRPPoint | SRPPoint |
| |
| typedef struct SRPTriangle | SRPTriangle |
| |
| void | emitFragment (const SRPFramebuffer *fb, const SRPShaderProgram *sp, int x, int y, SRPFragmentShaderIn *fsIn) |
| |
| static void | lineInterpolateData (SRPLine *line, float t, const SRPShaderProgram *restrict sp, SRPInterpolated *pInterpolatedBuffer, float *depth, float *recIntInvW) |
| |
| void | rasterizeLine (SRPLine *line, const SRPFramebuffer *fb, const SRPShaderProgram *restrict sp, void *interpolatedBuffer) |
| |
| void | setupLine (SRPLine *line, const SRPFramebuffer *fb) |
| |
| static bool | computeMathAndRasterBoundaries (vec3 ss, float pointSize, const SRPFramebuffer *fb, vec2 *outMinBP, vec2 *outMaxBP, int *outMinX, int *outMaxX, int *outMinY, int *outMaxY) |
| |
| void | rasterizePoint (SRPPoint *point, const SRPFramebuffer *fb, const SRPShaderProgram *restrict sp) |
| |
| void | setupPoint (SRPPoint *p) |
| |
| static float | signedAreaParallelogram (const vec3 *restrict a, const vec3 *restrict b) |
| |
| static bool | shouldCullTriangle (const SRPTriangle *tri, bool *isCCW, bool *isFrontFacing) |
| |
| static void | triangleChangeWinding (SRPTriangle *tri) |
| |
| static void | calculateBarycentrics (SRPTriangle *tri, float areaX2, vec2 point) |
| |
| static bool | isEdgeFlatTopOrLeft (const vec3 *restrict edge) |
| |
| static void | triangleInterpolateData (SRPTriangle *tri, const SRPShaderProgram *restrict sp, SRPInterpolated *pInterpolatedBuffer, float *depth, float *recIntInvW) |
| |
| void | rasterizeTriangle (SRPTriangle *tri, const SRPFramebuffer *fb, const SRPShaderProgram *restrict sp, void *interpolatedBuffer) |
| |
| bool | setupTriangle (SRPTriangle *tri, const SRPFramebuffer *fb) |
| |
Primitive rasterization functions.
◆ SRPLine
Line primitive. Stores data needed for its rasterization
◆ SRPPoint
Point primitive. Stores data needed for its rasterization
◆ SRPTriangle
Triangle primitive. Stores data needed for its rasterization
◆ calculateBarycentrics()
| static void calculateBarycentrics |
( |
SRPTriangle * |
tri, |
|
|
float |
areaX2, |
|
|
vec2 |
point |
|
) |
| |
|
static |
Calculate barycentric coordinates for a point and barycentric coordinates' delta values.
- Parameters
-
| [in] | tri | Triangle to calculate barycentric coordinates for. Must have its ss and edge fields initialized. |
| [in] | areaX2 | The triangle's area multiplied by 2 (to avoid division) |
| [in] | point | Point to calculate barycentric coordinates for (screen-space) |
◆ computeMathAndRasterBoundaries()
| static bool computeMathAndRasterBoundaries |
( |
vec3 |
ss, |
|
|
float |
pointSize, |
|
|
const SRPFramebuffer * |
fb, |
|
|
vec2 * |
outMinBP, |
|
|
vec2 * |
outMaxBP, |
|
|
int * |
outMinX, |
|
|
int * |
outMaxX, |
|
|
int * |
outMinY, |
|
|
int * |
outMaxY |
|
) |
| |
|
static |
Given screen-space point position, compute its math and raster boundaries.
- Parameters
-
| [in] | ss | Screen-space point position |
| [in] | pointSize | Point size, in pixels |
| [in] | fb | Pointer to the framebuffer, used to clip partially-OOB points |
| [out] | outMinBP,outMaxBP | Bounding points representing mathematical boundaries |
| [out] | outMinX,outMaxX,outMinY,outMaxY | Raster boundaries |
- Returns
true if point is fully OOB, false otherwise
◆ emitFragment()
Perform (early) depth check, run fragment shader, and draw a pixel
- Parameters
-
| [in] | fb | The framebuffer to use |
| [in] | sp | The shader program to use |
| [in] | x,y | Coordinates of the pixel |
| [in] | fsIn | Fragment shader input |
◆ isEdgeFlatTopOrLeft()
| static bool isEdgeFlatTopOrLeft |
( |
const vec3 *restrict |
edge | ) |
|
|
static |
Check if a triangle's edge is flat top or left. Assumes counter-clockwise vertex order!
- Parameters
-
| [in] | edge | A pointer to an edge vector (pointing from one vertex to the other) |
- Returns
- Whether or not this edge is flat top or left
◆ lineInterpolateData()
Interpolate the fragment position and vertex variables inside the line.
- Parameters
-
| [in] | line | Line to interpolate data for |
| [in] | t | Interpolation parameter (0 -> 0th vertex; 1 -> 1st vertex) |
| [in] | sp | A pointer to shader program to use |
| [out] | pInterpolatedBuffer | A pointer to the buffer where interpolated variables will appear. Must be big enough to hold all of them |
| [out] | depth | Fragment depth |
| [out] | recIntInvW | Reciprocal of interpolated inverse Wclip |
◆ rasterizeLine()
Rasterize a point
- Parameters
-
| [in] | line | Pointer to the line to draw |
| [in] | fb | The framebuffer to draw to |
| [in] | sp | The shader program to use |
| [in] | interpolatedBuffer | Pointer to a temporary buffer where varyings for each fragment will be stored. Must be big enough to hold all interpolated attributes for ONE vertex. |
◆ rasterizePoint()
Rasterize a point
- Parameters
-
| [in] | point | Pointer to the point to draw |
| [in] | fb | The framebuffer to draw to |
| [in] | sp | The shader program to use |
◆ rasterizeTriangle()
Rasterize a triangle
- Parameters
-
| [in] | triangle | Pointer to the triangle to draw |
| [in] | fb | The framebuffer to draw to |
| [in] | sp | The shader program to use |
| [in] | interpolatedBuffer | Pointer to a temporary buffer where varyings for each fragment will be stored. Must be big enough to hold all interpolated attributes for ONE vertex. |
◆ setupLine()
Setup line for rasterization, performing perspective divide and calculating internal variables
- Parameters
-
| [in] | line | The line to set up. Its v field is required to be filled |
| [in] | fb | The framebuffer to use for NDC to screen-space conversion |
◆ setupPoint()
◆ setupTriangle()
Setup triangle for rasterization, performing perspective divide and calculating internal variables
- Parameters
-
| [in] | tri | The triangle to set up. Its v field is required to be filled |
| [in] | fb | The framebuffer to use for NDC to screen-space conversion |
- Returns
false if it is culled and should not be rasterized, true otherwise
◆ shouldCullTriangle()
| static bool shouldCullTriangle |
( |
const SRPTriangle * |
tri, |
|
|
bool * |
isCCW, |
|
|
bool * |
isFrontFacing |
|
) |
| |
|
static |
Determine if a triangle should be culled (back-face culling)
- Parameters
-
| [in] | tri | Triangle to check. Must have its p_ndc field initialized. |
| [out] | isCCW | Whether or not the triangle's vertices are in counter-clockwise order |
| [out] | isFrontFacing | Whether or not the triangle is front facing |
- Returns
- Whether or not the triangle should be culled
◆ signedAreaParallelogram()
| static float signedAreaParallelogram |
( |
const vec3 *restrict |
a, |
|
|
const vec3 *restrict |
b |
|
) |
| |
|
static |
Get a parallelogram's signed area. The two vectors define a parallelogram. Used for barycentric coordinates' initialization in calculateBarycentrics()
◆ triangleChangeWinding()
Change the winding order of a triangle.
- Parameters
-
| [in] | tri | Triangle to change the winding order of. Must have its v, p_ndc and invW fields initialized. |
◆ triangleInterpolateData()
Interpolate the fragment position and vertex variables inside the triangle.
- Parameters
-
| [in] | tri | Triangle to interpolate data for |
| [in] | sp | A pointer to shader program to use |
| [out] | pInterpolatedBuffer | A pointer to the buffer where interpolated variables will appear. Must be big enough to hold all of them |
| [out] | depth | Fragment depth |
| [out] | recIntInvW | Reciprocal of interpolated inverse Wclip |