|
srp
software rendering pipeline
|
Primitive rasterization functions. More...

Files | |
| file | fragment.c |
| file | fragment.h |
| file | line.c |
| file | line.h |
| file | point.c |
| file | point.h |
| file | triangle.c |
| file | triangle.h |
Classes | |
| struct | SRPLine |
| struct | SRPPoint |
| struct | SRPTriangle |
| typedef struct SRPLine | SRPLine |
| typedef struct SRPPoint | SRPPoint |
| typedef struct SRPTriangle | SRPTriangle |
| static bool | scissorTest (size_t x, size_t y) |
| static bool | stencilTest (uint8_t *stencil, const SRPStencilFaceState *s) |
| static bool | stencilCompare (uint8_t ref, uint8_t stored, uint8_t mask, SRPCompareOp op) |
| static void | stencilFailOp (uint8_t *stencil, const SRPStencilFaceState *s) |
| static void | stencilDepthFailOp (uint8_t *stencil, const SRPStencilFaceState *s) |
| static void | stencilPassOp (uint8_t *stencil, const SRPStencilFaceState *s) |
| static uint8_t | applyStencilOp (SRPStencilOp op, uint8_t stored, uint8_t ref) |
| static bool | depthTest (float incoming, float stored) |
| 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.
| typedef struct SRPTriangle SRPTriangle |
Triangle primitive. Stores data needed for its rasterization
|
inlinestatic |
Apply an operation to a stencil value
|
static |
Calculate barycentric coordinates for a point and barycentric coordinates' delta values.
| [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) |
|
static |
Given screen-space point position, compute its math and raster boundaries.
| [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 |
true if point is fully OOB, false otherwise
|
inlinestatic |
Perform a depth test, respecting the user-set compare operation and whether or not the test is enabled
| [in] | incoming | The depth value of the currently processed fragment |
| [in] | stored | The depth value stored in the depth buffer |
true if depth test passes, false otherwise | void emitFragment | ( | const SRPFramebuffer * | fb, |
| const SRPShaderProgram * | sp, | ||
| int | x, | ||
| int | y, | ||
| SRPFragmentShaderIn * | fsIn | ||
| ) |
Perform (early) depth check, run fragment shader, and draw a pixel
| [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 |
|
static |
Check if a triangle's edge is flat top or left. Assumes counter-clockwise vertex order!
| [in] | edge | A pointer to an edge vector (pointing from one vertex to the other) |
|
static |
Interpolate the fragment position and vertex variables inside the line.
| [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 |
| void rasterizeLine | ( | SRPLine * | line, |
| const SRPFramebuffer * | fb, | ||
| const SRPShaderProgram *restrict | sp, | ||
| void * | interpolatedBuffer | ||
| ) |
Rasterize a point
| [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. |
| void rasterizePoint | ( | SRPPoint * | point, |
| const SRPFramebuffer * | fb, | ||
| const SRPShaderProgram *restrict | sp | ||
| ) |
Rasterize a point
| [in] | point | Pointer to the point to draw |
| [in] | fb | The framebuffer to draw to |
| [in] | sp | The shader program to use |
| void rasterizeTriangle | ( | SRPTriangle * | triangle, |
| const SRPFramebuffer * | fb, | ||
| const SRPShaderProgram *restrict | sp, | ||
| void * | interpolatedBuffer | ||
| ) |
Rasterize a triangle
| [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. |
|
inlinestatic |
Perform a scissor test, respecting the user-set runtime options
| [in] | x,y | Window-space position of the currently processed fragment |
true if scissor test passes, false otherwise | void setupLine | ( | SRPLine * | line, |
| const SRPFramebuffer * | fb | ||
| ) |
Setup line for rasterization, performing perspective divide and calculating internal variables
| [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 |
| void setupPoint | ( | SRPPoint * | p | ) |
Perform perspective divide on a point. Created to be structurally similar to setupTriangle(), setupLine()
| [in] | p | Point to setup |
| bool setupTriangle | ( | SRPTriangle * | tri, |
| const SRPFramebuffer * | fb | ||
| ) |
Setup triangle for rasterization, performing perspective divide and calculating internal variables
| [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 |
false if it is culled and should not be rasterized, true otherwise
|
static |
Determine if a triangle should be culled (back-face culling)
| [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 |
Get a parallelogram's signed area. The two vectors define a parallelogram. Used for barycentric coordinates' initialization in calculateBarycentrics()
|
inlinestatic |
Compare two masked stencil values with a certain operation
| [in] | ref | The reference stencil value |
| [in] | stored | The stored stencil value |
| [in] | mask | The mask to use with both values |
| [in] | op | Operation to compare with |
|
inlinestatic |
Apply a "stencil test passed, depth test failed" operation to a stencil value
| [in] | stencil | Pointer to the current stencil value |
| [in] | s | Pointer to the stencil state to use |
|
inlinestatic |
Apply a "stencil test failed" operation to a stencil value
| [in] | stencil | Pointer to the current stencil value |
| [in] | s | Pointer to the stencil state to use |
|
inlinestatic |
Apply a "stencil and depth tests passed" operation to a stencil value
| [in] | stencil | Pointer to the current stencil value |
| [in] | s | Pointer to the stencil state to use |
|
inlinestatic |
Perform an initial stage of the stencil test and potentially apply fail operation to the stencil value. Checks if the stencil test is enabled.
| [in] | stencil | Pointer to the current stencil value |
| [in] | s | Pointer to the stencil state to use |
|
static |
Change the winding order of a triangle.
| [in] | tri | Triangle to change the winding order of. Must have its v, p_ndc and invW fields initialized. |
|
static |
Interpolate the fragment position and vertex variables inside the triangle.
| [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 |